flat assembler
Message board for the users of flat assembler.

Index > Linux > sys_select -> EFAULT (bad address)

Author
Thread Post new topic Reply to topic
z33ky



Joined: 24 May 2010
Posts: 5
Location: Germany
z33ky
Well, I have a new problem.
Now I'm trying to getting timed input via select.

Code:
format elf executable

entry main

;syscalls
SYSCALL_EXIT           equ 1
SYSCALL_READ           equ 3
SYSCALL_WRITE          equ 4
SYSCALL_SELECT         equ 82

;standard I/O
STDIN    equ 0
STDOUT equ 1

;useful special characters
LF   equ 0x0a

;various defines
__NFDBITS   equ 8 * 4
__NFD_SETSIZE      equ 1024

;structs
struc timeval secs, usec{
  .tv_secs dd secs ;seconds
   .tv_usec dd usec ;microseconds
}

;static data
segment readable writeable

fds rd __NFD_SETSIZE / __NFDBITS
t timeval 5,0

;--------
segment executable
main:
     ;clear fds
  mov eax, 0
  mov ecx, __NFD_SETSIZE / __NFDBITS
  mov edi, fds
        rep stos dword [edi]

    ;select
     bts [fds], STDIN
    mov eax, SYSCALL_SELECT
     mov ebx, STDIN + 1 ;nfds
    mov ecx, fds ;readfds
       xor edx, edx ;writefds
      xor esi, esi ;exceptfds
     mov edi, t ;timeout
 int 0x80

        test eax, eax ;eax -> -errno
     js exit

 ;exit normally
      mov eax, 0

exit:
 ;exit with error-code
       mov ebx, eax
        neg ebx
     mov eax, SYSCALL_EXIT
       int 0x80    

For some reason the error is EFAULT (bad address), though that's the least I'd expect, since fds and t are clearly valid memory.
Post 25 May 2010, 10:17
View user's profile Send private message Visit poster's website Reply with quote
z33ky



Joined: 24 May 2010
Posts: 5
Location: Germany
z33ky
Maybe someone else could test it on their Linux and see if they get the same result?
The value of __NFDBITS is in sys/select.h (the type __fd_mask as well) and __FD_SETSIZE (__NFD_SETSIZE in that assembly up there; typo) in bits/typesizes.h.
Post 26 May 2010, 12:49
View user's profile Send private message Visit poster's website Reply with quote
Endre



Joined: 29 Dec 2003
Posts: 212
Location: Budapest, Hungary
Endre
What if you change the line
Code:
SYSCALL_SELECT          equ 82    
to this one here
Code:
SYSCALL_SELECT          equ 142    


I think you want to use sys_select but you just call to old_select (note: Linux has two select syscalls, additionally they expect different parameters)
Post 26 May 2010, 13:00
View user's profile Send private message Reply with quote
z33ky



Joined: 24 May 2010
Posts: 5
Location: Germany
z33ky
Yes, that fixed it! Damn man pages; I thought "man select" would show the entry of old_select.
Thanks!
Post 26 May 2010, 13:48
View user's profile Send private message Visit poster's website 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 YouTube, Twitter.

Website powered by rwasa.