Update copyright notices with scripts/update-copyrights.
[glibc.git] / sysdeps / unix / sysv / linux / x86_64 / x32 / arch_prctl.c
blob7f6dee309fc6ae8a42ac081012b5f04331b35217
1 /* arch_prctl call for Linux/x32.
2 Copyright (C) 2012-2013 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>
24 /* Since x32 arch_prctl stores 32-bit base address of segment registers
25 %fs and %gs as unsigned 64-bit value via ARCH_GET_FS and ARCH_GET_GS,
26 we use an unsigned 64-bit variable to hold the base address and copy
27 it to ADDR after the system call returns. */
29 int
30 __arch_prctl (int code, uintptr_t *addr)
32 int res;
33 uint64_t addr64;
34 void *prctl_arg = addr;
36 switch (code)
38 case ARCH_GET_FS:
39 case ARCH_GET_GS:
40 prctl_arg = &addr64;
41 break;
44 res = INLINE_SYSCALL (arch_prctl, 2, code, prctl_arg);
45 if (res == 0)
46 switch (code)
48 case ARCH_GET_FS:
49 case ARCH_GET_GS:
50 /* Check for a large value that overflows. */
51 if ((uintptr_t) addr64 != addr64)
53 __set_errno (EOVERFLOW);
54 return -1;
56 *addr = (uintptr_t) addr64;
57 break;
60 return res;
62 weak_alias (__arch_prctl, arch_prctl)