diff options
author | guenther <> | 2021-12-25 01:13:44 +0000 |
---|---|---|
committer | guenther <> | 2021-12-25 01:13:44 +0000 |
commit | 6142c0431dc485679ae167b6cb887a9afafb3427 (patch) | |
tree | fe6c8c8fab14f15d175064086a493709c5b8597c | |
parent | ac23186da5d268f74aad9527b2bf5525a7b8132d (diff) | |
download | openbsd-6142c0431dc485679ae167b6cb887a9afafb3427.tar.gz openbsd-6142c0431dc485679ae167b6cb887a9afafb3427.tar.bz2 openbsd-6142c0431dc485679ae167b6cb887a9afafb3427.zip |
Update to reflect changes over the last six years
-rw-r--r-- | src/lib/libc/include/README | 81 |
1 files changed, 47 insertions, 34 deletions
diff --git a/src/lib/libc/include/README b/src/lib/libc/include/README index 6410072c96..89acee491e 100644 --- a/src/lib/libc/include/README +++ b/src/lib/libc/include/README | |||
@@ -28,6 +28,7 @@ CASE II: external symbols | |||
28 | A) objects (variables) | 28 | A) objects (variables) |
29 | That's it, you're done. | 29 | That's it, you're done. |
30 | 30 | ||
31 | |||
31 | B) plain C functions (not syscalls) | 32 | B) plain C functions (not syscalls) |
32 | 1) functions that are *not* called from inside libc | 33 | 1) functions that are *not* called from inside libc |
33 | 34 | ||
@@ -42,6 +43,10 @@ CASE II: external symbols | |||
42 | this line: | 43 | this line: |
43 | PROTO_DEPRECATED(your_function_name); | 44 | PROTO_DEPRECATED(your_function_name); |
44 | 45 | ||
46 | Note: the "DEPRECATED" suffix is about a detail of | ||
47 | how the macros work and has nothing to do with whether the | ||
48 | function itself is a Good Thing vs deprecated. | ||
49 | |||
45 | 2) functions that are called from inside libc | 50 | 2) functions that are called from inside libc |
46 | 51 | ||
47 | In the hidden/* version of the header where you declared | 52 | In the hidden/* version of the header where you declared |
@@ -56,42 +61,50 @@ CASE II: external symbols | |||
56 | - otherwise, add: | 61 | - otherwise, add: |
57 | DEF_WEAK(your_function_name); | 62 | DEF_WEAK(your_function_name); |
58 | 63 | ||
59 | C) syscalls that require cancellation or other libpthread wrappers | ||
60 | You're done in libc, but go to libpthread and add the wrapper there. | ||
61 | 64 | ||
62 | D) syscalls that require libc wrappers for other reasons | 65 | C) syscalls that don't require any wrapping |
63 | First of all, make sure this really is the Right Thing. Talk | 66 | |
64 | with kettenis, deraadt, miod, and guenther. | ||
65 | |||
66 | 1) If the actual syscall doesn't have the same calling convention | ||
67 | as the C interface, then maybe it shouldn't be exported at | ||
68 | all and you should just have an ASM stub, like SYS___tfork | ||
69 | --> __tfork_thread() or SYS_break --> brk() and sbrk(). If | ||
70 | it _could_ be called from C, then give the syscall a name | ||
71 | different from the C API. Syscalls that fail this for | ||
72 | historical reasons (e.g., getlogin) are generated with | ||
73 | PSEUDO in libc/sys/Makefile.inc, so the ASM stub has a | ||
74 | leading underbar. Go read gen/getlogin.c for an example | ||
75 | of how to do this. | ||
76 | |||
77 | 2) Otherwise, you're sane and have a syscall like sigaction() | ||
78 | which requires a wrapper but whose syscall API is the same | ||
79 | as the C API. Then: | ||
80 | - generate the ASM stub with HIDDEN in libc/sys/Makefile.inc | ||
81 | - in the proper hidden/*.h file add | ||
82 | PROTO_WRAP(your_function_name) | ||
83 | - the wrapper function should be defined in | ||
84 | libc/sys/w_your_function_name.c | ||
85 | which should define WRAP(your_function_name) and | ||
86 | follow it with DEF_WRAP(your_function_name). Look at | ||
87 | libc/sys/w_sigaction.c for an example. | ||
88 | - by default, libc code that calls your_function_name() | ||
89 | will get the real syscall and *not* the wrapper. libc | ||
90 | calls that needd to go through the wrapper should invoke | ||
91 | WRAP(your_function_name) | ||
92 | |||
93 | E) syscalls that don't require any wrapping | ||
94 | In the hidden/* version of the header where you declared the | 67 | In the hidden/* version of the header where you declared the |
95 | function, add this line: | 68 | function, add this line: |
96 | PROTO_NORMAL(your_function_name); | 69 | PROTO_NORMAL(your_function_name); |
97 | 70 | ||
71 | Generate the stub by adding it to the ASM variable in | ||
72 | libc/sys/Makefile.inc | ||
73 | |||
74 | |||
75 | D) syscalls that require cancellation or similar wrappers that don't | ||
76 | change the function signature | ||
77 | |||
78 | Generate the stub by adding it to the HIDDEN (*not* ASM!) | ||
79 | variable in libc/sys/Makefile.inc | ||
80 | |||
81 | In the hidden/* version of the header where you declared the | ||
82 | function, add this line: | ||
83 | PROTO_WRAP(your_function_name); | ||
84 | |||
85 | The wrapper function should be defined in | ||
86 | libc/sys/w_your_function_name.c | ||
87 | which should define WRAP(your_function_name) and follow it | ||
88 | with DEF_WRAP(your_function_name). Look at libc/sys/w_sigaction.c | ||
89 | for an example. | ||
90 | |||
91 | By default, libc code that calls your_function_name() will get | ||
92 | the real syscall and *not* the wrapper. libc calls that need | ||
93 | to go through the wrapper should invoke WRAP(your_function_name) | ||
94 | |||
95 | |||
96 | E) syscalls that require libc wrappers for other reasons | ||
97 | First of all, make sure this really is the Right Thing. Talk | ||
98 | with kettenis, deraadt, millert, and guenther. | ||
99 | |||
100 | If the actual syscall doesn't have the same calling convention | ||
101 | as the C interface, then maybe it shouldn't be exported at all | ||
102 | and you should just have an ASM stub, like SYS___tfork --> | ||
103 | __tfork_thread() or SYS_break --> brk() and sbrk(). If it | ||
104 | _could_ be called from C, then give the syscall a name different | ||
105 | from the C API. Syscalls that fail this for historical reasons | ||
106 | (e.g., exit == _exit(2)) are generated with PSEUDO/PSEUDO_NOERR | ||
107 | in libc/sys/Makefile.inc, so the ASM stub has a leading underbar. | ||
108 | Go read gen/getlogin.c rev 1.13 for an example of how to do | ||
109 | this, but don't pick this option, really. | ||
110 | |||