Author Topic: linux mmap 64 bit parameter passing  (Read 21432 times)

nobody

  • Guest
linux mmap 64 bit parameter passing
« 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

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: linux mmap 64 bit parameter passing
« Reply #1 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

Offline H. Peter Anvin

  • NASM Developer
  • Jr. Member
  • *****
  • Posts: 18
Re: linux mmap 64 bit parameter passing
« Reply #2 on: April 18, 2009, 10:29:31 PM »
You may want to look at Appendix A in the ABI document.

Offline Cyrill Gorcunov

  • NASM Developer
  • Full Member
  • *****
  • Posts: 179
  • Country: 00
Re: linux mmap 64 bit parameter passing
« Reply #3 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).