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?
Re: How to make system calls having 64-bit arguments using 'int 80h'in 32-bit Linux
Visa Inquirer wrote:
[color=blue]
> 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.[/color]
Are you sure the offset really is 64-bits wide?
[url]http://lxr.linux.no/source/arch/i386/kernel/sys_i386.c#L43[/url]
asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
unsigned long prot, unsigned long flags,
unsigned long fd, unsigned long pgoff)
[color=blue]
> 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?[/color]
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:
[url]http://lxr.linux.no/source/fs/read_write.c#L154[/url]
asmlinkage long sys_llseek(unsigned int fd, unsigned long offset_high,
unsigned long offset_low, loff_t __user * result,
unsigned int origin)
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.
Re: How to make system calls having 64-bit arguments using 'int80h' in 32-bit Linux
Visa Inquirer <visa_desirer@yahoo.com> writes:
[color=blue]
> If I need to make a system call with 6 arguments I can use the code:
> " push %esi\n"[/color]
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.
Re: How to make system calls having 64-bit arguments using 'int 80h'in 32-bit Linux
Paul Pluzhnikov wrote:
[color=blue]
> 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...".[/color]
Typically, FreeBSD/i386 expects the parameters on the stack.
[url]http://www.freebsd.org/doc/en_US.ISO8859-1/books/developers-handbook/x86-system-calls.html[/url]
"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."
[color=blue]
> I do not have access to a FreeBSD system, but on Linux one can
> do this:
>
> gdb -q /lib/libc.so.6
> disas mmap64[/color]
As far as Linux is concerned, one can also peruse:
[url]http://sources.redhat.com/cgi-bin/cvsweb.cgi/~checkout~/libc/sysdeps/unix/sysv/linux/mmap64.c?cvsroot=glibc[/url]
[color=blue]
> disas lseek64[/color]
[url]http://sources.redhat.com/cgi-bin/cvsweb.cgi/~checkout~/libc/sysdeps/unix/sysv/linux/llseek.c?cvsroot=glibc[/url]
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[color=blue]
> 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...".[/color]
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.
Re: How to make system calls having 64-bit arguments using 'int80h' in 32-bit Linux
Visa Inquirer <visa_desirer@yahoo.com> writes:
[color=blue][color=green]
>> Your question is necessarily OS-specific, yet you didn't give any[/color]
>
> I specified in subject: ".. in 32-bit Linux".[/color]
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.
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.