Created
June 21, 2018 07:36
-
-
Save cubedtear/ea4048ab7f958be3fb76e7d5a950e0fd to your computer and use it in GitHub Desktop.
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
void myprint(*i8 str, int length) { | |
syscall3(1, 1, (int)str, length); | |
} | |
void exit(int code) { | |
syscall1(60, code); | |
} | |
void print(i8 val) { | |
} | |
void print(int val) { | |
} | |
*i8 itoa(int val) { | |
} | |
*i8 malloc(int bytes) { | |
static *i8 max = 0; | |
static *i8 used = 0; | |
if (max == 0) { | |
max = (*i8) brk(0); | |
used = max; | |
} | |
if (used + bytes <= max) { | |
max = (*i8) brk((int) max + bytes); | |
} | |
used = used + bytes; | |
return used - bytes; | |
} | |
int brk(int addr) { | |
return syscall1(12, addr); | |
} | |
int syscall(int call) { | |
int result; | |
asm("syscall; mov $1, %rax" : "=r"(result) : "{rax}"(call) : "{rcx}", "{r11}"); | |
return result; | |
} | |
int syscall1(int call, int arg1) { | |
int result; | |
asm("syscall; mov $1, %rax" : "=r"(result) : "{rax}"(call), "{rdi}"(arg1) : "{rcx}", "{r11}"); | |
return result; | |
} | |
int syscall2(int call, int arg1, int arg2) { | |
int result; | |
asm("syscall; mov $1, %rax" : "=r"(result) : "{rax}"(call), "{rdi}"(arg1), "{rsi}"(arg2) : "{rcx}", "{r11}"); | |
return result; | |
} | |
int syscall3(int call, int arg1, int arg2, int arg3) { | |
int result; | |
asm("syscall; mov $1, %rax" : "=r"(result) : "{rax}"(call), "{rdi}"(arg1), "{rsi}"(arg2), "{rdx}"(arg3) : "{rcx}", "{r11}"); | |
return result; | |
} | |
int syscall4(int call, int arg1, int arg2, int arg3, int arg4) { | |
int result; | |
asm("syscall; mov $1, %rax" : "=r"(result) : "{rax}"(call), "{rdi}"(arg1), "{rsi}"(arg2), "{rdx}"(arg3), "{r10}"(arg4) : "{rcx}", "{r11}"); | |
return result; | |
} | |
int syscall5(int call, int arg1, int arg2, int arg3, int arg4, int arg5) { | |
int result; | |
asm("syscall; mov $1, %rax" : "=r"(result) : "{rax}"(call), "{rdi}"(arg1), "{rsi}"(arg2), "{rdx}"(arg3), "{r10}"(arg4), "{r8}"(arg5) : "{rcx}", "{r11}"); | |
return result; | |
} | |
int syscall6(int call, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6) { | |
int result; | |
asm("syscall; mov $1, %rax" : "=r"(result) : "{rax}"(call), "{rdi}"(arg1), "{rsi}"(arg2), "{rdx}"(arg3), "{r10}"(arg4), "{r8}"(arg5), "{r9}"(arg6) : "{rcx}", "{r11}"); | |
return result; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment