It is currently Wed Jan 27, 2021 5:04 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Linux systemcall x86 and x64
PostPosted: Thu Jan 14, 2016 6:07 pm 
Offline
Always Here
Always Here

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 5219
Location: Germany
Hi,

big problem with small code.

This works on x86:
Code:
Procedure.i inotify_init()
    !mov  eax, 291
    !xor  ebx, ebx
    !xor  ecx, ecx
    !xor  edx, edx
    !int  byte  0x80
    !test eax, eax
    !js   _inotify_init_error                            ;Jump short if sign (SF=1) (if <> 0 => error)
    ProcedureReturn                               ; return value in EAX
    !_inotify_init_error:
    !mov  [v_inotify_errno], eax
    ProcedureReturn -1
EndProcedure


But this works not on x64:
Code:
Procedure.i inotify_init()
    !mov  rax, 253
    !xor  rbx, rbx
    !xor  rcx, rcx
    !xor  rdx, rdx
    !int  byte  0x80
    !test rax, rax
    !js   _inotify_init_error                            ;Jump short if sign (SF=1) (if <> 0 => error)
    ProcedureReturn                               ; return value in RAX
    !_inotify_init_error:
    !mov  [v_inotify_errno], rax
    ProcedureReturn -1
EndProcedure


On x64 it returns -1

The diifferent values for the same function (291 and 253) should be correct.

Any ideas?

Bernd

P.S.: I don't want to install libnotify, because this installs many things of X and I have only a small console only system.


Top
 Profile  
Reply with quote  
 Post subject: Re: Linux systemcall x86 and x64
PostPosted: Fri Jan 15, 2016 11:02 am 
Offline
Always Here
Always Here

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 5219
Location: Germany
Ok,

first bug found:

in x64 you have to use
Code:
!syscall

instead of
Code:
!int byte 0x80


inotify_init() works now.
But now I stuck at inotify_add_watch() :cry:

Bernd


Top
 Profile  
Reply with quote  
 Post subject: Re: Linux systemcall x86 and x64
PostPosted: Fri Jan 15, 2016 11:24 am 
Offline
Always Here
Always Here

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 5219
Location: Germany
Ok,

works now.

Also the registers are different:

http://man7.org/linux/man-pages/man2/syscall.2.html

Code:
  Procedure.i inotify_init()
    !mov  rax, 253
    !xor  rdi, rdi
    !xor  rsi, rsi
    !xor  rdx, rdx
    !syscall
    !test rax, rax
    !js   _inotify_init_error     ;Jump short if sign (SF=1) (if <> 0 => error)
    ProcedureReturn               ; return value in RAX
    !_inotify_init_error:
    !mov  [v_inotify_errno], rax
    ProcedureReturn -1
  EndProcedure


Hope this helps someone to save many hours.

Bernd


Top
 Profile  
Reply with quote  
 Post subject: Re: Linux systemcall x86 and x64
PostPosted: Sat Jan 16, 2016 8:30 pm 
Offline
Addict
Addict
User avatar

Joined: Fri Sep 21, 2007 5:52 am
Posts: 3556
Location: New Zealand
here's a link to a linux x64 sys call table
http://blog.rchapman.org/post/368010388 ... for-x86-64

Code:
Global inotify_errno

Procedure.i inotify_init()
    !mov  rax, 253
    !syscall
    !test rax, rax
    !js   _inotify_init_error     ;Jump short if sign (SF=1) (if <> 0 => error)
    ProcedureReturn               ; return value in RAX
    !_inotify_init_error:
    !mov  [v_inotify_errno], rax
    ProcedureReturn -1
  EndProcedure
 
Procedure.i inotify_add_watch(fd.l,charpath.s,mask.i)    ;rdi rsi rdx r10 r8 r9
  !mov rax, 254
  !mov rdi, [p.v_fd]
  !mov rsi, [p.v_charpath]
  !mov rdx, [p.v_mask]
  !syscall
  !test rax, rax
  !js   _inotify_add_error     ;Jump short if sign (SF=1) (if <> 0 => error)
    ProcedureReturn               ; return value in RAX
  !_inotify_add_error:
  !mov  [v_inotify_errno], rax
    ProcedureReturn -1
EndProcedure     

Procedure inotify_rm_watch(fd.l,wd.i)
  !mov rax, 255
  !mov rdi, [p.v_fd]
  !mov rsi, [p.v_wd]
  !syscall
  !test rax, rax
  !js   _inotify_rm_error     ;Jump short if sign (SF=1) (if <> 0 => error)
    ProcedureReturn               ; return value in RAX
  !_inotify_rm_error:
  !mov  [v_inotify_errno], rax
    ProcedureReturn -1
EndProcedure     

Procedure sys_read(fd,*buffer,size)
  !mov rax, 0
  !mov rdi, [p.v_fd]
  !mov rsi, [p.p_buffer]
  !mov rdx, [p.v_size]
  !syscall
  !test rax, rax
  !js   _sys_read_error     ;Jump short if sign (SF=1) (if <> 0 => error)
    ProcedureReturn               ; return value in RAX
  !_sys_read_error:
  !mov  [v_inotify_errno], rax
    ProcedureReturn -1
EndProcedure     


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


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

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye