wired
libc-free QUIC/HTTP3 SDK in C for x86_64-linux
Loading...
Searching...
No Matches
x8664.h
Go to the documentation of this file.
1#ifndef WIRED_ARCH_X8664_H
2#define WIRED_ARCH_X8664_H
3
11
12#include "common/arch/types.h"
13
14#define SYS_read 0
15#define SYS_write 1
16#define SYS_close 3
17#define SYS_newfstatat 262
18#define SYS_pread64 17
19#define SYS_mmap 9
20#define SYS_mprotect 10
21#define SYS_munmap 11
22#define SYS_rt_sigaction 13
23#define SYS_rt_sigprocmask 14
24#define SYS_rt_sigreturn 15
25#define SYS_rt_sigtimedwait 128
26#define SYS_socket 41
27#define SYS_sendmsg 46
28#define SYS_sendto 44
29#define SYS_recvfrom 45
30#define SYS_bind 49
31#define SYS_recvmmsg 299
32#define SYS_setsockopt 54
33#define SYS_clone 56
34#define SYS_exit 60
35#define SYS_gettid 186
36#define SYS_futex 202
37#define SYS_sched_setaffinity 203
38#define SYS_sched_getaffinity 204
39#define SYS_clock_gettime 228
40#define SYS_openat 257
41#define SYS_mkdirat 258
42#define SYS_getrandom 318
43#define SYS_fork 57
44#define SYS_wait4 61
45#define SYS_kill 62
46#define SYS_getpid 39
47#define SYS_getppid 110
48#define SYS_prctl 157
49#define SYS_exit_group 231
50#define SYS_poll 7
51#define SYS_getsockopt 55
52#define SYS_fcntl 72
53#define SYS_bpf 321
54
58#define SA_RESTORER 0x04000000u
59
77static inline i64 syscall6(i64 n, i64 a, i64 b, i64 c, i64 d, i64 e, i64 f) {
78 i64 ret;
79 register i64 r10 __asm__("r10") = d;
80 register i64 r8 __asm__("r8") = e;
81 register i64 r9 __asm__("r9") = f;
82 __asm__ volatile("syscall"
83 : "=a"(ret)
84 : "a"(n), "D"(a), "S"(b), "d"(c), "r"(r10), "r"(r8), "r"(r9)
85 : "rcx", "r11", "memory");
86 return ret;
87}
88
90#define syscall2(n, a, b) syscall6((n), (i64)(a), (i64)(b), 0, 0, 0, 0)
92#define syscall3(n, a, b, c) \
93 syscall6((n), (i64)(a), (i64)(b), (i64)(c), 0, 0, 0)
94
95#define syscall4(n, a, b, c, d) \
96 syscall6((n), (i64)(a), (i64)(b), (i64)(c), (i64)(d), 0, 0)
97
98#define syscall5(n, a, b, c, d, e) \
99 syscall6((n), (i64)(a), (i64)(b), (i64)(c), (i64)(d), (i64)(e), 0)
100
101#define syscall1(n, a) syscall6((n), (i64)(a), 0, 0, 0, 0, 0)
102
105static inline void wired_arch_pause(void) { __builtin_ia32_pause(); }
106
122 i64 flags, u8* child_stack, i32* parent_tid, i32* child_tid, i64 tls);
123
131
139#define WIRED_ARCH_START_ASM(entry) \
140 __asm__ volatile( \
141 "mov (%rsp), %rdi\n" \
142 "lea 8(%rsp), %rsi\n" \
143 "and $-16, %rsp\n" \
144 "call " #entry \
145 "\n" \
146 "mov %eax, %edi\n" \
147 "mov $60, %eax\n" /* SYS_exit */ \
148 "syscall\n")
149
150#endif
The SDK's fixed-width integer types (LP64 data model).
long i64
signed 64-bit integer
Definition types.h:14
int i32
signed 32-bit integer
Definition types.h:16
unsigned char u8
unsigned 8-bit integer / byte
Definition types.h:18
static i64 syscall6(i64 n, i64 a, i64 b, i64 c, i64 d, i64 e, i64 f)
Six-argument raw x86_64 Linux syscall.
Definition x8664.h:77
i64 wired_arch_clone_raw(i64 flags, u8 *child_stack, i32 *parent_tid, i32 *child_tid, i64 tls)
Raw clone(2) whose child starts on a new stack (assembly trampoline in clone.c; a C wrapper cannot be...
static void wired_arch_pause(void)
CPU spin-wait hint for busy-poll loops (x86 pause): tells the core a spin is in progress,...
Definition x8664.h:105
void wired_arch_sigreturn_restorer(void)
Signal-return trampoline for rt_sigaction(2)'s SA_RESTORER slot: the kernel jumps here when a handler...