arch/loongarch/kernel/signal.c
Source file repositories/reference/linux-study-clean/arch/loongarch/kernel/signal.c
File Facts
- System
- Linux kernel
- Corpus path
arch/loongarch/kernel/signal.c- Extension
.c- Size
- 26613 bytes
- Lines
- 1052
- Domain
- Architecture Layer
- Bucket
- arch/loongarch
- 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.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Defines or participates in a user/kernel boundary; inspect argument validation, copy_from_user/copy_to_user, credentials, and dispatch target.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/audit.hlinux/cache.hlinux/context_tracking.hlinux/entry-common.hlinux/irqflags.hlinux/rseq.hlinux/sched.hlinux/mm.hlinux/personality.hlinux/smp.hlinux/kernel.hlinux/signal.hlinux/errno.hlinux/wait.hlinux/ptrace.hlinux/unistd.hlinux/compiler.hlinux/syscalls.hlinux/uaccess.hasm/asm.hasm/cacheflush.hasm/cpu-features.hasm/fpu.hasm/lbt.hasm/sigframe.hasm/ucontext.hasm/vdso.h
Detected Declarations
syscall rt_sigreturnstruct _ctx_layoutstruct extctx_layoutfunction copy_fpu_to_sigcontextfunction copy_fpu_from_sigcontextfunction copy_lsx_to_sigcontextfunction copy_lsx_from_sigcontextfunction copy_lasx_to_sigcontextfunction copy_lasx_from_sigcontextfunction copy_lbt_to_sigcontextfunction copy_lbt_from_sigcontextfunction copy_ftop_to_sigcontextfunction copy_ftop_from_sigcontextfunction save_hw_fpu_contextfunction restore_hw_fpu_contextfunction save_hw_lsx_contextfunction restore_hw_lsx_contextfunction save_hw_lasx_contextfunction restore_hw_lasx_contextfunction save_hw_lbt_contextfunction restore_hw_lbt_contextfunction save_hw_ftop_contextfunction restore_hw_ftop_contextfunction fcsr_pendingfunction protected_save_fpu_contextfunction protected_restore_fpu_contextfunction protected_save_lsx_contextfunction protected_restore_lsx_contextfunction protected_save_lasx_contextfunction protected_restore_lasx_contextfunction protected_save_lbt_contextfunction protected_restore_lbt_contextfunction setup_sigcontextfunction parse_extcontextfunction restore_sigcontextfunction handle_flagsfunction extframe_allocfunction setup_extcontextfunction setup_rt_framefunction handle_signalfunction arch_do_signal_or_restart
Annotated Snippet
SYSCALL_DEFINE0(rt_sigreturn)
{
int sig;
sigset_t set;
struct pt_regs *regs;
struct rt_sigframe __user *frame;
regs = current_pt_regs();
frame = (struct rt_sigframe __user *)regs->regs[3];
if (!access_ok(frame, sizeof(*frame)))
goto badframe;
if (__copy_from_user(&set, &frame->rs_uctx.uc_sigmask, sizeof(set)))
goto badframe;
set_current_blocked(&set);
sig = restore_sigcontext(regs, &frame->rs_uctx.uc_mcontext);
if (sig < 0)
goto badframe;
else if (sig)
force_sig(sig);
regs->regs[0] = 0; /* No syscall restarting */
if (restore_altstack(&frame->rs_uctx.uc_stack))
goto badframe;
return regs->regs[4];
badframe:
force_sig(SIGSEGV);
return 0;
}
static int setup_rt_frame(void *sig_return, struct ksignal *ksig,
struct pt_regs *regs, sigset_t *set)
{
int err = 0;
struct extctx_layout extctx;
struct rt_sigframe __user *frame;
frame = get_sigframe(ksig, regs, &extctx);
if (!access_ok(frame, sizeof(*frame) + extctx.size))
return -EFAULT;
/* Create siginfo. */
err |= copy_siginfo_to_user(&frame->rs_info, &ksig->info);
/* Create the ucontext. */
err |= __put_user(0, &frame->rs_uctx.uc_flags);
err |= __put_user(NULL, &frame->rs_uctx.uc_link);
err |= __save_altstack(&frame->rs_uctx.uc_stack, regs->regs[3]);
err |= setup_sigcontext(regs, &frame->rs_uctx.uc_mcontext, &extctx);
err |= __copy_to_user(&frame->rs_uctx.uc_sigmask, set, sizeof(*set));
if (err)
return -EFAULT;
/*
* Arguments to signal handler:
*
* a0 = signal number
* a1 = pointer to siginfo
* a2 = pointer to ucontext
*
* c0_era point to the signal handler, $r3 (sp) points to
* the struct rt_sigframe.
*/
regs->regs[4] = ksig->sig;
regs->regs[5] = (unsigned long) &frame->rs_info;
regs->regs[6] = (unsigned long) &frame->rs_uctx;
regs->regs[3] = (unsigned long) frame;
regs->regs[1] = (unsigned long) sig_return;
regs->csr_era = (unsigned long) ksig->ka.sa.sa_handler;
DEBUGP("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%lx\n",
current->comm, current->pid,
frame, regs->csr_era, regs->regs[1]);
return 0;
}
static void handle_signal(struct ksignal *ksig, struct pt_regs *regs)
{
int ret;
sigset_t *oldset = sigmask_to_save();
void *vdso = current->mm->context.vdso;
/* Are we from a system call? */
if (regs->regs[0]) {
switch (regs->regs[4]) {
Annotation
- Immediate include surface: `linux/audit.h`, `linux/cache.h`, `linux/context_tracking.h`, `linux/entry-common.h`, `linux/irqflags.h`, `linux/rseq.h`, `linux/sched.h`, `linux/mm.h`.
- Detected declarations: `syscall rt_sigreturn`, `struct _ctx_layout`, `struct extctx_layout`, `function copy_fpu_to_sigcontext`, `function copy_fpu_from_sigcontext`, `function copy_lsx_to_sigcontext`, `function copy_lsx_from_sigcontext`, `function copy_lasx_to_sigcontext`, `function copy_lasx_from_sigcontext`, `function copy_lbt_to_sigcontext`.
- Atlas domain: Architecture Layer / arch/loongarch.
- Implementation status: core implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.