i have my allocation function:
malloc_:
pushq %rbp
movq %rsp, %rbp
mov %rdi, %rcx # store size
movl $9, %eax # system call 9 sys_mmap
movq $0, %rdi # start address
movq %rcx, %rsi # size
movl $3, %edx # page flags <--- PROT_READ | PROT_WRITE
mov $34, %r10 # mem flags <---- MAP_PRIVATE | MAP_ANONYMOUS
movl $-1, %r8d # file descriptor
movl $0, %r9d # offset
syscall
cmp $0, %rax
jg .L1.malloc_exit_
mov $0, %rax
.L1.malloc_exit_:
popq %rbp
retq
.globl main
main:
pushq %rbp
movq %rsp, %rbp
mov $512, %rdi
call malloc_
cmp $0, %rax
je exit
// movl (%eax), %edx // <---------crash
mov (%rax), %rdx // <---------norm
exit:
I showed an incomprehensible place for me. Why is this happening?
If I use system malloc, then in both cases everything is fine