arch/x86/um/ptrace_32.c
Source file repositories/reference/linux-study-clean/arch/x86/um/ptrace_32.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/um/ptrace_32.c- Extension
.c- Size
- 4507 bytes
- Lines
- 203
- Domain
- Architecture Layer
- Bucket
- arch/x86
- Inferred role
- Architecture Layer: implementation source
- Status
- source 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.
- 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/mm.hlinux/sched.hlinux/uaccess.hlinux/regset.hasm/ptrace-abi.hregisters.hskas.h
Detected Declarations
function Copyrightfunction putregfunction poke_userfunction getregfunction peek_userfunction subarch_ptrace
Annotated Snippet
#include <linux/mm.h>
#include <linux/sched.h>
#include <linux/uaccess.h>
#include <linux/regset.h>
#include <asm/ptrace-abi.h>
#include <registers.h>
#include <skas.h>
void arch_switch_to(struct task_struct *to)
{
int err = arch_switch_tls(to);
if (!err)
return;
if (err != -EINVAL)
printk(KERN_WARNING "arch_switch_tls failed, errno %d, "
"not EINVAL\n", -err);
else
printk(KERN_WARNING "arch_switch_tls failed, errno = EINVAL\n");
}
/* determines which flags the user has access to. */
/* 1 = access 0 = no access */
#define FLAG_MASK 0x00044dd5
static const int reg_offsets[] = {
[EBX] = HOST_BX,
[ECX] = HOST_CX,
[EDX] = HOST_DX,
[ESI] = HOST_SI,
[EDI] = HOST_DI,
[EBP] = HOST_BP,
[EAX] = HOST_AX,
[DS] = HOST_DS,
[ES] = HOST_ES,
[FS] = HOST_FS,
[GS] = HOST_GS,
[EIP] = HOST_IP,
[CS] = HOST_CS,
[EFL] = HOST_EFLAGS,
[UESP] = HOST_SP,
[SS] = HOST_SS,
[ORIG_EAX] = HOST_ORIG_AX,
};
int putreg(struct task_struct *child, int regno, unsigned long value)
{
regno >>= 2;
switch (regno) {
case EBX:
case ECX:
case EDX:
case ESI:
case EDI:
case EBP:
case EAX:
case EIP:
case UESP:
break;
case ORIG_EAX:
/* Update the syscall number. */
UPT_SYSCALL_NR(&child->thread.regs.regs) = value;
break;
case FS:
if (value && (value & 3) != 3)
return -EIO;
break;
case GS:
if (value && (value & 3) != 3)
return -EIO;
break;
case DS:
case ES:
if (value && (value & 3) != 3)
return -EIO;
value &= 0xffff;
break;
case SS:
case CS:
if ((value & 3) != 3)
return -EIO;
value &= 0xffff;
break;
case EFL:
value &= FLAG_MASK;
child->thread.regs.regs.gp[HOST_EFLAGS] |= value;
return 0;
default :
panic("Bad register in putreg() : %d\n", regno);
}
Annotation
- Immediate include surface: `linux/mm.h`, `linux/sched.h`, `linux/uaccess.h`, `linux/regset.h`, `asm/ptrace-abi.h`, `registers.h`, `skas.h`.
- Detected declarations: `function Copyright`, `function putreg`, `function poke_user`, `function getreg`, `function peek_user`, `function subarch_ptrace`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: source 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.