NASM - The Netwide Assembler

NASM Forum => Programming with NASM => Topic started by: nobody on February 25, 2009, 01:40:23 PM

Title: linux mmap 64 bit parameter passing
Post by: nobody on February 25, 2009, 01:40:23 PM
Hi,

I tried to use mmap to allocate dynamic memory on a 64 bit linux system.

mmap has 6 parameters:
void *mmap(void *addr, size_t length, int prot,
   int flags, int fd, off_t pgoffset);

According to the AMD64 ABI the 4th parameter is passed in rcx. mmap always failed and I finally figured out using strace that the 4th parameter is not get from rcx but from r10. All the other parameters were passed as described in the amd64 ABI (1th rdi, 2nd rsi ...).

Using the r10 as the 4th parameter solved the earlier problems and mmap worked as expected.

Do you know if this is a bug in the linux syscall (and e.g. kept for binary compatibility) or I missed something and this is the right behaviour of mmap?

Thanks,
Csaba
Title: Re: linux mmap 64 bit parameter passing
Post by: Frank Kotler on February 26, 2009, 08:43:53 AM
Hi Csaba,

I do not know. I haven't delved into 64-bit-land at all. I appreciate the tip, though!  There are a few(?) things - like using _newselect instead of select in 32-bit systems (or maybe that's just me?) - that you "just have to know". Won't find it in the documentation, so if we don't pass these tips around, we won't know. So, Thanks!

Best,
Frank
Title: Re: linux mmap 64 bit parameter passing
Post by: H. Peter Anvin on April 18, 2009, 10:29:31 PM
You may want to look at Appendix A in the ABI document.
Title: Re: linux mmap 64 bit parameter passing
Post by: Cyrill Gorcunov on January 30, 2010, 08:51:27 AM
You may want to look at Appendix A in the ABI document.

Yeah, or take a look on SYSCALL description (which explains why is that).