This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: Add x32 arch_prctl support


On Mon, May 21, 2012 at 5:46 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Mon, May 21, 2012 at 4:53 PM, Roland McGrath <roland@hack.frob.com> wrote:
>>> The goes back to user uint32_t vs kernel uint64_t:
>>>
>>> http://sourceware.org/ml/libc-alpha/2012-05/msg01519.html
>>>
>>> The difference is movq vs movl. ?There is no need for movq
>>> since x32 will only pass unsigned 32-bit value to kernel.
>>
>> I see. ?That one byte in a rarely-used call is not reason enough to
>> make the code uglier.
>
> Also since all inlined arguments will be casted to "long int",
> using unsigned long long int or uint64_t is quite strange.
>
>>> Thanks. ?But since x32 kernel takes PTRACE_ARCH_PRCTL, I
>>> still need x32 ptrace to either handle it properly or set EINVAL
>>> when PTRACE_ARCH_PRCTL is passed.
>>
>> It was my proposal that the kernel be changed to refuse PTRACE_ARCH_PRCTL
>> in a ptrace call made from an x32 task.
>>
>
> Adding Peter. ?The x32 PTRACE_ARCH_PRCTL change is in kernel 3.4.
> Peter, how hard to remove it from kernel?
>

I submitted a patch to remove x32 PTRACE_ARCH_PRCTL from
kernel.  Here is a patch with only arch_prctl.c. OK to install?

Thanks.

-- 
H.J.
---

	* sysdeps/unix/sysv/linux/x86_64/x32/Makefile (sysdep_routines):
	Add arch_prctl.
	* sysdeps/unix/sysv/linux/x86_64/x32/arch_prctl.c: New file.

diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/Makefile b/sysdeps/unix/sysv/lin
ux/x86_64/x32/Makefile
index 5f77df7..aa78238 100644
--- a/sysdeps/unix/sysv/linux/x86_64/x32/Makefile
+++ b/sysdeps/unix/sysv/linux/x86_64/x32/Makefile
@@ -1,3 +1,7 @@
+ifeq ($(subdir),misc)
+sysdep_routines += arch_prctl
+endif
+
 ifeq ($(subdir),posix)
 sysdep_routines += getcpu sched_getcpu-static
 endif
diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/arch_prctl.c b/sysdeps/unix/sysv
/linux/x86_64/x32/arch_prctl.c
new file mode 100644
index 0000000..44c100b
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/x86_64/x32/arch_prctl.c
@@ -0,0 +1,64 @@
+/* arch_prctl call for Linux/x32.
+   Copyright (C) 2012 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <sys/prctl.h>
+#include <sys/syscall.h>
+#include <sysdep.h>
+
+/* Since x32 arch_prctl stores 32-bit base address of segment register %fs
+   and %gs as unsigned 64-bit value via ARCH_GET_FS and ARCH_GET_GS, we
+   use a local unsigned 64-bit variable to hold the base address and copy
+   it to ADDR after arch_prctl return.  */
+
+int
+__arch_prctl (int code, uintptr_t *addr)
+{
+  int res;
+  uint64_t addr64;
+  uintptr_t *addr_saved;
+
+  switch (code)
+    {
+    case ARCH_GET_FS:
+    case ARCH_GET_GS:
+      addr_saved = addr;
+      addr = (uintptr_t *) &addr64;
+      break;
+    }
+
+  res = INLINE_SYSCALL (arch_prctl, 2, code, addr);
+  if (res == 0)
+    switch (code)
+      {
+      case ARCH_GET_FS:
+      case ARCH_GET_GS:
+	 /* Check for a large value that overflows.  */
+	if ((uintptr_t) addr64 != addr64)
+	  {
+	    __set_errno (EOVERFLOW);
+	    return -1;
+	  }
+	*addr_saved = (uintptr_t) addr64;
+	break;
+      }
+
+  return res;
+}
+
+weak_alias (__arch_prctl, arch_prctl)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]