Add support for openat on x86_64

This commit is contained in:
2025-04-14 20:59:04 -04:00
parent c8875d39f2
commit bd9a3d3b99
3 changed files with 34 additions and 1 deletions

View File

@@ -20,7 +20,7 @@ intptr_t write(int32_t fd, const void* buf, intptr_t size) {
"movq %0, %%rax\n"
: "=r"(n_written)
: "a"(SYS_WRITE), "D"(fd), "S"(buf), "d"(size) // RDI, RSI, RDX are used in x86-64 for write args
: "rcx", "r11", "memory"
: "rcx", "r11"
);
return n_written;
}
@@ -50,4 +50,18 @@ uint32_t fork() {
);
return (uint32_t)rtn;
}
#define SYS_OPENAT 257
int32_t openat(int32_t fd, const char* filename, uint32_t flags, uint32_t mode) {
int32_t file;
asm volatile (
"mov %%r10, %5\n"
"syscall\n"
: "=a"(file)
: "a"(SYS_OPENAT), "D"(fd), "S"(filename), "d"(flags), "r"((uint64_t)mode) // RDI, RSI, RDX are used in x86-64 for write args
: "rcx", "r10", "r11"
);
return file;
}
#endif /* ifdef __x86_64__ */