1/* Copyright (C) 2015-2022 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
17
18#include <sys/personality.h>
19#include <sysdep.h>
20
21extern __typeof (personality) __personality;
22
23int
24__personality (unsigned long persona)
25{
26#ifdef PERSONALITY_TRUNCATE_ARGUMENT
27 /* Starting with kernel commit v2.6.21-3117-g97dc32c, the type of
28 task_struct->pesonality is "unsigned int".
29 Starting with kernel commit v2.6.35-rc1-372-g485d527, the personality
30 syscall accepts "unsigned int" instead of "long unsigned int".
31 Inbetween, a personality argument that does not fit into "unsigned int"
32 would result to system call returning -EINVAL.
33 We explicitly truncate the personality argument to "unsigned int"
34 to eliminate the uncertainty. */
35 persona = (unsigned int) persona;
36#endif
37
38 long int ret = INTERNAL_SYSCALL_CALL (personality, persona);
39
40 /* Starting with kernel commit v2.6.29-6609-g11d06b2, the personality syscall
41 never fails. However, 32-bit kernels might flag valid values as errors, so
42 we need to reverse the error setting. We can't use the raw result as some
43 arches split the return/error values. */
44 if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (ret)))
45 ret = -INTERNAL_SYSCALL_ERRNO (ret);
46 return ret;
47}
48weak_alias (__personality, personality)
49

source code of glibc/sysdeps/unix/sysv/linux/personality.c