]>
Commit | Line | Data |
---|---|---|
da0331a8 | 1 | /* arch_prctl call for Linux/x32. |
688903eb | 2 | Copyright (C) 2012-2018 Free Software Foundation, Inc. |
da0331a8 L |
3 | This file is part of the GNU C Library. |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
6 | modify it under the terms of the GNU Lesser General Public | |
7 | License as published by the Free Software Foundation; either | |
8 | version 2.1 of the License, or (at your option) any later version. | |
9 | ||
10 | The GNU C Library is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | Lesser General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU Lesser General Public | |
16 | License along with the GNU C Library; if not, see | |
17 | <http://www.gnu.org/licenses/>. */ | |
18 | ||
19 | #include <errno.h> | |
20 | #include <sys/prctl.h> | |
21 | #include <sys/syscall.h> | |
22 | #include <sysdep.h> | |
e054f494 | 23 | #include <stdint.h> |
da0331a8 L |
24 | |
25 | /* Since x32 arch_prctl stores 32-bit base address of segment registers | |
26 | %fs and %gs as unsigned 64-bit value via ARCH_GET_FS and ARCH_GET_GS, | |
27 | we use an unsigned 64-bit variable to hold the base address and copy | |
28 | it to ADDR after the system call returns. */ | |
29 | ||
30 | int | |
31 | __arch_prctl (int code, uintptr_t *addr) | |
32 | { | |
33 | int res; | |
34 | uint64_t addr64; | |
35 | void *prctl_arg = addr; | |
36 | ||
37 | switch (code) | |
38 | { | |
39 | case ARCH_GET_FS: | |
40 | case ARCH_GET_GS: | |
41 | prctl_arg = &addr64; | |
42 | break; | |
43 | } | |
44 | ||
45 | res = INLINE_SYSCALL (arch_prctl, 2, code, prctl_arg); | |
46 | if (res == 0) | |
47 | switch (code) | |
48 | { | |
49 | case ARCH_GET_FS: | |
50 | case ARCH_GET_GS: | |
51 | /* Check for a large value that overflows. */ | |
52 | if ((uintptr_t) addr64 != addr64) | |
53 | { | |
54 | __set_errno (EOVERFLOW); | |
55 | return -1; | |
56 | } | |
57 | *addr = (uintptr_t) addr64; | |
58 | break; | |
59 | } | |
60 | ||
61 | return res; | |
62 | } | |
63 | weak_alias (__arch_prctl, arch_prctl) |