flat assembler
Message board for the users of flat assembler.

Index > Linux > Futex?

Author
Thread Post new topic Reply to topic
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
Did someone worked with futex syscall (sys_futex = $f0).
There is something wrong with them - According to the man page, the function have 6 arguments and then it expects eax=$f0 and ebx=ptr to arguments.
I am using the stack:
Code:
        push    0 0 0 0
        push    FUTEX_WAIT
        push    __TimerExpiredFutex

        mov     eax, sys_futex
        mov     ebx, esp
        int $80
        add     esp, 6*4
    


_TimerExpidedFutex is properly aligned (on 32bit) but the function still returns: ENOSYS = 38 ; Function not implemented
But I am sure it should be implemented.

Any ideas?
Post 28 Mar 2011, 17:41
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Perhaps it is not the problem but are you sure you have to use so few registers to pass the parameters?

If you are following this prototype:
Code:
int sys_futex(void *futex, int op, int val, const struct timespec *timeout, void *futex2, int val3);    


Then I would try this:
Code:
mov eax, sys_futex 
mov ebx, futex
mov ecx, [op]
mov edx, [val]
mov esi, timeout
mov edi, futex2
mov ebp, [val3]
int $80
    


[edit]The 6th parameter goes in EBP, not the stack, so I've corrected that[/edit]
Post 28 Mar 2011, 21:51
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
I know that when parameters are up to 5 they are placed in ebx, ecx, edx, esi and edi. With 6 or more parameters - ebx contains pointer to memory that contains parameters. In both cases eax contains the number of the system function.
Post 28 Mar 2011, 22:08
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
http://www.win.tue.nl/~aeb/linux/lk/lk-4.html wrote:
4.3 System call parameters

On i386, the parameters of a system call are transported via registers. The system call number goes into %eax, the first parameter in %ebx, the second in %ecx, the third in %edx, the fourth in %esi, the fifth in %edi, the sixth in %ebp.
Ancient history

Earlier versions of Linux could handle only four or five system call parameters, and therefore the system calls select() (5 parameters) and mmap() (6 parameters) used to have a single parameter that was a pointer to a parameter block in memory. Since Linux 1.3.0 five parameters are supported (and the earlier select with memory block was renamed old_select), and since Linux 2.3.31 six parameters are supported (and the earlier mmap with memory block was succeeded by the new mmap2).


I think your function was added after all these changes so probably you should use registers only. Also in http://git.kernel.org/?p=linux/kernel/git/stable/linux-2.6.38.y.git;a=blob;f=arch/x86/ia32/ia32entry.S;h=518bb99c339480820fc3995b1456d29704d67f07;hb=HEAD#l386 you'll see EBP as well (although I'm not so sure if this is actual proof or if something happens earlier to get everything mapped as the comments say)
Post 28 Mar 2011, 22:27
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
I see now. And I understand why mmap2 didn't work, so I was forced to use old one. Smile
Thanks for the help.
Post 29 Mar 2011, 04:42
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.