arch/powerpc/kernel/signal_32.c
Source file repositories/reference/linux-study-clean/arch/powerpc/kernel/signal_32.c
File Facts
- System
- Linux kernel
- Corpus path
arch/powerpc/kernel/signal_32.c- Extension
.c- Size
- 39079 bytes
- Lines
- 1360
- Domain
- Architecture Layer
- Bucket
- arch/powerpc
- 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/sched.hlinux/mm.hlinux/smp.hlinux/kernel.hlinux/signal.hlinux/errno.hlinux/elf.hlinux/ptrace.hlinux/pagemap.hlinux/ratelimit.hlinux/syscalls.hlinux/compat.hlinux/wait.hlinux/unistd.hlinux/stddef.hlinux/tty.hlinux/binfmts.hlinux/uaccess.hasm/cacheflush.hasm/syscalls.hasm/sigcontext.hasm/vdso.hasm/switch_to.hasm/tm.hasm/asm-prototypes.hasm/syscalls_32.hasm/unistd.hasm/ucontext.hsignal.h
Detected Declarations
syscall swapcontextsyscall rt_sigreturnsyscall debug_setcontextsyscall sigreturnstruct sigframestruct rt_sigframefunction Copyrightfunction __unsafe_restore_general_regsfunction __unsafe_save_general_regsfunction __unsafe_restore_general_regsfunction get_min_sigframe_size_32function prepare_save_user_regsfunction __unsafe_save_user_regsfunction __unsafe_save_user_regsfunction save_tm_user_regs_unsafefunction prepare_save_tm_user_regsfunction restore_user_regsfunction restore_tm_user_regsfunction restore_tm_user_regsfunction handle_rt_signal32function handle_signal32function do_setcontextfunction do_setcontext_tm
Annotated Snippet
SYSCALL_DEFINE3(swapcontext, struct ucontext __user *, old_ctx,
struct ucontext __user *, new_ctx, long, ctx_size)
#endif
{
struct pt_regs *regs = current_pt_regs();
int ctx_has_vsx_region = 0;
#ifdef CONFIG_PPC64
unsigned long new_msr = 0;
if (new_ctx) {
struct mcontext __user *mcp;
u32 cmcp;
/*
* Get pointer to the real mcontext. No need for
* access_ok since we are dealing with compat
* pointers.
*/
if (__get_user(cmcp, &new_ctx->uc_regs))
return -EFAULT;
mcp = (struct mcontext __user *)(u64)cmcp;
if (__get_user(new_msr, &mcp->mc_gregs[PT_MSR]))
return -EFAULT;
}
/*
* Check that the context is not smaller than the original
* size (with VMX but without VSX)
*/
if (ctx_size < UCONTEXTSIZEWITHOUTVSX)
return -EINVAL;
/*
* If the new context state sets the MSR VSX bits but
* it doesn't provide VSX state.
*/
if ((ctx_size < sizeof(struct ucontext)) &&
(new_msr & MSR_VSX))
return -EINVAL;
/* Does the context have enough room to store VSX data? */
if (ctx_size >= sizeof(struct ucontext))
ctx_has_vsx_region = 1;
#else
/* Context size is for future use. Right now, we only make sure
* we are passed something we understand
*/
if (ctx_size < sizeof(struct ucontext))
return -EINVAL;
#endif
if (old_ctx != NULL) {
struct mcontext __user *mctx;
/*
* old_ctx might not be 16-byte aligned, in which
* case old_ctx->uc_mcontext won't be either.
* Because we have the old_ctx->uc_pad2 field
* before old_ctx->uc_mcontext, we need to round down
* from &old_ctx->uc_mcontext to a 16-byte boundary.
*/
mctx = (struct mcontext __user *)
((unsigned long) &old_ctx->uc_mcontext & ~0xfUL);
prepare_save_user_regs(ctx_has_vsx_region);
if (!user_write_access_begin(old_ctx, ctx_size))
return -EFAULT;
unsafe_save_user_regs(regs, mctx, NULL, ctx_has_vsx_region, failed);
unsafe_put_sigset_t(&old_ctx->uc_sigmask, ¤t->blocked, failed);
unsafe_put_user(to_user_ptr(mctx), &old_ctx->uc_regs, failed);
user_write_access_end();
}
if (new_ctx == NULL)
return 0;
if (!access_ok(new_ctx, ctx_size) ||
fault_in_readable((char __user *)new_ctx, ctx_size))
return -EFAULT;
/*
* If we get a fault copying the context into the kernel's
* image of the user's registers, we can't just return -EFAULT
* because the user's registers will be corrupted. For instance
* the NIP value may have been updated but not some of the
* other registers. Given that we have done the access_ok
* and successfully read the first and last bytes of the region
* above, this should only happen in an out-of-memory situation
* or if another thread unmaps the region containing the context.
* We kill the task with a SIGSEGV in this situation.
*/
if (do_setcontext(new_ctx, regs, 0)) {
force_exit_sig(SIGSEGV);
return -EFAULT;
}
Annotation
- Immediate include surface: `linux/sched.h`, `linux/mm.h`, `linux/smp.h`, `linux/kernel.h`, `linux/signal.h`, `linux/errno.h`, `linux/elf.h`, `linux/ptrace.h`.
- Detected declarations: `syscall swapcontext`, `syscall rt_sigreturn`, `syscall debug_setcontext`, `syscall sigreturn`, `struct sigframe`, `struct rt_sigframe`, `function Copyright`, `function __unsafe_restore_general_regs`, `function __unsafe_save_general_regs`, `function __unsafe_restore_general_regs`.
- Atlas domain: Architecture Layer / arch/powerpc.
- 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.