flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Linux > System calls .inc files

Author
Thread Post new topic Reply to topic
triplefault



Joined: 28 Mar 2012
Posts: 12
System calls .inc files
Edit: as pointed out by alkap, this regex misses a few syscalls, see his answer below this one for a command that doesn't miss any of them.

I am a particularly lazy person so having to manually maintain an include file with system call numbers is not something I want to do. A few months ago I wrote a one-liner to automatically generate those files and now I'm sharing it here because I figured it could be useful to someone.
Note: I am using Debian x86_64 multiarch, the location of these files may be different in your distro. In Debian you must have the package linux-libc-dev installed because it provides the required files.

For the 32 bit calls I use:

Code:
sed -n 's/#define\s\s*[_A-Z][_A-Z]*//p' /usr/include/asm/unistd_32.h | sed -n 's/^\([a-z][_a-z]*\)\s\s*\([0-9][0-9]*\)/sys_\1 = \2/p' > lin32.inc


And for 64 bit I use:

Code:
sed -n 's/#define\s\s*[_A-Z][_A-Z]*//p' /usr/include/asm/unistd_64.h | sed -n 's/^\([a-z][_a-z]*\)\s\s*\([0-9][0-9]*\)/sys_\1 = \2/p' > lin64.inc


The command is the same for both files, only file names are changed. If you can't find the files in that location you can use locate <file> to search for them. These files contain all system calls in the format #define __NR_syscall_name syscall_number.

_________________


Last edited by triplefault on 14 Jul 2017, 02:09; edited 1 time in total
Post 13 Jul 2017, 03:27
View user's profile Send private message Reply with quote
alkap



Joined: 18 Feb 2015
Posts: 39
Location: Dnipro, Ukraine
You don't seem to capture all the system calls there are, as far as I can tell:

Code:

sed -n 's/#define\s\s*[_A-Z][_A-Z]*//p' /usr/include/asm/unistd_32.h | sed -n 's/^\([a-z][_a-z]*\)\s\s*\([0-9][0-9]*\)/sys_\1 = \2/p' | wc -l
303




Matching all the defines containing the NR pattern adds up to several more syscalls. See below.

Code:

sed '/NR/!d;s/#define[^a-z]*//;s/^/sys_/;s/ / = /' /usr/include/asm/unistd_32.h | wc -l
351




The same goes for the 64-bit include file:

Code:

sed -n 's/#define\s\s*[_A-Z][_A-Z]*//p' /usr/include/asm/unistd_64.h | sed -n 's/^\([a-z][_a-z]*\)\s\s*\([0-9][0-9]*\)/sys_\1 = \2/p' | wc -l
303





Code:

sed '/NR/!d;s/#define[^a-z]*//;s/^/sys_/;s/ / = /' /usr/include/asm/unistd_64.h | wc -l
320


Post 13 Jul 2017, 11:34
View user's profile Send private message Send e-mail Reply with quote
triplefault



Joined: 28 Mar 2012
Posts: 12

alkap wrote:
Matching all the defines containing the NR pattern adds up to several more syscalls.



You are absolutely right, my regex doesn't match syscalls that contain numbers in their names (like sys_vm86). Thank you for fixing and simplifying it.

_________________
Post 14 Jul 2017, 02:07
View user's profile Send private message Reply with quote
alkap



Joined: 18 Feb 2015
Posts: 39
Location: Dnipro, Ukraine
No worries at all.
Thanks for sharing this method of retrieving the syscalls.
Post 14 Jul 2017, 05:36
View user's profile Send private message Send e-mail Reply with quote
alkap



Joined: 18 Feb 2015
Posts: 39
Location: Dnipro, Ukraine
In retrospect, expressions 2 and 3 can be combined, like so:

Code:

sed '/NR/!d;s/#define[^a-z]*/sys_/;s/ / = /' /usr/include/asm/unistd_32.h
sed '/NR/!d;s/#define[^a-z]*/sys_/;s/ / = /' /usr/include/asm/unistd_64.h


Post 14 Jul 2017, 19:55
View user's profile Send private message Send e-mail 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


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.