Compare commits
2 Commits
80d5606a81
...
f4b2c5477b
| Author | SHA1 | Date | |
|---|---|---|---|
| f4b2c5477b | |||
| 06de3cc17d |
16
Makefile
16
Makefile
@ -1,20 +1,20 @@
|
|||||||
all: print print_x64 print_aarch64 print_mips32
|
all: print print_x64 print_aarch64 print_mips32
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm print
|
if test -f print; then rm print; fi
|
||||||
rm print_x64
|
if test -f print_x64; then rm print_x64; fi
|
||||||
rm print_aarch64
|
if test -f print_aarch64; then rm print_aarch64; fi
|
||||||
rm print_mips32
|
if test -f print_mips32; then rm print_mips32; fi
|
||||||
|
|
||||||
.PHONY: all clean
|
.PHONY: all clean
|
||||||
|
|
||||||
print:
|
print:
|
||||||
gcc -static -nostdlib -o print print.c
|
gcc -static -nostdlib -fno-stack-protector -o print print.c
|
||||||
print_x64: print.c
|
print_x64: print.c
|
||||||
clang --target=x86_64-linux-gnu -nostdlib -static -fuse-ld=lld -o print_x64 print.c
|
clang --target=x86_64-linux-gnu -nostdlib -static -fuse-ld=lld -fno-stack-protector -o print_x64 print.c
|
||||||
|
|
||||||
print_aarch64: print.c
|
print_aarch64: print.c
|
||||||
clang --target=aarch64-linux-gnu -nostdlib -static -fuse-ld=lld -o print_aarch64 print.c
|
clang --target=aarch64-linux-gnu -nostdlib -static -fuse-ld=lld -fno-stack-protector -o print_aarch64 print.c
|
||||||
|
|
||||||
print_mips32: print.c
|
print_mips32: print.c
|
||||||
clang --target=mips-linux-gnu -nostdlib -static -fuse-ld=lld -fno-pic -o print_mips32 print.c
|
clang --target=mips-linux-gnu -nostdlib -static -fuse-ld=lld -fno-stack-protector -fno-pic -o print_mips32 print.c
|
||||||
|
|||||||
38
print.c
38
print.c
@ -30,9 +30,9 @@ long print(const void *buf, long count) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(__aarch64__)
|
|
||||||
#define CLONE_CHILD_SETTID 0x1000000
|
#define CLONE_CHILD_SETTID 0x1000000
|
||||||
#define CLONE_CHILD_CLEARTID 0x200000
|
#define CLONE_CHILD_CLEARTID 0x200000
|
||||||
|
#if defined(__aarch64__)
|
||||||
long int fork() {
|
long int fork() {
|
||||||
long int rtn;
|
long int rtn;
|
||||||
long int flags = CLONE_CHILD_CLEARTID | CLONE_CHILD_SETTID;
|
long int flags = CLONE_CHILD_CLEARTID | CLONE_CHILD_SETTID;
|
||||||
@ -42,8 +42,8 @@ long int fork() {
|
|||||||
"mov x0, %1\n" // clone flags
|
"mov x0, %1\n" // clone flags
|
||||||
"mov x1, #0\n" // child stack pointer
|
"mov x1, #0\n" // child stack pointer
|
||||||
"mov x2, #0\n" // parent_tidptr
|
"mov x2, #0\n" // parent_tidptr
|
||||||
"mov x3, #0\n" // child_tidptr
|
"mov x3, #0\n" // tls
|
||||||
"mov x4, #0\n" // tls
|
"mov x4, #0\n" // child_tidptr
|
||||||
"svc #0\n" // Make the syscall
|
"svc #0\n" // Make the syscall
|
||||||
"mov %0, x0\n" // save return value
|
"mov %0, x0\n" // save return value
|
||||||
// Output operands
|
// Output operands
|
||||||
@ -55,6 +55,34 @@ long int fork() {
|
|||||||
);
|
);
|
||||||
return rtn;
|
return rtn;
|
||||||
}
|
}
|
||||||
|
#elif defined(__x86_64__)
|
||||||
|
long int fork() {
|
||||||
|
long int rtn;
|
||||||
|
/*
|
||||||
|
long int flags = CLONE_CHILD_CLEARTID | CLONE_CHILD_SETTID;
|
||||||
|
asm volatile(
|
||||||
|
"movq %%rax, 56\n" // syscall number for 'clone' is 56 for x86-64
|
||||||
|
"movq %%rdi, %1\n" // clone flags
|
||||||
|
"movq %%rsi, 0\n" // child stack pointer
|
||||||
|
"movq %%rdx, 0\n" // parent tidptr
|
||||||
|
"movq %%r10, 0\n" // child tidptr
|
||||||
|
"movq %%r8, 0\n" // tls
|
||||||
|
"syscall\n" // syscall
|
||||||
|
"movq %0, %%rax\n" // save return value
|
||||||
|
: "=r"(rtn)
|
||||||
|
: "r"(flags)
|
||||||
|
: "rax", "rdi", "rsi", "rdx", "r10", "r8", "r9", "r10", "r11"
|
||||||
|
);
|
||||||
|
*/
|
||||||
|
asm volatile(
|
||||||
|
"syscall\n" // syscall
|
||||||
|
"movq %0, %%rax\n" // save return value
|
||||||
|
: "=r"(rtn)
|
||||||
|
: "a"(57)
|
||||||
|
:
|
||||||
|
);
|
||||||
|
return rtn;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void exit(int status) {
|
void exit(int status) {
|
||||||
@ -87,7 +115,7 @@ void exit(int status) {
|
|||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
#if defined(__aarch64__)
|
#if defined(__x86_64__) || defined(__aarch64__)
|
||||||
long int pid = fork();
|
long int pid = fork();
|
||||||
char msg[17] = {' '};
|
char msg[17] = {' '};
|
||||||
msg[16] = '\n';
|
msg[16] = '\n';
|
||||||
@ -99,7 +127,7 @@ int main() {
|
|||||||
msg[i] = c;
|
msg[i] = c;
|
||||||
}
|
}
|
||||||
print(msg, 17);
|
print(msg, 17);
|
||||||
#elif
|
#else
|
||||||
char *msg = "Hello World!\n";
|
char *msg = "Hello World!\n";
|
||||||
print(msg, 13);
|
print(msg, 13);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user