]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man7/vdso.7
vdso.7: Update for ARM
[thirdparty/man-pages.git] / man7 / vdso.7
1 .\" Written by Mike Frysinger <vapier@gentoo.org>
2 .\"
3 .\" %%%LICENSE_START(PUBLIC_DOMAIN)
4 .\" This page is in the public domain.
5 .\" %%%LICENSE_END
6 .\"
7 .\" Useful background:
8 .\" http://articles.manugarg.com/systemcallinlinux2_6.html
9 .\" https://lwn.net/Articles/446528/
10 .\" http://www.linuxjournal.com/content/creating-vdso-colonels-other-chicken
11 .\" http://www.trilithium.com/johan/2005/08/linux-gate/
12 .\"
13 .TH VDSO 7 2014-08-19 "Linux" "Linux Programmer's Manual"
14 .SH NAME
15 vDSO \- overview of the virtual ELF dynamic shared object
16 .SH SYNOPSIS
17 .B #include <sys/auxv.h>
18
19 .B void *vdso = (uintptr_t) getauxval(AT_SYSINFO_EHDR);
20 .SH DESCRIPTION
21 The "vDSO" (virtual dynamic shared object) is a small shared library that
22 the kernel automatically maps into the
23 address space of all user-space applications.
24 Applications usually do not need to concern themselves with these details
25 as the vDSO is most commonly called by the C library.
26 This way you can code in the normal way using standard functions
27 and the C library will take care
28 of using any functionality that is available via the vDSO.
29
30 Why does the vDSO exist at all?
31 There are some system calls the kernel provides that
32 user-space code ends up using frequently,
33 to the point that such calls can dominate overall performance.
34 This is due both to the frequency of the call as well as the
35 context-switch overhead that results
36 from exiting user space and entering the kernel.
37
38 The rest of this documentation is geared toward the curious and/or
39 C library writers rather than general developers.
40 If you're trying to call the vDSO in your own application rather than using
41 the C library, you're most likely doing it wrong.
42 .SS Example background
43 Making system calls can be slow.
44 In x86 32-bit systems, you can trigger a software interrupt
45 .RI ( "int $0x80" )
46 to tell the kernel you wish to make a system call.
47 However, this instruction is expensive: it goes through
48 the full interrupt-handling paths
49 in the processor's microcode as well as in the kernel.
50 Newer processors have faster (but backward incompatible) instructions to
51 initiate system calls.
52 Rather than require the C library to figure out if this functionality is
53 available at run time,
54 the C library can use functions provided by the kernel in
55 the vDSO.
56
57 Note that the terminology can be confusing.
58 On x86 systems, the vDSO function
59 used to determine the preferred method of making a system call is
60 named "__kernel_vsyscall", but on x86_64,
61 the term "vsyscall" also refers to an obsolete way to ask the kernel
62 what time it is or what CPU the caller is on.
63
64 One frequently used system call is
65 .BR gettimeofday (2).
66 This system call is called both directly by user-space applications
67 as well as indirectly by
68 the C library.
69 Think timestamps or timing loops or polling\(emall of these
70 frequently need to know what time it is right now.
71 This information is also not secret\(emany application in any
72 privilege mode (root or any unprivileged user) will get the same answer.
73 Thus the kernel arranges for the information required to answer
74 this question to be placed in memory the process can access.
75 Now a call to
76 .BR gettimeofday (2)
77 changes from a system call to a normal function
78 call and a few memory accesses.
79 .SS Finding the vDSO
80 The base address of the vDSO (if one exists) is passed by the kernel to
81 each program in the initial auxiliary vector (see
82 .BR getauxval (3)),
83 via the
84 .B AT_SYSINFO_EHDR
85 tag.
86
87 You must not assume the vDSO is mapped at any particular location in the
88 user's memory map.
89 The base address will usually be randomized at run time every time a new
90 process image is created (at
91 .BR execve (2)
92 time).
93 This is done for security reasons,
94 to prevent "return-to-libc" attacks.
95
96 For some architectures, there is also an
97 .B AT_SYSINFO
98 tag.
99 This is used only for locating the vsyscall entry point and is frequently
100 omitted or set to 0 (meaning it's not available).
101 This tag is a throwback to the initial vDSO work (see
102 .IR History
103 below) and its use should be avoided.
104 .SS File format
105 Since the vDSO is a fully formed ELF image, you can do symbol lookups on it.
106 This allows new symbols to be added with newer kernel releases,
107 and allows the C library to detect available functionality at
108 run time when running under different kernel versions.
109 Oftentimes the C library will do detection with the first call and then
110 cache the result for subsequent calls.
111
112 All symbols are also versioned (using the GNU version format).
113 This allows the kernel to update the function signature without breaking
114 backward compatibility.
115 This means changing the arguments that the function accepts as well as the
116 return value.
117 Thus, when looking up a symbol in the vDSO,
118 you must always include the version
119 to match the ABI you expect.
120
121 Typically the vDSO follows the naming convention of prefixing
122 all symbols with "__vdso_" or "__kernel_"
123 so as to distinguish them from other standard symbols.
124 For example, the "gettimeofday" function is named "__vdso_gettimeofday".
125
126 You use the standard C calling conventions when calling
127 any of these functions.
128 No need to worry about weird register or stack behavior.
129 .SH NOTES
130 .SS Source
131 When you compile the kernel,
132 it will automatically compile and link the vDSO code for you.
133 You will frequently find it under the architecture-specific directory:
134
135 find arch/$ARCH/ -name '*vdso*.so*' -o -name '*gate*.so*'
136
137 .SS vDSO names
138 The name of the vDSO varies across architectures.
139 It will often show up in things like glibc's
140 .BR ldd (1)
141 output.
142 The exact name should not matter to any code, so do not hardcode it.
143 .if t \{\
144 .ft CW
145 \}
146 .TS
147 l l.
148 user ABI vDSO name
149 _
150 aarch64 linux-vdso.so.1
151 arm linux-vdso.so.1
152 ia64 linux-gate.so.1
153 ppc/32 linux-vdso32.so.1
154 ppc/64 linux-vdso64.so.1
155 s390 linux-vdso32.so.1
156 s390x linux-vdso64.so.1
157 sh linux-gate.so.1
158 i386 linux-gate.so.1
159 x86_64 linux-vdso.so.1
160 x86/x32 linux-vdso.so.1
161 .TE
162 .if t \{\
163 .in
164 .ft P
165 \}
166 .SH ARCHITECTURE-SPECIFIC NOTES
167 The subsections below provide architecture-specific notes
168 on the vDSO.
169
170 Note that the vDSO that is used is based on the ABI of your user-space code
171 and not the ABI of the kernel.
172 Thus, for example,
173 when you run an i386 32-bit ELF binary,
174 you'll get the same vDSO regardless of whether you run it under
175 an i386 32-bit kernel or under an x86_64 64-bit kernel.
176 Therefore, the name of the user-space ABI should be used to determine
177 which of the sections below is relevant.
178 .SS ARM functions
179 .\" See linux/arch/arm/vdso/vdso.lds.S
180 .\" Commit: 8512287a8165592466cb9cb347ba94892e9c56a5
181 The table below lists the symbols exported by the vDSO.
182 .if t \{\
183 .ft CW
184 \}
185 .TS
186 l l.
187 symbol version
188 _
189 __vdso_gettimeofday LINUX_2.6 (exported since Linux 4.1)
190 __vdso_clock_gettime LINUX_2.6 (exported since Linux 4.1)
191 .TE
192 .if t \{\
193 .in
194 .ft P
195 \}
196
197 .\" See linux/arch/arm/kernel/entry-armv.S
198 .\" See linux/Documentation/arm/kernel_user_helpers.txt
199 Additionally, the ARM port has a code page full of utility functions.
200 Since it's just a raw page of code, there is no ELF information for doing
201 symbol lookups or versioning.
202 It does provide support for different versions though.
203
204 For information on this code page,
205 it's best to refer to the kernel documentation
206 as it's extremely detailed and covers everything you need to know:
207 .IR Documentation/arm/kernel_user_helpers.txt .
208 .SS aarch64 functions
209 .\" See linux/arch/arm64/kernel/vdso/vdso.lds.S
210 The table below lists the symbols exported by the vDSO.
211 .if t \{\
212 .ft CW
213 \}
214 .TS
215 l l.
216 symbol version
217 _
218 __kernel_rt_sigreturn LINUX_2.6.39
219 __kernel_gettimeofday LINUX_2.6.39
220 __kernel_clock_gettime LINUX_2.6.39
221 __kernel_clock_getres LINUX_2.6.39
222 .TE
223 .if t \{\
224 .in
225 .ft P
226 \}
227 .SS bfin (Blackfin) functions
228 .\" See linux/arch/blackfin/kernel/fixed_code.S
229 .\" See http://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:fixed-code
230 As this CPU lacks a memory management unit (MMU),
231 it doesn't set up a vDSO in the normal sense.
232 Instead, it maps at boot time a few raw functions into
233 a fixed location in memory.
234 User-space applications then call directly into that region.
235 There is no provision for backward compatibility
236 beyond sniffing raw opcodes,
237 but as this is an embedded CPU, it can get away with things\(emsome of the
238 object formats it runs aren't even ELF based (they're bFLT/FLAT).
239
240 For information on this code page,
241 it's best to refer to the public documentation:
242 .br
243 http://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:fixed-code
244 .SS ia64 (Itanium) functions
245 .\" See linux/arch/ia64/kernel/gate.lds.S
246 .\" Also linux/arch/ia64/kernel/fsys.S and linux/Documentation/ia64/fsys.txt
247 The table below lists the symbols exported by the vDSO.
248 .if t \{\
249 .ft CW
250 \}
251 .TS
252 l l.
253 symbol version
254 _
255 __kernel_sigtramp LINUX_2.5
256 __kernel_syscall_via_break LINUX_2.5
257 __kernel_syscall_via_epc LINUX_2.5
258 .TE
259 .if t \{\
260 .in
261 .ft P
262 \}
263
264 The Itanium port is somewhat tricky.
265 In addition to the vDSO above, it also has "light-weight system calls"
266 (also known as "fast syscalls" or "fsys").
267 You can invoke these via the
268 .I __kernel_syscall_via_epc
269 vDSO helper.
270 The system calls listed here have the same semantics as if you called them
271 directly via
272 .BR syscall (2),
273 so refer to the relevant
274 documentation for each.
275 The table below lists the functions available via this mechanism.
276 .if t \{\
277 .ft CW
278 \}
279 .TS
280 l.
281 function
282 _
283 clock_gettime
284 getcpu
285 getpid
286 getppid
287 gettimeofday
288 set_tid_address
289 .TE
290 .if t \{\
291 .in
292 .ft P
293 \}
294 .SS parisc (hppa) functions
295 .\" See linux/arch/parisc/kernel/syscall.S
296 .\" See linux/Documentation/parisc/registers
297 The parisc port has a code page full of utility functions
298 called a gateway page.
299 Rather than use the normal ELF auxiliary vector approach,
300 it passes the address of
301 the page to the process via the SR2 register.
302 The permissions on the page are such that merely executing those addresses
303 automatically executes with kernel privileges and not in user space.
304 This is done to match the way HP-UX works.
305
306 Since it's just a raw page of code, there is no ELF information for doing
307 symbol lookups or versioning.
308 Simply call into the appropriate offset via the branch instruction,
309 for example:
310
311 ble <offset>(%sr2, %r0)
312 .if t \{\
313 .ft CW
314 \}
315 .TS
316 l l.
317 offset function
318 _
319 00b0 lws_entry
320 00e0 set_thread_pointer
321 0100 linux_gateway_entry (syscall)
322 0268 syscall_nosys
323 0274 tracesys
324 0324 tracesys_next
325 0368 tracesys_exit
326 03a0 tracesys_sigexit
327 03b8 lws_start
328 03dc lws_exit_nosys
329 03e0 lws_exit
330 03e4 lws_compare_and_swap64
331 03e8 lws_compare_and_swap
332 0404 cas_wouldblock
333 0410 cas_action
334 .TE
335 .if t \{\
336 .in
337 .ft P
338 \}
339 .SS ppc/32 functions
340 .\" See linux/arch/powerpc/kernel/vdso32/vdso32.lds.S
341 The table below lists the symbols exported by the vDSO.
342 The functions marked with a
343 .I *
344 are available only when the kernel is
345 a PowerPC64 (64-bit) kernel.
346 .if t \{\
347 .ft CW
348 \}
349 .TS
350 l l.
351 symbol version
352 _
353 __kernel_clock_getres LINUX_2.6.15
354 __kernel_clock_gettime LINUX_2.6.15
355 __kernel_datapage_offset LINUX_2.6.15
356 __kernel_get_syscall_map LINUX_2.6.15
357 __kernel_get_tbfreq LINUX_2.6.15
358 __kernel_getcpu \fI*\fR LINUX_2.6.15
359 __kernel_gettimeofday LINUX_2.6.15
360 __kernel_sigtramp_rt32 LINUX_2.6.15
361 __kernel_sigtramp32 LINUX_2.6.15
362 __kernel_sync_dicache LINUX_2.6.15
363 __kernel_sync_dicache_p5 LINUX_2.6.15
364 .TE
365 .if t \{\
366 .in
367 .ft P
368 \}
369 .SS ppc/64 functions
370 .\" See linux/arch/powerpc/kernel/vdso64/vdso64.lds.S
371 The table below lists the symbols exported by the vDSO.
372 .if t \{\
373 .ft CW
374 \}
375 .TS
376 l l.
377 symbol version
378 _
379 __kernel_clock_getres LINUX_2.6.15
380 __kernel_clock_gettime LINUX_2.6.15
381 __kernel_datapage_offset LINUX_2.6.15
382 __kernel_get_syscall_map LINUX_2.6.15
383 __kernel_get_tbfreq LINUX_2.6.15
384 __kernel_getcpu LINUX_2.6.15
385 __kernel_gettimeofday LINUX_2.6.15
386 __kernel_sigtramp_rt64 LINUX_2.6.15
387 __kernel_sync_dicache LINUX_2.6.15
388 __kernel_sync_dicache_p5 LINUX_2.6.15
389 .TE
390 .if t \{\
391 .in
392 .ft P
393 \}
394 .SS s390 functions
395 .\" See linux/arch/s390/kernel/vdso32/vdso32.lds.S
396 The table below lists the symbols exported by the vDSO.
397 .if t \{\
398 .ft CW
399 \}
400 .TS
401 l l.
402 symbol version
403 _
404 __kernel_clock_getres LINUX_2.6.29
405 __kernel_clock_gettime LINUX_2.6.29
406 __kernel_gettimeofday LINUX_2.6.29
407 .TE
408 .if t \{\
409 .in
410 .ft P
411 \}
412 .SS s390x functions
413 .\" See linux/arch/s390/kernel/vdso64/vdso64.lds.S
414 The table below lists the symbols exported by the vDSO.
415 .if t \{\
416 .ft CW
417 \}
418 .TS
419 l l.
420 symbol version
421 _
422 __kernel_clock_getres LINUX_2.6.29
423 __kernel_clock_gettime LINUX_2.6.29
424 __kernel_gettimeofday LINUX_2.6.29
425 .TE
426 .if t \{\
427 .in
428 .ft P
429 \}
430 .SS sh (SuperH) functions
431 .\" See linux/arch/sh/kernel/vsyscall/vsyscall.lds.S
432 The table below lists the symbols exported by the vDSO.
433 .if t \{\
434 .ft CW
435 \}
436 .TS
437 l l.
438 symbol version
439 _
440 __kernel_rt_sigreturn LINUX_2.6
441 __kernel_sigreturn LINUX_2.6
442 __kernel_vsyscall LINUX_2.6
443 .TE
444 .if t \{\
445 .in
446 .ft P
447 \}
448 .SS i386 functions
449 .\" See linux/arch/x86/vdso/vdso32/vdso32.lds.S
450 The table below lists the symbols exported by the vDSO.
451 .if t \{\
452 .ft CW
453 \}
454 .TS
455 l l.
456 symbol version
457 _
458 __kernel_sigreturn LINUX_2.5
459 __kernel_rt_sigreturn LINUX_2.5
460 __kernel_vsyscall LINUX_2.5
461 .\" Added in 7a59ed415f5b57469e22e41fc4188d5399e0b194 and updated
462 .\" in 37c975545ec63320789962bf307f000f08fabd48.
463 __vdso_clock_gettime LINUX_2.6 (exported since Linux 3.15)
464 __vdso_gettimeofday LINUX_2.6 (exported since Linux 3.15)
465 __vdso_time LINUX_2.6 (exported since Linux 3.15)
466 .TE
467 .if t \{\
468 .in
469 .ft P
470 \}
471 .SS x86_64 functions
472 .\" See linux/arch/x86/vdso/vdso.lds.S
473 The table below lists the symbols exported by the vDSO.
474 All of these symbols are also available without the "__vdso_" prefix, but
475 you should ignore those and stick to the names below.
476 .if t \{\
477 .ft CW
478 \}
479 .TS
480 l l.
481 symbol version
482 _
483 __vdso_clock_gettime LINUX_2.6
484 __vdso_getcpu LINUX_2.6
485 __vdso_gettimeofday LINUX_2.6
486 __vdso_time LINUX_2.6
487 .TE
488 .if t \{\
489 .in
490 .ft P
491 \}
492 .SS x86/x32 functions
493 .\" See linux/arch/x86/vdso/vdso32.lds.S
494 The table below lists the symbols exported by the vDSO.
495 .if t \{\
496 .ft CW
497 \}
498 .TS
499 l l.
500 symbol version
501 _
502 __vdso_clock_gettime LINUX_2.6
503 __vdso_getcpu LINUX_2.6
504 __vdso_gettimeofday LINUX_2.6
505 __vdso_time LINUX_2.6
506 .TE
507 .if t \{\
508 .in
509 .ft P
510 \}
511 .SS History
512 The vDSO was originally just a single function\(emthe vsyscall.
513 In older kernels, you might see that name
514 in a process's memory map rather than "vdso".
515 Over time, people realized that this mechanism
516 was a great way to pass more functionality
517 to user space, so it was reconceived as a vDSO in the current format.
518 .SH SEE ALSO
519 .BR syscalls (2),
520 .BR getauxval (3),
521 .BR proc (5)
522
523 The documents, examples, and source code in the Linux source code tree:
524 .in +4n
525 .nf
526
527 Documentation/ABI/stable/vdso
528 Documentation/ia64/fsys.txt
529 Documentation/vDSO/* (includes examples of using the vDSO)
530
531 find arch/ -iname '*vdso*' -o -iname '*gate*'
532 .fi
533 .in