porting dlmalloc (2.8.4) to my OS, I've encountered a very strange error: My sbrk function returns a void*, which is 8 bytes in size (I checked on the type almost 20 times), but the higher dword is stripped away in the dlmalloc code. To check what caused the error I compiled the following C code in both my main.c, where everything works correctly, and directly at the top of dlmalloc.c (after the required imports for types and console):
Code: Select all
uintptr_t result = heap_sbrk(0x2000);
console_print_hex(result);
Code: Select all
5a: bf 00 20 00 00 mov $0x2000,%edi
5f: 48 b8 00 00 00 00 00 movabs $0x0,%rax
66: 00 00 00
69: ff d0 callq *%rax
6b: 48 89 45 f8 mov %rax,-0x8(%rbp)
6f: 48 8b 45 f8 mov -0x8(%rbp),%rax
73: 48 89 c7 mov %rax,%rdi
76: 48 b8 00 00 00 00 00 movabs $0x0,%rax
7d: 00 00 00
80: ff d0 callq *%rax
Code: Select all
12: bf 00 20 00 00 mov $0x2000,%edi
17: b8 00 00 00 00 mov $0x0,%eax
1c: 48 ba 00 00 00 00 00 movabs $0x0,%rdx
23: 00 00 00
26: ff d2 callq *%rdx
28: 48 98 cltq
2a: 48 89 45 f8 mov %rax,-0x8(%rbp)
2e: 48 8b 45 f8 mov -0x8(%rbp),%rax
32: 48 89 c7 mov %rax,%rdi
35: 48 b8 00 00 00 00 00 movabs $0x0,%rax
3c: 00 00 00
3f: ff d0 callq *%rax
Both files are compiled with the same flags:
Code: Select all
-m64 \
-nostdlib -nostdinc -fno-builtin -fno-stack-protector \
-D__AMD64__ \
-D__DEBUG__ \
-x c \
-mcmodel=large \
-I./src/