/* * cc -Wall -O3 -c macos-syscall.c -o macos-syscall.o * ld -static -macosx_version_min 10.12 -pagezero_size 0x1000 macos-syscall.o -o macos-syscall */ __attribute__ ((visibility("default"))) extern void start(void) asm("start"); #define NR_exit 0x2000001 #define NR_write 0x2000004 static __inline long __syscall0(long n) { unsigned long ret; __asm__ __volatile__ ("syscall" : "=a"(ret) : "a"(n) : "rcx", "r11", "memory"); return ret; } static __inline long __syscall3(long n, long a1, long a2, long a3) { unsigned long ret; __asm__ __volatile__ ("syscall" : "=a"(ret) : "a"(n), "D"(a1), "S"(a2), "d"(a3) : "rcx", "r11", "memory"); return ret; } void exit(int status) { __syscall0(NR_exit); __builtin_unreachable(); } long write(int fildes, const void *buf, unsigned long nbyte) { return __syscall3(NR_write, fildes, (long)buf, nbyte); } void start() { write(1, "hello world\n", 12); exit(0); }