Created
April 30, 2017 08:55
-
-
Save michaeljclark/274c6a64f98d9e5e0bc2b320b1225dfd to your computer and use it in GitHub Desktop.
simple macos process with no dependency on libsystem.dylib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment