flat assembler
Message board for the users of flat assembler.

Index > Linux > linux 2.6+ system calls reference

Goto page Previous  1, 2, 3, 4
Author
Thread Post new topic Reply to topic
d.j.peters



Joined: 11 Aug 2004
Posts: 7
Location: Germany
d.j.peters 08 Aug 2010, 10:03
first sorry about my bad english.

i have a nobe question
what heppent if a 32 bit x86 binary with syscall execute on a 64 bit CPU with a 64 bit Linux distro ?

is it a unsupported instruction or exists a 32 bit syscall emulation on a 64 bit kernal ?

I can't test it, i have only one P4 and one 32 bit AMD Athlon linux box.

by the way
exist any 64 bit "software" CPU emulator for a 32 bit CPU ?
(like QEMU, Virtual Box, VM Ware, ...)

Thank you for any infos.

DJ

_________________
(sorry about my bad English)


Last edited by d.j.peters on 10 Aug 2010, 10:13; edited 1 time in total
Post 08 Aug 2010, 10:03
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 08 Aug 2010, 18:14
d.j.peters, Yes, I've tried it several times with Ubuntu for AMD64, using INT $80 from a 32-bit executable works correctly (and I think that also SYSENTER and maybe SYSCALL). In 64-bit, you should use SYSCALL instead (which is guaranteed to be available in both Intel and AMD). I think that INT $80 is also available in 64-bit, but I'm not sure (and it is slower anyway). Check the examples in the fasm for Linux package.
Post 08 Aug 2010, 18:14
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 02 Feb 2013, 14:14
Int 80h is supported in 64 bit Linux, so, all 32 bit ELF executables will work. The only possible problems is if the executable dynamically links to some 32 bit libraries. They are not installed by default, so the application will end with error.
Post 02 Feb 2013, 14:14
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
keantoken



Joined: 19 Mar 2008
Posts: 69
keantoken 27 Mar 2013, 01:58
Okay, let's look at the documentation for sys_clone. man clone:

Code:
On success, the thread ID of the child process is returned in the call
       er's thread of execution.  On failure, -1 is returned in  the  caller's
       context, no child process will be created, and errno will be set appro
       priately.    


And now the reference in the first post:

Code:
If the system call succeeds the return value is 0.
If the system call fails the return value is one of the following errno values:     


This is a direct contradiction. Also, doesn't anyone want to know what the return value is for the CHILD? Huh? How do you tell the child apart from the caller then!? It doesn't appear to be the same way it's done with sys_fork.
Post 27 Mar 2013, 01:58
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 27 Mar 2013, 06:15
keantoken wrote:
Okay, let's look at the documentation for sys_clone. man clone:

Code:
On success, the thread ID of the child process is returned in the call
       er's thread of execution.  On failure, -1 is returned in  the  caller's
       context, no child process will be created, and errno will be set appro
       priately.    



It seems to be the C/C++ wrapper description. There is no "errno" variable actually. The system calls return negative error codes instead.

_________________
Tox ID: 48C0321ADDB2FE5F644BB5E3D58B0D58C35E5BCBC81D7CD333633FEDF1047914A534256478D9
Post 27 Mar 2013, 06:15
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
randall



Joined: 03 Dec 2011
Posts: 155
Location: Poland
randall 27 Mar 2013, 15:11
keantoken wrote:
Okay, let's look at the documentation for sys_clone. man clone:

Code:
On success, the thread ID of the child process is returned in the call
       er's thread of execution.  On failure, -1 is returned in  the  caller's
       context, no child process will be created, and errno will be set appro
       priately.    


And now the reference in the first post:

Code:
If the system call succeeds the return value is 0.
If the system call fails the return value is one of the following errno values:     


This is a direct contradiction. Also, doesn't anyone want to know what the return value is for the CHILD? Huh? How do you tell the child apart from the caller then!? It doesn't appear to be the same way it's done with sys_fork.


sys_clone returns thread id (value grater than zero) in the parent thread and zero in the child thread.

For example:

Code:
        sys_clone
        test eax,eax
        jnz .L0
        ; child
        pop rsi rdi
        call rsi
        sys_exit 0
.L0:  ; parent
    
Post 27 Mar 2013, 15:11
View user's profile Send private message Visit poster's website Reply with quote
keantoken



Joined: 19 Mar 2008
Posts: 69
keantoken 28 Mar 2013, 00:57
Thanks!

You'd think that crucial detail would be included in the linux manpages..?

I did figure out the errno thing eventually.
Post 28 Mar 2013, 00:57
View user's profile Send private message Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 13041
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 0010456
sleepsleep 26 Jun 2013, 21:45
arafel wrote:
Hi,

I want to introduce a small project which came to life a couple of month ago.
You may get it from here (grab the latest release): http://sourceforge.net/project/showfiles.php?group_id=173983

It's a reference for Linux 2.6+ system calls. Which provides a description of (almost)all system calls found in kernel 2.6 and later branches from Assembly point of view Smile
Also it includes a set of include files for FASM and GAS with structures and symbol definitions necessary for programming with syscalls.
And also there is a number (currently only two..) of examples provided which demonstrate some syscalls usage.

The project is currently in an alpha stage. A lot of things has not been verified yet, so please take this into account Wink .

Hope someone will find it useful.


great and thanks!
Post 26 Jun 2013, 21:45
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 23 Feb 2014, 15:44
The lscr help pages about Linux system calls are now accessible online on: http://fresh.flatassembler.net/lscr/
Post 23 Feb 2014, 15:44
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
FlierMate



Joined: 21 Jan 2021
Posts: 219
FlierMate 02 Oct 2021, 06:25
JohnFound wrote:
The lscr help pages about Linux system calls are now accessible online on: http://fresh.flatassembler.net/lscr/


It is very handy to categorize them as tree view, but those are 32-bit system call numbers.

Do you happen to have similar list of 64-bit system call numbers in tree view?
Post 02 Oct 2021, 06:25
View user's profile Send private message Reply with quote
Ali.Z



Joined: 08 Jan 2018
Posts: 732
Ali.Z 03 Oct 2021, 22:48
there is no official reference for system calls in assembly, however many people have built their own from linux source.

the best imo is consult the man pages, and please dont check the man pages online; check them locally, i.e. man command.

things to do:
- read "/usr/include/x86_64-linux-gnu/asm/unistd_64.h"
- execute "man 2 syscall"
- execute "man ..." replace the dots with your desired function name to get its return value/errno and arg list. (e.g. "man lseek")

the header file lists all functions and their numbers, and syscall man page gives you info regarding your target architecture; calling conventions and few other things.


Description:
Filesize: 392.84 KB
Viewed: 9419 Time(s)

Screenshot_2021-10-03_15-47-46.png



_________________
Asm For Wise Humans
Post 03 Oct 2021, 22:48
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4073
Location: vpcmpistri
bitRAKE 04 Oct 2021, 03:19
There is a handy compact table at:
https://github.com/torvalds/linux/blob/master/arch/x86/entry/syscalls/syscall_64.tbl

Looking at the source, it is interesting to note that although many seem to use RAX for the call number, EAX is always extended as the value type is int. These kinds of discrepancies have me always wanting to grep the source to understand the correct typing of parameters.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 04 Oct 2021, 03:19
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:  
Goto page Previous  1, 2, 3, 4

< 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.