Files
linux-kernel-module-cheat/userland/arch/x86_64/inline_asm/freestanding/linux/hello.c
Ciro Santilli 六四事件 法轮功 15ffa40b6e inline_asm: remember register variables :-)
2020-06-25 10:00:09 +00:00

33 lines
774 B
C

/* x86_64 freestanding C inline assemby Linux hello world
* https://cirosantilli.com/linux-kernel-module-cheat#linux-system-calls */
#define _XOPEN_SOURCE 700
#include <inttypes.h>
#include <sys/types.h>
ssize_t my_write(int fd, const void *buf, size_t size) {
ssize_t ret;
__asm__ __volatile__ (
"syscall"
: "=a" (ret)
: "0" (1), "D" (fd), "S" (buf), "d" (size)
: "cc", "rcx", "r11", "memory"
);
return ret;
}
void my_exit(int exit_status) {
ssize_t ret;
__asm__ __volatile__ (
"syscall"
: "=a" (ret)
: "0" (60), "D" (exit_status)
: "cc", "rcx", "r11", "memory"
);
}
void _start(void) {
char msg[] = "hello\n";
my_exit(my_write(1, msg, sizeof(msg)) != sizeof(msg));
}