arch/mips/include/asm/syscall.h

Source file repositories/reference/linux-study-clean/arch/mips/include/asm/syscall.h

File Facts

System
Linux kernel
Corpus path
arch/mips/include/asm/syscall.h
Extension
.h
Size
4588 bytes
Lines
188
Domain
Architecture Layer
Bucket
arch/mips
Inferred role
Architecture Layer: syscall or user/kernel boundary
Status
core implementation candidate

Why This File Exists

CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.

Dependency Surface

Detected Declarations

Annotated Snippet

#ifndef __ASM_MIPS_SYSCALL_H
#define __ASM_MIPS_SYSCALL_H

#include <linux/compiler.h>
#include <uapi/linux/audit.h>
#include <linux/elf-em.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/uaccess.h>
#include <asm/ptrace.h>
#include <asm/unistd.h>

#ifndef __NR_syscall /* Only defined if _MIPS_SIM == _MIPS_SIM_ABI32 */
#define __NR_syscall 4000
#endif

static inline bool mips_syscall_is_indirect(struct task_struct *task,
					    struct pt_regs *regs)
{
	/* O32 ABI syscall() - Either 64-bit with O32 or 32-bit */
	return (IS_ENABLED(CONFIG_32BIT) ||
		test_tsk_thread_flag(task, TIF_32BIT_REGS)) &&
		(regs->regs[2] == __NR_syscall);
}

static inline long syscall_get_nr(struct task_struct *task,
				  struct pt_regs *regs)
{
	return task_thread_info(task)->syscall;
}

static inline void syscall_set_nr(struct task_struct *task,
				  struct pt_regs *regs,
				  int nr)
{
	/*
	 * New syscall number has to be assigned to regs[2] because
	 * it is loaded from there unconditionally after return from
	 * syscall_trace_enter() invocation.
	 *
	 * Consequently, if the syscall was indirect and nr != __NR_syscall,
	 * then after this assignment the syscall will cease to be indirect.
	 */
	task_thread_info(task)->syscall = regs->regs[2] = nr;
}

static inline void mips_syscall_update_nr(struct task_struct *task,
					  struct pt_regs *regs)
{
	/*
	 * v0 is the system call number, except for O32 ABI syscall(), where it
	 * ends up in a0.
	 */
	if (mips_syscall_is_indirect(task, regs))
		task_thread_info(task)->syscall = regs->regs[4];
	else
		task_thread_info(task)->syscall = regs->regs[2];
}

static inline void mips_get_syscall_arg(unsigned long *arg,
	struct task_struct *task, struct pt_regs *regs, unsigned int n)
{
#ifdef CONFIG_32BIT
	switch (n) {
	case 0: case 1: case 2: case 3:
		*arg = regs->regs[4 + n];
		return;
	case 4: case 5: case 6: case 7:
		*arg = regs->args[n];
		return;
	}
#else
	*arg = regs->regs[4 + n];
	if ((IS_ENABLED(CONFIG_MIPS32_O32) &&
	     test_tsk_thread_flag(task, TIF_32BIT_REGS)))
		*arg = (unsigned int)*arg;
#endif
}

static inline void mips_set_syscall_arg(unsigned long *arg,
	struct task_struct *task, struct pt_regs *regs, unsigned int n)
{
#ifdef CONFIG_32BIT
	switch (n) {
	case 0: case 1: case 2: case 3:
		regs->regs[4 + n] = *arg;
		return;
	case 4: case 5: case 6: case 7:
		*arg = regs->args[n] = *arg;
		return;

Annotation

Implementation Notes