Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using select() syscall in linux -- at&t syntax

Status
Not open for further replies.

comsatcat

Programmer
Jul 21, 2007
1
US
Hello,

I'm new to assembly so I'm having a bit of trouble interfacing with the linux system call SYS_select. My problem is I can not seem to correctly build the fd_set structure, and then add the file descriptors to it (FD_SET(descriptor, &fds) in C).

Could someone please provide an example of working with file descriptors and select()?


Here is my current code:

mov %esp, %ebp
// allocate space for fd_set --
// this was taken from a disassemble of fd_set fd;
sub $0x94, %esp

// move socket descriptor into eax from previous
// connect call
mov %edi, %eax

// assign the socket descriptor (FD_SET(eax, &fd))
bts %eax, 0xffffff7c(%ebp)

// move server socket descriptor into eax from
// previous accept call
mov %esi, %eax

// assign the socket descriptor (FD_SET(eax, &fd))
bts %eax, 0xffffff7c(%ebp)

// store &fds into eax
lea 0xffffff7c(%ebp), %ecx

// argv[1] - number of fds+1
mov $0x3, %ebx

// argv[2] - argv[4]
xor %edx, %edx
xor %esi, %esi
xor %edi, %edi

// index into syscall table for select()
movb $142, %al
int $0x80
 
Where is your equivalent of FD_CLR() ?

Also, please use [code][/code] tags when posting code.

Also, you can learn a lot by doing
[tt]gcc -S -c prog.c[/tt]
where prog.c contains the equivalent 'C' fragment, and then studying the resultant prog.s file.

> bts %eax, 0xffffff7c(%ebp)
This is only going to work on the low numbered fd's.
The FD_SET is an array of bits, where %eax / 32 is the array subscript, and %eax modulo 32 is the bit position.

> // argv[1] - number of fds+1
Are you sure about this?
The first parameter to select from the 'C' interface is the highest numbered fd+1, not the number of fd+1
So if you had fd's 0, 1 and 10
the correct value would be 11, not 4


--
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top