aboutsummaryrefslogtreecommitdiff
path: root/lib/std/os/linux/x86_64.zig
diff options
context:
space:
mode:
Diffstat (limited to 'lib/std/os/linux/x86_64.zig')
-rw-r--r--lib/std/os/linux/x86_64.zig201
1 files changed, 0 insertions, 201 deletions
diff --git a/lib/std/os/linux/x86_64.zig b/lib/std/os/linux/x86_64.zig
index 583fad872d..e3db9e99c4 100644
--- a/lib/std/os/linux/x86_64.zig
+++ b/lib/std/os/linux/x86_64.zig
@@ -190,32 +190,6 @@ pub const ARCH = struct {
pub const GET_GS = 0x1004;
};
-pub const REG = struct {
- pub const R8 = 0;
- pub const R9 = 1;
- pub const R10 = 2;
- pub const R11 = 3;
- pub const R12 = 4;
- pub const R13 = 5;
- pub const R14 = 6;
- pub const R15 = 7;
- pub const RDI = 8;
- pub const RSI = 9;
- pub const RBP = 10;
- pub const RBX = 11;
- pub const RDX = 12;
- pub const RAX = 13;
- pub const RCX = 14;
- pub const RSP = 15;
- pub const RIP = 16;
- pub const EFL = 17;
- pub const CSGSFS = 18;
- pub const ERR = 19;
- pub const TRAPNO = 20;
- pub const OLDMASK = 21;
- pub const CR2 = 22;
-};
-
pub const Flock = extern struct {
type: i16,
whence: i16,
@@ -272,178 +246,3 @@ pub const timezone = extern struct {
};
pub const Elf_Symndx = u32;
-
-pub const greg_t = usize;
-pub const gregset_t = [23]greg_t;
-pub const fpstate = extern struct {
- cwd: u16,
- swd: u16,
- ftw: u16,
- fop: u16,
- rip: usize,
- rdp: usize,
- mxcsr: u32,
- mxcr_mask: u32,
- st: [8]extern struct {
- significand: [4]u16,
- exponent: u16,
- padding: [3]u16 = undefined,
- },
- xmm: [16]extern struct {
- element: [4]u32,
- },
- padding: [24]u32 = undefined,
-};
-pub const fpregset_t = *fpstate;
-pub const sigcontext = extern struct {
- r8: usize,
- r9: usize,
- r10: usize,
- r11: usize,
- r12: usize,
- r13: usize,
- r14: usize,
- r15: usize,
-
- rdi: usize,
- rsi: usize,
- rbp: usize,
- rbx: usize,
- rdx: usize,
- rax: usize,
- rcx: usize,
- rsp: usize,
- rip: usize,
- eflags: usize,
-
- cs: u16,
- gs: u16,
- fs: u16,
- pad0: u16 = undefined,
-
- err: usize,
- trapno: usize,
- oldmask: usize,
- cr2: usize,
-
- fpstate: *fpstate,
- reserved1: [8]usize = undefined,
-};
-
-pub const mcontext_t = extern struct {
- gregs: gregset_t,
- fpregs: fpregset_t,
- reserved1: [8]usize = undefined,
-};
-
-/// ucontext_t is part of the state pushed on the stack by the kernel for
-/// a signal handler. And also a subset of the state returned from the
-/// makecontext/getcontext/swapcontext POSIX APIs.
-///
-/// Currently this structure matches the glibc/musl layout. It contains a
-/// 1024-bit signal mask, and `fpregs_mem`. This structure should be
-/// split into one for the kernel ABI and c.zig should define a glibc/musl
-/// compatible structure.
-pub const ucontext_t = extern struct {
- flags: usize,
- link: ?*ucontext_t,
- stack: stack_t,
- mcontext: mcontext_t,
- sigmask: [1024 / @bitSizeOf(c_ulong)]c_ulong, // Currently a glibc-compatible (1024-bit) sigmask.
- fpregs_mem: [64]usize, // Not part of kernel ABI, only part of glibc ucontext_t
-};
-
-fn gpRegisterOffset(comptime reg_index: comptime_int) usize {
- return @offsetOf(ucontext_t, "mcontext") + @offsetOf(mcontext_t, "gregs") + @sizeOf(usize) * reg_index;
-}
-
-fn getContextInternal() callconv(.naked) usize {
- // TODO: Read GS/FS registers?
- asm volatile (
- \\ movq $0, %[flags_offset:c](%%rdi)
- \\ movq $0, %[link_offset:c](%%rdi)
- \\ movq %%r8, %[r8_offset:c](%%rdi)
- \\ movq %%r9, %[r9_offset:c](%%rdi)
- \\ movq %%r10, %[r10_offset:c](%%rdi)
- \\ movq %%r11, %[r11_offset:c](%%rdi)
- \\ movq %%r12, %[r12_offset:c](%%rdi)
- \\ movq %%r13, %[r13_offset:c](%%rdi)
- \\ movq %%r14, %[r14_offset:c](%%rdi)
- \\ movq %%r15, %[r15_offset:c](%%rdi)
- \\ movq %%rdi, %[rdi_offset:c](%%rdi)
- \\ movq %%rsi, %[rsi_offset:c](%%rdi)
- \\ movq %%rbp, %[rbp_offset:c](%%rdi)
- \\ movq %%rbx, %[rbx_offset:c](%%rdi)
- \\ movq %%rdx, %[rdx_offset:c](%%rdi)
- \\ movq %%rax, %[rax_offset:c](%%rdi)
- \\ movq %%rcx, %[rcx_offset:c](%%rdi)
- \\ movq (%%rsp), %%rcx
- \\ movq %%rcx, %[rip_offset:c](%%rdi)
- \\ leaq 8(%%rsp), %%rcx
- \\ movq %%rcx, %[rsp_offset:c](%%rdi)
- \\ pushfq
- \\ popq %[efl_offset:c](%%rdi)
- \\ leaq %[fpmem_offset:c](%%rdi), %%rcx
- \\ movq %%rcx, %[fpstate_offset:c](%%rdi)
- \\ fnstenv (%%rcx)
- \\ fldenv (%%rcx)
- \\ stmxcsr %[mxcsr_offset:c](%%rdi)
- \\ leaq %[stack_offset:c](%%rdi), %%rsi
- \\ movq %%rdi, %%r8
- \\ xorl %%edi, %%edi
- \\ movl %[sigaltstack], %%eax
- \\ syscall
- \\ testq %%rax, %%rax
- \\ jnz 0f
- \\ movl %[sigprocmask], %%eax
- \\ xorl %%esi, %%esi
- \\ leaq %[sigmask_offset:c](%%r8), %%rdx
- \\ movl %[sigset_size], %%r10d
- \\ syscall
- \\0:
- \\ retq
- :
- : [flags_offset] "i" (@offsetOf(ucontext_t, "flags")),
- [link_offset] "i" (@offsetOf(ucontext_t, "link")),
- [r8_offset] "i" (comptime gpRegisterOffset(REG.R8)),
- [r9_offset] "i" (comptime gpRegisterOffset(REG.R9)),
- [r10_offset] "i" (comptime gpRegisterOffset(REG.R10)),
- [r11_offset] "i" (comptime gpRegisterOffset(REG.R11)),
- [r12_offset] "i" (comptime gpRegisterOffset(REG.R12)),
- [r13_offset] "i" (comptime gpRegisterOffset(REG.R13)),
- [r14_offset] "i" (comptime gpRegisterOffset(REG.R14)),
- [r15_offset] "i" (comptime gpRegisterOffset(REG.R15)),
- [rdi_offset] "i" (comptime gpRegisterOffset(REG.RDI)),
- [rsi_offset] "i" (comptime gpRegisterOffset(REG.RSI)),
- [rbp_offset] "i" (comptime gpRegisterOffset(REG.RBP)),
- [rbx_offset] "i" (comptime gpRegisterOffset(REG.RBX)),
- [rdx_offset] "i" (comptime gpRegisterOffset(REG.RDX)),
- [rax_offset] "i" (comptime gpRegisterOffset(REG.RAX)),
- [rcx_offset] "i" (comptime gpRegisterOffset(REG.RCX)),
- [rsp_offset] "i" (comptime gpRegisterOffset(REG.RSP)),
- [rip_offset] "i" (comptime gpRegisterOffset(REG.RIP)),
- [efl_offset] "i" (comptime gpRegisterOffset(REG.EFL)),
- [fpstate_offset] "i" (@offsetOf(ucontext_t, "mcontext") + @offsetOf(mcontext_t, "fpregs")),
- [fpmem_offset] "i" (@offsetOf(ucontext_t, "fpregs_mem")),
- [mxcsr_offset] "i" (@offsetOf(ucontext_t, "fpregs_mem") + @offsetOf(fpstate, "mxcsr")),
- [sigaltstack] "i" (@intFromEnum(linux.SYS.sigaltstack)),
- [stack_offset] "i" (@offsetOf(ucontext_t, "stack")),
- [sigprocmask] "i" (@intFromEnum(linux.SYS.rt_sigprocmask)),
- [sigmask_offset] "i" (@offsetOf(ucontext_t, "sigmask")),
- [sigset_size] "i" (@sizeOf(sigset_t)),
- : .{ .cc = true, .memory = true, .rax = true, .rcx = true, .rdx = true, .rdi = true, .rsi = true, .r8 = true, .r10 = true, .r11 = true });
-}
-
-pub inline fn getcontext(context: *ucontext_t) usize {
- // This method is used so that getContextInternal can control
- // its prologue in order to read RSP from a constant offset
- // An aligned stack is not needed for getContextInternal.
- var clobber_rdi: usize = undefined;
- return asm volatile (
- \\ callq %[getContextInternal:P]
- : [_] "={rax}" (-> usize),
- [_] "={rdi}" (clobber_rdi),
- : [_] "{rdi}" (context),
- [getContextInternal] "X" (&getContextInternal),
- : .{ .cc = true, .memory = true, .rcx = true, .rdx = true, .rsi = true, .r8 = true, .r10 = true, .r11 = true });
-}