• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..15-Mar-2021-

tests/H15-Mar-2021-437209

.gitignoreH A D15-Mar-202110 42

README.mdH A D15-Mar-20215.7 KiB13897

codereview.settingsH A D15-Mar-2021261 65

linux_syscall_support.hH A D15-Mar-2021179.7 KiB4,5543,878

README.md

1# Linux Syscall Support (LSS)
2
3Every so often, projects need to directly embed Linux system calls instead of
4calling the implementations in the system runtime library.
5
6This project provides a header file that can be included into your application
7whenever you need to make direct system calls.
8
9The goal is to provide an API that generally mirrors the standard C library
10while still making direct syscalls.  We try to hide some of the differences
11between arches when reasonably feasible.  e.g. Newer architectures no longer
12provide an `open` syscall, but do provide `openat`.  We will still expose a
13`sys_open` helper by default that calls into `openat` instead.
14
15We explicitly do not expose the raw syscall ABI including all of its historical
16warts to the user.  We want people to be able to easily make a syscall, not have
17to worry that on some arches size args are swapped or they are shifted.
18
19Please be sure to review the Caveats section below however.
20
21## How to include linux\_syscall\_support.h in your project
22
23You can either copy the file into your project, or preferably, you can set up
24Git submodules to automatically pull from our source repository.
25
26## Supported targets
27
28The following architectures/ABIs have been tested (at some point) and should
29generally work.  If you don't see your combo listed here, please double check
30the header itself as this list might be out of date.
31
32* x86 32-bit (i.e. i386, i486, i586, i686, Intel, AMD, etc...)
33* [x86_64 64-bit](https://en.wikipedia.org/wiki/X86-64) (i.e. x86-64, amd64, etc...)
34* [x32 32-bit](https://sites.google.com/site/x32abi/)
35* [ARM 32-bit](https://en.wikipedia.org/wiki/ARM_architecture) OABI
36* [ARM 32-bit](https://en.wikipedia.org/wiki/ARM_architecture) EABI (i.e. armv6, armv7, etc...)
37* AARCH64 64-bit (i.e. arm64, armv8, etc...)
38* PowerPC 32-bit (i.e. ppc, ppc32, etc...)
39* MIPS 32-bit o32 ABI
40* MIPS 32-bit n32 ABI
41* MIPS 64-bit n64 ABI
42
43## API
44
45By default, you can just add a `sys_` prefix to any function you want to call.
46So if you want to call `open(...)`, use `sys_open(...)` instead.
47
48### Knobs
49
50The linux\_syscall\_support.h header provides many knobs for you to control
51the exported API.  These are all documented in the top of the header in a big
52comment block, so refer to that instead.
53
54## Caveats
55
56### ABI differences
57
58Some functions that the standard C library exposes use a different ABI than
59what the Linux kernel uses.  Care must be taken when making syscalls directly
60that you use the right structure and flags.  e.g. Most C libraries define a
61`struct stat` (commonly in `sys/stat.h` or `bits/stat.h`) that is different
62from the `struct stat` the kernel uses (commonly in `asm/stat.h`).  If you use
63the wrong structure layout, then you can see errors like memory corruption or
64weird/shifted values.  If you plan on making syscalls directly, you should
65focus on headers that are available under the `linux/` and `asm/` namespaces.
66
67Note: LSS provides structs for most of these cases.  For `sys_stat()`, it
68provides `struct kernel_stat` for you to use.
69
70### Transparent backwards compatibility with older kernels
71
72While some C libraries (notably, glibc) take care to fallback to older syscalls
73when running on older kernels, there is no such support in LSS.  If you plan on
74trying to run on older kernels, you will need to handle errors yourself (e.g.
75`ENOSYS` when using a too new syscall).
76
77Remember that this can happen with new flag bits too.  e.g. The `O_CLOEXEC`
78flag was added to many syscalls, but if you try to run use it on older kernels,
79it will fail with `EINVAL`.  In that case, you must handle the fallback logic
80yourself.
81
82### Variable arguments (varargs)
83
84We do not support vararg type functions.  e.g. While the standard `open()`
85function can accept 2 or 3 arguments (with the mode field being optional),
86the `sys_open()` function always requires 3 arguments.
87
88## Bug reports & feature requests
89
90If you wish to report a problem or request a feature, please file them in our
91[bug tracker](https://bugs.chromium.org/p/linux-syscall-support/issues/).
92
93Please do not post patches to the tracker.  Instead, see below for how to send
94patches to us directly.
95
96While we welcome feature requests, please keep in mind that it is unlikely that
97anyone will find time to implement them for you.  Sending patches is strongly
98preferred and will often move things much faster.
99
100## Projects that use LSS
101
102* [Chromium](https://www.chromium.org/)
103* [Breakpad](https://chromium.googlesource.com/breakpad/breakpad)
104* [Native Client](https://developer.chrome.com/native-client), in nacl\_bootstrap.c
105
106## How to get an LSS change committed
107
108### Review
109
110You get your change reviewed, you can upload it to
111[Gerrit](https://chromium-review.googlesource.com/q/project:linux-syscall-support+status:open)
112using `git cl upload` from
113[Chromium's depot-tools](https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html).
114
115### Testing
116
117Tests are found in the [tests/](./tests/) subdirectory.  It does not (yet) offer
118100% coverage, but should grow over time.
119
120New commits that update/change/add syscall wrappers should include tests for
121them too.  Consult the [test documentation](./tests/README.md) for more details.
122
123To run, just run `make` inside the tests directory.  It will compile & execute
124the tests locally.
125
126There is some limited cross-compile coverage available if you run `make cross`.
127It only compiles things (does not execute at all).
128
129### Rolling into Chromium
130
131If you commit a change to LSS, please also commit a Chromium change to update
132`lss_revision` in
133[Chromium's DEPS](https://chromium.googlesource.com/chromium/src/+/master/DEPS)
134file.
135
136This ensures that the LSS change gets tested, so that people who commit later
137LSS changes don't run into problems with updating `lss_revision`.
138