mirror of
https://sourceware.org/git/glibc.git
synced 2025-06-05 00:22:17 +03:00
X32 has 32-bit long and pointer with 64-bit off_t. Since x32 psABI requires that pointers passed in registers must be zero-extended to 64bit, x32 can share many syscall interfaces with LP64. When a LP64 syscall with long and unsigned long arguments is used for x32, these arguments must be properly extended to 64-bit. Otherwise if the upper 32 bits of the register have undefined value, such a syscall will be rejected by kernel. Enforce zero-extension for pointers and array system call arguments. For integer types, extend to int64_t (the full register) using a regular cast, resulting in zero or sign extension based on the signedness of the original type. For void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset); we now generate 0: 41 f7 c1 ff 0f 00 00 test $0xfff,%r9d 7: 75 1f jne 28 <__mmap64+0x28> 9: 48 63 d2 movslq %edx,%rdx c: 89 f6 mov %esi,%esi e: 4d 63 c0 movslq %r8d,%r8 11: 4c 63 d1 movslq %ecx,%r10 14: b8 09 00 00 40 mov $0x40000009,%eax 19: 0f 05 syscall That is 1. addr is unchanged. 2. length is zero-extend to 64 bits. 3. prot is sign-extend to 64 bits. 4. flags is sign-extend to 64 bits. 5. fd is sign-extend to 64 bits. 6. offset is unchanged. For int arguments, since kernel uses only the lower 32 bits and ignores the upper 32 bits in 64-bit registers, these work correctly. Tested on x86-64 and x32. There are no code changes on x86-64.
46 lines
1.7 KiB
C
46 lines
1.7 KiB
C
/* Copyright (C) 2012-2020 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
|
|
<https://www.gnu.org/licenses/>. */
|
|
|
|
#ifndef _LINUX_X32_SYSDEP_H
|
|
#define _LINUX_X32_SYSDEP_H 1
|
|
|
|
/* There is some commonality. */
|
|
#include <sysdeps/unix/sysv/linux/x86_64/sysdep.h>
|
|
#include <sysdeps/x86_64/x32/sysdep.h>
|
|
|
|
/* How to pass the off{64}_t argument on p{readv,writev}{64}. */
|
|
#undef LO_HI_LONG
|
|
#define LO_HI_LONG(val) (val)
|
|
|
|
#ifndef __ASSEMBLER__
|
|
# undef ARGIFY
|
|
/* Enforce zero-extension for pointers and array system call arguments.
|
|
For integer types, extend to int64_t (the full register) using a
|
|
regular cast, resulting in zero or sign extension based on the
|
|
signedness of the original type. */
|
|
# define ARGIFY(X) \
|
|
({ \
|
|
_Pragma ("GCC diagnostic push"); \
|
|
_Pragma ("GCC diagnostic ignored \"-Wpointer-to-int-cast\""); \
|
|
(__builtin_classify_type (X) == 5 \
|
|
? (uintptr_t) (X) : (int64_t) (X)); \
|
|
_Pragma ("GCC diagnostic pop"); \
|
|
})
|
|
#endif /* __ASSEMBLER__ */
|
|
|
|
#endif /* linux/x86_64/x32/sysdep.h */
|