Update copyright notices with scripts/update-copyrights
[glibc.git] / sysdeps / unix / sysv / linux / x86_64 / x32 / arch_prctl.c
blob14b91f0d9d1374e46094ca2b46924ba115277321
1 /* arch_prctl call for Linux/x32.
2 Copyright (C) 2012-2014 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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/>. */
19 #include <errno.h>
20 #include <sys/prctl.h>
21 #include <sys/syscall.h>
22 #include <sysdep.h>
23 #include <stdint.h>
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. */
30 int
31 __arch_prctl (int code, uintptr_t *addr)
33 int res;
34 uint64_t addr64;
35 void *prctl_arg = addr;
37 switch (code)
39 case ARCH_GET_FS:
40 case ARCH_GET_GS:
41 prctl_arg = &addr64;
42 break;
45 res = INLINE_SYSCALL (arch_prctl, 2, code, prctl_arg);
46 if (res == 0)
47 switch (code)
49 case ARCH_GET_FS:
50 case ARCH_GET_GS:
51 /* Check for a large value that overflows. */
52 if ((uintptr_t) addr64 != addr64)
54 __set_errno (EOVERFLOW);
55 return -1;
57 *addr = (uintptr_t) addr64;
58 break;
61 return res;
63 weak_alias (__arch_prctl, arch_prctl)