Python package for system calls information

Python is my favourite language. System calls table is my favourite side project. So why not merge them?

That’s how “system-calls” Python package was born.

Why?

Mostly because I could. And thought that maybe someone else will find it useful. Also found out that it allows me to learn how to build own Python package, how Pypi uploads work etc. stuff. And I can remind myself how packaging works as having it in Debian and Fedora would be useful experience.

What it can do?

Module allows to check information about Linux system calls in several ways:

Code for it is quite simple:

import system_calls

syscalls = system_calls.syscalls()

for test_call in ['openat', 'osf_uadmin', 'nosuchcall']:
    try:
        print(f"System call '{test_call}' has number: {syscalls[test_call]}")
    except system_calls.NoSuchSystemCall:
        print(f"No such system call '{test_call}' on any architecture")
    except system_calls.NotSupportedSystemCall:
        print(f"System call '{test_call}' is not supported on this "
              "architecture")

Above example shows usage for host architecture. But treating “system_calls.syscalls” as dictionary does not allow to ask for data of different architecture. For such use there is “get()” method:

import system_calls

syscalls = system_calls.syscalls()

for test_call in ['openat', 'osf_uadmin', 'nosuchcall']:
    try:
        print(f"System call '{test_call}' on arm64 has number: "
              f"{syscalls.get(test_call, 'arm64')}")
    except system_calls.NoSuchSystemCall:
        print(f"No such system call '{test_call}' on any architecture")
    except system_calls.NotSupportedSystemCall:
        print(f"System call '{test_call}' is not supported on this "
              "architecture")

You can also use “get()” method for host architecture as second argument is optional.

You can find more examples in project’s repository.

Extras

There is one bonus script in this project: “syscall”. Can be used to check for information about system calls for host or any supported architecture:

$ syscall open
On x86_64 system call number 2 is open()
$ syscall open arm64
On arm64 system call open() is not supported.
$ syscall 32
On x86_64 system call number 32 is dup()
$ syscall 32 arm64
On arm64 system call number 32 is flock()
$ syscall openat mipso32
On mipso32 system call number 4288 is openat()
$ syscall open noa
Architecture noa is not supported.
$ syscall nos
There is no such system call as nos().
$

Mistakes happen

When I wrote first version I did not thought about uploading it to Pypi and sharing with other users. And when I started packaging it for Fedora I realized that I made some serious mistake.

Package is called “system-calls” but code was stored in “syscalls” directory. Fixed that in 5.15.2 version so it is now stored in “system_calls” one.

5.15.3 has all tests and examples fixed to use proper names.

If you find some other issue then please report it in project’s repository.

Packaging

Fedora 35 and above have “python3-system-calls” package available in distribution repository.

Debian users can use my private APT repository. Not decided yet do I want to became Debian Maintainer/Developer.

development python syscalls