How to make system calls having 64-bit arguments using 'int 80h' in 32-bit Linux - Unix

This is a discussion on How to make system calls having 64-bit arguments using 'int 80h' in 32-bit Linux - Unix ; If I need to make a system call with 6 arguments I can use the code: " push %esi\n" " push %edi\n" " push %ebx\n" " push %ebp\n" " movl 16+ 4(%esp),%eax\n" // syscall_num " movl 16+ 8(%esp),%ebx\n" // arg1 ...

+ Reply to Thread
Results 1 to 8 of 8

Thread: How to make system calls having 64-bit arguments using 'int 80h' in 32-bit Linux

  1. How to make system calls having 64-bit arguments using 'int 80h' in 32-bit Linux

    If I need to make a system call with 6 arguments I can use the code:
    " push %esi\n"
    " push %edi\n"
    " push %ebx\n"
    " push %ebp\n"
    " movl 16+ 4(%esp),%eax\n" // syscall_num
    " movl 16+ 8(%esp),%ebx\n" // arg1
    " movl 16+12(%esp),%ecx\n" // arg2
    " movl 16+16(%esp),%edx\n" // arg3
    " movl 16+20(%esp),%esi\n" // arg4
    " movl 16+24(%esp),%edi\n" // arg5
    " movl 16+28(%esp),%ebp\n" // arg6
    " int $0x80\n"
    " popl %ebp\n"
    " popl %ebx\n"
    " popl %edi\n"
    " popl %esi\n"
    " ret\n"

    But what happens for system calls like 'mmap'?
    void * mmap(void *start, size_t length, int prot , int flags, int
    fd, off_t offset);
    It's last argument is off_t which is 64-bit. Where should the high
    part of this offset fit in? There is not enough registers...
    Same for lseek:
    off_t lseek(int fildes, off_t offset, int whence);
    how will the high part of 'offset' argument be passed?

    Is there any documentation about this?


  2. Re: How to make system calls having 64-bit arguments using 'int 80h'in 32-bit Linux

    Visa Inquirer wrote:

    > If I need to make a system call with 6 arguments I can use the code:
    > " push %esi\n"
    > " push %edi\n"
    > " push %ebx\n"
    > " push %ebp\n"
    > " movl 16+ 4(%esp),%eax\n" // syscall_num
    > " movl 16+ 8(%esp),%ebx\n" // arg1
    > " movl 16+12(%esp),%ecx\n" // arg2
    > " movl 16+16(%esp),%edx\n" // arg3
    > " movl 16+20(%esp),%esi\n" // arg4
    > " movl 16+24(%esp),%edi\n" // arg5
    > " movl 16+28(%esp),%ebp\n" // arg6
    > " int $0x80\n"
    > " popl %ebp\n"
    > " popl %ebx\n"
    > " popl %edi\n"
    > " popl %esi\n"
    > " ret\n"
    >
    > But what happens for system calls like 'mmap'?
    > void *mmap(void *start, size_t length, int prot, int flags,
    > int fd, off_t offset);
    > Its last argument is off_t which is 64-bit.


    Are you sure the offset really is 64-bits wide?
    http://lxr.linux.no/source/arch/i386...sys_i386.c#L43
    asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
    unsigned long prot, unsigned long flags,
    unsigned long fd, unsigned long pgoff)

    > Where should the high
    > part of this offset fit in? There is not enough registers...
    > Same for lseek:
    > off_t lseek(int fildes, off_t offset, int whence);
    > how will the high part of 'offset' argument be passed?


    Are you sure the offset really is 64-bits wide?
    asmlinkage off_t sys_lseek(unsigned int fd, off_t offset,
    unsigned int origin)
    typedef __kernel_off_t off_t;
    typedef long __kernel_off_t;

    llseek explicitly breaks a 64-bit argument into two 32-bit pieces:
    http://lxr.linux.no/source/fs/read_write.c#L154
    asmlinkage long sys_llseek(unsigned int fd, unsigned long offset_high,
    unsigned long offset_low, loff_t __user * result,
    unsigned int origin)

  3. How to make system calls having 64-bit arguments using 'int 80h' in 32-bit Linux

    VI> If I need to make a system call with 6 arguments I can use the
    code: [...]

    Not if you are doing Unix programming, you cannot. And not if you are
    using, say, 32-bit Motorola 680x0 Linux.


  4. Re: How to make system calls having 64-bit arguments using 'int80h' in 32-bit Linux

    Visa Inquirer writes:

    > If I need to make a system call with 6 arguments I can use the code:
    > " push %esi\n"


    Your question is necessarily OS-specific, yet you didn't give any
    indication of which OS you are using.

    The UserAgent gives a clue that you might be interested in something
    other than Linux: "Mozilla/5.0 (X11; U; FreeBSD i386...".

    I do not have access to a FreeBSD system, but on Linux one can
    do this:


    gdb -q /lib/libc.so.6
    disas mmap64
    disas lseek64

    I imagine this would also work on FreeBSD, and give you exactly
    what you are looking for.

    Cheers,
    --
    In order to understand recursion you must first understand recursion.
    Remove /-nsp/ for email.

  5. Re: How to make system calls having 64-bit arguments using 'int 80h'in 32-bit Linux

    Paul Pluzhnikov wrote:

    > Your question is necessarily OS-specific, yet you didn't give any
    > indication of which OS you are using.
    >
    > The UserAgent gives a clue that you might be interested in something
    > other than Linux: "Mozilla/5.0 (X11; U; FreeBSD i386...".


    Typically, FreeBSD/i386 expects the parameters on the stack.
    http://www.freebsd.org/doc/en_US.ISO...tem-calls.html

    "By default, the FreeBSD kernel uses the C calling convention. Further,
    although the kernel is accessed using int 80h, it is assumed the program
    will call a function that issues int 80h, rather than issuing int 80h
    directly."

    > I do not have access to a FreeBSD system, but on Linux one can
    > do this:
    >
    > gdb -q /lib/libc.so.6
    > disas mmap64


    As far as Linux is concerned, one can also peruse:
    http://sources.redhat.com/cgi-bin/cv...?cvsroot=glibc

    > disas lseek64


    http://sources.redhat.com/cgi-bin/cv...?cvsroot=glibc

  6. Re: How to make system calls having 64-bit arguments using 'int 80h' in 32-bit Linux

    > Your question is necessarily OS-specific, yet you didn't give any
    > indication of which OS you are using.
    >
    > The UserAgent gives a clue that you might be interested in something
    > other than Linux: "Mozilla/5.0 (X11; U; FreeBSD i386...".


    I specified in subject: ".. in 32-bit Linux". This + assembly language
    used narrows OS down to x86-lInox.
    I use FreeBSD for posting but my question refers to Linux.



  7. Re: How to make system calls having 64-bit arguments using 'int80h' in 32-bit Linux

    Visa Inquirer writes:

    >> Your question is necessarily OS-specific, yet you didn't give any

    >
    > I specified in subject: ".. in 32-bit Linux".


    Indeed. But the subject is displayed in one place on the screen,
    and the discussion happens in another. Which is why it is usually
    a good idea to repeat *all* relevant details in the message body.

    Cheers,
    --
    In order to understand recursion you must first understand recursion.
    Remove /-nsp/ for email.

  8. Re: How to make system calls having 64-bit arguments using 'int 80h' in 32-bit Linux

    > But what happens for system calls like 'mmap'?

    Thanks for your replies. Now I see that it's impossible to have 64-bit
    args in 32-bit Linux and also it's impossible to have syscalls with
    more than 6 arguments.


+ Reply to Thread