MrSmith33 / vox

Vox language compiler. AOT / JIT / Linker. Zero dependencies
Boost Software License 1.0
338 stars 18 forks source link

Wrong stack alignment on Linux for entry point #30

Closed MrSmith33 closed 2 years ago

MrSmith33 commented 2 years ago

Discussed in https://github.com/MrSmith33/vox/discussions/29

Originally posted by **rempas** December 3, 2021 I'm trying to implement the "mmap" system call on Linux 64bit. I have the following code: ``` /* mmap system call */ /* Protections */ enum PROT_READ = 0x1; /* Page can be read. */ enum PROT_WRITE = 0x2; /* Page can be written. */ enum PROT_EXEC = 0x4; /* Page can be executed. */ enum PROT_NONE = 0x0; /* Page can not be accessed. */ /* Flags */ enum MAP_SHARED = 0x01; /* Share changes. */ enum MAP_PRIVATE = 0x02; /* Changes are private. */ enum MAP_FIXED = 0x10; /* Interpret addr exactly. */ enum MAP_ANONYMOUS = 0x20; /* Don't use a file. */ @extern(syscall, 9) void* sys_mmap(void* addr, u64 len, i32 prot, i32 flags, i32 fd, i64 off); void* malloc(u64 len) { return sys_mmap(null, len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); } void main() { u8* val = cast(u8*)malloc(4096); // PAGESIZE *val = 10; exit(0); } ``` I got the signature for "mmap" from the [man](https://www.man7.org/linux/man-pages/man2/mmap.2.html) pages. This code will work under C but it will throw a "segmentation fault" on Vox when I try to de-reference the pointer. Any ideas?