Back to home page

OSCL-LXR

 
 

    


0001 
0002 .. _addsyscalls:
0003 
0004 Adding a New System Call
0005 ========================
0006 
0007 This document describes what's involved in adding a new system call to the
0008 Linux kernel, over and above the normal submission advice in
0009 :ref:`Documentation/process/submitting-patches.rst <submittingpatches>`.
0010 
0011 
0012 System Call Alternatives
0013 ------------------------
0014 
0015 The first thing to consider when adding a new system call is whether one of
0016 the alternatives might be suitable instead.  Although system calls are the
0017 most traditional and most obvious interaction points between userspace and the
0018 kernel, there are other possibilities -- choose what fits best for your
0019 interface.
0020 
0021  - If the operations involved can be made to look like a filesystem-like
0022    object, it may make more sense to create a new filesystem or device.  This
0023    also makes it easier to encapsulate the new functionality in a kernel module
0024    rather than requiring it to be built into the main kernel.
0025 
0026      - If the new functionality involves operations where the kernel notifies
0027        userspace that something has happened, then returning a new file
0028        descriptor for the relevant object allows userspace to use
0029        ``poll``/``select``/``epoll`` to receive that notification.
0030      - However, operations that don't map to
0031        :manpage:`read(2)`/:manpage:`write(2)`-like operations
0032        have to be implemented as :manpage:`ioctl(2)` requests, which can lead
0033        to a somewhat opaque API.
0034 
0035  - If you're just exposing runtime system information, a new node in sysfs
0036    (see ``Documentation/filesystems/sysfs.rst``) or the ``/proc`` filesystem may
0037    be more appropriate.  However, access to these mechanisms requires that the
0038    relevant filesystem is mounted, which might not always be the case (e.g.
0039    in a namespaced/sandboxed/chrooted environment).  Avoid adding any API to
0040    debugfs, as this is not considered a 'production' interface to userspace.
0041  - If the operation is specific to a particular file or file descriptor, then
0042    an additional :manpage:`fcntl(2)` command option may be more appropriate.  However,
0043    :manpage:`fcntl(2)` is a multiplexing system call that hides a lot of complexity, so
0044    this option is best for when the new function is closely analogous to
0045    existing :manpage:`fcntl(2)` functionality, or the new functionality is very simple
0046    (for example, getting/setting a simple flag related to a file descriptor).
0047  - If the operation is specific to a particular task or process, then an
0048    additional :manpage:`prctl(2)` command option may be more appropriate.  As
0049    with :manpage:`fcntl(2)`, this system call is a complicated multiplexor so
0050    is best reserved for near-analogs of existing ``prctl()`` commands or
0051    getting/setting a simple flag related to a process.
0052 
0053 
0054 Designing the API: Planning for Extension
0055 -----------------------------------------
0056 
0057 A new system call forms part of the API of the kernel, and has to be supported
0058 indefinitely.  As such, it's a very good idea to explicitly discuss the
0059 interface on the kernel mailing list, and it's important to plan for future
0060 extensions of the interface.
0061 
0062 (The syscall table is littered with historical examples where this wasn't done,
0063 together with the corresponding follow-up system calls --
0064 ``eventfd``/``eventfd2``, ``dup2``/``dup3``, ``inotify_init``/``inotify_init1``,
0065 ``pipe``/``pipe2``, ``renameat``/``renameat2`` -- so
0066 learn from the history of the kernel and plan for extensions from the start.)
0067 
0068 For simpler system calls that only take a couple of arguments, the preferred
0069 way to allow for future extensibility is to include a flags argument to the
0070 system call.  To make sure that userspace programs can safely use flags
0071 between kernel versions, check whether the flags value holds any unknown
0072 flags, and reject the system call (with ``EINVAL``) if it does::
0073 
0074     if (flags & ~(THING_FLAG1 | THING_FLAG2 | THING_FLAG3))
0075         return -EINVAL;
0076 
0077 (If no flags values are used yet, check that the flags argument is zero.)
0078 
0079 For more sophisticated system calls that involve a larger number of arguments,
0080 it's preferred to encapsulate the majority of the arguments into a structure
0081 that is passed in by pointer.  Such a structure can cope with future extension
0082 by including a size argument in the structure::
0083 
0084     struct xyzzy_params {
0085         u32 size; /* userspace sets p->size = sizeof(struct xyzzy_params) */
0086         u32 param_1;
0087         u64 param_2;
0088         u64 param_3;
0089     };
0090 
0091 As long as any subsequently added field, say ``param_4``, is designed so that a
0092 zero value gives the previous behaviour, then this allows both directions of
0093 version mismatch:
0094 
0095  - To cope with a later userspace program calling an older kernel, the kernel
0096    code should check that any memory beyond the size of the structure that it
0097    expects is zero (effectively checking that ``param_4 == 0``).
0098  - To cope with an older userspace program calling a newer kernel, the kernel
0099    code can zero-extend a smaller instance of the structure (effectively
0100    setting ``param_4 = 0``).
0101 
0102 See :manpage:`perf_event_open(2)` and the ``perf_copy_attr()`` function (in
0103 ``kernel/events/core.c``) for an example of this approach.
0104 
0105 
0106 Designing the API: Other Considerations
0107 ---------------------------------------
0108 
0109 If your new system call allows userspace to refer to a kernel object, it
0110 should use a file descriptor as the handle for that object -- don't invent a
0111 new type of userspace object handle when the kernel already has mechanisms and
0112 well-defined semantics for using file descriptors.
0113 
0114 If your new :manpage:`xyzzy(2)` system call does return a new file descriptor,
0115 then the flags argument should include a value that is equivalent to setting
0116 ``O_CLOEXEC`` on the new FD.  This makes it possible for userspace to close
0117 the timing window between ``xyzzy()`` and calling
0118 ``fcntl(fd, F_SETFD, FD_CLOEXEC)``, where an unexpected ``fork()`` and
0119 ``execve()`` in another thread could leak a descriptor to
0120 the exec'ed program. (However, resist the temptation to re-use the actual value
0121 of the ``O_CLOEXEC`` constant, as it is architecture-specific and is part of a
0122 numbering space of ``O_*`` flags that is fairly full.)
0123 
0124 If your system call returns a new file descriptor, you should also consider
0125 what it means to use the :manpage:`poll(2)` family of system calls on that file
0126 descriptor. Making a file descriptor ready for reading or writing is the
0127 normal way for the kernel to indicate to userspace that an event has
0128 occurred on the corresponding kernel object.
0129 
0130 If your new :manpage:`xyzzy(2)` system call involves a filename argument::
0131 
0132     int sys_xyzzy(const char __user *path, ..., unsigned int flags);
0133 
0134 you should also consider whether an :manpage:`xyzzyat(2)` version is more appropriate::
0135 
0136     int sys_xyzzyat(int dfd, const char __user *path, ..., unsigned int flags);
0137 
0138 This allows more flexibility for how userspace specifies the file in question;
0139 in particular it allows userspace to request the functionality for an
0140 already-opened file descriptor using the ``AT_EMPTY_PATH`` flag, effectively
0141 giving an :manpage:`fxyzzy(3)` operation for free::
0142 
0143  - xyzzyat(AT_FDCWD, path, ..., 0) is equivalent to xyzzy(path,...)
0144  - xyzzyat(fd, "", ..., AT_EMPTY_PATH) is equivalent to fxyzzy(fd, ...)
0145 
0146 (For more details on the rationale of the \*at() calls, see the
0147 :manpage:`openat(2)` man page; for an example of AT_EMPTY_PATH, see the
0148 :manpage:`fstatat(2)` man page.)
0149 
0150 If your new :manpage:`xyzzy(2)` system call involves a parameter describing an
0151 offset within a file, make its type ``loff_t`` so that 64-bit offsets can be
0152 supported even on 32-bit architectures.
0153 
0154 If your new :manpage:`xyzzy(2)` system call involves privileged functionality,
0155 it needs to be governed by the appropriate Linux capability bit (checked with
0156 a call to ``capable()``), as described in the :manpage:`capabilities(7)` man
0157 page.  Choose an existing capability bit that governs related functionality,
0158 but try to avoid combining lots of only vaguely related functions together
0159 under the same bit, as this goes against capabilities' purpose of splitting
0160 the power of root.  In particular, avoid adding new uses of the already
0161 overly-general ``CAP_SYS_ADMIN`` capability.
0162 
0163 If your new :manpage:`xyzzy(2)` system call manipulates a process other than
0164 the calling process, it should be restricted (using a call to
0165 ``ptrace_may_access()``) so that only a calling process with the same
0166 permissions as the target process, or with the necessary capabilities, can
0167 manipulate the target process.
0168 
0169 Finally, be aware that some non-x86 architectures have an easier time if
0170 system call parameters that are explicitly 64-bit fall on odd-numbered
0171 arguments (i.e. parameter 1, 3, 5), to allow use of contiguous pairs of 32-bit
0172 registers.  (This concern does not apply if the arguments are part of a
0173 structure that's passed in by pointer.)
0174 
0175 
0176 Proposing the API
0177 -----------------
0178 
0179 To make new system calls easy to review, it's best to divide up the patchset
0180 into separate chunks.  These should include at least the following items as
0181 distinct commits (each of which is described further below):
0182 
0183  - The core implementation of the system call, together with prototypes,
0184    generic numbering, Kconfig changes and fallback stub implementation.
0185  - Wiring up of the new system call for one particular architecture, usually
0186    x86 (including all of x86_64, x86_32 and x32).
0187  - A demonstration of the use of the new system call in userspace via a
0188    selftest in ``tools/testing/selftests/``.
0189  - A draft man-page for the new system call, either as plain text in the
0190    cover letter, or as a patch to the (separate) man-pages repository.
0191 
0192 New system call proposals, like any change to the kernel's API, should always
0193 be cc'ed to linux-api@vger.kernel.org.
0194 
0195 
0196 Generic System Call Implementation
0197 ----------------------------------
0198 
0199 The main entry point for your new :manpage:`xyzzy(2)` system call will be called
0200 ``sys_xyzzy()``, but you add this entry point with the appropriate
0201 ``SYSCALL_DEFINEn()`` macro rather than explicitly.  The 'n' indicates the
0202 number of arguments to the system call, and the macro takes the system call name
0203 followed by the (type, name) pairs for the parameters as arguments.  Using
0204 this macro allows metadata about the new system call to be made available for
0205 other tools.
0206 
0207 The new entry point also needs a corresponding function prototype, in
0208 ``include/linux/syscalls.h``, marked as asmlinkage to match the way that system
0209 calls are invoked::
0210 
0211     asmlinkage long sys_xyzzy(...);
0212 
0213 Some architectures (e.g. x86) have their own architecture-specific syscall
0214 tables, but several other architectures share a generic syscall table. Add your
0215 new system call to the generic list by adding an entry to the list in
0216 ``include/uapi/asm-generic/unistd.h``::
0217 
0218     #define __NR_xyzzy 292
0219     __SYSCALL(__NR_xyzzy, sys_xyzzy)
0220 
0221 Also update the __NR_syscalls count to reflect the additional system call, and
0222 note that if multiple new system calls are added in the same merge window,
0223 your new syscall number may get adjusted to resolve conflicts.
0224 
0225 The file ``kernel/sys_ni.c`` provides a fallback stub implementation of each
0226 system call, returning ``-ENOSYS``.  Add your new system call here too::
0227 
0228     COND_SYSCALL(xyzzy);
0229 
0230 Your new kernel functionality, and the system call that controls it, should
0231 normally be optional, so add a ``CONFIG`` option (typically to
0232 ``init/Kconfig``) for it. As usual for new ``CONFIG`` options:
0233 
0234  - Include a description of the new functionality and system call controlled
0235    by the option.
0236  - Make the option depend on EXPERT if it should be hidden from normal users.
0237  - Make any new source files implementing the function dependent on the CONFIG
0238    option in the Makefile (e.g. ``obj-$(CONFIG_XYZZY_SYSCALL) += xyzzy.o``).
0239  - Double check that the kernel still builds with the new CONFIG option turned
0240    off.
0241 
0242 To summarize, you need a commit that includes:
0243 
0244  - ``CONFIG`` option for the new function, normally in ``init/Kconfig``
0245  - ``SYSCALL_DEFINEn(xyzzy, ...)`` for the entry point
0246  - corresponding prototype in ``include/linux/syscalls.h``
0247  - generic table entry in ``include/uapi/asm-generic/unistd.h``
0248  - fallback stub in ``kernel/sys_ni.c``
0249 
0250 
0251 x86 System Call Implementation
0252 ------------------------------
0253 
0254 To wire up your new system call for x86 platforms, you need to update the
0255 master syscall tables.  Assuming your new system call isn't special in some
0256 way (see below), this involves a "common" entry (for x86_64 and x32) in
0257 arch/x86/entry/syscalls/syscall_64.tbl::
0258 
0259     333   common   xyzzy     sys_xyzzy
0260 
0261 and an "i386" entry in ``arch/x86/entry/syscalls/syscall_32.tbl``::
0262 
0263     380   i386     xyzzy     sys_xyzzy
0264 
0265 Again, these numbers are liable to be changed if there are conflicts in the
0266 relevant merge window.
0267 
0268 
0269 Compatibility System Calls (Generic)
0270 ------------------------------------
0271 
0272 For most system calls the same 64-bit implementation can be invoked even when
0273 the userspace program is itself 32-bit; even if the system call's parameters
0274 include an explicit pointer, this is handled transparently.
0275 
0276 However, there are a couple of situations where a compatibility layer is
0277 needed to cope with size differences between 32-bit and 64-bit.
0278 
0279 The first is if the 64-bit kernel also supports 32-bit userspace programs, and
0280 so needs to parse areas of (``__user``) memory that could hold either 32-bit or
0281 64-bit values.  In particular, this is needed whenever a system call argument
0282 is:
0283 
0284  - a pointer to a pointer
0285  - a pointer to a struct containing a pointer (e.g. ``struct iovec __user *``)
0286  - a pointer to a varying sized integral type (``time_t``, ``off_t``,
0287    ``long``, ...)
0288  - a pointer to a struct containing a varying sized integral type.
0289 
0290 The second situation that requires a compatibility layer is if one of the
0291 system call's arguments has a type that is explicitly 64-bit even on a 32-bit
0292 architecture, for example ``loff_t`` or ``__u64``.  In this case, a value that
0293 arrives at a 64-bit kernel from a 32-bit application will be split into two
0294 32-bit values, which then need to be re-assembled in the compatibility layer.
0295 
0296 (Note that a system call argument that's a pointer to an explicit 64-bit type
0297 does **not** need a compatibility layer; for example, :manpage:`splice(2)`'s arguments of
0298 type ``loff_t __user *`` do not trigger the need for a ``compat_`` system call.)
0299 
0300 The compatibility version of the system call is called ``compat_sys_xyzzy()``,
0301 and is added with the ``COMPAT_SYSCALL_DEFINEn()`` macro, analogously to
0302 SYSCALL_DEFINEn.  This version of the implementation runs as part of a 64-bit
0303 kernel, but expects to receive 32-bit parameter values and does whatever is
0304 needed to deal with them.  (Typically, the ``compat_sys_`` version converts the
0305 values to 64-bit versions and either calls on to the ``sys_`` version, or both of
0306 them call a common inner implementation function.)
0307 
0308 The compat entry point also needs a corresponding function prototype, in
0309 ``include/linux/compat.h``, marked as asmlinkage to match the way that system
0310 calls are invoked::
0311 
0312     asmlinkage long compat_sys_xyzzy(...);
0313 
0314 If the system call involves a structure that is laid out differently on 32-bit
0315 and 64-bit systems, say ``struct xyzzy_args``, then the include/linux/compat.h
0316 header file should also include a compat version of the structure (``struct
0317 compat_xyzzy_args``) where each variable-size field has the appropriate
0318 ``compat_`` type that corresponds to the type in ``struct xyzzy_args``.  The
0319 ``compat_sys_xyzzy()`` routine can then use this ``compat_`` structure to
0320 parse the arguments from a 32-bit invocation.
0321 
0322 For example, if there are fields::
0323 
0324     struct xyzzy_args {
0325         const char __user *ptr;
0326         __kernel_long_t varying_val;
0327         u64 fixed_val;
0328         /* ... */
0329     };
0330 
0331 in struct xyzzy_args, then struct compat_xyzzy_args would have::
0332 
0333     struct compat_xyzzy_args {
0334         compat_uptr_t ptr;
0335         compat_long_t varying_val;
0336         u64 fixed_val;
0337         /* ... */
0338     };
0339 
0340 The generic system call list also needs adjusting to allow for the compat
0341 version; the entry in ``include/uapi/asm-generic/unistd.h`` should use
0342 ``__SC_COMP`` rather than ``__SYSCALL``::
0343 
0344     #define __NR_xyzzy 292
0345     __SC_COMP(__NR_xyzzy, sys_xyzzy, compat_sys_xyzzy)
0346 
0347 To summarize, you need:
0348 
0349  - a ``COMPAT_SYSCALL_DEFINEn(xyzzy, ...)`` for the compat entry point
0350  - corresponding prototype in ``include/linux/compat.h``
0351  - (if needed) 32-bit mapping struct in ``include/linux/compat.h``
0352  - instance of ``__SC_COMP`` not ``__SYSCALL`` in
0353    ``include/uapi/asm-generic/unistd.h``
0354 
0355 
0356 Compatibility System Calls (x86)
0357 --------------------------------
0358 
0359 To wire up the x86 architecture of a system call with a compatibility version,
0360 the entries in the syscall tables need to be adjusted.
0361 
0362 First, the entry in ``arch/x86/entry/syscalls/syscall_32.tbl`` gets an extra
0363 column to indicate that a 32-bit userspace program running on a 64-bit kernel
0364 should hit the compat entry point::
0365 
0366     380   i386     xyzzy     sys_xyzzy    __ia32_compat_sys_xyzzy
0367 
0368 Second, you need to figure out what should happen for the x32 ABI version of
0369 the new system call.  There's a choice here: the layout of the arguments
0370 should either match the 64-bit version or the 32-bit version.
0371 
0372 If there's a pointer-to-a-pointer involved, the decision is easy: x32 is
0373 ILP32, so the layout should match the 32-bit version, and the entry in
0374 ``arch/x86/entry/syscalls/syscall_64.tbl`` is split so that x32 programs hit
0375 the compatibility wrapper::
0376 
0377     333   64       xyzzy     sys_xyzzy
0378     ...
0379     555   x32      xyzzy     __x32_compat_sys_xyzzy
0380 
0381 If no pointers are involved, then it is preferable to re-use the 64-bit system
0382 call for the x32 ABI (and consequently the entry in
0383 arch/x86/entry/syscalls/syscall_64.tbl is unchanged).
0384 
0385 In either case, you should check that the types involved in your argument
0386 layout do indeed map exactly from x32 (-mx32) to either the 32-bit (-m32) or
0387 64-bit (-m64) equivalents.
0388 
0389 
0390 System Calls Returning Elsewhere
0391 --------------------------------
0392 
0393 For most system calls, once the system call is complete the user program
0394 continues exactly where it left off -- at the next instruction, with the
0395 stack the same and most of the registers the same as before the system call,
0396 and with the same virtual memory space.
0397 
0398 However, a few system calls do things differently.  They might return to a
0399 different location (``rt_sigreturn``) or change the memory space
0400 (``fork``/``vfork``/``clone``) or even architecture (``execve``/``execveat``)
0401 of the program.
0402 
0403 To allow for this, the kernel implementation of the system call may need to
0404 save and restore additional registers to the kernel stack, allowing complete
0405 control of where and how execution continues after the system call.
0406 
0407 This is arch-specific, but typically involves defining assembly entry points
0408 that save/restore additional registers and invoke the real system call entry
0409 point.
0410 
0411 For x86_64, this is implemented as a ``stub_xyzzy`` entry point in
0412 ``arch/x86/entry/entry_64.S``, and the entry in the syscall table
0413 (``arch/x86/entry/syscalls/syscall_64.tbl``) is adjusted to match::
0414 
0415     333   common   xyzzy     stub_xyzzy
0416 
0417 The equivalent for 32-bit programs running on a 64-bit kernel is normally
0418 called ``stub32_xyzzy`` and implemented in ``arch/x86/entry/entry_64_compat.S``,
0419 with the corresponding syscall table adjustment in
0420 ``arch/x86/entry/syscalls/syscall_32.tbl``::
0421 
0422     380   i386     xyzzy     sys_xyzzy    stub32_xyzzy
0423 
0424 If the system call needs a compatibility layer (as in the previous section)
0425 then the ``stub32_`` version needs to call on to the ``compat_sys_`` version
0426 of the system call rather than the native 64-bit version.  Also, if the x32 ABI
0427 implementation is not common with the x86_64 version, then its syscall
0428 table will also need to invoke a stub that calls on to the ``compat_sys_``
0429 version.
0430 
0431 For completeness, it's also nice to set up a mapping so that user-mode Linux
0432 still works -- its syscall table will reference stub_xyzzy, but the UML build
0433 doesn't include ``arch/x86/entry/entry_64.S`` implementation (because UML
0434 simulates registers etc).  Fixing this is as simple as adding a #define to
0435 ``arch/x86/um/sys_call_table_64.c``::
0436 
0437     #define stub_xyzzy sys_xyzzy
0438 
0439 
0440 Other Details
0441 -------------
0442 
0443 Most of the kernel treats system calls in a generic way, but there is the
0444 occasional exception that may need updating for your particular system call.
0445 
0446 The audit subsystem is one such special case; it includes (arch-specific)
0447 functions that classify some special types of system call -- specifically
0448 file open (``open``/``openat``), program execution (``execve``/``exeveat``) or
0449 socket multiplexor (``socketcall``) operations. If your new system call is
0450 analogous to one of these, then the audit system should be updated.
0451 
0452 More generally, if there is an existing system call that is analogous to your
0453 new system call, it's worth doing a kernel-wide grep for the existing system
0454 call to check there are no other special cases.
0455 
0456 
0457 Testing
0458 -------
0459 
0460 A new system call should obviously be tested; it is also useful to provide
0461 reviewers with a demonstration of how user space programs will use the system
0462 call.  A good way to combine these aims is to include a simple self-test
0463 program in a new directory under ``tools/testing/selftests/``.
0464 
0465 For a new system call, there will obviously be no libc wrapper function and so
0466 the test will need to invoke it using ``syscall()``; also, if the system call
0467 involves a new userspace-visible structure, the corresponding header will need
0468 to be installed to compile the test.
0469 
0470 Make sure the selftest runs successfully on all supported architectures.  For
0471 example, check that it works when compiled as an x86_64 (-m64), x86_32 (-m32)
0472 and x32 (-mx32) ABI program.
0473 
0474 For more extensive and thorough testing of new functionality, you should also
0475 consider adding tests to the Linux Test Project, or to the xfstests project
0476 for filesystem-related changes.
0477 
0478  - https://linux-test-project.github.io/
0479  - git://git.kernel.org/pub/scm/fs/xfs/xfstests-dev.git
0480 
0481 
0482 Man Page
0483 --------
0484 
0485 All new system calls should come with a complete man page, ideally using groff
0486 markup, but plain text will do.  If groff is used, it's helpful to include a
0487 pre-rendered ASCII version of the man page in the cover email for the
0488 patchset, for the convenience of reviewers.
0489 
0490 The man page should be cc'ed to linux-man@vger.kernel.org
0491 For more details, see https://www.kernel.org/doc/man-pages/patches.html
0492 
0493 
0494 Do not call System Calls in the Kernel
0495 --------------------------------------
0496 
0497 System calls are, as stated above, interaction points between userspace and
0498 the kernel.  Therefore, system call functions such as ``sys_xyzzy()`` or
0499 ``compat_sys_xyzzy()`` should only be called from userspace via the syscall
0500 table, but not from elsewhere in the kernel.  If the syscall functionality is
0501 useful to be used within the kernel, needs to be shared between an old and a
0502 new syscall, or needs to be shared between a syscall and its compatibility
0503 variant, it should be implemented by means of a "helper" function (such as
0504 ``ksys_xyzzy()``).  This kernel function may then be called within the
0505 syscall stub (``sys_xyzzy()``), the compatibility syscall stub
0506 (``compat_sys_xyzzy()``), and/or other kernel code.
0507 
0508 At least on 64-bit x86, it will be a hard requirement from v4.17 onwards to not
0509 call system call functions in the kernel.  It uses a different calling
0510 convention for system calls where ``struct pt_regs`` is decoded on-the-fly in a
0511 syscall wrapper which then hands processing over to the actual syscall function.
0512 This means that only those parameters which are actually needed for a specific
0513 syscall are passed on during syscall entry, instead of filling in six CPU
0514 registers with random user space content all the time (which may cause serious
0515 trouble down the call chain).
0516 
0517 Moreover, rules on how data may be accessed may differ between kernel data and
0518 user data.  This is another reason why calling ``sys_xyzzy()`` is generally a
0519 bad idea.
0520 
0521 Exceptions to this rule are only allowed in architecture-specific overrides,
0522 architecture-specific compatibility wrappers, or other code in arch/.
0523 
0524 
0525 References and Sources
0526 ----------------------
0527 
0528  - LWN article from Michael Kerrisk on use of flags argument in system calls:
0529    https://lwn.net/Articles/585415/
0530  - LWN article from Michael Kerrisk on how to handle unknown flags in a system
0531    call: https://lwn.net/Articles/588444/
0532  - LWN article from Jake Edge describing constraints on 64-bit system call
0533    arguments: https://lwn.net/Articles/311630/
0534  - Pair of LWN articles from David Drysdale that describe the system call
0535    implementation paths in detail for v3.14:
0536 
0537     - https://lwn.net/Articles/604287/
0538     - https://lwn.net/Articles/604515/
0539 
0540  - Architecture-specific requirements for system calls are discussed in the
0541    :manpage:`syscall(2)` man-page:
0542    http://man7.org/linux/man-pages/man2/syscall.2.html#NOTES
0543  - Collated emails from Linus Torvalds discussing the problems with ``ioctl()``:
0544    https://yarchive.net/comp/linux/ioctl.html
0545  - "How to not invent kernel interfaces", Arnd Bergmann,
0546    https://www.ukuug.org/events/linux2007/2007/papers/Bergmann.pdf
0547  - LWN article from Michael Kerrisk on avoiding new uses of CAP_SYS_ADMIN:
0548    https://lwn.net/Articles/486306/
0549  - Recommendation from Andrew Morton that all related information for a new
0550    system call should come in the same email thread:
0551    https://lore.kernel.org/r/20140724144747.3041b208832bbdf9fbce5d96@linux-foundation.org
0552  - Recommendation from Michael Kerrisk that a new system call should come with
0553    a man page: https://lore.kernel.org/r/CAKgNAkgMA39AfoSoA5Pe1r9N+ZzfYQNvNPvcRN7tOvRb8+v06Q@mail.gmail.com
0554  - Suggestion from Thomas Gleixner that x86 wire-up should be in a separate
0555    commit: https://lore.kernel.org/r/alpine.DEB.2.11.1411191249560.3909@nanos
0556  - Suggestion from Greg Kroah-Hartman that it's good for new system calls to
0557    come with a man-page & selftest: https://lore.kernel.org/r/20140320025530.GA25469@kroah.com
0558  - Discussion from Michael Kerrisk of new system call vs. :manpage:`prctl(2)` extension:
0559    https://lore.kernel.org/r/CAHO5Pa3F2MjfTtfNxa8LbnkeeU8=YJ+9tDqxZpw7Gz59E-4AUg@mail.gmail.com
0560  - Suggestion from Ingo Molnar that system calls that involve multiple
0561    arguments should encapsulate those arguments in a struct, which includes a
0562    size field for future extensibility: https://lore.kernel.org/r/20150730083831.GA22182@gmail.com
0563  - Numbering oddities arising from (re-)use of O_* numbering space flags:
0564 
0565     - commit 75069f2b5bfb ("vfs: renumber FMODE_NONOTIFY and add to uniqueness
0566       check")
0567     - commit 12ed2e36c98a ("fanotify: FMODE_NONOTIFY and __O_SYNC in sparc
0568       conflict")
0569     - commit bb458c644a59 ("Safer ABI for O_TMPFILE")
0570 
0571  - Discussion from Matthew Wilcox about restrictions on 64-bit arguments:
0572    https://lore.kernel.org/r/20081212152929.GM26095@parisc-linux.org
0573  - Recommendation from Greg Kroah-Hartman that unknown flags should be
0574    policed: https://lore.kernel.org/r/20140717193330.GB4703@kroah.com
0575  - Recommendation from Linus Torvalds that x32 system calls should prefer
0576    compatibility with 64-bit versions rather than 32-bit versions:
0577    https://lore.kernel.org/r/CA+55aFxfmwfB7jbbrXxa=K7VBYPfAvmu3XOkGrLbB1UFjX1+Ew@mail.gmail.com