adding-syscalls.rst 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. Adding a New System Call
  2. ========================
  3. This document describes what's involved in adding a new system call to the
  4. Linux kernel, over and above the normal submission advice in
  5. :ref:`Documentation/process/submitting-patches.rst <submittingpatches>`.
  6. System Call Alternatives
  7. ------------------------
  8. The first thing to consider when adding a new system call is whether one of
  9. the alternatives might be suitable instead. Although system calls are the
  10. most traditional and most obvious interaction points between userspace and the
  11. kernel, there are other possibilities -- choose what fits best for your
  12. interface.
  13. - If the operations involved can be made to look like a filesystem-like
  14. object, it may make more sense to create a new filesystem or device. This
  15. also makes it easier to encapsulate the new functionality in a kernel module
  16. rather than requiring it to be built into the main kernel.
  17. - If the new functionality involves operations where the kernel notifies
  18. userspace that something has happened, then returning a new file
  19. descriptor for the relevant object allows userspace to use
  20. ``poll``/``select``/``epoll`` to receive that notification.
  21. - However, operations that don't map to
  22. :manpage:`read(2)`/:manpage:`write(2)`-like operations
  23. have to be implemented as :manpage:`ioctl(2)` requests, which can lead
  24. to a somewhat opaque API.
  25. - If you're just exposing runtime system information, a new node in sysfs
  26. (see ``Documentation/filesystems/sysfs.txt``) or the ``/proc`` filesystem may
  27. be more appropriate. However, access to these mechanisms requires that the
  28. relevant filesystem is mounted, which might not always be the case (e.g.
  29. in a namespaced/sandboxed/chrooted environment). Avoid adding any API to
  30. debugfs, as this is not considered a 'production' interface to userspace.
  31. - If the operation is specific to a particular file or file descriptor, then
  32. an additional :manpage:`fcntl(2)` command option may be more appropriate. However,
  33. :manpage:`fcntl(2)` is a multiplexing system call that hides a lot of complexity, so
  34. this option is best for when the new function is closely analogous to
  35. existing :manpage:`fcntl(2)` functionality, or the new functionality is very simple
  36. (for example, getting/setting a simple flag related to a file descriptor).
  37. - If the operation is specific to a particular task or process, then an
  38. additional :manpage:`prctl(2)` command option may be more appropriate. As
  39. with :manpage:`fcntl(2)`, this system call is a complicated multiplexor so
  40. is best reserved for near-analogs of existing ``prctl()`` commands or
  41. getting/setting a simple flag related to a process.
  42. Designing the API: Planning for Extension
  43. -----------------------------------------
  44. A new system call forms part of the API of the kernel, and has to be supported
  45. indefinitely. As such, it's a very good idea to explicitly discuss the
  46. interface on the kernel mailing list, and it's important to plan for future
  47. extensions of the interface.
  48. (The syscall table is littered with historical examples where this wasn't done,
  49. together with the corresponding follow-up system calls --
  50. ``eventfd``/``eventfd2``, ``dup2``/``dup3``, ``inotify_init``/``inotify_init1``,
  51. ``pipe``/``pipe2``, ``renameat``/``renameat2`` -- so
  52. learn from the history of the kernel and plan for extensions from the start.)
  53. For simpler system calls that only take a couple of arguments, the preferred
  54. way to allow for future extensibility is to include a flags argument to the
  55. system call. To make sure that userspace programs can safely use flags
  56. between kernel versions, check whether the flags value holds any unknown
  57. flags, and reject the system call (with ``EINVAL``) if it does::
  58. if (flags & ~(THING_FLAG1 | THING_FLAG2 | THING_FLAG3))
  59. return -EINVAL;
  60. (If no flags values are used yet, check that the flags argument is zero.)
  61. For more sophisticated system calls that involve a larger number of arguments,
  62. it's preferred to encapsulate the majority of the arguments into a structure
  63. that is passed in by pointer. Such a structure can cope with future extension
  64. by including a size argument in the structure::
  65. struct xyzzy_params {
  66. u32 size; /* userspace sets p->size = sizeof(struct xyzzy_params) */
  67. u32 param_1;
  68. u64 param_2;
  69. u64 param_3;
  70. };
  71. As long as any subsequently added field, say ``param_4``, is designed so that a
  72. zero value gives the previous behaviour, then this allows both directions of
  73. version mismatch:
  74. - To cope with a later userspace program calling an older kernel, the kernel
  75. code should check that any memory beyond the size of the structure that it
  76. expects is zero (effectively checking that ``param_4 == 0``).
  77. - To cope with an older userspace program calling a newer kernel, the kernel
  78. code can zero-extend a smaller instance of the structure (effectively
  79. setting ``param_4 = 0``).
  80. See :manpage:`perf_event_open(2)` and the ``perf_copy_attr()`` function (in
  81. ``kernel/events/core.c``) for an example of this approach.
  82. Designing the API: Other Considerations
  83. ---------------------------------------
  84. If your new system call allows userspace to refer to a kernel object, it
  85. should use a file descriptor as the handle for that object -- don't invent a
  86. new type of userspace object handle when the kernel already has mechanisms and
  87. well-defined semantics for using file descriptors.
  88. If your new :manpage:`xyzzy(2)` system call does return a new file descriptor,
  89. then the flags argument should include a value that is equivalent to setting
  90. ``O_CLOEXEC`` on the new FD. This makes it possible for userspace to close
  91. the timing window between ``xyzzy()`` and calling
  92. ``fcntl(fd, F_SETFD, FD_CLOEXEC)``, where an unexpected ``fork()`` and
  93. ``execve()`` in another thread could leak a descriptor to
  94. the exec'ed program. (However, resist the temptation to re-use the actual value
  95. of the ``O_CLOEXEC`` constant, as it is architecture-specific and is part of a
  96. numbering space of ``O_*`` flags that is fairly full.)
  97. If your system call returns a new file descriptor, you should also consider
  98. what it means to use the :manpage:`poll(2)` family of system calls on that file
  99. descriptor. Making a file descriptor ready for reading or writing is the
  100. normal way for the kernel to indicate to userspace that an event has
  101. occurred on the corresponding kernel object.
  102. If your new :manpage:`xyzzy(2)` system call involves a filename argument::
  103. int sys_xyzzy(const char __user *path, ..., unsigned int flags);
  104. you should also consider whether an :manpage:`xyzzyat(2)` version is more appropriate::
  105. int sys_xyzzyat(int dfd, const char __user *path, ..., unsigned int flags);
  106. This allows more flexibility for how userspace specifies the file in question;
  107. in particular it allows userspace to request the functionality for an
  108. already-opened file descriptor using the ``AT_EMPTY_PATH`` flag, effectively
  109. giving an :manpage:`fxyzzy(3)` operation for free::
  110. - xyzzyat(AT_FDCWD, path, ..., 0) is equivalent to xyzzy(path,...)
  111. - xyzzyat(fd, "", ..., AT_EMPTY_PATH) is equivalent to fxyzzy(fd, ...)
  112. (For more details on the rationale of the \*at() calls, see the
  113. :manpage:`openat(2)` man page; for an example of AT_EMPTY_PATH, see the
  114. :manpage:`fstatat(2)` man page.)
  115. If your new :manpage:`xyzzy(2)` system call involves a parameter describing an
  116. offset within a file, make its type ``loff_t`` so that 64-bit offsets can be
  117. supported even on 32-bit architectures.
  118. If your new :manpage:`xyzzy(2)` system call involves privileged functionality,
  119. it needs to be governed by the appropriate Linux capability bit (checked with
  120. a call to ``capable()``), as described in the :manpage:`capabilities(7)` man
  121. page. Choose an existing capability bit that governs related functionality,
  122. but try to avoid combining lots of only vaguely related functions together
  123. under the same bit, as this goes against capabilities' purpose of splitting
  124. the power of root. In particular, avoid adding new uses of the already
  125. overly-general ``CAP_SYS_ADMIN`` capability.
  126. If your new :manpage:`xyzzy(2)` system call manipulates a process other than
  127. the calling process, it should be restricted (using a call to
  128. ``ptrace_may_access()``) so that only a calling process with the same
  129. permissions as the target process, or with the necessary capabilities, can
  130. manipulate the target process.
  131. Finally, be aware that some non-x86 architectures have an easier time if
  132. system call parameters that are explicitly 64-bit fall on odd-numbered
  133. arguments (i.e. parameter 1, 3, 5), to allow use of contiguous pairs of 32-bit
  134. registers. (This concern does not apply if the arguments are part of a
  135. structure that's passed in by pointer.)
  136. Proposing the API
  137. -----------------
  138. To make new system calls easy to review, it's best to divide up the patchset
  139. into separate chunks. These should include at least the following items as
  140. distinct commits (each of which is described further below):
  141. - The core implementation of the system call, together with prototypes,
  142. generic numbering, Kconfig changes and fallback stub implementation.
  143. - Wiring up of the new system call for one particular architecture, usually
  144. x86 (including all of x86_64, x86_32 and x32).
  145. - A demonstration of the use of the new system call in userspace via a
  146. selftest in ``tools/testing/selftests/``.
  147. - A draft man-page for the new system call, either as plain text in the
  148. cover letter, or as a patch to the (separate) man-pages repository.
  149. New system call proposals, like any change to the kernel's API, should always
  150. be cc'ed to linux-api@vger.kernel.org.
  151. Generic System Call Implementation
  152. ----------------------------------
  153. The main entry point for your new :manpage:`xyzzy(2)` system call will be called
  154. ``sys_xyzzy()``, but you add this entry point with the appropriate
  155. ``SYSCALL_DEFINEn()`` macro rather than explicitly. The 'n' indicates the
  156. number of arguments to the system call, and the macro takes the system call name
  157. followed by the (type, name) pairs for the parameters as arguments. Using
  158. this macro allows metadata about the new system call to be made available for
  159. other tools.
  160. The new entry point also needs a corresponding function prototype, in
  161. ``include/linux/syscalls.h``, marked as asmlinkage to match the way that system
  162. calls are invoked::
  163. asmlinkage long sys_xyzzy(...);
  164. Some architectures (e.g. x86) have their own architecture-specific syscall
  165. tables, but several other architectures share a generic syscall table. Add your
  166. new system call to the generic list by adding an entry to the list in
  167. ``include/uapi/asm-generic/unistd.h``::
  168. #define __NR_xyzzy 292
  169. __SYSCALL(__NR_xyzzy, sys_xyzzy)
  170. Also update the __NR_syscalls count to reflect the additional system call, and
  171. note that if multiple new system calls are added in the same merge window,
  172. your new syscall number may get adjusted to resolve conflicts.
  173. The file ``kernel/sys_ni.c`` provides a fallback stub implementation of each
  174. system call, returning ``-ENOSYS``. Add your new system call here too::
  175. COND_SYSCALL(xyzzy);
  176. Your new kernel functionality, and the system call that controls it, should
  177. normally be optional, so add a ``CONFIG`` option (typically to
  178. ``init/Kconfig``) for it. As usual for new ``CONFIG`` options:
  179. - Include a description of the new functionality and system call controlled
  180. by the option.
  181. - Make the option depend on EXPERT if it should be hidden from normal users.
  182. - Make any new source files implementing the function dependent on the CONFIG
  183. option in the Makefile (e.g. ``obj-$(CONFIG_XYZZY_SYSCALL) += xyzzy.c``).
  184. - Double check that the kernel still builds with the new CONFIG option turned
  185. off.
  186. To summarize, you need a commit that includes:
  187. - ``CONFIG`` option for the new function, normally in ``init/Kconfig``
  188. - ``SYSCALL_DEFINEn(xyzzy, ...)`` for the entry point
  189. - corresponding prototype in ``include/linux/syscalls.h``
  190. - generic table entry in ``include/uapi/asm-generic/unistd.h``
  191. - fallback stub in ``kernel/sys_ni.c``
  192. x86 System Call Implementation
  193. ------------------------------
  194. To wire up your new system call for x86 platforms, you need to update the
  195. master syscall tables. Assuming your new system call isn't special in some
  196. way (see below), this involves a "common" entry (for x86_64 and x32) in
  197. arch/x86/entry/syscalls/syscall_64.tbl::
  198. 333 common xyzzy sys_xyzzy
  199. and an "i386" entry in ``arch/x86/entry/syscalls/syscall_32.tbl``::
  200. 380 i386 xyzzy sys_xyzzy
  201. Again, these numbers are liable to be changed if there are conflicts in the
  202. relevant merge window.
  203. Compatibility System Calls (Generic)
  204. ------------------------------------
  205. For most system calls the same 64-bit implementation can be invoked even when
  206. the userspace program is itself 32-bit; even if the system call's parameters
  207. include an explicit pointer, this is handled transparently.
  208. However, there are a couple of situations where a compatibility layer is
  209. needed to cope with size differences between 32-bit and 64-bit.
  210. The first is if the 64-bit kernel also supports 32-bit userspace programs, and
  211. so needs to parse areas of (``__user``) memory that could hold either 32-bit or
  212. 64-bit values. In particular, this is needed whenever a system call argument
  213. is:
  214. - a pointer to a pointer
  215. - a pointer to a struct containing a pointer (e.g. ``struct iovec __user *``)
  216. - a pointer to a varying sized integral type (``time_t``, ``off_t``,
  217. ``long``, ...)
  218. - a pointer to a struct containing a varying sized integral type.
  219. The second situation that requires a compatibility layer is if one of the
  220. system call's arguments has a type that is explicitly 64-bit even on a 32-bit
  221. architecture, for example ``loff_t`` or ``__u64``. In this case, a value that
  222. arrives at a 64-bit kernel from a 32-bit application will be split into two
  223. 32-bit values, which then need to be re-assembled in the compatibility layer.
  224. (Note that a system call argument that's a pointer to an explicit 64-bit type
  225. does **not** need a compatibility layer; for example, :manpage:`splice(2)`'s arguments of
  226. type ``loff_t __user *`` do not trigger the need for a ``compat_`` system call.)
  227. The compatibility version of the system call is called ``compat_sys_xyzzy()``,
  228. and is added with the ``COMPAT_SYSCALL_DEFINEn()`` macro, analogously to
  229. SYSCALL_DEFINEn. This version of the implementation runs as part of a 64-bit
  230. kernel, but expects to receive 32-bit parameter values and does whatever is
  231. needed to deal with them. (Typically, the ``compat_sys_`` version converts the
  232. values to 64-bit versions and either calls on to the ``sys_`` version, or both of
  233. them call a common inner implementation function.)
  234. The compat entry point also needs a corresponding function prototype, in
  235. ``include/linux/compat.h``, marked as asmlinkage to match the way that system
  236. calls are invoked::
  237. asmlinkage long compat_sys_xyzzy(...);
  238. If the system call involves a structure that is laid out differently on 32-bit
  239. and 64-bit systems, say ``struct xyzzy_args``, then the include/linux/compat.h
  240. header file should also include a compat version of the structure (``struct
  241. compat_xyzzy_args``) where each variable-size field has the appropriate
  242. ``compat_`` type that corresponds to the type in ``struct xyzzy_args``. The
  243. ``compat_sys_xyzzy()`` routine can then use this ``compat_`` structure to
  244. parse the arguments from a 32-bit invocation.
  245. For example, if there are fields::
  246. struct xyzzy_args {
  247. const char __user *ptr;
  248. __kernel_long_t varying_val;
  249. u64 fixed_val;
  250. /* ... */
  251. };
  252. in struct xyzzy_args, then struct compat_xyzzy_args would have::
  253. struct compat_xyzzy_args {
  254. compat_uptr_t ptr;
  255. compat_long_t varying_val;
  256. u64 fixed_val;
  257. /* ... */
  258. };
  259. The generic system call list also needs adjusting to allow for the compat
  260. version; the entry in ``include/uapi/asm-generic/unistd.h`` should use
  261. ``__SC_COMP`` rather than ``__SYSCALL``::
  262. #define __NR_xyzzy 292
  263. __SC_COMP(__NR_xyzzy, sys_xyzzy, compat_sys_xyzzy)
  264. To summarize, you need:
  265. - a ``COMPAT_SYSCALL_DEFINEn(xyzzy, ...)`` for the compat entry point
  266. - corresponding prototype in ``include/linux/compat.h``
  267. - (if needed) 32-bit mapping struct in ``include/linux/compat.h``
  268. - instance of ``__SC_COMP`` not ``__SYSCALL`` in
  269. ``include/uapi/asm-generic/unistd.h``
  270. Compatibility System Calls (x86)
  271. --------------------------------
  272. To wire up the x86 architecture of a system call with a compatibility version,
  273. the entries in the syscall tables need to be adjusted.
  274. First, the entry in ``arch/x86/entry/syscalls/syscall_32.tbl`` gets an extra
  275. column to indicate that a 32-bit userspace program running on a 64-bit kernel
  276. should hit the compat entry point::
  277. 380 i386 xyzzy sys_xyzzy __ia32_compat_sys_xyzzy
  278. Second, you need to figure out what should happen for the x32 ABI version of
  279. the new system call. There's a choice here: the layout of the arguments
  280. should either match the 64-bit version or the 32-bit version.
  281. If there's a pointer-to-a-pointer involved, the decision is easy: x32 is
  282. ILP32, so the layout should match the 32-bit version, and the entry in
  283. ``arch/x86/entry/syscalls/syscall_64.tbl`` is split so that x32 programs hit
  284. the compatibility wrapper::
  285. 333 64 xyzzy sys_xyzzy
  286. ...
  287. 555 x32 xyzzy __x32_compat_sys_xyzzy
  288. If no pointers are involved, then it is preferable to re-use the 64-bit system
  289. call for the x32 ABI (and consequently the entry in
  290. arch/x86/entry/syscalls/syscall_64.tbl is unchanged).
  291. In either case, you should check that the types involved in your argument
  292. layout do indeed map exactly from x32 (-mx32) to either the 32-bit (-m32) or
  293. 64-bit (-m64) equivalents.
  294. System Calls Returning Elsewhere
  295. --------------------------------
  296. For most system calls, once the system call is complete the user program
  297. continues exactly where it left off -- at the next instruction, with the
  298. stack the same and most of the registers the same as before the system call,
  299. and with the same virtual memory space.
  300. However, a few system calls do things differently. They might return to a
  301. different location (``rt_sigreturn``) or change the memory space
  302. (``fork``/``vfork``/``clone``) or even architecture (``execve``/``execveat``)
  303. of the program.
  304. To allow for this, the kernel implementation of the system call may need to
  305. save and restore additional registers to the kernel stack, allowing complete
  306. control of where and how execution continues after the system call.
  307. This is arch-specific, but typically involves defining assembly entry points
  308. that save/restore additional registers and invoke the real system call entry
  309. point.
  310. For x86_64, this is implemented as a ``stub_xyzzy`` entry point in
  311. ``arch/x86/entry/entry_64.S``, and the entry in the syscall table
  312. (``arch/x86/entry/syscalls/syscall_64.tbl``) is adjusted to match::
  313. 333 common xyzzy stub_xyzzy
  314. The equivalent for 32-bit programs running on a 64-bit kernel is normally
  315. called ``stub32_xyzzy`` and implemented in ``arch/x86/entry/entry_64_compat.S``,
  316. with the corresponding syscall table adjustment in
  317. ``arch/x86/entry/syscalls/syscall_32.tbl``::
  318. 380 i386 xyzzy sys_xyzzy stub32_xyzzy
  319. If the system call needs a compatibility layer (as in the previous section)
  320. then the ``stub32_`` version needs to call on to the ``compat_sys_`` version
  321. of the system call rather than the native 64-bit version. Also, if the x32 ABI
  322. implementation is not common with the x86_64 version, then its syscall
  323. table will also need to invoke a stub that calls on to the ``compat_sys_``
  324. version.
  325. For completeness, it's also nice to set up a mapping so that user-mode Linux
  326. still works -- its syscall table will reference stub_xyzzy, but the UML build
  327. doesn't include ``arch/x86/entry/entry_64.S`` implementation (because UML
  328. simulates registers etc). Fixing this is as simple as adding a #define to
  329. ``arch/x86/um/sys_call_table_64.c``::
  330. #define stub_xyzzy sys_xyzzy
  331. Other Details
  332. -------------
  333. Most of the kernel treats system calls in a generic way, but there is the
  334. occasional exception that may need updating for your particular system call.
  335. The audit subsystem is one such special case; it includes (arch-specific)
  336. functions that classify some special types of system call -- specifically
  337. file open (``open``/``openat``), program execution (``execve``/``exeveat``) or
  338. socket multiplexor (``socketcall``) operations. If your new system call is
  339. analogous to one of these, then the audit system should be updated.
  340. More generally, if there is an existing system call that is analogous to your
  341. new system call, it's worth doing a kernel-wide grep for the existing system
  342. call to check there are no other special cases.
  343. Testing
  344. -------
  345. A new system call should obviously be tested; it is also useful to provide
  346. reviewers with a demonstration of how user space programs will use the system
  347. call. A good way to combine these aims is to include a simple self-test
  348. program in a new directory under ``tools/testing/selftests/``.
  349. For a new system call, there will obviously be no libc wrapper function and so
  350. the test will need to invoke it using ``syscall()``; also, if the system call
  351. involves a new userspace-visible structure, the corresponding header will need
  352. to be installed to compile the test.
  353. Make sure the selftest runs successfully on all supported architectures. For
  354. example, check that it works when compiled as an x86_64 (-m64), x86_32 (-m32)
  355. and x32 (-mx32) ABI program.
  356. For more extensive and thorough testing of new functionality, you should also
  357. consider adding tests to the Linux Test Project, or to the xfstests project
  358. for filesystem-related changes.
  359. - https://linux-test-project.github.io/
  360. - git://git.kernel.org/pub/scm/fs/xfs/xfstests-dev.git
  361. Man Page
  362. --------
  363. All new system calls should come with a complete man page, ideally using groff
  364. markup, but plain text will do. If groff is used, it's helpful to include a
  365. pre-rendered ASCII version of the man page in the cover email for the
  366. patchset, for the convenience of reviewers.
  367. The man page should be cc'ed to linux-man@vger.kernel.org
  368. For more details, see https://www.kernel.org/doc/man-pages/patches.html
  369. Do not call System Calls in the Kernel
  370. --------------------------------------
  371. System calls are, as stated above, interaction points between userspace and
  372. the kernel. Therefore, system call functions such as ``sys_xyzzy()`` or
  373. ``compat_sys_xyzzy()`` should only be called from userspace via the syscall
  374. table, but not from elsewhere in the kernel. If the syscall functionality is
  375. useful to be used within the kernel, needs to be shared between an old and a
  376. new syscall, or needs to be shared between a syscall and its compatibility
  377. variant, it should be implemented by means of a "helper" function (such as
  378. ``kern_xyzzy()``). This kernel function may then be called within the
  379. syscall stub (``sys_xyzzy()``), the compatibility syscall stub
  380. (``compat_sys_xyzzy()``), and/or other kernel code.
  381. At least on 64-bit x86, it will be a hard requirement from v4.17 onwards to not
  382. call system call functions in the kernel. It uses a different calling
  383. convention for system calls where ``struct pt_regs`` is decoded on-the-fly in a
  384. syscall wrapper which then hands processing over to the actual syscall function.
  385. This means that only those parameters which are actually needed for a specific
  386. syscall are passed on during syscall entry, instead of filling in six CPU
  387. registers with random user space content all the time (which may cause serious
  388. trouble down the call chain).
  389. Moreover, rules on how data may be accessed may differ between kernel data and
  390. user data. This is another reason why calling ``sys_xyzzy()`` is generally a
  391. bad idea.
  392. Exceptions to this rule are only allowed in architecture-specific overrides,
  393. architecture-specific compatibility wrappers, or other code in arch/.
  394. References and Sources
  395. ----------------------
  396. - LWN article from Michael Kerrisk on use of flags argument in system calls:
  397. https://lwn.net/Articles/585415/
  398. - LWN article from Michael Kerrisk on how to handle unknown flags in a system
  399. call: https://lwn.net/Articles/588444/
  400. - LWN article from Jake Edge describing constraints on 64-bit system call
  401. arguments: https://lwn.net/Articles/311630/
  402. - Pair of LWN articles from David Drysdale that describe the system call
  403. implementation paths in detail for v3.14:
  404. - https://lwn.net/Articles/604287/
  405. - https://lwn.net/Articles/604515/
  406. - Architecture-specific requirements for system calls are discussed in the
  407. :manpage:`syscall(2)` man-page:
  408. http://man7.org/linux/man-pages/man2/syscall.2.html#NOTES
  409. - Collated emails from Linus Torvalds discussing the problems with ``ioctl()``:
  410. http://yarchive.net/comp/linux/ioctl.html
  411. - "How to not invent kernel interfaces", Arnd Bergmann,
  412. http://www.ukuug.org/events/linux2007/2007/papers/Bergmann.pdf
  413. - LWN article from Michael Kerrisk on avoiding new uses of CAP_SYS_ADMIN:
  414. https://lwn.net/Articles/486306/
  415. - Recommendation from Andrew Morton that all related information for a new
  416. system call should come in the same email thread:
  417. https://lkml.org/lkml/2014/7/24/641
  418. - Recommendation from Michael Kerrisk that a new system call should come with
  419. a man page: https://lkml.org/lkml/2014/6/13/309
  420. - Suggestion from Thomas Gleixner that x86 wire-up should be in a separate
  421. commit: https://lkml.org/lkml/2014/11/19/254
  422. - Suggestion from Greg Kroah-Hartman that it's good for new system calls to
  423. come with a man-page & selftest: https://lkml.org/lkml/2014/3/19/710
  424. - Discussion from Michael Kerrisk of new system call vs. :manpage:`prctl(2)` extension:
  425. https://lkml.org/lkml/2014/6/3/411
  426. - Suggestion from Ingo Molnar that system calls that involve multiple
  427. arguments should encapsulate those arguments in a struct, which includes a
  428. size field for future extensibility: https://lkml.org/lkml/2015/7/30/117
  429. - Numbering oddities arising from (re-)use of O_* numbering space flags:
  430. - commit 75069f2b5bfb ("vfs: renumber FMODE_NONOTIFY and add to uniqueness
  431. check")
  432. - commit 12ed2e36c98a ("fanotify: FMODE_NONOTIFY and __O_SYNC in sparc
  433. conflict")
  434. - commit bb458c644a59 ("Safer ABI for O_TMPFILE")
  435. - Discussion from Matthew Wilcox about restrictions on 64-bit arguments:
  436. https://lkml.org/lkml/2008/12/12/187
  437. - Recommendation from Greg Kroah-Hartman that unknown flags should be
  438. policed: https://lkml.org/lkml/2014/7/17/577
  439. - Recommendation from Linus Torvalds that x32 system calls should prefer
  440. compatibility with 64-bit versions rather than 32-bit versions:
  441. https://lkml.org/lkml/2011/8/31/244