Blame sysdeps/unix/sysv/linux/personality.c

Packit Service 82fcde
/* Copyright (C) 2015-2018 Free Software Foundation, Inc.
Packit Service 82fcde
   This file is part of the GNU C Library.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is free software; you can redistribute it and/or
Packit Service 82fcde
   modify it under the terms of the GNU Lesser General Public
Packit Service 82fcde
   License as published by the Free Software Foundation; either
Packit Service 82fcde
   version 2.1 of the License, or (at your option) any later version.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service 82fcde
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 82fcde
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 82fcde
   Lesser General Public License for more details.
Packit Service 82fcde
Packit Service 82fcde
   You should have received a copy of the GNU Lesser General Public
Packit Service 82fcde
   License along with the GNU C Library; if not, see
Packit Service 82fcde
   <http://www.gnu.org/licenses/>.  */
Packit Service 82fcde
Packit Service 82fcde
#include <sys/personality.h>
Packit Service 82fcde
#include <sysdep.h>
Packit Service 82fcde
Packit Service 82fcde
extern __typeof (personality) __personality;
Packit Service 82fcde
Packit Service 82fcde
int
Packit Service 82fcde
__personality (unsigned long persona)
Packit Service 82fcde
{
Packit Service 82fcde
#ifdef PERSONALITY_TRUNCATE_ARGUMENT
Packit Service 82fcde
  /* Starting with kernel commit v2.6.21-3117-g97dc32c, the type of
Packit Service 82fcde
     task_struct->pesonality is "unsigned int".
Packit Service 82fcde
     Starting with kernel commit v2.6.35-rc1-372-g485d527, the personality
Packit Service 82fcde
     syscall accepts "unsigned int" instead of "long unsigned int".
Packit Service 82fcde
     Inbetween, a personality argument that does not fit into "unsigned int"
Packit Service 82fcde
     would result to system call returning -EINVAL.
Packit Service 82fcde
     We explicitly truncate the personality argument to "unsigned int"
Packit Service 82fcde
     to eliminate the uncertainty.  */
Packit Service 82fcde
  persona = (unsigned int) persona;
Packit Service 82fcde
#endif
Packit Service 82fcde
Packit Service 82fcde
  INTERNAL_SYSCALL_DECL (err);
Packit Service 82fcde
  long ret = INTERNAL_SYSCALL (personality, err, 1, persona);
Packit Service 82fcde
Packit Service 82fcde
  /* Starting with kernel commit v2.6.29-6609-g11d06b2, the personality syscall
Packit Service 82fcde
     never fails.  However, 32-bit kernels might flag valid values as errors, so
Packit Service 82fcde
     we need to reverse the error setting.  We can't use the raw result as some
Packit Service 82fcde
     arches split the return/error values.  */
Packit Service 82fcde
  if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (ret, err)))
Packit Service 82fcde
    ret = -INTERNAL_SYSCALL_ERRNO (ret, err);
Packit Service 82fcde
  return ret;
Packit Service 82fcde
}
Packit Service 82fcde
weak_alias (__personality, personality)