aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-03-29 21:12:23 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-03-29 21:12:23 -0400
commita591afc01d9e48affbacb365558a31e53c85af45 (patch)
tree9bb91f4eb94ec69fc4706c4944788ec5f3586063
parent820d41cf0cd0e94a5661e093821e2e5c6b36a9d8 (diff)
parent31796ac4e8f0e88f5c10f1ad6dab8f19bebe44a4 (diff)
Merge branch 'x86-x32-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x32 support for x86-64 from Ingo Molnar: "This tree introduces the X32 binary format and execution mode for x86: 32-bit data space binaries using 64-bit instructions and 64-bit kernel syscalls. This allows applications whose working set fits into a 32 bits address space to make use of 64-bit instructions while using a 32-bit address space with shorter pointers, more compressed data structures, etc." Fix up trivial context conflicts in arch/x86/{Kconfig,vdso/vma.c} * 'x86-x32-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (71 commits) x32: Fix alignment fail in struct compat_siginfo x32: Fix stupid ia32/x32 inversion in the siginfo format x32: Add ptrace for x32 x32: Switch to a 64-bit clock_t x32: Provide separate is_ia32_task() and is_x32_task() predicates x86, mtrr: Use explicit sizing and padding for the 64-bit ioctls x86/x32: Fix the binutils auto-detect x32: Warn and disable rather than error if binutils too old x32: Only clear TIF_X32 flag once x32: Make sure TS_COMPAT is cleared for x32 tasks fs: Remove missed ->fds_bits from cessation use of fd_set structs internally fs: Fix close_on_exec pointer in alloc_fdtable x32: Drop non-__vdso weak symbols from the x32 VDSO x32: Fix coding style violations in the x32 VDSO code x32: Add x32 VDSO support x32: Allow x32 to be configured x32: If configured, add x32 system calls to system call tables x32: Handle process creation x32: Signal-related system calls x86: Add #ifdef CONFIG_COMPAT to <asm/sys_ia32.h> ...
-rw-r--r--Documentation/filesystems/files.txt4
-rw-r--r--arch/alpha/include/asm/posix_types.h113
-rw-r--r--arch/arm/include/asm/posix_types.h55
-rw-r--r--arch/avr32/include/asm/posix_types.h107
-rw-r--r--arch/cris/include/asm/posix_types.h50
-rw-r--r--arch/frv/include/asm/posix_types.h53
-rw-r--r--arch/h8300/include/asm/posix_types.h49
-rw-r--r--arch/ia64/include/asm/posix_types.h121
-rw-r--r--arch/m32r/include/asm/posix_types.h108
-rw-r--r--arch/m68k/include/asm/posix_types.h53
-rw-r--r--arch/mips/include/asm/posix_types.h121
-rw-r--r--arch/mips/kernel/kspd.c2
-rw-r--r--arch/mn10300/include/asm/posix_types.h111
-rw-r--r--arch/parisc/include/asm/posix_types.h119
-rw-r--r--arch/powerpc/include/asm/posix_types.h118
-rw-r--r--arch/powerpc/platforms/cell/spufs/coredump.c2
-rw-r--r--arch/s390/include/asm/posix_types.h70
-rw-r--r--arch/sh/include/asm/posix_types_32.h5
-rw-r--r--arch/sh/include/asm/posix_types_64.h4
-rw-r--r--arch/sparc/include/asm/posix_types.h133
-rw-r--r--arch/x86/Kconfig21
-rw-r--r--arch/x86/Makefile16
-rw-r--r--arch/x86/ia32/ia32_signal.c22
-rw-r--r--arch/x86/ia32/sys_ia32.c40
-rw-r--r--arch/x86/include/asm/Kbuild2
-rw-r--r--arch/x86/include/asm/compat.h49
-rw-r--r--arch/x86/include/asm/elf.h31
-rw-r--r--arch/x86/include/asm/ia32.h18
-rw-r--r--arch/x86/include/asm/mtrr.h28
-rw-r--r--arch/x86/include/asm/posix_types.h4
-rw-r--r--arch/x86/include/asm/posix_types_32.h75
-rw-r--r--arch/x86/include/asm/posix_types_64.h106
-rw-r--r--arch/x86/include/asm/posix_types_x32.h19
-rw-r--r--arch/x86/include/asm/processor.h10
-rw-r--r--arch/x86/include/asm/ptrace.h1
-rw-r--r--arch/x86/include/asm/sigcontext.h57
-rw-r--r--arch/x86/include/asm/sigframe.h13
-rw-r--r--arch/x86/include/asm/sighandling.h24
-rw-r--r--arch/x86/include/asm/sys_ia32.h7
-rw-r--r--arch/x86/include/asm/syscall.h5
-rw-r--r--arch/x86/include/asm/thread_info.h6
-rw-r--r--arch/x86/include/asm/unistd.h15
-rw-r--r--arch/x86/kernel/asm-offsets_64.c6
-rw-r--r--arch/x86/kernel/cpu/mtrr/if.c10
-rw-r--r--arch/x86/kernel/cpu/perf_event.c4
-rw-r--r--arch/x86/kernel/entry_64.S44
-rw-r--r--arch/x86/kernel/process_64.c27
-rw-r--r--arch/x86/kernel/ptrace.c99
-rw-r--r--arch/x86/kernel/signal.c138
-rw-r--r--arch/x86/kernel/sys_x86_64.c6
-rw-r--r--arch/x86/kernel/syscall_64.c8
-rw-r--r--arch/x86/oprofile/backtrace.c2
-rw-r--r--arch/x86/syscalls/Makefile22
-rw-r--r--arch/x86/syscalls/syscall_32.tbl2
-rw-r--r--arch/x86/syscalls/syscall_64.tbl579
-rw-r--r--arch/x86/um/sys_call_table_64.c3
-rw-r--r--arch/x86/um/user-offsets.c2
-rw-r--r--arch/x86/vdso/.gitignore2
-rw-r--r--arch/x86/vdso/Makefile46
-rw-r--r--arch/x86/vdso/vdso32-setup.c5
-rw-r--r--arch/x86/vdso/vdsox32.S22
-rw-r--r--arch/x86/vdso/vdsox32.lds.S28
-rw-r--r--arch/x86/vdso/vma.c78
-rw-r--r--arch/xtensa/include/asm/posix_types.h97
-rw-r--r--drivers/char/lp.c5
-rw-r--r--drivers/input/input-compat.c4
-rw-r--r--drivers/input/input-compat.h2
-rw-r--r--drivers/staging/android/binder.c13
-rw-r--r--fs/autofs4/dev-ioctl.c2
-rw-r--r--fs/binfmt_elf.c24
-rw-r--r--fs/compat.c26
-rw-r--r--fs/exec.c8
-rw-r--r--fs/fcntl.c18
-rw-r--r--fs/file.c52
-rw-r--r--fs/open.c4
-rw-r--r--fs/proc/base.c2
-rw-r--r--fs/select.c2
-rw-r--r--include/asm-generic/posix_types.h109
-rw-r--r--include/linux/Kbuild1
-rw-r--r--include/linux/aio_abi.h2
-rw-r--r--include/linux/compat.h20
-rw-r--r--include/linux/fdtable.h46
-rw-r--r--include/linux/kernel.h21
-rw-r--r--include/linux/sysinfo.h24
-rw-r--r--include/linux/time.h1
-rw-r--r--kernel/compat.c68
-rw-r--r--kernel/exit.c2
-rw-r--r--net/bluetooth/hci_sock.c3
-rw-r--r--net/compat.c65
-rw-r--r--net/socket.c18
-rw-r--r--security/selinux/hooks.c2
91 files changed, 1561 insertions, 2180 deletions
diff --git a/Documentation/filesystems/files.txt b/Documentation/filesystems/files.txt
index ac2facc50d2a..46dfc6b038c3 100644
--- a/Documentation/filesystems/files.txt
+++ b/Documentation/filesystems/files.txt
@@ -113,8 +113,8 @@ the fdtable structure -
113 if (fd >= 0) { 113 if (fd >= 0) {
114 /* locate_fd() may have expanded fdtable, load the ptr */ 114 /* locate_fd() may have expanded fdtable, load the ptr */
115 fdt = files_fdtable(files); 115 fdt = files_fdtable(files);
116 FD_SET(fd, fdt->open_fds); 116 __set_open_fd(fd, fdt);
117 FD_CLR(fd, fdt->close_on_exec); 117 __clear_close_on_exec(fd, fdt);
118 spin_unlock(&files->file_lock); 118 spin_unlock(&files->file_lock);
119 ..... 119 .....
120 120
diff --git a/arch/alpha/include/asm/posix_types.h b/arch/alpha/include/asm/posix_types.h
index db167413300b..24779fc95994 100644
--- a/arch/alpha/include/asm/posix_types.h
+++ b/arch/alpha/include/asm/posix_types.h
@@ -8,116 +8,13 @@
8 */ 8 */
9 9
10typedef unsigned int __kernel_ino_t; 10typedef unsigned int __kernel_ino_t;
11typedef unsigned int __kernel_mode_t; 11#define __kernel_ino_t __kernel_ino_t
12typedef unsigned int __kernel_nlink_t;
13typedef long __kernel_off_t;
14typedef long long __kernel_loff_t;
15typedef int __kernel_pid_t;
16typedef int __kernel_ipc_pid_t;
17typedef unsigned int __kernel_uid_t;
18typedef unsigned int __kernel_gid_t;
19typedef unsigned long __kernel_size_t;
20typedef long __kernel_ssize_t;
21typedef long __kernel_ptrdiff_t;
22typedef long __kernel_time_t;
23typedef long __kernel_suseconds_t;
24typedef long __kernel_clock_t;
25typedef int __kernel_daddr_t;
26typedef char * __kernel_caddr_t;
27typedef unsigned long __kernel_sigset_t; /* at least 32 bits */
28typedef unsigned short __kernel_uid16_t;
29typedef unsigned short __kernel_gid16_t;
30typedef int __kernel_clockid_t;
31typedef int __kernel_timer_t;
32
33typedef struct {
34 int val[2];
35} __kernel_fsid_t;
36
37typedef __kernel_uid_t __kernel_old_uid_t;
38typedef __kernel_gid_t __kernel_old_gid_t;
39typedef __kernel_uid_t __kernel_uid32_t;
40typedef __kernel_gid_t __kernel_gid32_t;
41
42typedef unsigned int __kernel_old_dev_t;
43
44#ifdef __KERNEL__
45
46#ifndef __GNUC__
47
48#define __FD_SET(d, set) ((set)->fds_bits[__FDELT(d)] |= __FDMASK(d))
49#define __FD_CLR(d, set) ((set)->fds_bits[__FDELT(d)] &= ~__FDMASK(d))
50#define __FD_ISSET(d, set) (((set)->fds_bits[__FDELT(d)] & __FDMASK(d)) != 0)
51#define __FD_ZERO(set) \
52 ((void) memset ((void *) (set), 0, sizeof (__kernel_fd_set)))
53
54#else /* __GNUC__ */
55
56/* With GNU C, use inline functions instead so args are evaluated only once: */
57 12
58#undef __FD_SET 13typedef unsigned int __kernel_nlink_t;
59static __inline__ void __FD_SET(unsigned long fd, __kernel_fd_set *fdsetp) 14#define __kernel_nlink_t __kernel_nlink_t
60{
61 unsigned long _tmp = fd / __NFDBITS;
62 unsigned long _rem = fd % __NFDBITS;
63 fdsetp->fds_bits[_tmp] |= (1UL<<_rem);
64}
65
66#undef __FD_CLR
67static __inline__ void __FD_CLR(unsigned long fd, __kernel_fd_set *fdsetp)
68{
69 unsigned long _tmp = fd / __NFDBITS;
70 unsigned long _rem = fd % __NFDBITS;
71 fdsetp->fds_bits[_tmp] &= ~(1UL<<_rem);
72}
73
74#undef __FD_ISSET
75static __inline__ int __FD_ISSET(unsigned long fd, const __kernel_fd_set *p)
76{
77 unsigned long _tmp = fd / __NFDBITS;
78 unsigned long _rem = fd % __NFDBITS;
79 return (p->fds_bits[_tmp] & (1UL<<_rem)) != 0;
80}
81
82/*
83 * This will unroll the loop for the normal constant case (8 ints,
84 * for a 256-bit fd_set)
85 */
86#undef __FD_ZERO
87static __inline__ void __FD_ZERO(__kernel_fd_set *p)
88{
89 unsigned long *tmp = p->fds_bits;
90 int i;
91
92 if (__builtin_constant_p(__FDSET_LONGS)) {
93 switch (__FDSET_LONGS) {
94 case 16:
95 tmp[ 0] = 0; tmp[ 1] = 0; tmp[ 2] = 0; tmp[ 3] = 0;
96 tmp[ 4] = 0; tmp[ 5] = 0; tmp[ 6] = 0; tmp[ 7] = 0;
97 tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0;
98 tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0;
99 return;
100
101 case 8:
102 tmp[ 0] = 0; tmp[ 1] = 0; tmp[ 2] = 0; tmp[ 3] = 0;
103 tmp[ 4] = 0; tmp[ 5] = 0; tmp[ 6] = 0; tmp[ 7] = 0;
104 return;
105
106 case 4:
107 tmp[ 0] = 0; tmp[ 1] = 0; tmp[ 2] = 0; tmp[ 3] = 0;
108 return;
109 }
110 }
111 i = __FDSET_LONGS;
112 while (i) {
113 i--;
114 *tmp = 0;
115 tmp++;
116 }
117}
118 15
119#endif /* __GNUC__ */ 16typedef unsigned long __kernel_sigset_t; /* at least 32 bits */
120 17
121#endif /* __KERNEL__ */ 18#include <asm-generic/posix_types.h>
122 19
123#endif /* _ALPHA_POSIX_TYPES_H */ 20#endif /* _ALPHA_POSIX_TYPES_H */
diff --git a/arch/arm/include/asm/posix_types.h b/arch/arm/include/asm/posix_types.h
index 2446d23bfdbf..efdf99045d87 100644
--- a/arch/arm/include/asm/posix_types.h
+++ b/arch/arm/include/asm/posix_types.h
@@ -19,59 +19,22 @@
19 * assume GCC is being used. 19 * assume GCC is being used.
20 */ 20 */
21 21
22typedef unsigned long __kernel_ino_t;
23typedef unsigned short __kernel_mode_t; 22typedef unsigned short __kernel_mode_t;
23#define __kernel_mode_t __kernel_mode_t
24
24typedef unsigned short __kernel_nlink_t; 25typedef unsigned short __kernel_nlink_t;
25typedef long __kernel_off_t; 26#define __kernel_nlink_t __kernel_nlink_t
26typedef int __kernel_pid_t; 27
27typedef unsigned short __kernel_ipc_pid_t; 28typedef unsigned short __kernel_ipc_pid_t;
29#define __kernel_ipc_pid_t __kernel_ipc_pid_t
30
28typedef unsigned short __kernel_uid_t; 31typedef unsigned short __kernel_uid_t;
29typedef unsigned short __kernel_gid_t; 32typedef unsigned short __kernel_gid_t;
30typedef unsigned int __kernel_size_t; 33#define __kernel_uid_t __kernel_uid_t
31typedef int __kernel_ssize_t;
32typedef int __kernel_ptrdiff_t;
33typedef long __kernel_time_t;
34typedef long __kernel_suseconds_t;
35typedef long __kernel_clock_t;
36typedef int __kernel_timer_t;
37typedef int __kernel_clockid_t;
38typedef int __kernel_daddr_t;
39typedef char * __kernel_caddr_t;
40typedef unsigned short __kernel_uid16_t;
41typedef unsigned short __kernel_gid16_t;
42typedef unsigned int __kernel_uid32_t;
43typedef unsigned int __kernel_gid32_t;
44 34
45typedef unsigned short __kernel_old_uid_t;
46typedef unsigned short __kernel_old_gid_t;
47typedef unsigned short __kernel_old_dev_t; 35typedef unsigned short __kernel_old_dev_t;
36#define __kernel_old_dev_t __kernel_old_dev_t
48 37
49#ifdef __GNUC__ 38#include <asm-generic/posix_types.h>
50typedef long long __kernel_loff_t;
51#endif
52
53typedef struct {
54 int val[2];
55} __kernel_fsid_t;
56
57#if defined(__KERNEL__)
58
59#undef __FD_SET
60#define __FD_SET(fd, fdsetp) \
61 (((fd_set *)(fdsetp))->fds_bits[(fd) >> 5] |= (1<<((fd) & 31)))
62
63#undef __FD_CLR
64#define __FD_CLR(fd, fdsetp) \
65 (((fd_set *)(fdsetp))->fds_bits[(fd) >> 5] &= ~(1<<((fd) & 31)))
66
67#undef __FD_ISSET
68#define __FD_ISSET(fd, fdsetp) \
69 ((((fd_set *)(fdsetp))->fds_bits[(fd) >> 5] & (1<<((fd) & 31))) != 0)
70
71#undef __FD_ZERO
72#define __FD_ZERO(fdsetp) \
73 (memset (fdsetp, 0, sizeof (*(fd_set *)(fdsetp))))
74
75#endif
76 39
77#endif 40#endif
diff --git a/arch/avr32/include/asm/posix_types.h b/arch/avr32/include/asm/posix_types.h
index fe0c0c014389..74667bfc88cc 100644
--- a/arch/avr32/include/asm/posix_types.h
+++ b/arch/avr32/include/asm/posix_types.h
@@ -14,112 +14,27 @@
14 * assume GCC is being used. 14 * assume GCC is being used.
15 */ 15 */
16 16
17typedef unsigned long __kernel_ino_t;
18typedef unsigned short __kernel_mode_t; 17typedef unsigned short __kernel_mode_t;
18#define __kernel_mode_t __kernel_mode_t
19
19typedef unsigned short __kernel_nlink_t; 20typedef unsigned short __kernel_nlink_t;
20typedef long __kernel_off_t; 21#define __kernel_nlink_t __kernel_nlink_t
21typedef int __kernel_pid_t; 22
22typedef unsigned short __kernel_ipc_pid_t; 23typedef unsigned short __kernel_ipc_pid_t;
23typedef unsigned int __kernel_uid_t; 24#define __kernel_ipc_pid_t __kernel_ipc_pid_t
24typedef unsigned int __kernel_gid_t; 25
25typedef unsigned long __kernel_size_t; 26typedef unsigned long __kernel_size_t;
26typedef long __kernel_ssize_t; 27typedef long __kernel_ssize_t;
27typedef int __kernel_ptrdiff_t; 28typedef int __kernel_ptrdiff_t;
28typedef long __kernel_time_t; 29#define __kernel_size_t __kernel_size_t
29typedef long __kernel_suseconds_t;
30typedef long __kernel_clock_t;
31typedef int __kernel_timer_t;
32typedef int __kernel_clockid_t;
33typedef int __kernel_daddr_t;
34typedef char * __kernel_caddr_t;
35typedef unsigned short __kernel_uid16_t;
36typedef unsigned short __kernel_gid16_t;
37typedef unsigned int __kernel_uid32_t;
38typedef unsigned int __kernel_gid32_t;
39 30
40typedef unsigned short __kernel_old_uid_t; 31typedef unsigned short __kernel_old_uid_t;
41typedef unsigned short __kernel_old_gid_t; 32typedef unsigned short __kernel_old_gid_t;
42typedef unsigned short __kernel_old_dev_t; 33#define __kernel_old_uid_t __kernel_old_uid_t
43
44#ifdef __GNUC__
45typedef long long __kernel_loff_t;
46#endif
47
48typedef struct {
49 int val[2];
50} __kernel_fsid_t;
51
52#if defined(__KERNEL__)
53
54#undef __FD_SET
55static __inline__ void __FD_SET(unsigned long __fd, __kernel_fd_set *__fdsetp)
56{
57 unsigned long __tmp = __fd / __NFDBITS;
58 unsigned long __rem = __fd % __NFDBITS;
59 __fdsetp->fds_bits[__tmp] |= (1UL<<__rem);
60}
61
62#undef __FD_CLR
63static __inline__ void __FD_CLR(unsigned long __fd, __kernel_fd_set *__fdsetp)
64{
65 unsigned long __tmp = __fd / __NFDBITS;
66 unsigned long __rem = __fd % __NFDBITS;
67 __fdsetp->fds_bits[__tmp] &= ~(1UL<<__rem);
68}
69 34
35typedef unsigned short __kernel_old_dev_t;
36#define __kernel_old_dev_t __kernel_old_dev_t
70 37
71#undef __FD_ISSET 38#include <asm-generic/posix_types.h>
72static __inline__ int __FD_ISSET(unsigned long __fd, const __kernel_fd_set *__p)
73{
74 unsigned long __tmp = __fd / __NFDBITS;
75 unsigned long __rem = __fd % __NFDBITS;
76 return (__p->fds_bits[__tmp] & (1UL<<__rem)) != 0;
77}
78
79/*
80 * This will unroll the loop for the normal constant case (8 ints,
81 * for a 256-bit fd_set)
82 */
83#undef __FD_ZERO
84static __inline__ void __FD_ZERO(__kernel_fd_set *__p)
85{
86 unsigned long *__tmp = __p->fds_bits;
87 int __i;
88
89 if (__builtin_constant_p(__FDSET_LONGS)) {
90 switch (__FDSET_LONGS) {
91 case 16:
92 __tmp[ 0] = 0; __tmp[ 1] = 0;
93 __tmp[ 2] = 0; __tmp[ 3] = 0;
94 __tmp[ 4] = 0; __tmp[ 5] = 0;
95 __tmp[ 6] = 0; __tmp[ 7] = 0;
96 __tmp[ 8] = 0; __tmp[ 9] = 0;
97 __tmp[10] = 0; __tmp[11] = 0;
98 __tmp[12] = 0; __tmp[13] = 0;
99 __tmp[14] = 0; __tmp[15] = 0;
100 return;
101
102 case 8:
103 __tmp[ 0] = 0; __tmp[ 1] = 0;
104 __tmp[ 2] = 0; __tmp[ 3] = 0;
105 __tmp[ 4] = 0; __tmp[ 5] = 0;
106 __tmp[ 6] = 0; __tmp[ 7] = 0;
107 return;
108
109 case 4:
110 __tmp[ 0] = 0; __tmp[ 1] = 0;
111 __tmp[ 2] = 0; __tmp[ 3] = 0;
112 return;
113 }
114 }
115 __i = __FDSET_LONGS;
116 while (__i) {
117 __i--;
118 *__tmp = 0;
119 __tmp++;
120 }
121}
122
123#endif /* defined(__KERNEL__) */
124 39
125#endif /* __ASM_AVR32_POSIX_TYPES_H */ 40#endif /* __ASM_AVR32_POSIX_TYPES_H */
diff --git a/arch/cris/include/asm/posix_types.h b/arch/cris/include/asm/posix_types.h
index ce3fb25a460b..72b3cd6eda0b 100644
--- a/arch/cris/include/asm/posix_types.h
+++ b/arch/cris/include/asm/posix_types.h
@@ -12,55 +12,25 @@
12 * assume GCC is being used. 12 * assume GCC is being used.
13 */ 13 */
14 14
15typedef unsigned long __kernel_ino_t;
16typedef unsigned short __kernel_mode_t; 15typedef unsigned short __kernel_mode_t;
16#define __kernel_mode_t __kernel_mode_t
17
17typedef unsigned short __kernel_nlink_t; 18typedef unsigned short __kernel_nlink_t;
18typedef long __kernel_off_t; 19#define __kernel_nlink_t __kernel_nlink_t
19typedef int __kernel_pid_t; 20
20typedef unsigned short __kernel_ipc_pid_t; 21typedef unsigned short __kernel_ipc_pid_t;
22#define __kernel_ipc_pid_t __kernel_ipc_pid_t
23
21typedef unsigned short __kernel_uid_t; 24typedef unsigned short __kernel_uid_t;
22typedef unsigned short __kernel_gid_t; 25typedef unsigned short __kernel_gid_t;
26#define __kernel_uid_t __kernel_uid_t
27
23typedef __SIZE_TYPE__ __kernel_size_t; 28typedef __SIZE_TYPE__ __kernel_size_t;
24typedef long __kernel_ssize_t; 29typedef long __kernel_ssize_t;
25typedef int __kernel_ptrdiff_t; 30typedef int __kernel_ptrdiff_t;
26typedef long __kernel_time_t; 31#define __kernel_size_t __kernel_size_t
27typedef long __kernel_suseconds_t;
28typedef long __kernel_clock_t;
29typedef int __kernel_timer_t;
30typedef int __kernel_clockid_t;
31typedef int __kernel_daddr_t;
32typedef char * __kernel_caddr_t;
33typedef unsigned short __kernel_uid16_t;
34typedef unsigned short __kernel_gid16_t;
35typedef unsigned int __kernel_uid32_t;
36typedef unsigned int __kernel_gid32_t;
37 32
38typedef unsigned short __kernel_old_uid_t;
39typedef unsigned short __kernel_old_gid_t;
40typedef unsigned short __kernel_old_dev_t; 33typedef unsigned short __kernel_old_dev_t;
41 34#define __kernel_old_dev_t __kernel_old_dev_t
42#ifdef __GNUC__
43typedef long long __kernel_loff_t;
44#endif
45
46typedef struct {
47 int val[2];
48} __kernel_fsid_t;
49
50#ifdef __KERNEL__
51
52#undef __FD_SET
53#define __FD_SET(fd,fdsetp) set_bit(fd, (void *)(fdsetp))
54
55#undef __FD_CLR
56#define __FD_CLR(fd,fdsetp) clear_bit(fd, (void *)(fdsetp))
57
58#undef __FD_ISSET
59#define __FD_ISSET(fd,fdsetp) test_bit(fd, (void *)(fdsetp))
60
61#undef __FD_ZERO
62#define __FD_ZERO(fdsetp) memset((void *)(fdsetp), 0, __FDSET_LONGS << 2)
63
64#endif /* __KERNEL__ */
65 35
66#endif /* __ARCH_CRIS_POSIX_TYPES_H */ 36#endif /* __ARCH_CRIS_POSIX_TYPES_H */
diff --git a/arch/frv/include/asm/posix_types.h b/arch/frv/include/asm/posix_types.h
index a9f1f5be0632..3f34cb45fbb3 100644
--- a/arch/frv/include/asm/posix_types.h
+++ b/arch/frv/include/asm/posix_types.h
@@ -7,56 +7,23 @@
7 * assume GCC is being used. 7 * assume GCC is being used.
8 */ 8 */
9 9
10typedef unsigned long __kernel_ino_t;
11typedef unsigned short __kernel_mode_t; 10typedef unsigned short __kernel_mode_t;
11#define __kernel_mode_t __kernel_mode_t
12
12typedef unsigned short __kernel_nlink_t; 13typedef unsigned short __kernel_nlink_t;
13typedef long __kernel_off_t; 14#define __kernel_nlink_t __kernel_nlink_t
14typedef int __kernel_pid_t; 15
15typedef unsigned short __kernel_ipc_pid_t; 16typedef unsigned short __kernel_ipc_pid_t;
17#define __kernel_ipc_pid_t __kernel_ipc_pid_t
18
16typedef unsigned short __kernel_uid_t; 19typedef unsigned short __kernel_uid_t;
17typedef unsigned short __kernel_gid_t; 20typedef unsigned short __kernel_gid_t;
18typedef unsigned int __kernel_size_t; 21#define __kernel_uid_t __kernel_uid_t
19typedef int __kernel_ssize_t;
20typedef int __kernel_ptrdiff_t;
21typedef long __kernel_time_t;
22typedef long __kernel_suseconds_t;
23typedef long __kernel_clock_t;
24typedef int __kernel_timer_t;
25typedef int __kernel_clockid_t;
26typedef int __kernel_daddr_t;
27typedef char * __kernel_caddr_t;
28typedef unsigned short __kernel_uid16_t;
29typedef unsigned short __kernel_gid16_t;
30typedef unsigned int __kernel_uid32_t;
31typedef unsigned int __kernel_gid32_t;
32
33typedef unsigned short __kernel_old_uid_t;
34typedef unsigned short __kernel_old_gid_t;
35typedef unsigned short __kernel_old_dev_t;
36
37#ifdef __GNUC__
38typedef long long __kernel_loff_t;
39#endif
40 22
41typedef struct { 23typedef unsigned short __kernel_old_dev_t;
42 int val[2]; 24#define __kernel_old_dev_t __kernel_old_dev_t
43} __kernel_fsid_t;
44
45#if defined(__KERNEL__)
46
47#undef __FD_SET
48#define __FD_SET(d, set) ((set)->fds_bits[__FDELT(d)] |= __FDMASK(d))
49
50#undef __FD_CLR
51#define __FD_CLR(d, set) ((set)->fds_bits[__FDELT(d)] &= ~__FDMASK(d))
52
53#undef __FD_ISSET
54#define __FD_ISSET(d, set) (!!((set)->fds_bits[__FDELT(d)] & __FDMASK(d)))
55
56#undef __FD_ZERO
57#define __FD_ZERO(fdsetp) (memset (fdsetp, 0, sizeof(*(fd_set *)fdsetp)))
58 25
59#endif /* defined(__KERNEL__) */ 26#include <asm-generic/posix_types.h>
60 27
61#endif 28#endif
62 29
diff --git a/arch/h8300/include/asm/posix_types.h b/arch/h8300/include/asm/posix_types.h
index 6f833a16f694..bc4c34efb1ad 100644
--- a/arch/h8300/include/asm/posix_types.h
+++ b/arch/h8300/include/asm/posix_types.h
@@ -7,54 +7,23 @@
7 * assume GCC is being used. 7 * assume GCC is being used.
8 */ 8 */
9 9
10typedef unsigned long __kernel_ino_t;
11typedef unsigned short __kernel_mode_t; 10typedef unsigned short __kernel_mode_t;
11#define __kernel_mode_t __kernel_mode_t
12
12typedef unsigned short __kernel_nlink_t; 13typedef unsigned short __kernel_nlink_t;
13typedef long __kernel_off_t; 14#define __kernel_nlink_t __kernel_nlink_t
14typedef int __kernel_pid_t; 15
15typedef unsigned short __kernel_ipc_pid_t; 16typedef unsigned short __kernel_ipc_pid_t;
17#define __kernel_ipc_pid_t __kernel_ipc_pid_t
18
16typedef unsigned short __kernel_uid_t; 19typedef unsigned short __kernel_uid_t;
17typedef unsigned short __kernel_gid_t; 20typedef unsigned short __kernel_gid_t;
18typedef unsigned int __kernel_size_t; 21#define __kernel_uid_t __kernel_uid_t
19typedef int __kernel_ssize_t;
20typedef int __kernel_ptrdiff_t;
21typedef long __kernel_time_t;
22typedef long __kernel_suseconds_t;
23typedef long __kernel_clock_t;
24typedef int __kernel_timer_t;
25typedef int __kernel_clockid_t;
26typedef int __kernel_daddr_t;
27typedef char * __kernel_caddr_t;
28typedef unsigned short __kernel_uid16_t;
29typedef unsigned short __kernel_gid16_t;
30typedef unsigned int __kernel_uid32_t;
31typedef unsigned int __kernel_gid32_t;
32 22
33typedef unsigned short __kernel_old_uid_t; 23typedef unsigned short __kernel_old_uid_t;
34typedef unsigned short __kernel_old_gid_t; 24typedef unsigned short __kernel_old_gid_t;
25#define __kernel_old_uid_t __kernel_old_uid_t
35 26
36#ifdef __GNUC__ 27#include <asm-generic/posix_types.h>
37typedef long long __kernel_loff_t;
38#endif
39
40typedef struct {
41 int val[2];
42} __kernel_fsid_t;
43
44#if defined(__KERNEL__)
45
46#undef __FD_SET
47#define __FD_SET(d, set) ((set)->fds_bits[__FDELT(d)] |= __FDMASK(d))
48
49#undef __FD_CLR
50#define __FD_CLR(d, set) ((set)->fds_bits[__FDELT(d)] &= ~__FDMASK(d))
51
52#undef __FD_ISSET
53#define __FD_ISSET(d, set) (!!((set)->fds_bits[__FDELT(d)] & __FDMASK(d)))
54
55#undef __FD_ZERO
56#define __FD_ZERO(fdsetp) (memset (fdsetp, 0, sizeof(*(fd_set *)fdsetp)))
57
58#endif /* defined(__KERNEL__) */
59 28
60#endif 29#endif
diff --git a/arch/ia64/include/asm/posix_types.h b/arch/ia64/include/asm/posix_types.h
index 17885567b731..7323ab9467eb 100644
--- a/arch/ia64/include/asm/posix_types.h
+++ b/arch/ia64/include/asm/posix_types.h
@@ -1,126 +1,11 @@
1#ifndef _ASM_IA64_POSIX_TYPES_H 1#ifndef _ASM_IA64_POSIX_TYPES_H
2#define _ASM_IA64_POSIX_TYPES_H 2#define _ASM_IA64_POSIX_TYPES_H
3 3
4/*
5 * This file is generally used by user-level software, so you need to
6 * be a little careful about namespace pollution etc. Also, we cannot
7 * assume GCC is being used.
8 *
9 * Based on <asm-alpha/posix_types.h>.
10 *
11 * Modified 1998-2000, 2003
12 * David Mosberger-Tang <davidm@hpl.hp.com>, Hewlett-Packard Co
13 */
14
15typedef unsigned long __kernel_ino_t;
16typedef unsigned int __kernel_mode_t;
17typedef unsigned int __kernel_nlink_t; 4typedef unsigned int __kernel_nlink_t;
18typedef long __kernel_off_t; 5#define __kernel_nlink_t __kernel_nlink_t
19typedef long long __kernel_loff_t;
20typedef int __kernel_pid_t;
21typedef int __kernel_ipc_pid_t;
22typedef unsigned int __kernel_uid_t;
23typedef unsigned int __kernel_gid_t;
24typedef unsigned long __kernel_size_t;
25typedef long __kernel_ssize_t;
26typedef long __kernel_ptrdiff_t;
27typedef long __kernel_time_t;
28typedef long __kernel_suseconds_t;
29typedef long __kernel_clock_t;
30typedef int __kernel_timer_t;
31typedef int __kernel_clockid_t;
32typedef int __kernel_daddr_t;
33typedef char * __kernel_caddr_t;
34typedef unsigned long __kernel_sigset_t; /* at least 32 bits */
35typedef unsigned short __kernel_uid16_t;
36typedef unsigned short __kernel_gid16_t;
37
38typedef struct {
39 int val[2];
40} __kernel_fsid_t;
41
42typedef __kernel_uid_t __kernel_old_uid_t;
43typedef __kernel_gid_t __kernel_old_gid_t;
44typedef __kernel_uid_t __kernel_uid32_t;
45typedef __kernel_gid_t __kernel_gid32_t;
46
47typedef unsigned int __kernel_old_dev_t;
48
49# ifdef __KERNEL__
50
51# ifndef __GNUC__
52
53#define __FD_SET(d, set) ((set)->fds_bits[__FDELT(d)] |= __FDMASK(d))
54#define __FD_CLR(d, set) ((set)->fds_bits[__FDELT(d)] &= ~__FDMASK(d))
55#define __FD_ISSET(d, set) (((set)->fds_bits[__FDELT(d)] & __FDMASK(d)) != 0)
56#define __FD_ZERO(set) \
57 ((void) memset ((void *) (set), 0, sizeof (__kernel_fd_set)))
58 6
59# else /* !__GNUC__ */ 7typedef unsigned long __kernel_sigset_t; /* at least 32 bits */
60
61/* With GNU C, use inline functions instead so args are evaluated only once: */
62
63#undef __FD_SET
64static __inline__ void __FD_SET(unsigned long fd, __kernel_fd_set *fdsetp)
65{
66 unsigned long _tmp = fd / __NFDBITS;
67 unsigned long _rem = fd % __NFDBITS;
68 fdsetp->fds_bits[_tmp] |= (1UL<<_rem);
69}
70
71#undef __FD_CLR
72static __inline__ void __FD_CLR(unsigned long fd, __kernel_fd_set *fdsetp)
73{
74 unsigned long _tmp = fd / __NFDBITS;
75 unsigned long _rem = fd % __NFDBITS;
76 fdsetp->fds_bits[_tmp] &= ~(1UL<<_rem);
77}
78
79#undef __FD_ISSET
80static __inline__ int __FD_ISSET(unsigned long fd, const __kernel_fd_set *p)
81{
82 unsigned long _tmp = fd / __NFDBITS;
83 unsigned long _rem = fd % __NFDBITS;
84 return (p->fds_bits[_tmp] & (1UL<<_rem)) != 0;
85}
86
87/*
88 * This will unroll the loop for the normal constant case (8 ints,
89 * for a 256-bit fd_set)
90 */
91#undef __FD_ZERO
92static __inline__ void __FD_ZERO(__kernel_fd_set *p)
93{
94 unsigned long *tmp = p->fds_bits;
95 int i;
96
97 if (__builtin_constant_p(__FDSET_LONGS)) {
98 switch (__FDSET_LONGS) {
99 case 16:
100 tmp[ 0] = 0; tmp[ 1] = 0; tmp[ 2] = 0; tmp[ 3] = 0;
101 tmp[ 4] = 0; tmp[ 5] = 0; tmp[ 6] = 0; tmp[ 7] = 0;
102 tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0;
103 tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0;
104 return;
105
106 case 8:
107 tmp[ 0] = 0; tmp[ 1] = 0; tmp[ 2] = 0; tmp[ 3] = 0;
108 tmp[ 4] = 0; tmp[ 5] = 0; tmp[ 6] = 0; tmp[ 7] = 0;
109 return;
110 8
111 case 4: 9#include <asm-generic/posix_types.h>
112 tmp[ 0] = 0; tmp[ 1] = 0; tmp[ 2] = 0; tmp[ 3] = 0;
113 return;
114 }
115 }
116 i = __FDSET_LONGS;
117 while (i) {
118 i--;
119 *tmp = 0;
120 tmp++;
121 }
122}
123 10
124# endif /* !__GNUC__ */
125# endif /* __KERNEL__ */
126#endif /* _ASM_IA64_POSIX_TYPES_H */ 11#endif /* _ASM_IA64_POSIX_TYPES_H */
diff --git a/arch/m32r/include/asm/posix_types.h b/arch/m32r/include/asm/posix_types.h
index b309c5858637..0195850e1f88 100644
--- a/arch/m32r/include/asm/posix_types.h
+++ b/arch/m32r/include/asm/posix_types.h
@@ -7,112 +7,22 @@
7 * assume GCC is being used. 7 * assume GCC is being used.
8 */ 8 */
9 9
10typedef unsigned long __kernel_ino_t;
11typedef unsigned short __kernel_mode_t; 10typedef unsigned short __kernel_mode_t;
11#define __kernel_mode_t __kernel_mode_t
12
12typedef unsigned short __kernel_nlink_t; 13typedef unsigned short __kernel_nlink_t;
13typedef long __kernel_off_t; 14#define __kernel_nlink_t __kernel_nlink_t
14typedef int __kernel_pid_t; 15
15typedef unsigned short __kernel_ipc_pid_t; 16typedef unsigned short __kernel_ipc_pid_t;
17#define __kernel_ipc_pid_t __kernel_ipc_pid_t
18
16typedef unsigned short __kernel_uid_t; 19typedef unsigned short __kernel_uid_t;
17typedef unsigned short __kernel_gid_t; 20typedef unsigned short __kernel_gid_t;
18typedef unsigned int __kernel_size_t; 21#define __kernel_uid_t __kernel_uid_t
19typedef int __kernel_ssize_t;
20typedef int __kernel_ptrdiff_t;
21typedef long __kernel_time_t;
22typedef long __kernel_suseconds_t;
23typedef long __kernel_clock_t;
24typedef int __kernel_timer_t;
25typedef int __kernel_clockid_t;
26typedef int __kernel_daddr_t;
27typedef char * __kernel_caddr_t;
28typedef unsigned short __kernel_uid16_t;
29typedef unsigned short __kernel_gid16_t;
30typedef unsigned int __kernel_uid32_t;
31typedef unsigned int __kernel_gid32_t;
32 22
33typedef unsigned short __kernel_old_uid_t;
34typedef unsigned short __kernel_old_gid_t;
35typedef unsigned short __kernel_old_dev_t; 23typedef unsigned short __kernel_old_dev_t;
24#define __kernel_old_dev_t __kernel_old_dev_t
36 25
37#ifdef __GNUC__ 26#include <asm-generic/posix_types.h>
38typedef long long __kernel_loff_t;
39#endif
40
41typedef struct {
42 int val[2];
43} __kernel_fsid_t;
44
45#if defined(__KERNEL__)
46
47#undef __FD_SET
48static __inline__ void __FD_SET(unsigned long __fd, __kernel_fd_set *__fdsetp)
49{
50 unsigned long __tmp = __fd / __NFDBITS;
51 unsigned long __rem = __fd % __NFDBITS;
52 __fdsetp->fds_bits[__tmp] |= (1UL<<__rem);
53}
54
55#undef __FD_CLR
56static __inline__ void __FD_CLR(unsigned long __fd, __kernel_fd_set *__fdsetp)
57{
58 unsigned long __tmp = __fd / __NFDBITS;
59 unsigned long __rem = __fd % __NFDBITS;
60 __fdsetp->fds_bits[__tmp] &= ~(1UL<<__rem);
61}
62
63
64#undef __FD_ISSET
65static __inline__ int __FD_ISSET(unsigned long __fd, const __kernel_fd_set *__p)
66{
67 unsigned long __tmp = __fd / __NFDBITS;
68 unsigned long __rem = __fd % __NFDBITS;
69 return (__p->fds_bits[__tmp] & (1UL<<__rem)) != 0;
70}
71
72/*
73 * This will unroll the loop for the normal constant case (8 ints,
74 * for a 256-bit fd_set)
75 */
76#undef __FD_ZERO
77static __inline__ void __FD_ZERO(__kernel_fd_set *__p)
78{
79 unsigned long *__tmp = __p->fds_bits;
80 int __i;
81
82 if (__builtin_constant_p(__FDSET_LONGS)) {
83 switch (__FDSET_LONGS) {
84 case 16:
85 __tmp[ 0] = 0; __tmp[ 1] = 0;
86 __tmp[ 2] = 0; __tmp[ 3] = 0;
87 __tmp[ 4] = 0; __tmp[ 5] = 0;
88 __tmp[ 6] = 0; __tmp[ 7] = 0;
89 __tmp[ 8] = 0; __tmp[ 9] = 0;
90 __tmp[10] = 0; __tmp[11] = 0;
91 __tmp[12] = 0; __tmp[13] = 0;
92 __tmp[14] = 0; __tmp[15] = 0;
93 return;
94
95 case 8:
96 __tmp[ 0] = 0; __tmp[ 1] = 0;
97 __tmp[ 2] = 0; __tmp[ 3] = 0;
98 __tmp[ 4] = 0; __tmp[ 5] = 0;
99 __tmp[ 6] = 0; __tmp[ 7] = 0;
100 return;
101
102 case 4:
103 __tmp[ 0] = 0; __tmp[ 1] = 0;
104 __tmp[ 2] = 0; __tmp[ 3] = 0;
105 return;
106 }
107 }
108 __i = __FDSET_LONGS;
109 while (__i) {
110 __i--;
111 *__tmp = 0;
112 __tmp++;
113 }
114}
115
116#endif /* defined(__KERNEL__) */
117 27
118#endif /* _ASM_M32R_POSIX_TYPES_H */ 28#endif /* _ASM_M32R_POSIX_TYPES_H */
diff --git a/arch/m68k/include/asm/posix_types.h b/arch/m68k/include/asm/posix_types.h
index 98d0970d9bad..6373093be72b 100644
--- a/arch/m68k/include/asm/posix_types.h
+++ b/arch/m68k/include/asm/posix_types.h
@@ -7,55 +7,22 @@
7 * assume GCC is being used. 7 * assume GCC is being used.
8 */ 8 */
9 9
10typedef unsigned long __kernel_ino_t;
11typedef unsigned short __kernel_mode_t; 10typedef unsigned short __kernel_mode_t;
11#define __kernel_mode_t __kernel_mode_t
12
12typedef unsigned short __kernel_nlink_t; 13typedef unsigned short __kernel_nlink_t;
13typedef long __kernel_off_t; 14#define __kernel_nlink_t __kernel_nlink_t
14typedef int __kernel_pid_t; 15
15typedef unsigned short __kernel_ipc_pid_t; 16typedef unsigned short __kernel_ipc_pid_t;
17#define __kernel_ipc_pid_t __kernel_ipc_pid_t
18
16typedef unsigned short __kernel_uid_t; 19typedef unsigned short __kernel_uid_t;
17typedef unsigned short __kernel_gid_t; 20typedef unsigned short __kernel_gid_t;
18typedef unsigned int __kernel_size_t; 21#define __kernel_uid_t __kernel_uid_t
19typedef int __kernel_ssize_t;
20typedef int __kernel_ptrdiff_t;
21typedef long __kernel_time_t;
22typedef long __kernel_suseconds_t;
23typedef long __kernel_clock_t;
24typedef int __kernel_timer_t;
25typedef int __kernel_clockid_t;
26typedef int __kernel_daddr_t;
27typedef char * __kernel_caddr_t;
28typedef unsigned short __kernel_uid16_t;
29typedef unsigned short __kernel_gid16_t;
30typedef unsigned int __kernel_uid32_t;
31typedef unsigned int __kernel_gid32_t;
32
33typedef unsigned short __kernel_old_uid_t;
34typedef unsigned short __kernel_old_gid_t;
35typedef unsigned short __kernel_old_dev_t;
36
37#ifdef __GNUC__
38typedef long long __kernel_loff_t;
39#endif
40 22
41typedef struct { 23typedef unsigned short __kernel_old_dev_t;
42 int val[2]; 24#define __kernel_old_dev_t __kernel_old_dev_t
43} __kernel_fsid_t;
44
45#if defined(__KERNEL__)
46
47#undef __FD_SET
48#define __FD_SET(d, set) ((set)->fds_bits[__FDELT(d)] |= __FDMASK(d))
49
50#undef __FD_CLR
51#define __FD_CLR(d, set) ((set)->fds_bits[__FDELT(d)] &= ~__FDMASK(d))
52
53#undef __FD_ISSET
54#define __FD_ISSET(d, set) (!!((set)->fds_bits[__FDELT(d)] & __FDMASK(d)))
55
56#undef __FD_ZERO
57#define __FD_ZERO(fdsetp) (memset (fdsetp, 0, sizeof(*(fd_set *)fdsetp)))
58 25
59#endif /* defined(__KERNEL__) */ 26#include <asm-generic/posix_types.h>
60 27
61#endif 28#endif
diff --git a/arch/mips/include/asm/posix_types.h b/arch/mips/include/asm/posix_types.h
index c200102c8586..e0308dcca135 100644
--- a/arch/mips/include/asm/posix_types.h
+++ b/arch/mips/include/asm/posix_types.h
@@ -17,128 +17,21 @@
17 * assume GCC is being used. 17 * assume GCC is being used.
18 */ 18 */
19 19
20typedef unsigned long __kernel_ino_t;
21typedef unsigned int __kernel_mode_t;
22#if (_MIPS_SZLONG == 32)
23typedef unsigned long __kernel_nlink_t;
24#endif
25#if (_MIPS_SZLONG == 64) 20#if (_MIPS_SZLONG == 64)
26typedef unsigned int __kernel_nlink_t; 21typedef unsigned int __kernel_nlink_t;
22#define __kernel_nlink_t __kernel_nlink_t
27#endif 23#endif
28typedef long __kernel_off_t;
29typedef int __kernel_pid_t;
30typedef int __kernel_ipc_pid_t;
31typedef unsigned int __kernel_uid_t;
32typedef unsigned int __kernel_gid_t;
33#if (_MIPS_SZLONG == 32)
34typedef unsigned int __kernel_size_t;
35typedef int __kernel_ssize_t;
36typedef int __kernel_ptrdiff_t;
37#endif
38#if (_MIPS_SZLONG == 64)
39typedef unsigned long __kernel_size_t;
40typedef long __kernel_ssize_t;
41typedef long __kernel_ptrdiff_t;
42#endif
43typedef long __kernel_time_t;
44typedef long __kernel_suseconds_t;
45typedef long __kernel_clock_t;
46typedef int __kernel_timer_t;
47typedef int __kernel_clockid_t;
48typedef long __kernel_daddr_t;
49typedef char * __kernel_caddr_t;
50 24
51typedef unsigned short __kernel_uid16_t; 25typedef long __kernel_daddr_t;
52typedef unsigned short __kernel_gid16_t; 26#define __kernel_daddr_t __kernel_daddr_t
53typedef unsigned int __kernel_uid32_t;
54typedef unsigned int __kernel_gid32_t;
55typedef __kernel_uid_t __kernel_old_uid_t;
56typedef __kernel_gid_t __kernel_old_gid_t;
57typedef unsigned int __kernel_old_dev_t;
58
59#ifdef __GNUC__
60typedef long long __kernel_loff_t;
61#endif
62 27
63typedef struct {
64#if (_MIPS_SZLONG == 32) 28#if (_MIPS_SZLONG == 32)
29typedef struct {
65 long val[2]; 30 long val[2];
66#endif
67#if (_MIPS_SZLONG == 64)
68 int val[2];
69#endif
70} __kernel_fsid_t; 31} __kernel_fsid_t;
32#define __kernel_fsid_t __kernel_fsid_t
33#endif
71 34
72#if defined(__KERNEL__) 35#include <asm-generic/posix_types.h>
73
74#undef __FD_SET
75static __inline__ void __FD_SET(unsigned long __fd, __kernel_fd_set *__fdsetp)
76{
77 unsigned long __tmp = __fd / __NFDBITS;
78 unsigned long __rem = __fd % __NFDBITS;
79 __fdsetp->fds_bits[__tmp] |= (1UL<<__rem);
80}
81
82#undef __FD_CLR
83static __inline__ void __FD_CLR(unsigned long __fd, __kernel_fd_set *__fdsetp)
84{
85 unsigned long __tmp = __fd / __NFDBITS;
86 unsigned long __rem = __fd % __NFDBITS;
87 __fdsetp->fds_bits[__tmp] &= ~(1UL<<__rem);
88}
89
90#undef __FD_ISSET
91static __inline__ int __FD_ISSET(unsigned long __fd, const __kernel_fd_set *__p)
92{
93 unsigned long __tmp = __fd / __NFDBITS;
94 unsigned long __rem = __fd % __NFDBITS;
95 return (__p->fds_bits[__tmp] & (1UL<<__rem)) != 0;
96}
97
98/*
99 * This will unroll the loop for the normal constant case (8 ints,
100 * for a 256-bit fd_set)
101 */
102#undef __FD_ZERO
103static __inline__ void __FD_ZERO(__kernel_fd_set *__p)
104{
105 unsigned long *__tmp = __p->fds_bits;
106 int __i;
107
108 if (__builtin_constant_p(__FDSET_LONGS)) {
109 switch (__FDSET_LONGS) {
110 case 16:
111 __tmp[ 0] = 0; __tmp[ 1] = 0;
112 __tmp[ 2] = 0; __tmp[ 3] = 0;
113 __tmp[ 4] = 0; __tmp[ 5] = 0;
114 __tmp[ 6] = 0; __tmp[ 7] = 0;
115 __tmp[ 8] = 0; __tmp[ 9] = 0;
116 __tmp[10] = 0; __tmp[11] = 0;
117 __tmp[12] = 0; __tmp[13] = 0;
118 __tmp[14] = 0; __tmp[15] = 0;
119 return;
120
121 case 8:
122 __tmp[ 0] = 0; __tmp[ 1] = 0;
123 __tmp[ 2] = 0; __tmp[ 3] = 0;
124 __tmp[ 4] = 0; __tmp[ 5] = 0;
125 __tmp[ 6] = 0; __tmp[ 7] = 0;
126 return;
127
128 case 4:
129 __tmp[ 0] = 0; __tmp[ 1] = 0;
130 __tmp[ 2] = 0; __tmp[ 3] = 0;
131 return;
132 }
133 }
134 __i = __FDSET_LONGS;
135 while (__i) {
136 __i--;
137 *__tmp = 0;
138 __tmp++;
139 }
140}
141
142#endif /* defined(__KERNEL__) */
143 36
144#endif /* _ASM_POSIX_TYPES_H */ 37#endif /* _ASM_POSIX_TYPES_H */
diff --git a/arch/mips/kernel/kspd.c b/arch/mips/kernel/kspd.c
index 29811f043399..84d0639e4580 100644
--- a/arch/mips/kernel/kspd.c
+++ b/arch/mips/kernel/kspd.c
@@ -326,7 +326,7 @@ static void sp_cleanup(void)
326 i = j * __NFDBITS; 326 i = j * __NFDBITS;
327 if (i >= fdt->max_fds) 327 if (i >= fdt->max_fds)
328 break; 328 break;
329 set = fdt->open_fds->fds_bits[j++]; 329 set = fdt->open_fds[j++];
330 while (set) { 330 while (set) {
331 if (set & 1) { 331 if (set & 1) {
332 struct file * file = xchg(&fdt->fd[i], NULL); 332 struct file * file = xchg(&fdt->fd[i], NULL);
diff --git a/arch/mn10300/include/asm/posix_types.h b/arch/mn10300/include/asm/posix_types.h
index 56ffbc158798..ab506181ec31 100644
--- a/arch/mn10300/include/asm/posix_types.h
+++ b/arch/mn10300/include/asm/posix_types.h
@@ -17,14 +17,19 @@
17 * assume GCC is being used. 17 * assume GCC is being used.
18 */ 18 */
19 19
20typedef unsigned long __kernel_ino_t;
21typedef unsigned short __kernel_mode_t; 20typedef unsigned short __kernel_mode_t;
21#define __kernel_mode_t __kernel_mode_t
22
22typedef unsigned short __kernel_nlink_t; 23typedef unsigned short __kernel_nlink_t;
23typedef long __kernel_off_t; 24#define __kernel_nlink_t __kernel_nlink_t
24typedef int __kernel_pid_t; 25
25typedef unsigned short __kernel_ipc_pid_t; 26typedef unsigned short __kernel_ipc_pid_t;
27#define __kernel_ipc_pid_t __kernel_ipc_pid_t
28
26typedef unsigned short __kernel_uid_t; 29typedef unsigned short __kernel_uid_t;
27typedef unsigned short __kernel_gid_t; 30typedef unsigned short __kernel_gid_t;
31#define __kernel_uid_t __kernel_uid_t
32
28#if __GNUC__ == 4 33#if __GNUC__ == 4
29typedef unsigned int __kernel_size_t; 34typedef unsigned int __kernel_size_t;
30typedef signed int __kernel_ssize_t; 35typedef signed int __kernel_ssize_t;
@@ -33,105 +38,11 @@ typedef unsigned long __kernel_size_t;
33typedef signed long __kernel_ssize_t; 38typedef signed long __kernel_ssize_t;
34#endif 39#endif
35typedef int __kernel_ptrdiff_t; 40typedef int __kernel_ptrdiff_t;
36typedef long __kernel_time_t; 41#define __kernel_size_t __kernel_size_t
37typedef long __kernel_suseconds_t;
38typedef long __kernel_clock_t;
39typedef int __kernel_timer_t;
40typedef int __kernel_clockid_t;
41typedef int __kernel_daddr_t;
42typedef char * __kernel_caddr_t;
43typedef unsigned short __kernel_uid16_t;
44typedef unsigned short __kernel_gid16_t;
45typedef unsigned int __kernel_uid32_t;
46typedef unsigned int __kernel_gid32_t;
47 42
48typedef unsigned short __kernel_old_uid_t;
49typedef unsigned short __kernel_old_gid_t;
50typedef unsigned short __kernel_old_dev_t; 43typedef unsigned short __kernel_old_dev_t;
44#define __kernel_old_dev_t __kernel_old_dev_t
51 45
52#ifdef __GNUC__ 46#include <asm-generic/posix_types.h>
53typedef long long __kernel_loff_t;
54#endif
55
56typedef struct {
57#if defined(__KERNEL__) || defined(__USE_ALL)
58 int val[2];
59#else /* !defined(__KERNEL__) && !defined(__USE_ALL) */
60 int __val[2];
61#endif /* !defined(__KERNEL__) && !defined(__USE_ALL) */
62} __kernel_fsid_t;
63
64#if defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2)
65
66#undef __FD_SET
67static inline void __FD_SET(unsigned long __fd, __kernel_fd_set *__fdsetp)
68{
69 unsigned long __tmp = __fd / __NFDBITS;
70 unsigned long __rem = __fd % __NFDBITS;
71 __fdsetp->fds_bits[__tmp] |= (1UL<<__rem);
72}
73
74#undef __FD_CLR
75static inline void __FD_CLR(unsigned long __fd, __kernel_fd_set *__fdsetp)
76{
77 unsigned long __tmp = __fd / __NFDBITS;
78 unsigned long __rem = __fd % __NFDBITS;
79 __fdsetp->fds_bits[__tmp] &= ~(1UL<<__rem);
80}
81
82
83#undef __FD_ISSET
84static inline int __FD_ISSET(unsigned long __fd, const __kernel_fd_set *__p)
85{
86 unsigned long __tmp = __fd / __NFDBITS;
87 unsigned long __rem = __fd % __NFDBITS;
88 return (__p->fds_bits[__tmp] & (1UL<<__rem)) != 0;
89}
90
91/*
92 * This will unroll the loop for the normal constant case (8 ints,
93 * for a 256-bit fd_set)
94 */
95#undef __FD_ZERO
96static inline void __FD_ZERO(__kernel_fd_set *__p)
97{
98 unsigned long *__tmp = __p->fds_bits;
99 int __i;
100
101 if (__builtin_constant_p(__FDSET_LONGS)) {
102 switch (__FDSET_LONGS) {
103 case 16:
104 __tmp[ 0] = 0; __tmp[ 1] = 0;
105 __tmp[ 2] = 0; __tmp[ 3] = 0;
106 __tmp[ 4] = 0; __tmp[ 5] = 0;
107 __tmp[ 6] = 0; __tmp[ 7] = 0;
108 __tmp[ 8] = 0; __tmp[ 9] = 0;
109 __tmp[10] = 0; __tmp[11] = 0;
110 __tmp[12] = 0; __tmp[13] = 0;
111 __tmp[14] = 0; __tmp[15] = 0;
112 return;
113
114 case 8:
115 __tmp[ 0] = 0; __tmp[ 1] = 0;
116 __tmp[ 2] = 0; __tmp[ 3] = 0;
117 __tmp[ 4] = 0; __tmp[ 5] = 0;
118 __tmp[ 6] = 0; __tmp[ 7] = 0;
119 return;
120
121 case 4:
122 __tmp[ 0] = 0; __tmp[ 1] = 0;
123 __tmp[ 2] = 0; __tmp[ 3] = 0;
124 return;
125 }
126 }
127 __i = __FDSET_LONGS;
128 while (__i) {
129 __i--;
130 *__tmp = 0;
131 __tmp++;
132 }
133}
134
135#endif /* defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2) */
136 47
137#endif /* _ASM_POSIX_TYPES_H */ 48#endif /* _ASM_POSIX_TYPES_H */
diff --git a/arch/parisc/include/asm/posix_types.h b/arch/parisc/include/asm/posix_types.h
index 00da29a340ba..5212b0357daf 100644
--- a/arch/parisc/include/asm/posix_types.h
+++ b/arch/parisc/include/asm/posix_types.h
@@ -6,123 +6,22 @@
6 * be a little careful about namespace pollution etc. Also, we cannot 6 * be a little careful about namespace pollution etc. Also, we cannot
7 * assume GCC is being used. 7 * assume GCC is being used.
8 */ 8 */
9typedef unsigned long __kernel_ino_t; 9
10typedef unsigned short __kernel_mode_t; 10typedef unsigned short __kernel_mode_t;
11#define __kernel_mode_t __kernel_mode_t
12
11typedef unsigned short __kernel_nlink_t; 13typedef unsigned short __kernel_nlink_t;
12typedef long __kernel_off_t; 14#define __kernel_nlink_t __kernel_nlink_t
13typedef int __kernel_pid_t; 15
14typedef unsigned short __kernel_ipc_pid_t; 16typedef unsigned short __kernel_ipc_pid_t;
15typedef unsigned int __kernel_uid_t; 17#define __kernel_ipc_pid_t __kernel_ipc_pid_t
16typedef unsigned int __kernel_gid_t;
17typedef int __kernel_suseconds_t;
18typedef long __kernel_clock_t;
19typedef int __kernel_timer_t;
20typedef int __kernel_clockid_t;
21typedef int __kernel_daddr_t;
22/* Note these change from narrow to wide kernels */
23#ifdef CONFIG_64BIT
24typedef unsigned long __kernel_size_t;
25typedef long __kernel_ssize_t;
26typedef long __kernel_ptrdiff_t;
27#else
28typedef unsigned int __kernel_size_t;
29typedef int __kernel_ssize_t;
30typedef int __kernel_ptrdiff_t;
31#endif
32typedef long __kernel_time_t;
33typedef char * __kernel_caddr_t;
34 18
35typedef unsigned short __kernel_uid16_t; 19typedef int __kernel_suseconds_t;
36typedef unsigned short __kernel_gid16_t; 20#define __kernel_suseconds_t __kernel_suseconds_t
37typedef unsigned int __kernel_uid32_t;
38typedef unsigned int __kernel_gid32_t;
39 21
40#ifdef __GNUC__
41typedef long long __kernel_loff_t;
42typedef long long __kernel_off64_t; 22typedef long long __kernel_off64_t;
43typedef unsigned long long __kernel_ino64_t; 23typedef unsigned long long __kernel_ino64_t;
44#endif
45
46typedef unsigned int __kernel_old_dev_t;
47
48typedef struct {
49 int val[2];
50} __kernel_fsid_t;
51
52/* compatibility stuff */
53typedef __kernel_uid_t __kernel_old_uid_t;
54typedef __kernel_gid_t __kernel_old_gid_t;
55
56#if defined(__KERNEL__)
57
58#undef __FD_SET
59static __inline__ void __FD_SET(unsigned long __fd, __kernel_fd_set *__fdsetp)
60{
61 unsigned long __tmp = __fd / __NFDBITS;
62 unsigned long __rem = __fd % __NFDBITS;
63 __fdsetp->fds_bits[__tmp] |= (1UL<<__rem);
64}
65
66#undef __FD_CLR
67static __inline__ void __FD_CLR(unsigned long __fd, __kernel_fd_set *__fdsetp)
68{
69 unsigned long __tmp = __fd / __NFDBITS;
70 unsigned long __rem = __fd % __NFDBITS;
71 __fdsetp->fds_bits[__tmp] &= ~(1UL<<__rem);
72}
73
74#undef __FD_ISSET
75static __inline__ int __FD_ISSET(unsigned long __fd, const __kernel_fd_set *__p)
76{
77 unsigned long __tmp = __fd / __NFDBITS;
78 unsigned long __rem = __fd % __NFDBITS;
79 return (__p->fds_bits[__tmp] & (1UL<<__rem)) != 0;
80}
81
82/*
83 * This will unroll the loop for the normal constant case (8 ints,
84 * for a 256-bit fd_set)
85 */
86#undef __FD_ZERO
87static __inline__ void __FD_ZERO(__kernel_fd_set *__p)
88{
89 unsigned long *__tmp = __p->fds_bits;
90 int __i;
91
92 if (__builtin_constant_p(__FDSET_LONGS)) {
93 switch (__FDSET_LONGS) {
94 case 16:
95 __tmp[ 0] = 0; __tmp[ 1] = 0;
96 __tmp[ 2] = 0; __tmp[ 3] = 0;
97 __tmp[ 4] = 0; __tmp[ 5] = 0;
98 __tmp[ 6] = 0; __tmp[ 7] = 0;
99 __tmp[ 8] = 0; __tmp[ 9] = 0;
100 __tmp[10] = 0; __tmp[11] = 0;
101 __tmp[12] = 0; __tmp[13] = 0;
102 __tmp[14] = 0; __tmp[15] = 0;
103 return;
104
105 case 8:
106 __tmp[ 0] = 0; __tmp[ 1] = 0;
107 __tmp[ 2] = 0; __tmp[ 3] = 0;
108 __tmp[ 4] = 0; __tmp[ 5] = 0;
109 __tmp[ 6] = 0; __tmp[ 7] = 0;
110 return;
111
112 case 4:
113 __tmp[ 0] = 0; __tmp[ 1] = 0;
114 __tmp[ 2] = 0; __tmp[ 3] = 0;
115 return;
116 }
117 }
118 __i = __FDSET_LONGS;
119 while (__i) {
120 __i--;
121 *__tmp = 0;
122 __tmp++;
123 }
124}
125 24
126#endif /* defined(__KERNEL__) */ 25#include <asm-generic/posix_types.h>
127 26
128#endif 27#endif
diff --git a/arch/powerpc/include/asm/posix_types.h b/arch/powerpc/include/asm/posix_types.h
index c4e396b540df..f1393252bbda 100644
--- a/arch/powerpc/include/asm/posix_types.h
+++ b/arch/powerpc/include/asm/posix_types.h
@@ -7,122 +7,22 @@
7 * assume GCC is being used. 7 * assume GCC is being used.
8 */ 8 */
9 9
10typedef unsigned long __kernel_ino_t;
11typedef unsigned int __kernel_mode_t;
12typedef long __kernel_off_t;
13typedef int __kernel_pid_t;
14typedef unsigned int __kernel_uid_t;
15typedef unsigned int __kernel_gid_t;
16typedef long __kernel_ptrdiff_t;
17typedef long __kernel_time_t;
18typedef long __kernel_clock_t;
19typedef int __kernel_timer_t;
20typedef int __kernel_clockid_t;
21typedef long __kernel_suseconds_t;
22typedef int __kernel_daddr_t;
23typedef char * __kernel_caddr_t;
24typedef unsigned short __kernel_uid16_t;
25typedef unsigned short __kernel_gid16_t;
26typedef unsigned int __kernel_uid32_t;
27typedef unsigned int __kernel_gid32_t;
28typedef unsigned int __kernel_old_uid_t;
29typedef unsigned int __kernel_old_gid_t;
30
31#ifdef __powerpc64__ 10#ifdef __powerpc64__
32typedef unsigned long __kernel_nlink_t;
33typedef int __kernel_ipc_pid_t;
34typedef unsigned long __kernel_size_t;
35typedef long __kernel_ssize_t;
36typedef unsigned long __kernel_old_dev_t; 11typedef unsigned long __kernel_old_dev_t;
12#define __kernel_old_dev_t __kernel_old_dev_t
37#else 13#else
38typedef unsigned short __kernel_nlink_t;
39typedef short __kernel_ipc_pid_t;
40typedef unsigned int __kernel_size_t; 14typedef unsigned int __kernel_size_t;
41typedef int __kernel_ssize_t; 15typedef int __kernel_ssize_t;
42typedef unsigned int __kernel_old_dev_t; 16typedef long __kernel_ptrdiff_t;
43#endif 17#define __kernel_size_t __kernel_size_t
44
45#ifdef __powerpc64__
46typedef long long __kernel_loff_t;
47#else
48#ifdef __GNUC__
49typedef long long __kernel_loff_t;
50#endif
51#endif
52
53typedef struct {
54 int val[2];
55} __kernel_fsid_t;
56
57#ifndef __GNUC__
58
59#define __FD_SET(d, set) ((set)->fds_bits[__FDELT(d)] |= __FDMASK(d))
60#define __FD_CLR(d, set) ((set)->fds_bits[__FDELT(d)] &= ~__FDMASK(d))
61#define __FD_ISSET(d, set) (((set)->fds_bits[__FDELT(d)] & __FDMASK(d)) != 0)
62#define __FD_ZERO(set) \
63 ((void) memset ((void *) (set), 0, sizeof (__kernel_fd_set)))
64
65#else /* __GNUC__ */
66
67#if defined(__KERNEL__)
68/* With GNU C, use inline functions instead so args are evaluated only once: */
69
70#undef __FD_SET
71static __inline__ void __FD_SET(unsigned long fd, __kernel_fd_set *fdsetp)
72{
73 unsigned long _tmp = fd / __NFDBITS;
74 unsigned long _rem = fd % __NFDBITS;
75 fdsetp->fds_bits[_tmp] |= (1UL<<_rem);
76}
77
78#undef __FD_CLR
79static __inline__ void __FD_CLR(unsigned long fd, __kernel_fd_set *fdsetp)
80{
81 unsigned long _tmp = fd / __NFDBITS;
82 unsigned long _rem = fd % __NFDBITS;
83 fdsetp->fds_bits[_tmp] &= ~(1UL<<_rem);
84}
85
86#undef __FD_ISSET
87static __inline__ int __FD_ISSET(unsigned long fd, __kernel_fd_set *p)
88{
89 unsigned long _tmp = fd / __NFDBITS;
90 unsigned long _rem = fd % __NFDBITS;
91 return (p->fds_bits[_tmp] & (1UL<<_rem)) != 0;
92}
93
94/*
95 * This will unroll the loop for the normal constant case (8 ints,
96 * for a 256-bit fd_set)
97 */
98#undef __FD_ZERO
99static __inline__ void __FD_ZERO(__kernel_fd_set *p)
100{
101 unsigned long *tmp = (unsigned long *)p->fds_bits;
102 int i;
103 18
104 if (__builtin_constant_p(__FDSET_LONGS)) { 19typedef unsigned short __kernel_nlink_t;
105 switch (__FDSET_LONGS) { 20#define __kernel_nlink_t __kernel_nlink_t
106 case 16:
107 tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0;
108 tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0;
109 21
110 case 8: 22typedef short __kernel_ipc_pid_t;
111 tmp[ 4] = 0; tmp[ 5] = 0; tmp[ 6] = 0; tmp[ 7] = 0; 23#define __kernel_ipc_pid_t __kernel_ipc_pid_t
24#endif
112 25
113 case 4: 26#include <asm-generic/posix_types.h>
114 tmp[ 0] = 0; tmp[ 1] = 0; tmp[ 2] = 0; tmp[ 3] = 0;
115 return;
116 }
117 }
118 i = __FDSET_LONGS;
119 while (i) {
120 i--;
121 *tmp = 0;
122 tmp++;
123 }
124}
125 27
126#endif /* defined(__KERNEL__) */
127#endif /* __GNUC__ */
128#endif /* _ASM_POWERPC_POSIX_TYPES_H */ 28#endif /* _ASM_POWERPC_POSIX_TYPES_H */
diff --git a/arch/powerpc/platforms/cell/spufs/coredump.c b/arch/powerpc/platforms/cell/spufs/coredump.c
index 03c5fce2a5b3..c2c5b078ba80 100644
--- a/arch/powerpc/platforms/cell/spufs/coredump.c
+++ b/arch/powerpc/platforms/cell/spufs/coredump.c
@@ -122,7 +122,7 @@ static struct spu_context *coredump_next_context(int *fd)
122 struct spu_context *ctx = NULL; 122 struct spu_context *ctx = NULL;
123 123
124 for (; *fd < fdt->max_fds; (*fd)++) { 124 for (; *fd < fdt->max_fds; (*fd)++) {
125 if (!FD_ISSET(*fd, fdt->open_fds)) 125 if (!fd_is_open(*fd, fdt))
126 continue; 126 continue;
127 127
128 file = fcheck(*fd); 128 file = fcheck(*fd);
diff --git a/arch/s390/include/asm/posix_types.h b/arch/s390/include/asm/posix_types.h
index 8cc113f92523..edf8527ff08d 100644
--- a/arch/s390/include/asm/posix_types.h
+++ b/arch/s390/include/asm/posix_types.h
@@ -3,7 +3,6 @@
3 * 3 *
4 * S390 version 4 * S390 version
5 * 5 *
6 * Derived from "include/asm-i386/posix_types.h"
7 */ 6 */
8 7
9#ifndef __ARCH_S390_POSIX_TYPES_H 8#ifndef __ARCH_S390_POSIX_TYPES_H
@@ -15,22 +14,11 @@
15 * assume GCC is being used. 14 * assume GCC is being used.
16 */ 15 */
17 16
18typedef long __kernel_off_t;
19typedef int __kernel_pid_t;
20typedef unsigned long __kernel_size_t; 17typedef unsigned long __kernel_size_t;
21typedef long __kernel_time_t; 18#define __kernel_size_t __kernel_size_t
22typedef long __kernel_suseconds_t;
23typedef long __kernel_clock_t;
24typedef int __kernel_timer_t;
25typedef int __kernel_clockid_t;
26typedef int __kernel_daddr_t;
27typedef char * __kernel_caddr_t;
28typedef unsigned short __kernel_uid16_t;
29typedef unsigned short __kernel_gid16_t;
30 19
31#ifdef __GNUC__ 20typedef unsigned short __kernel_old_dev_t;
32typedef long long __kernel_loff_t; 21#define __kernel_old_dev_t __kernel_old_dev_t
33#endif
34 22
35#ifndef __s390x__ 23#ifndef __s390x__
36 24
@@ -42,11 +30,6 @@ typedef unsigned short __kernel_uid_t;
42typedef unsigned short __kernel_gid_t; 30typedef unsigned short __kernel_gid_t;
43typedef int __kernel_ssize_t; 31typedef int __kernel_ssize_t;
44typedef int __kernel_ptrdiff_t; 32typedef int __kernel_ptrdiff_t;
45typedef unsigned int __kernel_uid32_t;
46typedef unsigned int __kernel_gid32_t;
47typedef unsigned short __kernel_old_uid_t;
48typedef unsigned short __kernel_old_gid_t;
49typedef unsigned short __kernel_old_dev_t;
50 33
51#else /* __s390x__ */ 34#else /* __s390x__ */
52 35
@@ -59,49 +42,16 @@ typedef unsigned int __kernel_gid_t;
59typedef long __kernel_ssize_t; 42typedef long __kernel_ssize_t;
60typedef long __kernel_ptrdiff_t; 43typedef long __kernel_ptrdiff_t;
61typedef unsigned long __kernel_sigset_t; /* at least 32 bits */ 44typedef unsigned long __kernel_sigset_t; /* at least 32 bits */
62typedef __kernel_uid_t __kernel_old_uid_t;
63typedef __kernel_gid_t __kernel_old_gid_t;
64typedef __kernel_uid_t __kernel_uid32_t;
65typedef __kernel_gid_t __kernel_gid32_t;
66typedef unsigned short __kernel_old_dev_t;
67 45
68#endif /* __s390x__ */ 46#endif /* __s390x__ */
69 47
70typedef struct { 48#define __kernel_ino_t __kernel_ino_t
71 int val[2]; 49#define __kernel_mode_t __kernel_mode_t
72} __kernel_fsid_t; 50#define __kernel_nlink_t __kernel_nlink_t
73 51#define __kernel_ipc_pid_t __kernel_ipc_pid_t
74 52#define __kernel_uid_t __kernel_uid_t
75#ifdef __KERNEL__ 53#define __kernel_gid_t __kernel_gid_t
76
77#undef __FD_SET
78static inline void __FD_SET(unsigned long fd, __kernel_fd_set *fdsetp)
79{
80 unsigned long _tmp = fd / __NFDBITS;
81 unsigned long _rem = fd % __NFDBITS;
82 fdsetp->fds_bits[_tmp] |= (1UL<<_rem);
83}
84
85#undef __FD_CLR
86static inline void __FD_CLR(unsigned long fd, __kernel_fd_set *fdsetp)
87{
88 unsigned long _tmp = fd / __NFDBITS;
89 unsigned long _rem = fd % __NFDBITS;
90 fdsetp->fds_bits[_tmp] &= ~(1UL<<_rem);
91}
92
93#undef __FD_ISSET
94static inline int __FD_ISSET(unsigned long fd, const __kernel_fd_set *fdsetp)
95{
96 unsigned long _tmp = fd / __NFDBITS;
97 unsigned long _rem = fd % __NFDBITS;
98 return (fdsetp->fds_bits[_tmp] & (1UL<<_rem)) != 0;
99}
100
101#undef __FD_ZERO
102#define __FD_ZERO(fdsetp) \
103 ((void) memset ((void *) (fdsetp), 0, sizeof (__kernel_fd_set)))
104 54
105#endif /* __KERNEL__ */ 55#include <asm-generic/posix_types.h>
106 56
107#endif 57#endif
diff --git a/arch/sh/include/asm/posix_types_32.h b/arch/sh/include/asm/posix_types_32.h
index 6a9ceaaf1aea..abda58467ece 100644
--- a/arch/sh/include/asm/posix_types_32.h
+++ b/arch/sh/include/asm/posix_types_32.h
@@ -12,11 +12,6 @@ typedef unsigned short __kernel_uid_t;
12typedef unsigned short __kernel_gid_t; 12typedef unsigned short __kernel_gid_t;
13#define __kernel_gid_t __kernel_gid_t 13#define __kernel_gid_t __kernel_gid_t
14 14
15typedef unsigned int __kernel_uid32_t;
16#define __kernel_uid32_t __kernel_uid32_t
17typedef unsigned int __kernel_gid32_t;
18#define __kernel_gid32_t __kernel_gid32_t
19
20typedef unsigned short __kernel_old_uid_t; 15typedef unsigned short __kernel_old_uid_t;
21#define __kernel_old_uid_t __kernel_old_uid_t 16#define __kernel_old_uid_t __kernel_old_uid_t
22typedef unsigned short __kernel_old_gid_t; 17typedef unsigned short __kernel_old_gid_t;
diff --git a/arch/sh/include/asm/posix_types_64.h b/arch/sh/include/asm/posix_types_64.h
index 8cd11485c06b..fcda07b4a616 100644
--- a/arch/sh/include/asm/posix_types_64.h
+++ b/arch/sh/include/asm/posix_types_64.h
@@ -17,10 +17,6 @@ typedef int __kernel_ssize_t;
17#define __kernel_ssize_t __kernel_ssize_t 17#define __kernel_ssize_t __kernel_ssize_t
18typedef int __kernel_ptrdiff_t; 18typedef int __kernel_ptrdiff_t;
19#define __kernel_ptrdiff_t __kernel_ptrdiff_t 19#define __kernel_ptrdiff_t __kernel_ptrdiff_t
20typedef unsigned int __kernel_uid32_t;
21#define __kernel_uid32_t __kernel_uid32_t
22typedef unsigned int __kernel_gid32_t;
23#define __kernel_gid32_t __kernel_gid32_t
24 20
25typedef unsigned short __kernel_old_uid_t; 21typedef unsigned short __kernel_old_uid_t;
26#define __kernel_old_uid_t __kernel_old_uid_t 22#define __kernel_old_uid_t __kernel_old_uid_t
diff --git a/arch/sparc/include/asm/posix_types.h b/arch/sparc/include/asm/posix_types.h
index dbfc1a34b3a2..3070f25ae90a 100644
--- a/arch/sparc/include/asm/posix_types.h
+++ b/arch/sparc/include/asm/posix_types.h
@@ -9,35 +9,16 @@
9 9
10#if defined(__sparc__) && defined(__arch64__) 10#if defined(__sparc__) && defined(__arch64__)
11/* sparc 64 bit */ 11/* sparc 64 bit */
12typedef unsigned long __kernel_size_t;
13typedef long __kernel_ssize_t;
14typedef long __kernel_ptrdiff_t;
15typedef long __kernel_time_t;
16typedef long __kernel_clock_t;
17typedef int __kernel_pid_t;
18typedef int __kernel_ipc_pid_t;
19typedef unsigned int __kernel_uid_t;
20typedef unsigned int __kernel_gid_t;
21typedef unsigned long __kernel_ino_t;
22typedef unsigned int __kernel_mode_t;
23typedef unsigned int __kernel_nlink_t; 12typedef unsigned int __kernel_nlink_t;
24typedef int __kernel_daddr_t; 13#define __kernel_nlink_t __kernel_nlink_t
25typedef long __kernel_off_t;
26typedef char * __kernel_caddr_t;
27typedef unsigned short __kernel_uid16_t;
28typedef unsigned short __kernel_gid16_t;
29typedef int __kernel_clockid_t;
30typedef int __kernel_timer_t;
31 14
32typedef unsigned short __kernel_old_uid_t; 15typedef unsigned short __kernel_old_uid_t;
33typedef unsigned short __kernel_old_gid_t; 16typedef unsigned short __kernel_old_gid_t;
34typedef __kernel_uid_t __kernel_uid32_t; 17#define __kernel_old_uid_t __kernel_old_uid_t
35typedef __kernel_gid_t __kernel_gid32_t;
36
37typedef unsigned int __kernel_old_dev_t;
38 18
39/* Note this piece of asymmetry from the v9 ABI. */ 19/* Note this piece of asymmetry from the v9 ABI. */
40typedef int __kernel_suseconds_t; 20typedef int __kernel_suseconds_t;
21#define __kernel_suseconds_t __kernel_suseconds_t
41 22
42#else 23#else
43/* sparc 32 bit */ 24/* sparc 32 bit */
@@ -45,109 +26,29 @@ typedef int __kernel_suseconds_t;
45typedef unsigned int __kernel_size_t; 26typedef unsigned int __kernel_size_t;
46typedef int __kernel_ssize_t; 27typedef int __kernel_ssize_t;
47typedef long int __kernel_ptrdiff_t; 28typedef long int __kernel_ptrdiff_t;
48typedef long __kernel_time_t; 29#define __kernel_size_t __kernel_size_t
49typedef long __kernel_suseconds_t; 30
50typedef long __kernel_clock_t;
51typedef int __kernel_pid_t;
52typedef unsigned short __kernel_ipc_pid_t; 31typedef unsigned short __kernel_ipc_pid_t;
32#define __kernel_ipc_pid_t __kernel_ipc_pid_t
33
53typedef unsigned short __kernel_uid_t; 34typedef unsigned short __kernel_uid_t;
54typedef unsigned short __kernel_gid_t; 35typedef unsigned short __kernel_gid_t;
55typedef unsigned long __kernel_ino_t; 36#define __kernel_uid_t __kernel_uid_t
37
56typedef unsigned short __kernel_mode_t; 38typedef unsigned short __kernel_mode_t;
39#define __kernel_mode_t __kernel_mode_t
40
57typedef short __kernel_nlink_t; 41typedef short __kernel_nlink_t;
42#define __kernel_nlink_t __kernel_nlink_t
43
58typedef long __kernel_daddr_t; 44typedef long __kernel_daddr_t;
59typedef long __kernel_off_t; 45#define __kernel_daddr_t __kernel_daddr_t
60typedef char * __kernel_caddr_t; 46
61typedef unsigned short __kernel_uid16_t;
62typedef unsigned short __kernel_gid16_t;
63typedef unsigned int __kernel_uid32_t;
64typedef unsigned int __kernel_gid32_t;
65typedef unsigned short __kernel_old_uid_t;
66typedef unsigned short __kernel_old_gid_t;
67typedef unsigned short __kernel_old_dev_t; 47typedef unsigned short __kernel_old_dev_t;
68typedef int __kernel_clockid_t; 48#define __kernel_old_dev_t __kernel_old_dev_t
69typedef int __kernel_timer_t;
70 49
71#endif /* defined(__sparc__) && defined(__arch64__) */ 50#endif /* defined(__sparc__) && defined(__arch64__) */
72 51
73#ifdef __GNUC__ 52#include <asm-generic/posix_types.h>
74typedef long long __kernel_loff_t;
75#endif
76
77typedef struct {
78 int val[2];
79} __kernel_fsid_t;
80
81#ifdef __KERNEL__
82
83#undef __FD_SET
84static inline void __FD_SET(unsigned long fd, __kernel_fd_set *fdsetp)
85{
86 unsigned long _tmp = fd / __NFDBITS;
87 unsigned long _rem = fd % __NFDBITS;
88 fdsetp->fds_bits[_tmp] |= (1UL<<_rem);
89}
90
91#undef __FD_CLR
92static inline void __FD_CLR(unsigned long fd, __kernel_fd_set *fdsetp)
93{
94 unsigned long _tmp = fd / __NFDBITS;
95 unsigned long _rem = fd % __NFDBITS;
96 fdsetp->fds_bits[_tmp] &= ~(1UL<<_rem);
97}
98
99#undef __FD_ISSET
100static inline int __FD_ISSET(unsigned long fd, __const__ __kernel_fd_set *p)
101{
102 unsigned long _tmp = fd / __NFDBITS;
103 unsigned long _rem = fd % __NFDBITS;
104 return (p->fds_bits[_tmp] & (1UL<<_rem)) != 0;
105}
106
107/*
108 * This will unroll the loop for the normal constant cases (8 or 32 longs,
109 * for 256 and 1024-bit fd_sets respectively)
110 */
111#undef __FD_ZERO
112static inline void __FD_ZERO(__kernel_fd_set *p)
113{
114 unsigned long *tmp = p->fds_bits;
115 int i;
116
117 if (__builtin_constant_p(__FDSET_LONGS)) {
118 switch (__FDSET_LONGS) {
119 case 32:
120 tmp[ 0] = 0; tmp[ 1] = 0; tmp[ 2] = 0; tmp[ 3] = 0;
121 tmp[ 4] = 0; tmp[ 5] = 0; tmp[ 6] = 0; tmp[ 7] = 0;
122 tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0;
123 tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0;
124 tmp[16] = 0; tmp[17] = 0; tmp[18] = 0; tmp[19] = 0;
125 tmp[20] = 0; tmp[21] = 0; tmp[22] = 0; tmp[23] = 0;
126 tmp[24] = 0; tmp[25] = 0; tmp[26] = 0; tmp[27] = 0;
127 tmp[28] = 0; tmp[29] = 0; tmp[30] = 0; tmp[31] = 0;
128 return;
129 case 16:
130 tmp[ 0] = 0; tmp[ 1] = 0; tmp[ 2] = 0; tmp[ 3] = 0;
131 tmp[ 4] = 0; tmp[ 5] = 0; tmp[ 6] = 0; tmp[ 7] = 0;
132 tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0;
133 tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0;
134 return;
135 case 8:
136 tmp[ 0] = 0; tmp[ 1] = 0; tmp[ 2] = 0; tmp[ 3] = 0;
137 tmp[ 4] = 0; tmp[ 5] = 0; tmp[ 6] = 0; tmp[ 7] = 0;
138 return;
139 case 4:
140 tmp[ 0] = 0; tmp[ 1] = 0; tmp[ 2] = 0; tmp[ 3] = 0;
141 return;
142 }
143 }
144 i = __FDSET_LONGS;
145 while (i) {
146 i--;
147 *tmp = 0;
148 tmp++;
149 }
150}
151 53
152#endif /* __KERNEL__ */
153#endif /* __SPARC_POSIX_TYPES_H */ 54#endif /* __SPARC_POSIX_TYPES_H */
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index abfb953c131d..1d14cc6b79ad 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -2163,9 +2163,9 @@ config IA32_EMULATION
2163 depends on X86_64 2163 depends on X86_64
2164 select COMPAT_BINFMT_ELF 2164 select COMPAT_BINFMT_ELF
2165 ---help--- 2165 ---help---
2166 Include code to run 32-bit programs under a 64-bit kernel. You should 2166 Include code to run legacy 32-bit programs under a
2167 likely turn this on, unless you're 100% sure that you don't have any 2167 64-bit kernel. You should likely turn this on, unless you're
2168 32-bit programs left. 2168 100% sure that you don't have any 32-bit programs left.
2169 2169
2170config IA32_AOUT 2170config IA32_AOUT
2171 tristate "IA32 a.out support" 2171 tristate "IA32 a.out support"
@@ -2173,9 +2173,22 @@ config IA32_AOUT
2173 ---help--- 2173 ---help---
2174 Support old a.out binaries in the 32bit emulation. 2174 Support old a.out binaries in the 32bit emulation.
2175 2175
2176config X86_X32
2177 bool "x32 ABI for 64-bit mode (EXPERIMENTAL)"
2178 depends on X86_64 && IA32_EMULATION && EXPERIMENTAL
2179 ---help---
2180 Include code to run binaries for the x32 native 32-bit ABI
2181 for 64-bit processors. An x32 process gets access to the
2182 full 64-bit register file and wide data path while leaving
2183 pointers at 32 bits for smaller memory footprint.
2184
2185 You will need a recent binutils (2.22 or later) with
2186 elf32_x86_64 support enabled to compile a kernel with this
2187 option set.
2188
2176config COMPAT 2189config COMPAT
2177 def_bool y 2190 def_bool y
2178 depends on IA32_EMULATION 2191 depends on IA32_EMULATION || X86_X32
2179 select ARCH_WANT_OLD_COMPAT_IPC 2192 select ARCH_WANT_OLD_COMPAT_IPC
2180 2193
2181config COMPAT_FOR_U64_ALIGNMENT 2194config COMPAT_FOR_U64_ALIGNMENT
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 209ba1294592..968dbe24a255 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -82,6 +82,22 @@ ifdef CONFIG_CC_STACKPROTECTOR
82 endif 82 endif
83endif 83endif
84 84
85ifdef CONFIG_X86_X32
86 x32_ld_ok := $(call try-run,\
87 /bin/echo -e '1: .quad 1b' | \
88 $(CC) $(KBUILD_AFLAGS) -c -xassembler -o "$$TMP" - && \
89 $(OBJCOPY) -O elf32-x86-64 "$$TMP" "$$TMPO" && \
90 $(LD) -m elf32_x86_64 "$$TMPO" -o "$$TMP",y,n)
91 ifeq ($(x32_ld_ok),y)
92 CONFIG_X86_X32_ABI := y
93 KBUILD_AFLAGS += -DCONFIG_X86_X32_ABI
94 KBUILD_CFLAGS += -DCONFIG_X86_X32_ABI
95 else
96 $(warning CONFIG_X86_X32 enabled but no binutils support)
97 endif
98endif
99export CONFIG_X86_X32_ABI
100
85# Don't unroll struct assignments with kmemcheck enabled 101# Don't unroll struct assignments with kmemcheck enabled
86ifeq ($(CONFIG_KMEMCHECK),y) 102ifeq ($(CONFIG_KMEMCHECK),y)
87 KBUILD_CFLAGS += $(call cc-option,-fno-builtin-memcpy) 103 KBUILD_CFLAGS += $(call cc-option,-fno-builtin-memcpy)
diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
index 5563ba1cf513..8ff8e7ddfc55 100644
--- a/arch/x86/ia32/ia32_signal.c
+++ b/arch/x86/ia32/ia32_signal.c
@@ -12,10 +12,8 @@
12#include <linux/mm.h> 12#include <linux/mm.h>
13#include <linux/smp.h> 13#include <linux/smp.h>
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/signal.h>
16#include <linux/errno.h> 15#include <linux/errno.h>
17#include <linux/wait.h> 16#include <linux/wait.h>
18#include <linux/ptrace.h>
19#include <linux/unistd.h> 17#include <linux/unistd.h>
20#include <linux/stddef.h> 18#include <linux/stddef.h>
21#include <linux/personality.h> 19#include <linux/personality.h>
@@ -32,20 +30,15 @@
32#include <asm/proto.h> 30#include <asm/proto.h>
33#include <asm/vdso.h> 31#include <asm/vdso.h>
34#include <asm/sigframe.h> 32#include <asm/sigframe.h>
33#include <asm/sighandling.h>
35#include <asm/sys_ia32.h> 34#include <asm/sys_ia32.h>
36 35
37#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP))) 36#define FIX_EFLAGS __FIX_EFLAGS
38
39#define FIX_EFLAGS (X86_EFLAGS_AC | X86_EFLAGS_OF | \
40 X86_EFLAGS_DF | X86_EFLAGS_TF | X86_EFLAGS_SF | \
41 X86_EFLAGS_ZF | X86_EFLAGS_AF | X86_EFLAGS_PF | \
42 X86_EFLAGS_CF)
43
44void signal_fault(struct pt_regs *regs, void __user *frame, char *where);
45 37
46int copy_siginfo_to_user32(compat_siginfo_t __user *to, siginfo_t *from) 38int copy_siginfo_to_user32(compat_siginfo_t __user *to, siginfo_t *from)
47{ 39{
48 int err = 0; 40 int err = 0;
41 bool ia32 = is_ia32_task();
49 42
50 if (!access_ok(VERIFY_WRITE, to, sizeof(compat_siginfo_t))) 43 if (!access_ok(VERIFY_WRITE, to, sizeof(compat_siginfo_t)))
51 return -EFAULT; 44 return -EFAULT;
@@ -75,8 +68,13 @@ int copy_siginfo_to_user32(compat_siginfo_t __user *to, siginfo_t *from)
75 case __SI_FAULT >> 16: 68 case __SI_FAULT >> 16:
76 break; 69 break;
77 case __SI_CHLD >> 16: 70 case __SI_CHLD >> 16:
78 put_user_ex(from->si_utime, &to->si_utime); 71 if (ia32) {
79 put_user_ex(from->si_stime, &to->si_stime); 72 put_user_ex(from->si_utime, &to->si_utime);
73 put_user_ex(from->si_stime, &to->si_stime);
74 } else {
75 put_user_ex(from->si_utime, &to->_sifields._sigchld_x32._utime);
76 put_user_ex(from->si_stime, &to->_sifields._sigchld_x32._stime);
77 }
80 put_user_ex(from->si_status, &to->si_status); 78 put_user_ex(from->si_status, &to->si_status);
81 /* FALL THROUGH */ 79 /* FALL THROUGH */
82 default: 80 default:
diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
index f6f5c53dc903..aec2202a596c 100644
--- a/arch/x86/ia32/sys_ia32.c
+++ b/arch/x86/ia32/sys_ia32.c
@@ -287,46 +287,6 @@ asmlinkage long sys32_sigaction(int sig, struct old_sigaction32 __user *act,
287 return ret; 287 return ret;
288} 288}
289 289
290asmlinkage long sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
291 compat_sigset_t __user *oset,
292 unsigned int sigsetsize)
293{
294 sigset_t s;
295 compat_sigset_t s32;
296 int ret;
297 mm_segment_t old_fs = get_fs();
298
299 if (set) {
300 if (copy_from_user(&s32, set, sizeof(compat_sigset_t)))
301 return -EFAULT;
302 switch (_NSIG_WORDS) {
303 case 4: s.sig[3] = s32.sig[6] | (((long)s32.sig[7]) << 32);
304 case 3: s.sig[2] = s32.sig[4] | (((long)s32.sig[5]) << 32);
305 case 2: s.sig[1] = s32.sig[2] | (((long)s32.sig[3]) << 32);
306 case 1: s.sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
307 }
308 }
309 set_fs(KERNEL_DS);
310 ret = sys_rt_sigprocmask(how,
311 set ? (sigset_t __user *)&s : NULL,
312 oset ? (sigset_t __user *)&s : NULL,
313 sigsetsize);
314 set_fs(old_fs);
315 if (ret)
316 return ret;
317 if (oset) {
318 switch (_NSIG_WORDS) {
319 case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
320 case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
321 case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
322 case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
323 }
324 if (copy_to_user(oset, &s32, sizeof(compat_sigset_t)))
325 return -EFAULT;
326 }
327 return 0;
328}
329
330asmlinkage long sys32_alarm(unsigned int seconds) 290asmlinkage long sys32_alarm(unsigned int seconds)
331{ 291{
332 return alarm_setitimer(seconds); 292 return alarm_setitimer(seconds);
diff --git a/arch/x86/include/asm/Kbuild b/arch/x86/include/asm/Kbuild
index b57e6a43a37a..f9c0d3ba9e84 100644
--- a/arch/x86/include/asm/Kbuild
+++ b/arch/x86/include/asm/Kbuild
@@ -14,6 +14,7 @@ header-y += msr.h
14header-y += mtrr.h 14header-y += mtrr.h
15header-y += posix_types_32.h 15header-y += posix_types_32.h
16header-y += posix_types_64.h 16header-y += posix_types_64.h
17header-y += posix_types_x32.h
17header-y += prctl.h 18header-y += prctl.h
18header-y += processor-flags.h 19header-y += processor-flags.h
19header-y += ptrace-abi.h 20header-y += ptrace-abi.h
@@ -24,3 +25,4 @@ header-y += vsyscall.h
24 25
25genhdr-y += unistd_32.h 26genhdr-y += unistd_32.h
26genhdr-y += unistd_64.h 27genhdr-y += unistd_64.h
28genhdr-y += unistd_x32.h
diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
index 30d737ef2a42..355edc091604 100644
--- a/arch/x86/include/asm/compat.h
+++ b/arch/x86/include/asm/compat.h
@@ -6,7 +6,9 @@
6 */ 6 */
7#include <linux/types.h> 7#include <linux/types.h>
8#include <linux/sched.h> 8#include <linux/sched.h>
9#include <asm/processor.h>
9#include <asm/user32.h> 10#include <asm/user32.h>
11#include <asm/unistd.h>
10 12
11#define COMPAT_USER_HZ 100 13#define COMPAT_USER_HZ 100
12#define COMPAT_UTS_MACHINE "i686\0\0" 14#define COMPAT_UTS_MACHINE "i686\0\0"
@@ -186,7 +188,20 @@ struct compat_shmid64_ds {
186/* 188/*
187 * The type of struct elf_prstatus.pr_reg in compatible core dumps. 189 * The type of struct elf_prstatus.pr_reg in compatible core dumps.
188 */ 190 */
191#ifdef CONFIG_X86_X32_ABI
192typedef struct user_regs_struct compat_elf_gregset_t;
193
194#define PR_REG_SIZE(S) (test_thread_flag(TIF_IA32) ? 68 : 216)
195#define PRSTATUS_SIZE(S) (test_thread_flag(TIF_IA32) ? 144 : 296)
196#define SET_PR_FPVALID(S,V) \
197 do { *(int *) (((void *) &((S)->pr_reg)) + PR_REG_SIZE(0)) = (V); } \
198 while (0)
199
200#define COMPAT_USE_64BIT_TIME \
201 (!!(task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT))
202#else
189typedef struct user_regs_struct32 compat_elf_gregset_t; 203typedef struct user_regs_struct32 compat_elf_gregset_t;
204#endif
190 205
191/* 206/*
192 * A pointer passed in from user mode. This should not 207 * A pointer passed in from user mode. This should not
@@ -208,13 +223,39 @@ static inline compat_uptr_t ptr_to_compat(void __user *uptr)
208 223
209static inline void __user *arch_compat_alloc_user_space(long len) 224static inline void __user *arch_compat_alloc_user_space(long len)
210{ 225{
211 struct pt_regs *regs = task_pt_regs(current); 226 compat_uptr_t sp;
212 return (void __user *)regs->sp - len; 227
228 if (test_thread_flag(TIF_IA32)) {
229 sp = task_pt_regs(current)->sp;
230 } else {
231 /* -128 for the x32 ABI redzone */
232 sp = percpu_read(old_rsp) - 128;
233 }
234
235 return (void __user *)round_down(sp - len, 16);
236}
237
238static inline bool is_ia32_task(void)
239{
240#ifdef CONFIG_IA32_EMULATION
241 if (current_thread_info()->status & TS_COMPAT)
242 return true;
243#endif
244 return false;
245}
246
247static inline bool is_x32_task(void)
248{
249#ifdef CONFIG_X86_X32_ABI
250 if (task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT)
251 return true;
252#endif
253 return false;
213} 254}
214 255
215static inline int is_compat_task(void) 256static inline bool is_compat_task(void)
216{ 257{
217 return current_thread_info()->status & TS_COMPAT; 258 return is_ia32_task() || is_x32_task();
218} 259}
219 260
220#endif /* _ASM_X86_COMPAT_H */ 261#endif /* _ASM_X86_COMPAT_H */
diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
index f27f79abe021..5939f44fe0c0 100644
--- a/arch/x86/include/asm/elf.h
+++ b/arch/x86/include/asm/elf.h
@@ -155,7 +155,12 @@ do { \
155#define elf_check_arch(x) \ 155#define elf_check_arch(x) \
156 ((x)->e_machine == EM_X86_64) 156 ((x)->e_machine == EM_X86_64)
157 157
158#define compat_elf_check_arch(x) elf_check_arch_ia32(x) 158#define compat_elf_check_arch(x) \
159 (elf_check_arch_ia32(x) || (x)->e_machine == EM_X86_64)
160
161#if __USER32_DS != __USER_DS
162# error "The following code assumes __USER32_DS == __USER_DS"
163#endif
159 164
160static inline void elf_common_init(struct thread_struct *t, 165static inline void elf_common_init(struct thread_struct *t,
161 struct pt_regs *regs, const u16 ds) 166 struct pt_regs *regs, const u16 ds)
@@ -178,8 +183,9 @@ static inline void elf_common_init(struct thread_struct *t,
178void start_thread_ia32(struct pt_regs *regs, u32 new_ip, u32 new_sp); 183void start_thread_ia32(struct pt_regs *regs, u32 new_ip, u32 new_sp);
179#define compat_start_thread start_thread_ia32 184#define compat_start_thread start_thread_ia32
180 185
181void set_personality_ia32(void); 186void set_personality_ia32(bool);
182#define COMPAT_SET_PERSONALITY(ex) set_personality_ia32() 187#define COMPAT_SET_PERSONALITY(ex) \
188 set_personality_ia32((ex).e_machine == EM_X86_64)
183 189
184#define COMPAT_ELF_PLATFORM ("i686") 190#define COMPAT_ELF_PLATFORM ("i686")
185 191
@@ -286,7 +292,7 @@ do { \
286#define VDSO_HIGH_BASE 0xffffe000U /* CONFIG_COMPAT_VDSO address */ 292#define VDSO_HIGH_BASE 0xffffe000U /* CONFIG_COMPAT_VDSO address */
287 293
288/* 1GB for 64bit, 8MB for 32bit */ 294/* 1GB for 64bit, 8MB for 32bit */
289#define STACK_RND_MASK (test_thread_flag(TIF_IA32) ? 0x7ff : 0x3fffff) 295#define STACK_RND_MASK (test_thread_flag(TIF_ADDR32) ? 0x7ff : 0x3fffff)
290 296
291#define ARCH_DLINFO \ 297#define ARCH_DLINFO \
292do { \ 298do { \
@@ -295,9 +301,20 @@ do { \
295 (unsigned long)current->mm->context.vdso); \ 301 (unsigned long)current->mm->context.vdso); \
296} while (0) 302} while (0)
297 303
304#define ARCH_DLINFO_X32 \
305do { \
306 if (vdso_enabled) \
307 NEW_AUX_ENT(AT_SYSINFO_EHDR, \
308 (unsigned long)current->mm->context.vdso); \
309} while (0)
310
298#define AT_SYSINFO 32 311#define AT_SYSINFO 32
299 312
300#define COMPAT_ARCH_DLINFO ARCH_DLINFO_IA32(sysctl_vsyscall32) 313#define COMPAT_ARCH_DLINFO \
314if (test_thread_flag(TIF_X32)) \
315 ARCH_DLINFO_X32; \
316else \
317 ARCH_DLINFO_IA32(sysctl_vsyscall32)
301 318
302#define COMPAT_ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000) 319#define COMPAT_ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
303 320
@@ -313,6 +330,8 @@ struct linux_binprm;
313#define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1 330#define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
314extern int arch_setup_additional_pages(struct linux_binprm *bprm, 331extern int arch_setup_additional_pages(struct linux_binprm *bprm,
315 int uses_interp); 332 int uses_interp);
333extern int x32_setup_additional_pages(struct linux_binprm *bprm,
334 int uses_interp);
316 335
317extern int syscall32_setup_pages(struct linux_binprm *, int exstack); 336extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
318#define compat_arch_setup_additional_pages syscall32_setup_pages 337#define compat_arch_setup_additional_pages syscall32_setup_pages
@@ -329,7 +348,7 @@ static inline int mmap_is_ia32(void)
329 return 1; 348 return 1;
330#endif 349#endif
331#ifdef CONFIG_IA32_EMULATION 350#ifdef CONFIG_IA32_EMULATION
332 if (test_thread_flag(TIF_IA32)) 351 if (test_thread_flag(TIF_ADDR32))
333 return 1; 352 return 1;
334#endif 353#endif
335 return 0; 354 return 0;
diff --git a/arch/x86/include/asm/ia32.h b/arch/x86/include/asm/ia32.h
index 1f7e62517284..ee52760549f0 100644
--- a/arch/x86/include/asm/ia32.h
+++ b/arch/x86/include/asm/ia32.h
@@ -43,6 +43,15 @@ struct ucontext_ia32 {
43 compat_sigset_t uc_sigmask; /* mask last for extensibility */ 43 compat_sigset_t uc_sigmask; /* mask last for extensibility */
44}; 44};
45 45
46struct ucontext_x32 {
47 unsigned int uc_flags;
48 unsigned int uc_link;
49 stack_ia32_t uc_stack;
50 unsigned int uc__pad0; /* needed for alignment */
51 struct sigcontext uc_mcontext; /* the 64-bit sigcontext type */
52 compat_sigset_t uc_sigmask; /* mask last for extensibility */
53};
54
46/* This matches struct stat64 in glibc2.2, hence the absolutely 55/* This matches struct stat64 in glibc2.2, hence the absolutely
47 * insane amounts of padding around dev_t's. 56 * insane amounts of padding around dev_t's.
48 */ 57 */
@@ -116,6 +125,15 @@ typedef struct compat_siginfo {
116 compat_clock_t _stime; 125 compat_clock_t _stime;
117 } _sigchld; 126 } _sigchld;
118 127
128 /* SIGCHLD (x32 version) */
129 struct {
130 unsigned int _pid; /* which child */
131 unsigned int _uid; /* sender's uid */
132 int _status; /* exit code */
133 compat_s64 _utime;
134 compat_s64 _stime;
135 } _sigchld_x32;
136
119 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS */ 137 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS */
120 struct { 138 struct {
121 unsigned int _addr; /* faulting insn/memory ref. */ 139 unsigned int _addr; /* faulting insn/memory ref. */
diff --git a/arch/x86/include/asm/mtrr.h b/arch/x86/include/asm/mtrr.h
index 4365ffdb461f..7e3f17f92c66 100644
--- a/arch/x86/include/asm/mtrr.h
+++ b/arch/x86/include/asm/mtrr.h
@@ -29,18 +29,18 @@
29 29
30#define MTRR_IOCTL_BASE 'M' 30#define MTRR_IOCTL_BASE 'M'
31 31
32struct mtrr_sentry {
33 unsigned long base; /* Base address */
34 unsigned int size; /* Size of region */
35 unsigned int type; /* Type of region */
36};
37
38/* Warning: this structure has a different order from i386 32/* Warning: this structure has a different order from i386
39 on x86-64. The 32bit emulation code takes care of that. 33 on x86-64. The 32bit emulation code takes care of that.
40 But you need to use this for 64bit, otherwise your X server 34 But you need to use this for 64bit, otherwise your X server
41 will break. */ 35 will break. */
42 36
43#ifdef __i386__ 37#ifdef __i386__
38struct mtrr_sentry {
39 unsigned long base; /* Base address */
40 unsigned int size; /* Size of region */
41 unsigned int type; /* Type of region */
42};
43
44struct mtrr_gentry { 44struct mtrr_gentry {
45 unsigned int regnum; /* Register number */ 45 unsigned int regnum; /* Register number */
46 unsigned long base; /* Base address */ 46 unsigned long base; /* Base address */
@@ -50,12 +50,20 @@ struct mtrr_gentry {
50 50
51#else /* __i386__ */ 51#else /* __i386__ */
52 52
53struct mtrr_sentry {
54 __u64 base; /* Base address */
55 __u32 size; /* Size of region */
56 __u32 type; /* Type of region */
57};
58
53struct mtrr_gentry { 59struct mtrr_gentry {
54 unsigned long base; /* Base address */ 60 __u64 base; /* Base address */
55 unsigned int size; /* Size of region */ 61 __u32 size; /* Size of region */
56 unsigned int regnum; /* Register number */ 62 __u32 regnum; /* Register number */
57 unsigned int type; /* Type of region */ 63 __u32 type; /* Type of region */
64 __u32 _pad; /* Unused */
58}; 65};
66
59#endif /* !__i386__ */ 67#endif /* !__i386__ */
60 68
61struct mtrr_var_range { 69struct mtrr_var_range {
diff --git a/arch/x86/include/asm/posix_types.h b/arch/x86/include/asm/posix_types.h
index bb7133dc155d..3427b7798dbc 100644
--- a/arch/x86/include/asm/posix_types.h
+++ b/arch/x86/include/asm/posix_types.h
@@ -7,7 +7,9 @@
7#else 7#else
8# ifdef __i386__ 8# ifdef __i386__
9# include "posix_types_32.h" 9# include "posix_types_32.h"
10# else 10# elif defined(__LP64__)
11# include "posix_types_64.h" 11# include "posix_types_64.h"
12# else
13# include "posix_types_x32.h"
12# endif 14# endif
13#endif 15#endif
diff --git a/arch/x86/include/asm/posix_types_32.h b/arch/x86/include/asm/posix_types_32.h
index f7d9adf82e53..99f262e04b91 100644
--- a/arch/x86/include/asm/posix_types_32.h
+++ b/arch/x86/include/asm/posix_types_32.h
@@ -7,79 +7,22 @@
7 * assume GCC is being used. 7 * assume GCC is being used.
8 */ 8 */
9 9
10typedef unsigned long __kernel_ino_t;
11typedef unsigned short __kernel_mode_t; 10typedef unsigned short __kernel_mode_t;
11#define __kernel_mode_t __kernel_mode_t
12
12typedef unsigned short __kernel_nlink_t; 13typedef unsigned short __kernel_nlink_t;
13typedef long __kernel_off_t; 14#define __kernel_nlink_t __kernel_nlink_t
14typedef int __kernel_pid_t; 15
15typedef unsigned short __kernel_ipc_pid_t; 16typedef unsigned short __kernel_ipc_pid_t;
17#define __kernel_ipc_pid_t __kernel_ipc_pid_t
18
16typedef unsigned short __kernel_uid_t; 19typedef unsigned short __kernel_uid_t;
17typedef unsigned short __kernel_gid_t; 20typedef unsigned short __kernel_gid_t;
18typedef unsigned int __kernel_size_t; 21#define __kernel_uid_t __kernel_uid_t
19typedef int __kernel_ssize_t;
20typedef int __kernel_ptrdiff_t;
21typedef long __kernel_time_t;
22typedef long __kernel_suseconds_t;
23typedef long __kernel_clock_t;
24typedef int __kernel_timer_t;
25typedef int __kernel_clockid_t;
26typedef int __kernel_daddr_t;
27typedef char * __kernel_caddr_t;
28typedef unsigned short __kernel_uid16_t;
29typedef unsigned short __kernel_gid16_t;
30typedef unsigned int __kernel_uid32_t;
31typedef unsigned int __kernel_gid32_t;
32 22
33typedef unsigned short __kernel_old_uid_t;
34typedef unsigned short __kernel_old_gid_t;
35typedef unsigned short __kernel_old_dev_t; 23typedef unsigned short __kernel_old_dev_t;
24#define __kernel_old_dev_t __kernel_old_dev_t
36 25
37#ifdef __GNUC__ 26#include <asm-generic/posix_types.h>
38typedef long long __kernel_loff_t;
39#endif
40
41typedef struct {
42 int val[2];
43} __kernel_fsid_t;
44
45#if defined(__KERNEL__)
46
47#undef __FD_SET
48#define __FD_SET(fd,fdsetp) \
49 asm volatile("btsl %1,%0": \
50 "+m" (*(__kernel_fd_set *)(fdsetp)) \
51 : "r" ((int)(fd)))
52
53#undef __FD_CLR
54#define __FD_CLR(fd,fdsetp) \
55 asm volatile("btrl %1,%0": \
56 "+m" (*(__kernel_fd_set *)(fdsetp)) \
57 : "r" ((int) (fd)))
58
59#undef __FD_ISSET
60#define __FD_ISSET(fd,fdsetp) \
61 (__extension__ \
62 ({ \
63 unsigned char __result; \
64 asm volatile("btl %1,%2 ; setb %0" \
65 : "=q" (__result) \
66 : "r" ((int)(fd)), \
67 "m" (*(__kernel_fd_set *)(fdsetp))); \
68 __result; \
69}))
70
71#undef __FD_ZERO
72#define __FD_ZERO(fdsetp) \
73do { \
74 int __d0, __d1; \
75 asm volatile("cld ; rep ; stosl" \
76 : "=m" (*(__kernel_fd_set *)(fdsetp)), \
77 "=&c" (__d0), "=&D" (__d1) \
78 : "a" (0), "1" (__FDSET_LONGS), \
79 "2" ((__kernel_fd_set *)(fdsetp)) \
80 : "memory"); \
81} while (0)
82
83#endif /* defined(__KERNEL__) */
84 27
85#endif /* _ASM_X86_POSIX_TYPES_32_H */ 28#endif /* _ASM_X86_POSIX_TYPES_32_H */
diff --git a/arch/x86/include/asm/posix_types_64.h b/arch/x86/include/asm/posix_types_64.h
index eb8d2d92b63e..cba0c1ead162 100644
--- a/arch/x86/include/asm/posix_types_64.h
+++ b/arch/x86/include/asm/posix_types_64.h
@@ -7,113 +7,13 @@
7 * assume GCC is being used. 7 * assume GCC is being used.
8 */ 8 */
9 9
10typedef unsigned long __kernel_ino_t;
11typedef unsigned int __kernel_mode_t;
12typedef unsigned long __kernel_nlink_t;
13typedef long __kernel_off_t;
14typedef int __kernel_pid_t;
15typedef int __kernel_ipc_pid_t;
16typedef unsigned int __kernel_uid_t;
17typedef unsigned int __kernel_gid_t;
18typedef unsigned long __kernel_size_t;
19typedef long __kernel_ssize_t;
20typedef long __kernel_ptrdiff_t;
21typedef long __kernel_time_t;
22typedef long __kernel_suseconds_t;
23typedef long __kernel_clock_t;
24typedef int __kernel_timer_t;
25typedef int __kernel_clockid_t;
26typedef int __kernel_daddr_t;
27typedef char * __kernel_caddr_t;
28typedef unsigned short __kernel_uid16_t;
29typedef unsigned short __kernel_gid16_t;
30
31#ifdef __GNUC__
32typedef long long __kernel_loff_t;
33#endif
34
35typedef struct {
36 int val[2];
37} __kernel_fsid_t;
38
39typedef unsigned short __kernel_old_uid_t; 10typedef unsigned short __kernel_old_uid_t;
40typedef unsigned short __kernel_old_gid_t; 11typedef unsigned short __kernel_old_gid_t;
41typedef __kernel_uid_t __kernel_uid32_t; 12#define __kernel_old_uid_t __kernel_old_uid_t
42typedef __kernel_gid_t __kernel_gid32_t;
43 13
44typedef unsigned long __kernel_old_dev_t; 14typedef unsigned long __kernel_old_dev_t;
15#define __kernel_old_dev_t __kernel_old_dev_t
45 16
46#ifdef __KERNEL__ 17#include <asm-generic/posix_types.h>
47
48#undef __FD_SET
49static inline void __FD_SET(unsigned long fd, __kernel_fd_set *fdsetp)
50{
51 unsigned long _tmp = fd / __NFDBITS;
52 unsigned long _rem = fd % __NFDBITS;
53 fdsetp->fds_bits[_tmp] |= (1UL<<_rem);
54}
55
56#undef __FD_CLR
57static inline void __FD_CLR(unsigned long fd, __kernel_fd_set *fdsetp)
58{
59 unsigned long _tmp = fd / __NFDBITS;
60 unsigned long _rem = fd % __NFDBITS;
61 fdsetp->fds_bits[_tmp] &= ~(1UL<<_rem);
62}
63
64#undef __FD_ISSET
65static inline int __FD_ISSET(unsigned long fd, __const__ __kernel_fd_set *p)
66{
67 unsigned long _tmp = fd / __NFDBITS;
68 unsigned long _rem = fd % __NFDBITS;
69 return (p->fds_bits[_tmp] & (1UL<<_rem)) != 0;
70}
71
72/*
73 * This will unroll the loop for the normal constant cases (8 or 32 longs,
74 * for 256 and 1024-bit fd_sets respectively)
75 */
76#undef __FD_ZERO
77static inline void __FD_ZERO(__kernel_fd_set *p)
78{
79 unsigned long *tmp = p->fds_bits;
80 int i;
81
82 if (__builtin_constant_p(__FDSET_LONGS)) {
83 switch (__FDSET_LONGS) {
84 case 32:
85 tmp[ 0] = 0; tmp[ 1] = 0; tmp[ 2] = 0; tmp[ 3] = 0;
86 tmp[ 4] = 0; tmp[ 5] = 0; tmp[ 6] = 0; tmp[ 7] = 0;
87 tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0;
88 tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0;
89 tmp[16] = 0; tmp[17] = 0; tmp[18] = 0; tmp[19] = 0;
90 tmp[20] = 0; tmp[21] = 0; tmp[22] = 0; tmp[23] = 0;
91 tmp[24] = 0; tmp[25] = 0; tmp[26] = 0; tmp[27] = 0;
92 tmp[28] = 0; tmp[29] = 0; tmp[30] = 0; tmp[31] = 0;
93 return;
94 case 16:
95 tmp[ 0] = 0; tmp[ 1] = 0; tmp[ 2] = 0; tmp[ 3] = 0;
96 tmp[ 4] = 0; tmp[ 5] = 0; tmp[ 6] = 0; tmp[ 7] = 0;
97 tmp[ 8] = 0; tmp[ 9] = 0; tmp[10] = 0; tmp[11] = 0;
98 tmp[12] = 0; tmp[13] = 0; tmp[14] = 0; tmp[15] = 0;
99 return;
100 case 8:
101 tmp[ 0] = 0; tmp[ 1] = 0; tmp[ 2] = 0; tmp[ 3] = 0;
102 tmp[ 4] = 0; tmp[ 5] = 0; tmp[ 6] = 0; tmp[ 7] = 0;
103 return;
104 case 4:
105 tmp[ 0] = 0; tmp[ 1] = 0; tmp[ 2] = 0; tmp[ 3] = 0;
106 return;
107 }
108 }
109 i = __FDSET_LONGS;
110 while (i) {
111 i--;
112 *tmp = 0;
113 tmp++;
114 }
115}
116
117#endif /* defined(__KERNEL__) */
118 18
119#endif /* _ASM_X86_POSIX_TYPES_64_H */ 19#endif /* _ASM_X86_POSIX_TYPES_64_H */
diff --git a/arch/x86/include/asm/posix_types_x32.h b/arch/x86/include/asm/posix_types_x32.h
new file mode 100644
index 000000000000..85f9bdafa93c
--- /dev/null
+++ b/arch/x86/include/asm/posix_types_x32.h
@@ -0,0 +1,19 @@
1#ifndef _ASM_X86_POSIX_TYPES_X32_H
2#define _ASM_X86_POSIX_TYPES_X32_H
3
4/*
5 * This file is only used by user-level software, so you need to
6 * be a little careful about namespace pollution etc. Also, we cannot
7 * assume GCC is being used.
8 *
9 * These types should generally match the ones used by the 64-bit kernel,
10 *
11 */
12
13typedef long long __kernel_long_t;
14typedef unsigned long long __kernel_ulong_t;
15#define __kernel_long_t __kernel_long_t
16
17#include <asm/posix_types_64.h>
18
19#endif /* _ASM_X86_POSIX_TYPES_X32_H */
diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index a19542c1685e..f302ef6bb200 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -873,9 +873,9 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
873#define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \ 873#define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
874 0xc0000000 : 0xFFFFe000) 874 0xc0000000 : 0xFFFFe000)
875 875
876#define TASK_SIZE (test_thread_flag(TIF_IA32) ? \ 876#define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
877 IA32_PAGE_OFFSET : TASK_SIZE_MAX) 877 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
878#define TASK_SIZE_OF(child) ((test_tsk_thread_flag(child, TIF_IA32)) ? \ 878#define TASK_SIZE_OF(child) ((test_tsk_thread_flag(child, TIF_ADDR32)) ? \
879 IA32_PAGE_OFFSET : TASK_SIZE_MAX) 879 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
880 880
881#define STACK_TOP TASK_SIZE 881#define STACK_TOP TASK_SIZE
@@ -897,6 +897,12 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
897 897
898#define task_pt_regs(tsk) ((struct pt_regs *)(tsk)->thread.sp0 - 1) 898#define task_pt_regs(tsk) ((struct pt_regs *)(tsk)->thread.sp0 - 1)
899extern unsigned long KSTK_ESP(struct task_struct *task); 899extern unsigned long KSTK_ESP(struct task_struct *task);
900
901/*
902 * User space RSP while inside the SYSCALL fast path
903 */
904DECLARE_PER_CPU(unsigned long, old_rsp);
905
900#endif /* CONFIG_X86_64 */ 906#endif /* CONFIG_X86_64 */
901 907
902extern void start_thread(struct pt_regs *regs, unsigned long new_ip, 908extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
index 35664547125b..dcfde52979c3 100644
--- a/arch/x86/include/asm/ptrace.h
+++ b/arch/x86/include/asm/ptrace.h
@@ -145,7 +145,6 @@ extern unsigned long
145convert_ip_to_linear(struct task_struct *child, struct pt_regs *regs); 145convert_ip_to_linear(struct task_struct *child, struct pt_regs *regs);
146extern void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs, 146extern void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
147 int error_code, int si_code); 147 int error_code, int si_code);
148void signal_fault(struct pt_regs *regs, void __user *frame, char *where);
149 148
150extern long syscall_trace_enter(struct pt_regs *); 149extern long syscall_trace_enter(struct pt_regs *);
151extern void syscall_trace_leave(struct pt_regs *); 150extern void syscall_trace_leave(struct pt_regs *);
diff --git a/arch/x86/include/asm/sigcontext.h b/arch/x86/include/asm/sigcontext.h
index 04459d25e66e..4a085383af27 100644
--- a/arch/x86/include/asm/sigcontext.h
+++ b/arch/x86/include/asm/sigcontext.h
@@ -230,34 +230,37 @@ struct sigcontext {
230 * User-space might still rely on the old definition: 230 * User-space might still rely on the old definition:
231 */ 231 */
232struct sigcontext { 232struct sigcontext {
233 unsigned long r8; 233 __u64 r8;
234 unsigned long r9; 234 __u64 r9;
235 unsigned long r10; 235 __u64 r10;
236 unsigned long r11; 236 __u64 r11;
237 unsigned long r12; 237 __u64 r12;
238 unsigned long r13; 238 __u64 r13;
239 unsigned long r14; 239 __u64 r14;
240 unsigned long r15; 240 __u64 r15;
241 unsigned long rdi; 241 __u64 rdi;
242 unsigned long rsi; 242 __u64 rsi;
243 unsigned long rbp; 243 __u64 rbp;
244 unsigned long rbx; 244 __u64 rbx;
245 unsigned long rdx; 245 __u64 rdx;
246 unsigned long rax; 246 __u64 rax;
247 unsigned long rcx; 247 __u64 rcx;
248 unsigned long rsp; 248 __u64 rsp;
249 unsigned long rip; 249 __u64 rip;
250 unsigned long eflags; /* RFLAGS */ 250 __u64 eflags; /* RFLAGS */
251 unsigned short cs; 251 __u16 cs;
252 unsigned short gs; 252 __u16 gs;
253 unsigned short fs; 253 __u16 fs;
254 unsigned short __pad0; 254 __u16 __pad0;
255 unsigned long err; 255 __u64 err;
256 unsigned long trapno; 256 __u64 trapno;
257 unsigned long oldmask; 257 __u64 oldmask;
258 unsigned long cr2; 258 __u64 cr2;
259 struct _fpstate __user *fpstate; /* zero when no FPU context */ 259 struct _fpstate __user *fpstate; /* zero when no FPU context */
260 unsigned long reserved1[8]; 260#ifndef __LP64__
261 __u32 __fpstate_pad;
262#endif
263 __u64 reserved1[8];
261}; 264};
262#endif /* !__KERNEL__ */ 265#endif /* !__KERNEL__ */
263 266
diff --git a/arch/x86/include/asm/sigframe.h b/arch/x86/include/asm/sigframe.h
index 4e0fe26d27d3..7c7c27c97daa 100644
--- a/arch/x86/include/asm/sigframe.h
+++ b/arch/x86/include/asm/sigframe.h
@@ -59,12 +59,25 @@ struct rt_sigframe_ia32 {
59#endif /* defined(CONFIG_X86_32) || defined(CONFIG_IA32_EMULATION) */ 59#endif /* defined(CONFIG_X86_32) || defined(CONFIG_IA32_EMULATION) */
60 60
61#ifdef CONFIG_X86_64 61#ifdef CONFIG_X86_64
62
62struct rt_sigframe { 63struct rt_sigframe {
63 char __user *pretcode; 64 char __user *pretcode;
64 struct ucontext uc; 65 struct ucontext uc;
65 struct siginfo info; 66 struct siginfo info;
66 /* fp state follows here */ 67 /* fp state follows here */
67}; 68};
69
70#ifdef CONFIG_X86_X32_ABI
71
72struct rt_sigframe_x32 {
73 u64 pretcode;
74 struct ucontext_x32 uc;
75 compat_siginfo_t info;
76 /* fp state follows here */
77};
78
79#endif /* CONFIG_X86_X32_ABI */
80
68#endif /* CONFIG_X86_64 */ 81#endif /* CONFIG_X86_64 */
69 82
70#endif /* _ASM_X86_SIGFRAME_H */ 83#endif /* _ASM_X86_SIGFRAME_H */
diff --git a/arch/x86/include/asm/sighandling.h b/arch/x86/include/asm/sighandling.h
new file mode 100644
index 000000000000..ada93b3b8c66
--- /dev/null
+++ b/arch/x86/include/asm/sighandling.h
@@ -0,0 +1,24 @@
1#ifndef _ASM_X86_SIGHANDLING_H
2#define _ASM_X86_SIGHANDLING_H
3
4#include <linux/compiler.h>
5#include <linux/ptrace.h>
6#include <linux/signal.h>
7
8#include <asm/processor-flags.h>
9
10#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
11
12#define __FIX_EFLAGS (X86_EFLAGS_AC | X86_EFLAGS_OF | \
13 X86_EFLAGS_DF | X86_EFLAGS_TF | X86_EFLAGS_SF | \
14 X86_EFLAGS_ZF | X86_EFLAGS_AF | X86_EFLAGS_PF | \
15 X86_EFLAGS_CF)
16
17void signal_fault(struct pt_regs *regs, void __user *frame, char *where);
18
19int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc,
20 unsigned long *pax);
21int setup_sigcontext(struct sigcontext __user *sc, void __user *fpstate,
22 struct pt_regs *regs, unsigned long mask);
23
24#endif /* _ASM_X86_SIGHANDLING_H */
diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
index cb238526a9f1..3fda9db48819 100644
--- a/arch/x86/include/asm/sys_ia32.h
+++ b/arch/x86/include/asm/sys_ia32.h
@@ -10,6 +10,8 @@
10#ifndef _ASM_X86_SYS_IA32_H 10#ifndef _ASM_X86_SYS_IA32_H
11#define _ASM_X86_SYS_IA32_H 11#define _ASM_X86_SYS_IA32_H
12 12
13#ifdef CONFIG_COMPAT
14
13#include <linux/compiler.h> 15#include <linux/compiler.h>
14#include <linux/linkage.h> 16#include <linux/linkage.h>
15#include <linux/types.h> 17#include <linux/types.h>
@@ -36,8 +38,6 @@ asmlinkage long sys32_rt_sigaction(int, struct sigaction32 __user *,
36 struct sigaction32 __user *, unsigned int); 38 struct sigaction32 __user *, unsigned int);
37asmlinkage long sys32_sigaction(int, struct old_sigaction32 __user *, 39asmlinkage long sys32_sigaction(int, struct old_sigaction32 __user *,
38 struct old_sigaction32 __user *); 40 struct old_sigaction32 __user *);
39asmlinkage long sys32_rt_sigprocmask(int, compat_sigset_t __user *,
40 compat_sigset_t __user *, unsigned int);
41asmlinkage long sys32_alarm(unsigned int); 41asmlinkage long sys32_alarm(unsigned int);
42 42
43asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int); 43asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
@@ -83,4 +83,7 @@ asmlinkage long sys32_ipc(u32, int, int, int, compat_uptr_t, u32);
83 83
84asmlinkage long sys32_fanotify_mark(int, unsigned int, u32, u32, int, 84asmlinkage long sys32_fanotify_mark(int, unsigned int, u32, u32, int,
85 const char __user *); 85 const char __user *);
86
87#endif /* CONFIG_COMPAT */
88
86#endif /* _ASM_X86_SYS_IA32_H */ 89#endif /* _ASM_X86_SYS_IA32_H */
diff --git a/arch/x86/include/asm/syscall.h b/arch/x86/include/asm/syscall.h
index d962e5652a73..386b78686c4d 100644
--- a/arch/x86/include/asm/syscall.h
+++ b/arch/x86/include/asm/syscall.h
@@ -16,6 +16,7 @@
16#include <linux/sched.h> 16#include <linux/sched.h>
17#include <linux/err.h> 17#include <linux/err.h>
18#include <asm/asm-offsets.h> /* For NR_syscalls */ 18#include <asm/asm-offsets.h> /* For NR_syscalls */
19#include <asm/unistd.h>
19 20
20extern const unsigned long sys_call_table[]; 21extern const unsigned long sys_call_table[];
21 22
@@ -26,13 +27,13 @@ extern const unsigned long sys_call_table[];
26 */ 27 */
27static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs) 28static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
28{ 29{
29 return regs->orig_ax; 30 return regs->orig_ax & __SYSCALL_MASK;
30} 31}
31 32
32static inline void syscall_rollback(struct task_struct *task, 33static inline void syscall_rollback(struct task_struct *task,
33 struct pt_regs *regs) 34 struct pt_regs *regs)
34{ 35{
35 regs->ax = regs->orig_ax; 36 regs->ax = regs->orig_ax & __SYSCALL_MASK;
36} 37}
37 38
38static inline long syscall_get_error(struct task_struct *task, 39static inline long syscall_get_error(struct task_struct *task,
diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
index cfd8144d5527..af1db7e722f4 100644
--- a/arch/x86/include/asm/thread_info.h
+++ b/arch/x86/include/asm/thread_info.h
@@ -86,7 +86,7 @@ struct thread_info {
86#define TIF_MCE_NOTIFY 10 /* notify userspace of an MCE */ 86#define TIF_MCE_NOTIFY 10 /* notify userspace of an MCE */
87#define TIF_USER_RETURN_NOTIFY 11 /* notify kernel of userspace return */ 87#define TIF_USER_RETURN_NOTIFY 11 /* notify kernel of userspace return */
88#define TIF_NOTSC 16 /* TSC is not accessible in userland */ 88#define TIF_NOTSC 16 /* TSC is not accessible in userland */
89#define TIF_IA32 17 /* 32bit process */ 89#define TIF_IA32 17 /* IA32 compatibility process */
90#define TIF_FORK 18 /* ret_from_fork */ 90#define TIF_FORK 18 /* ret_from_fork */
91#define TIF_MEMDIE 20 /* is terminating due to OOM killer */ 91#define TIF_MEMDIE 20 /* is terminating due to OOM killer */
92#define TIF_DEBUG 21 /* uses debug registers */ 92#define TIF_DEBUG 21 /* uses debug registers */
@@ -95,6 +95,8 @@ struct thread_info {
95#define TIF_BLOCKSTEP 25 /* set when we want DEBUGCTLMSR_BTF */ 95#define TIF_BLOCKSTEP 25 /* set when we want DEBUGCTLMSR_BTF */
96#define TIF_LAZY_MMU_UPDATES 27 /* task is updating the mmu lazily */ 96#define TIF_LAZY_MMU_UPDATES 27 /* task is updating the mmu lazily */
97#define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */ 97#define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
98#define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
99#define TIF_X32 30 /* 32-bit native x86-64 binary */
98 100
99#define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE) 101#define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
100#define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME) 102#define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
@@ -116,6 +118,8 @@ struct thread_info {
116#define _TIF_BLOCKSTEP (1 << TIF_BLOCKSTEP) 118#define _TIF_BLOCKSTEP (1 << TIF_BLOCKSTEP)
117#define _TIF_LAZY_MMU_UPDATES (1 << TIF_LAZY_MMU_UPDATES) 119#define _TIF_LAZY_MMU_UPDATES (1 << TIF_LAZY_MMU_UPDATES)
118#define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT) 120#define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
121#define _TIF_ADDR32 (1 << TIF_ADDR32)
122#define _TIF_X32 (1 << TIF_X32)
119 123
120/* work to do in syscall_trace_enter() */ 124/* work to do in syscall_trace_enter() */
121#define _TIF_WORK_SYSCALL_ENTRY \ 125#define _TIF_WORK_SYSCALL_ENTRY \
diff --git a/arch/x86/include/asm/unistd.h b/arch/x86/include/asm/unistd.h
index 21f77b89e47a..37cdc9d99bb1 100644
--- a/arch/x86/include/asm/unistd.h
+++ b/arch/x86/include/asm/unistd.h
@@ -1,7 +1,17 @@
1#ifndef _ASM_X86_UNISTD_H 1#ifndef _ASM_X86_UNISTD_H
2#define _ASM_X86_UNISTD_H 1 2#define _ASM_X86_UNISTD_H 1
3 3
4/* x32 syscall flag bit */
5#define __X32_SYSCALL_BIT 0x40000000
6
4#ifdef __KERNEL__ 7#ifdef __KERNEL__
8
9# ifdef CONFIG_X86_X32_ABI
10# define __SYSCALL_MASK (~(__X32_SYSCALL_BIT))
11# else
12# define __SYSCALL_MASK (~0)
13# endif
14
5# ifdef CONFIG_X86_32 15# ifdef CONFIG_X86_32
6 16
7# include <asm/unistd_32.h> 17# include <asm/unistd_32.h>
@@ -14,6 +24,7 @@
14# else 24# else
15 25
16# include <asm/unistd_64.h> 26# include <asm/unistd_64.h>
27# include <asm/unistd_64_x32.h>
17# define __ARCH_WANT_COMPAT_SYS_TIME 28# define __ARCH_WANT_COMPAT_SYS_TIME
18 29
19# endif 30# endif
@@ -52,8 +63,10 @@
52#else 63#else
53# ifdef __i386__ 64# ifdef __i386__
54# include <asm/unistd_32.h> 65# include <asm/unistd_32.h>
55# else 66# elif defined(__LP64__)
56# include <asm/unistd_64.h> 67# include <asm/unistd_64.h>
68# else
69# include <asm/unistd_x32.h>
57# endif 70# endif
58#endif 71#endif
59 72
diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
index 834e897b1e25..1b4754f82ba7 100644
--- a/arch/x86/kernel/asm-offsets_64.c
+++ b/arch/x86/kernel/asm-offsets_64.c
@@ -1,6 +1,12 @@
1#include <asm/ia32.h> 1#include <asm/ia32.h>
2 2
3#define __SYSCALL_64(nr, sym, compat) [nr] = 1, 3#define __SYSCALL_64(nr, sym, compat) [nr] = 1,
4#define __SYSCALL_COMMON(nr, sym, compat) [nr] = 1,
5#ifdef CONFIG_X86_X32_ABI
6# define __SYSCALL_X32(nr, sym, compat) [nr] = 1,
7#else
8# define __SYSCALL_X32(nr, sym, compat) /* nothing */
9#endif
4static char syscalls_64[] = { 10static char syscalls_64[] = {
5#include <asm/syscalls_64.h> 11#include <asm/syscalls_64.h>
6}; 12};
diff --git a/arch/x86/kernel/cpu/mtrr/if.c b/arch/x86/kernel/cpu/mtrr/if.c
index 79289632cb27..a041e094b8b9 100644
--- a/arch/x86/kernel/cpu/mtrr/if.c
+++ b/arch/x86/kernel/cpu/mtrr/if.c
@@ -167,6 +167,7 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg)
167{ 167{
168 int err = 0; 168 int err = 0;
169 mtrr_type type; 169 mtrr_type type;
170 unsigned long base;
170 unsigned long size; 171 unsigned long size;
171 struct mtrr_sentry sentry; 172 struct mtrr_sentry sentry;
172 struct mtrr_gentry gentry; 173 struct mtrr_gentry gentry;
@@ -267,14 +268,14 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg)
267#endif 268#endif
268 if (gentry.regnum >= num_var_ranges) 269 if (gentry.regnum >= num_var_ranges)
269 return -EINVAL; 270 return -EINVAL;
270 mtrr_if->get(gentry.regnum, &gentry.base, &size, &type); 271 mtrr_if->get(gentry.regnum, &base, &size, &type);
271 272
272 /* Hide entries that go above 4GB */ 273 /* Hide entries that go above 4GB */
273 if (gentry.base + size - 1 >= (1UL << (8 * sizeof(gentry.size) - PAGE_SHIFT)) 274 if (base + size - 1 >= (1UL << (8 * sizeof(gentry.size) - PAGE_SHIFT))
274 || size >= (1UL << (8 * sizeof(gentry.size) - PAGE_SHIFT))) 275 || size >= (1UL << (8 * sizeof(gentry.size) - PAGE_SHIFT)))
275 gentry.base = gentry.size = gentry.type = 0; 276 gentry.base = gentry.size = gentry.type = 0;
276 else { 277 else {
277 gentry.base <<= PAGE_SHIFT; 278 gentry.base = base << PAGE_SHIFT;
278 gentry.size = size << PAGE_SHIFT; 279 gentry.size = size << PAGE_SHIFT;
279 gentry.type = type; 280 gentry.type = type;
280 } 281 }
@@ -321,11 +322,12 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg)
321#endif 322#endif
322 if (gentry.regnum >= num_var_ranges) 323 if (gentry.regnum >= num_var_ranges)
323 return -EINVAL; 324 return -EINVAL;
324 mtrr_if->get(gentry.regnum, &gentry.base, &size, &type); 325 mtrr_if->get(gentry.regnum, &base, &size, &type);
325 /* Hide entries that would overflow */ 326 /* Hide entries that would overflow */
326 if (size != (__typeof__(gentry.size))size) 327 if (size != (__typeof__(gentry.size))size)
327 gentry.base = gentry.size = gentry.type = 0; 328 gentry.base = gentry.size = gentry.type = 0;
328 else { 329 else {
330 gentry.base = base;
329 gentry.size = size; 331 gentry.size = size;
330 gentry.type = type; 332 gentry.type = type;
331 } 333 }
diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
index fa2900c0e398..40883ffe2da9 100644
--- a/arch/x86/kernel/cpu/perf_event.c
+++ b/arch/x86/kernel/cpu/perf_event.c
@@ -29,7 +29,6 @@
29#include <asm/apic.h> 29#include <asm/apic.h>
30#include <asm/stacktrace.h> 30#include <asm/stacktrace.h>
31#include <asm/nmi.h> 31#include <asm/nmi.h>
32#include <asm/compat.h>
33#include <asm/smp.h> 32#include <asm/smp.h>
34#include <asm/alternative.h> 33#include <asm/alternative.h>
35#include <asm/timer.h> 34#include <asm/timer.h>
@@ -1748,6 +1747,9 @@ perf_callchain_kernel(struct perf_callchain_entry *entry, struct pt_regs *regs)
1748} 1747}
1749 1748
1750#ifdef CONFIG_COMPAT 1749#ifdef CONFIG_COMPAT
1750
1751#include <asm/compat.h>
1752
1751static inline int 1753static inline int
1752perf_callchain_user32(struct pt_regs *regs, struct perf_callchain_entry *entry) 1754perf_callchain_user32(struct pt_regs *regs, struct perf_callchain_entry *entry)
1753{ 1755{
diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index 734ebd1d3caa..cdc79b5cfcd9 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -481,7 +481,12 @@ GLOBAL(system_call_after_swapgs)
481 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET) 481 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
482 jnz tracesys 482 jnz tracesys
483system_call_fastpath: 483system_call_fastpath:
484#if __SYSCALL_MASK == ~0
484 cmpq $__NR_syscall_max,%rax 485 cmpq $__NR_syscall_max,%rax
486#else
487 andl $__SYSCALL_MASK,%eax
488 cmpl $__NR_syscall_max,%eax
489#endif
485 ja badsys 490 ja badsys
486 movq %r10,%rcx 491 movq %r10,%rcx
487 call *sys_call_table(,%rax,8) # XXX: rip relative 492 call *sys_call_table(,%rax,8) # XXX: rip relative
@@ -595,7 +600,12 @@ tracesys:
595 */ 600 */
596 LOAD_ARGS ARGOFFSET, 1 601 LOAD_ARGS ARGOFFSET, 1
597 RESTORE_REST 602 RESTORE_REST
603#if __SYSCALL_MASK == ~0
598 cmpq $__NR_syscall_max,%rax 604 cmpq $__NR_syscall_max,%rax
605#else
606 andl $__SYSCALL_MASK,%eax
607 cmpl $__NR_syscall_max,%eax
608#endif
599 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */ 609 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
600 movq %r10,%rcx /* fixup for C */ 610 movq %r10,%rcx /* fixup for C */
601 call *sys_call_table(,%rax,8) 611 call *sys_call_table(,%rax,8)
@@ -735,6 +745,40 @@ ENTRY(stub_rt_sigreturn)
735 CFI_ENDPROC 745 CFI_ENDPROC
736END(stub_rt_sigreturn) 746END(stub_rt_sigreturn)
737 747
748#ifdef CONFIG_X86_X32_ABI
749 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
750
751ENTRY(stub_x32_rt_sigreturn)
752 CFI_STARTPROC
753 addq $8, %rsp
754 PARTIAL_FRAME 0
755 SAVE_REST
756 movq %rsp,%rdi
757 FIXUP_TOP_OF_STACK %r11
758 call sys32_x32_rt_sigreturn
759 movq %rax,RAX(%rsp) # fixme, this could be done at the higher layer
760 RESTORE_REST
761 jmp int_ret_from_sys_call
762 CFI_ENDPROC
763END(stub_x32_rt_sigreturn)
764
765ENTRY(stub_x32_execve)
766 CFI_STARTPROC
767 addq $8, %rsp
768 PARTIAL_FRAME 0
769 SAVE_REST
770 FIXUP_TOP_OF_STACK %r11
771 movq %rsp, %rcx
772 call sys32_execve
773 RESTORE_TOP_OF_STACK %r11
774 movq %rax,RAX(%rsp)
775 RESTORE_REST
776 jmp int_ret_from_sys_call
777 CFI_ENDPROC
778END(stub_x32_execve)
779
780#endif
781
738/* 782/*
739 * Build the entry stubs and pointer table with some assembler magic. 783 * Build the entry stubs and pointer table with some assembler magic.
740 * We pack 7 stubs into a single 32-byte chunk, which will fit in a 784 * We pack 7 stubs into a single 32-byte chunk, which will fit in a
diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
index 2b154da0b6d3..733ca39f367e 100644
--- a/arch/x86/kernel/process_64.c
+++ b/arch/x86/kernel/process_64.c
@@ -258,7 +258,9 @@ start_thread(struct pt_regs *regs, unsigned long new_ip, unsigned long new_sp)
258void start_thread_ia32(struct pt_regs *regs, u32 new_ip, u32 new_sp) 258void start_thread_ia32(struct pt_regs *regs, u32 new_ip, u32 new_sp)
259{ 259{
260 start_thread_common(regs, new_ip, new_sp, 260 start_thread_common(regs, new_ip, new_sp,
261 __USER32_CS, __USER32_DS, __USER32_DS); 261 test_thread_flag(TIF_X32)
262 ? __USER_CS : __USER32_CS,
263 __USER_DS, __USER_DS);
262} 264}
263#endif 265#endif
264 266
@@ -381,6 +383,8 @@ void set_personality_64bit(void)
381 383
382 /* Make sure to be in 64bit mode */ 384 /* Make sure to be in 64bit mode */
383 clear_thread_flag(TIF_IA32); 385 clear_thread_flag(TIF_IA32);
386 clear_thread_flag(TIF_ADDR32);
387 clear_thread_flag(TIF_X32);
384 388
385 /* Ensure the corresponding mm is not marked. */ 389 /* Ensure the corresponding mm is not marked. */
386 if (current->mm) 390 if (current->mm)
@@ -393,20 +397,31 @@ void set_personality_64bit(void)
393 current->personality &= ~READ_IMPLIES_EXEC; 397 current->personality &= ~READ_IMPLIES_EXEC;
394} 398}
395 399
396void set_personality_ia32(void) 400void set_personality_ia32(bool x32)
397{ 401{
398 /* inherit personality from parent */ 402 /* inherit personality from parent */
399 403
400 /* Make sure to be in 32bit mode */ 404 /* Make sure to be in 32bit mode */
401 set_thread_flag(TIF_IA32); 405 set_thread_flag(TIF_ADDR32);
402 current->personality |= force_personality32;
403 406
404 /* Mark the associated mm as containing 32-bit tasks. */ 407 /* Mark the associated mm as containing 32-bit tasks. */
405 if (current->mm) 408 if (current->mm)
406 current->mm->context.ia32_compat = 1; 409 current->mm->context.ia32_compat = 1;
407 410
408 /* Prepare the first "return" to user space */ 411 if (x32) {
409 current_thread_info()->status |= TS_COMPAT; 412 clear_thread_flag(TIF_IA32);
413 set_thread_flag(TIF_X32);
414 current->personality &= ~READ_IMPLIES_EXEC;
415 /* is_compat_task() uses the presence of the x32
416 syscall bit flag to determine compat status */
417 current_thread_info()->status &= ~TS_COMPAT;
418 } else {
419 set_thread_flag(TIF_IA32);
420 clear_thread_flag(TIF_X32);
421 current->personality |= force_personality32;
422 /* Prepare the first "return" to user space */
423 current_thread_info()->status |= TS_COMPAT;
424 }
410} 425}
411 426
412unsigned long get_wchan(struct task_struct *p) 427unsigned long get_wchan(struct task_struct *p)
diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
index 8a634c887652..284c35ae60e4 100644
--- a/arch/x86/kernel/ptrace.c
+++ b/arch/x86/kernel/ptrace.c
@@ -1130,6 +1130,100 @@ static int genregs32_set(struct task_struct *target,
1130 return ret; 1130 return ret;
1131} 1131}
1132 1132
1133#ifdef CONFIG_X86_X32_ABI
1134static long x32_arch_ptrace(struct task_struct *child,
1135 compat_long_t request, compat_ulong_t caddr,
1136 compat_ulong_t cdata)
1137{
1138 unsigned long addr = caddr;
1139 unsigned long data = cdata;
1140 void __user *datap = compat_ptr(data);
1141 int ret;
1142
1143 switch (request) {
1144 /* Read 32bits at location addr in the USER area. Only allow
1145 to return the lower 32bits of segment and debug registers. */
1146 case PTRACE_PEEKUSR: {
1147 u32 tmp;
1148
1149 ret = -EIO;
1150 if ((addr & (sizeof(data) - 1)) || addr >= sizeof(struct user) ||
1151 addr < offsetof(struct user_regs_struct, cs))
1152 break;
1153
1154 tmp = 0; /* Default return condition */
1155 if (addr < sizeof(struct user_regs_struct))
1156 tmp = getreg(child, addr);
1157 else if (addr >= offsetof(struct user, u_debugreg[0]) &&
1158 addr <= offsetof(struct user, u_debugreg[7])) {
1159 addr -= offsetof(struct user, u_debugreg[0]);
1160 tmp = ptrace_get_debugreg(child, addr / sizeof(data));
1161 }
1162 ret = put_user(tmp, (__u32 __user *)datap);
1163 break;
1164 }
1165
1166 /* Write the word at location addr in the USER area. Only allow
1167 to update segment and debug registers with the upper 32bits
1168 zero-extended. */
1169 case PTRACE_POKEUSR:
1170 ret = -EIO;
1171 if ((addr & (sizeof(data) - 1)) || addr >= sizeof(struct user) ||
1172 addr < offsetof(struct user_regs_struct, cs))
1173 break;
1174
1175 if (addr < sizeof(struct user_regs_struct))
1176 ret = putreg(child, addr, data);
1177 else if (addr >= offsetof(struct user, u_debugreg[0]) &&
1178 addr <= offsetof(struct user, u_debugreg[7])) {
1179 addr -= offsetof(struct user, u_debugreg[0]);
1180 ret = ptrace_set_debugreg(child,
1181 addr / sizeof(data), data);
1182 }
1183 break;
1184
1185 case PTRACE_GETREGS: /* Get all gp regs from the child. */
1186 return copy_regset_to_user(child,
1187 task_user_regset_view(current),
1188 REGSET_GENERAL,
1189 0, sizeof(struct user_regs_struct),
1190 datap);
1191
1192 case PTRACE_SETREGS: /* Set all gp regs in the child. */
1193 return copy_regset_from_user(child,
1194 task_user_regset_view(current),
1195 REGSET_GENERAL,
1196 0, sizeof(struct user_regs_struct),
1197 datap);
1198
1199 case PTRACE_GETFPREGS: /* Get the child FPU state. */
1200 return copy_regset_to_user(child,
1201 task_user_regset_view(current),
1202 REGSET_FP,
1203 0, sizeof(struct user_i387_struct),
1204 datap);
1205
1206 case PTRACE_SETFPREGS: /* Set the child FPU state. */
1207 return copy_regset_from_user(child,
1208 task_user_regset_view(current),
1209 REGSET_FP,
1210 0, sizeof(struct user_i387_struct),
1211 datap);
1212
1213 /* normal 64bit interface to access TLS data.
1214 Works just like arch_prctl, except that the arguments
1215 are reversed. */
1216 case PTRACE_ARCH_PRCTL:
1217 return do_arch_prctl(child, data, addr);
1218
1219 default:
1220 return compat_ptrace_request(child, request, addr, data);
1221 }
1222
1223 return ret;
1224}
1225#endif
1226
1133long compat_arch_ptrace(struct task_struct *child, compat_long_t request, 1227long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
1134 compat_ulong_t caddr, compat_ulong_t cdata) 1228 compat_ulong_t caddr, compat_ulong_t cdata)
1135{ 1229{
@@ -1139,6 +1233,11 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
1139 int ret; 1233 int ret;
1140 __u32 val; 1234 __u32 val;
1141 1235
1236#ifdef CONFIG_X86_X32_ABI
1237 if (!is_ia32_task())
1238 return x32_arch_ptrace(child, request, caddr, cdata);
1239#endif
1240
1142 switch (request) { 1241 switch (request) {
1143 case PTRACE_PEEKUSR: 1242 case PTRACE_PEEKUSR:
1144 ret = getreg32(child, addr, &val); 1243 ret = getreg32(child, addr, &val);
diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
index 25edcfc9ba5b..5134e17855f0 100644
--- a/arch/x86/kernel/signal.c
+++ b/arch/x86/kernel/signal.c
@@ -10,10 +10,8 @@
10#include <linux/mm.h> 10#include <linux/mm.h>
11#include <linux/smp.h> 11#include <linux/smp.h>
12#include <linux/kernel.h> 12#include <linux/kernel.h>
13#include <linux/signal.h>
14#include <linux/errno.h> 13#include <linux/errno.h>
15#include <linux/wait.h> 14#include <linux/wait.h>
16#include <linux/ptrace.h>
17#include <linux/tracehook.h> 15#include <linux/tracehook.h>
18#include <linux/unistd.h> 16#include <linux/unistd.h>
19#include <linux/stddef.h> 17#include <linux/stddef.h>
@@ -27,10 +25,12 @@
27#include <asm/fpu-internal.h> 25#include <asm/fpu-internal.h>
28#include <asm/vdso.h> 26#include <asm/vdso.h>
29#include <asm/mce.h> 27#include <asm/mce.h>
28#include <asm/sighandling.h>
30 29
31#ifdef CONFIG_X86_64 30#ifdef CONFIG_X86_64
32#include <asm/proto.h> 31#include <asm/proto.h>
33#include <asm/ia32_unistd.h> 32#include <asm/ia32_unistd.h>
33#include <asm/sys_ia32.h>
34#endif /* CONFIG_X86_64 */ 34#endif /* CONFIG_X86_64 */
35 35
36#include <asm/syscall.h> 36#include <asm/syscall.h>
@@ -38,13 +38,6 @@
38 38
39#include <asm/sigframe.h> 39#include <asm/sigframe.h>
40 40
41#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
42
43#define __FIX_EFLAGS (X86_EFLAGS_AC | X86_EFLAGS_OF | \
44 X86_EFLAGS_DF | X86_EFLAGS_TF | X86_EFLAGS_SF | \
45 X86_EFLAGS_ZF | X86_EFLAGS_AF | X86_EFLAGS_PF | \
46 X86_EFLAGS_CF)
47
48#ifdef CONFIG_X86_32 41#ifdef CONFIG_X86_32
49# define FIX_EFLAGS (__FIX_EFLAGS | X86_EFLAGS_RF) 42# define FIX_EFLAGS (__FIX_EFLAGS | X86_EFLAGS_RF)
50#else 43#else
@@ -69,9 +62,8 @@
69 regs->seg = GET_SEG(seg) | 3; \ 62 regs->seg = GET_SEG(seg) | 3; \
70} while (0) 63} while (0)
71 64
72static int 65int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc,
73restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc, 66 unsigned long *pax)
74 unsigned long *pax)
75{ 67{
76 void __user *buf; 68 void __user *buf;
77 unsigned int tmpflags; 69 unsigned int tmpflags;
@@ -126,9 +118,8 @@ restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc,
126 return err; 118 return err;
127} 119}
128 120
129static int 121int setup_sigcontext(struct sigcontext __user *sc, void __user *fpstate,
130setup_sigcontext(struct sigcontext __user *sc, void __user *fpstate, 122 struct pt_regs *regs, unsigned long mask)
131 struct pt_regs *regs, unsigned long mask)
132{ 123{
133 int err = 0; 124 int err = 0;
134 125
@@ -643,6 +634,16 @@ static int signr_convert(int sig)
643#define is_ia32 0 634#define is_ia32 0
644#endif /* CONFIG_IA32_EMULATION */ 635#endif /* CONFIG_IA32_EMULATION */
645 636
637#ifdef CONFIG_X86_X32_ABI
638#define is_x32 test_thread_flag(TIF_X32)
639
640static int x32_setup_rt_frame(int sig, struct k_sigaction *ka,
641 siginfo_t *info, compat_sigset_t *set,
642 struct pt_regs *regs);
643#else /* !CONFIG_X86_X32_ABI */
644#define is_x32 0
645#endif /* CONFIG_X86_X32_ABI */
646
646int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, 647int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
647 sigset_t *set, struct pt_regs *regs); 648 sigset_t *set, struct pt_regs *regs);
648int ia32_setup_frame(int sig, struct k_sigaction *ka, 649int ia32_setup_frame(int sig, struct k_sigaction *ka,
@@ -667,8 +668,14 @@ setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
667 ret = ia32_setup_rt_frame(usig, ka, info, set, regs); 668 ret = ia32_setup_rt_frame(usig, ka, info, set, regs);
668 else 669 else
669 ret = ia32_setup_frame(usig, ka, set, regs); 670 ret = ia32_setup_frame(usig, ka, set, regs);
670 } else 671#ifdef CONFIG_X86_X32_ABI
672 } else if (is_x32) {
673 ret = x32_setup_rt_frame(usig, ka, info,
674 (compat_sigset_t *)set, regs);
675#endif
676 } else {
671 ret = __setup_rt_frame(sig, ka, info, set, regs); 677 ret = __setup_rt_frame(sig, ka, info, set, regs);
678 }
672 679
673 if (ret) { 680 if (ret) {
674 force_sigsegv(sig, current); 681 force_sigsegv(sig, current);
@@ -851,3 +858,102 @@ void signal_fault(struct pt_regs *regs, void __user *frame, char *where)
851 858
852 force_sig(SIGSEGV, me); 859 force_sig(SIGSEGV, me);
853} 860}
861
862#ifdef CONFIG_X86_X32_ABI
863static int x32_setup_rt_frame(int sig, struct k_sigaction *ka,
864 siginfo_t *info, compat_sigset_t *set,
865 struct pt_regs *regs)
866{
867 struct rt_sigframe_x32 __user *frame;
868 void __user *restorer;
869 int err = 0;
870 void __user *fpstate = NULL;
871
872 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
873
874 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
875 return -EFAULT;
876
877 if (ka->sa.sa_flags & SA_SIGINFO) {
878 if (copy_siginfo_to_user32(&frame->info, info))
879 return -EFAULT;
880 }
881
882 put_user_try {
883 /* Create the ucontext. */
884 if (cpu_has_xsave)
885 put_user_ex(UC_FP_XSTATE, &frame->uc.uc_flags);
886 else
887 put_user_ex(0, &frame->uc.uc_flags);
888 put_user_ex(0, &frame->uc.uc_link);
889 put_user_ex(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
890 put_user_ex(sas_ss_flags(regs->sp),
891 &frame->uc.uc_stack.ss_flags);
892 put_user_ex(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
893 put_user_ex(0, &frame->uc.uc__pad0);
894 err |= setup_sigcontext(&frame->uc.uc_mcontext, fpstate,
895 regs, set->sig[0]);
896 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
897
898 if (ka->sa.sa_flags & SA_RESTORER) {
899 restorer = ka->sa.sa_restorer;
900 } else {
901 /* could use a vstub here */
902 restorer = NULL;
903 err |= -EFAULT;
904 }
905 put_user_ex(restorer, &frame->pretcode);
906 } put_user_catch(err);
907
908 if (err)
909 return -EFAULT;
910
911 /* Set up registers for signal handler */
912 regs->sp = (unsigned long) frame;
913 regs->ip = (unsigned long) ka->sa.sa_handler;
914
915 /* We use the x32 calling convention here... */
916 regs->di = sig;
917 regs->si = (unsigned long) &frame->info;
918 regs->dx = (unsigned long) &frame->uc;
919
920 loadsegment(ds, __USER_DS);
921 loadsegment(es, __USER_DS);
922
923 regs->cs = __USER_CS;
924 regs->ss = __USER_DS;
925
926 return 0;
927}
928
929asmlinkage long sys32_x32_rt_sigreturn(struct pt_regs *regs)
930{
931 struct rt_sigframe_x32 __user *frame;
932 sigset_t set;
933 unsigned long ax;
934 struct pt_regs tregs;
935
936 frame = (struct rt_sigframe_x32 __user *)(regs->sp - 8);
937
938 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
939 goto badframe;
940 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
941 goto badframe;
942
943 sigdelsetmask(&set, ~_BLOCKABLE);
944 set_current_blocked(&set);
945
946 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax))
947 goto badframe;
948
949 tregs = *regs;
950 if (sys32_sigaltstack(&frame->uc.uc_stack, NULL, &tregs) == -EFAULT)
951 goto badframe;
952
953 return ax;
954
955badframe:
956 signal_fault(regs, frame, "x32 rt_sigreturn");
957 return 0;
958}
959#endif
diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
index ef59642ff1bf..b4d3c3927dd8 100644
--- a/arch/x86/kernel/sys_x86_64.c
+++ b/arch/x86/kernel/sys_x86_64.c
@@ -98,7 +98,7 @@ out:
98static void find_start_end(unsigned long flags, unsigned long *begin, 98static void find_start_end(unsigned long flags, unsigned long *begin,
99 unsigned long *end) 99 unsigned long *end)
100{ 100{
101 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) { 101 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
102 unsigned long new_begin; 102 unsigned long new_begin;
103 /* This is usually used needed to map code in small 103 /* This is usually used needed to map code in small
104 model, so it needs to be in the first 31bit. Limit 104 model, so it needs to be in the first 31bit. Limit
@@ -144,7 +144,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
144 (!vma || addr + len <= vma->vm_start)) 144 (!vma || addr + len <= vma->vm_start))
145 return addr; 145 return addr;
146 } 146 }
147 if (((flags & MAP_32BIT) || test_thread_flag(TIF_IA32)) 147 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
148 && len <= mm->cached_hole_size) { 148 && len <= mm->cached_hole_size) {
149 mm->cached_hole_size = 0; 149 mm->cached_hole_size = 0;
150 mm->free_area_cache = begin; 150 mm->free_area_cache = begin;
@@ -205,7 +205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
205 return addr; 205 return addr;
206 206
207 /* for MAP_32BIT mappings we force the legact mmap base */ 207 /* for MAP_32BIT mappings we force the legact mmap base */
208 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) 208 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
209 goto bottomup; 209 goto bottomup;
210 210
211 /* requesting a specific address */ 211 /* requesting a specific address */
diff --git a/arch/x86/kernel/syscall_64.c b/arch/x86/kernel/syscall_64.c
index 7ac7943be02c..5c7f8c20da74 100644
--- a/arch/x86/kernel/syscall_64.c
+++ b/arch/x86/kernel/syscall_64.c
@@ -5,6 +5,14 @@
5#include <linux/cache.h> 5#include <linux/cache.h>
6#include <asm/asm-offsets.h> 6#include <asm/asm-offsets.h>
7 7
8#define __SYSCALL_COMMON(nr, sym, compat) __SYSCALL_64(nr, sym, compat)
9
10#ifdef CONFIG_X86_X32_ABI
11# define __SYSCALL_X32(nr, sym, compat) __SYSCALL_64(nr, sym, compat)
12#else
13# define __SYSCALL_X32(nr, sym, compat) /* nothing */
14#endif
15
8#define __SYSCALL_64(nr, sym, compat) extern asmlinkage void sym(void) ; 16#define __SYSCALL_64(nr, sym, compat) extern asmlinkage void sym(void) ;
9#include <asm/syscalls_64.h> 17#include <asm/syscalls_64.h>
10#undef __SYSCALL_64 18#undef __SYSCALL_64
diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
index bff89dfe3619..d6aa6e8315d1 100644
--- a/arch/x86/oprofile/backtrace.c
+++ b/arch/x86/oprofile/backtrace.c
@@ -67,7 +67,7 @@ x86_backtrace_32(struct pt_regs * const regs, unsigned int depth)
67{ 67{
68 struct stack_frame_ia32 *head; 68 struct stack_frame_ia32 *head;
69 69
70 /* User process is 32-bit */ 70 /* User process is IA32 */
71 if (!current || !test_thread_flag(TIF_IA32)) 71 if (!current || !test_thread_flag(TIF_IA32))
72 return 0; 72 return 0;
73 73
diff --git a/arch/x86/syscalls/Makefile b/arch/x86/syscalls/Makefile
index 564b2476fede..3236aebc828d 100644
--- a/arch/x86/syscalls/Makefile
+++ b/arch/x86/syscalls/Makefile
@@ -10,8 +10,10 @@ syshdr := $(srctree)/$(src)/syscallhdr.sh
10systbl := $(srctree)/$(src)/syscalltbl.sh 10systbl := $(srctree)/$(src)/syscalltbl.sh
11 11
12quiet_cmd_syshdr = SYSHDR $@ 12quiet_cmd_syshdr = SYSHDR $@
13 cmd_syshdr = $(CONFIG_SHELL) '$(syshdr)' $< $@ \ 13 cmd_syshdr = $(CONFIG_SHELL) '$(syshdr)' '$<' '$@' \
14 $(syshdr_abi_$(basetarget)) $(syshdr_pfx_$(basetarget)) 14 '$(syshdr_abi_$(basetarget))' \
15 '$(syshdr_pfx_$(basetarget))' \
16 '$(syshdr_offset_$(basetarget))'
15quiet_cmd_systbl = SYSTBL $@ 17quiet_cmd_systbl = SYSTBL $@
16 cmd_systbl = $(CONFIG_SHELL) '$(systbl)' $< $@ 18 cmd_systbl = $(CONFIG_SHELL) '$(systbl)' $< $@
17 19
@@ -24,18 +26,28 @@ syshdr_pfx_unistd_32_ia32 := ia32_
24$(out)/unistd_32_ia32.h: $(syscall32) $(syshdr) 26$(out)/unistd_32_ia32.h: $(syscall32) $(syshdr)
25 $(call if_changed,syshdr) 27 $(call if_changed,syshdr)
26 28
27syshdr_abi_unistd_64 := 64 29syshdr_abi_unistd_x32 := common,x32
30syshdr_offset_unistd_x32 := __X32_SYSCALL_BIT
31$(out)/unistd_x32.h: $(syscall64) $(syshdr)
32 $(call if_changed,syshdr)
33
34syshdr_abi_unistd_64 := common,64
28$(out)/unistd_64.h: $(syscall64) $(syshdr) 35$(out)/unistd_64.h: $(syscall64) $(syshdr)
29 $(call if_changed,syshdr) 36 $(call if_changed,syshdr)
30 37
38syshdr_abi_unistd_64_x32 := x32
39syshdr_pfx_unistd_64_x32 := x32_
40$(out)/unistd_64_x32.h: $(syscall64) $(syshdr)
41 $(call if_changed,syshdr)
42
31$(out)/syscalls_32.h: $(syscall32) $(systbl) 43$(out)/syscalls_32.h: $(syscall32) $(systbl)
32 $(call if_changed,systbl) 44 $(call if_changed,systbl)
33$(out)/syscalls_64.h: $(syscall64) $(systbl) 45$(out)/syscalls_64.h: $(syscall64) $(systbl)
34 $(call if_changed,systbl) 46 $(call if_changed,systbl)
35 47
36syshdr-y += unistd_32.h unistd_64.h 48syshdr-y += unistd_32.h unistd_64.h unistd_x32.h
37syshdr-y += syscalls_32.h 49syshdr-y += syscalls_32.h
38syshdr-$(CONFIG_X86_64) += unistd_32_ia32.h 50syshdr-$(CONFIG_X86_64) += unistd_32_ia32.h unistd_64_x32.h
39syshdr-$(CONFIG_X86_64) += syscalls_64.h 51syshdr-$(CONFIG_X86_64) += syscalls_64.h
40 52
41targets += $(syshdr-y) 53targets += $(syshdr-y)
diff --git a/arch/x86/syscalls/syscall_32.tbl b/arch/x86/syscalls/syscall_32.tbl
index e7e67cc3c14b..29f9f0554f7d 100644
--- a/arch/x86/syscalls/syscall_32.tbl
+++ b/arch/x86/syscalls/syscall_32.tbl
@@ -181,7 +181,7 @@
181172 i386 prctl sys_prctl 181172 i386 prctl sys_prctl
182173 i386 rt_sigreturn ptregs_rt_sigreturn stub32_rt_sigreturn 182173 i386 rt_sigreturn ptregs_rt_sigreturn stub32_rt_sigreturn
183174 i386 rt_sigaction sys_rt_sigaction sys32_rt_sigaction 183174 i386 rt_sigaction sys_rt_sigaction sys32_rt_sigaction
184175 i386 rt_sigprocmask sys_rt_sigprocmask sys32_rt_sigprocmask 184175 i386 rt_sigprocmask sys_rt_sigprocmask
185176 i386 rt_sigpending sys_rt_sigpending sys32_rt_sigpending 185176 i386 rt_sigpending sys_rt_sigpending sys32_rt_sigpending
186177 i386 rt_sigtimedwait sys_rt_sigtimedwait compat_sys_rt_sigtimedwait 186177 i386 rt_sigtimedwait sys_rt_sigtimedwait compat_sys_rt_sigtimedwait
187178 i386 rt_sigqueueinfo sys_rt_sigqueueinfo sys32_rt_sigqueueinfo 187178 i386 rt_sigqueueinfo sys_rt_sigqueueinfo sys32_rt_sigqueueinfo
diff --git a/arch/x86/syscalls/syscall_64.tbl b/arch/x86/syscalls/syscall_64.tbl
index b440a8f7eefa..dd29a9ea27c5 100644
--- a/arch/x86/syscalls/syscall_64.tbl
+++ b/arch/x86/syscalls/syscall_64.tbl
@@ -4,317 +4,350 @@
4# The format is: 4# The format is:
5# <number> <abi> <name> <entry point> 5# <number> <abi> <name> <entry point>
6# 6#
7# The abi is always "64" for this file (for now.) 7# The abi is "common", "64" or "x32" for this file.
8# 8#
90 64 read sys_read 90 common read sys_read
101 64 write sys_write 101 common write sys_write
112 64 open sys_open 112 common open sys_open
123 64 close sys_close 123 common close sys_close
134 64 stat sys_newstat 134 common stat sys_newstat
145 64 fstat sys_newfstat 145 common fstat sys_newfstat
156 64 lstat sys_newlstat 156 common lstat sys_newlstat
167 64 poll sys_poll 167 common poll sys_poll
178 64 lseek sys_lseek 178 common lseek sys_lseek
189 64 mmap sys_mmap 189 common mmap sys_mmap
1910 64 mprotect sys_mprotect 1910 common mprotect sys_mprotect
2011 64 munmap sys_munmap 2011 common munmap sys_munmap
2112 64 brk sys_brk 2112 common brk sys_brk
2213 64 rt_sigaction sys_rt_sigaction 2213 64 rt_sigaction sys_rt_sigaction
2314 64 rt_sigprocmask sys_rt_sigprocmask 2314 common rt_sigprocmask sys_rt_sigprocmask
2415 64 rt_sigreturn stub_rt_sigreturn 2415 64 rt_sigreturn stub_rt_sigreturn
2516 64 ioctl sys_ioctl 2516 64 ioctl sys_ioctl
2617 64 pread64 sys_pread64 2617 common pread64 sys_pread64
2718 64 pwrite64 sys_pwrite64 2718 common pwrite64 sys_pwrite64
2819 64 readv sys_readv 2819 64 readv sys_readv
2920 64 writev sys_writev 2920 64 writev sys_writev
3021 64 access sys_access 3021 common access sys_access
3122 64 pipe sys_pipe 3122 common pipe sys_pipe
3223 64 select sys_select 3223 common select sys_select
3324 64 sched_yield sys_sched_yield 3324 common sched_yield sys_sched_yield
3425 64 mremap sys_mremap 3425 common mremap sys_mremap
3526 64 msync sys_msync 3526 common msync sys_msync
3627 64 mincore sys_mincore 3627 common mincore sys_mincore
3728 64 madvise sys_madvise 3728 common madvise sys_madvise
3829 64 shmget sys_shmget 3829 common shmget sys_shmget
3930 64 shmat sys_shmat 3930 common shmat sys_shmat
4031 64 shmctl sys_shmctl 4031 common shmctl sys_shmctl
4132 64 dup sys_dup 4132 common dup sys_dup
4233 64 dup2 sys_dup2 4233 common dup2 sys_dup2
4334 64 pause sys_pause 4334 common pause sys_pause
4435 64 nanosleep sys_nanosleep 4435 common nanosleep sys_nanosleep
4536 64 getitimer sys_getitimer 4536 common getitimer sys_getitimer
4637 64 alarm sys_alarm 4637 common alarm sys_alarm
4738 64 setitimer sys_setitimer 4738 common setitimer sys_setitimer
4839 64 getpid sys_getpid 4839 common getpid sys_getpid
4940 64 sendfile sys_sendfile64 4940 common sendfile sys_sendfile64
5041 64 socket sys_socket 5041 common socket sys_socket
5142 64 connect sys_connect 5142 common connect sys_connect
5243 64 accept sys_accept 5243 common accept sys_accept
5344 64 sendto sys_sendto 5344 common sendto sys_sendto
5445 64 recvfrom sys_recvfrom 5445 64 recvfrom sys_recvfrom
5546 64 sendmsg sys_sendmsg 5546 64 sendmsg sys_sendmsg
5647 64 recvmsg sys_recvmsg 5647 64 recvmsg sys_recvmsg
5748 64 shutdown sys_shutdown 5748 common shutdown sys_shutdown
5849 64 bind sys_bind 5849 common bind sys_bind
5950 64 listen sys_listen 5950 common listen sys_listen
6051 64 getsockname sys_getsockname 6051 common getsockname sys_getsockname
6152 64 getpeername sys_getpeername 6152 common getpeername sys_getpeername
6253 64 socketpair sys_socketpair 6253 common socketpair sys_socketpair
6354 64 setsockopt sys_setsockopt 6354 common setsockopt sys_setsockopt
6455 64 getsockopt sys_getsockopt 6455 common getsockopt sys_getsockopt
6556 64 clone stub_clone 6556 common clone stub_clone
6657 64 fork stub_fork 6657 common fork stub_fork
6758 64 vfork stub_vfork 6758 common vfork stub_vfork
6859 64 execve stub_execve 6859 64 execve stub_execve
6960 64 exit sys_exit 6960 common exit sys_exit
7061 64 wait4 sys_wait4 7061 common wait4 sys_wait4
7162 64 kill sys_kill 7162 common kill sys_kill
7263 64 uname sys_newuname 7263 common uname sys_newuname
7364 64 semget sys_semget 7364 common semget sys_semget
7465 64 semop sys_semop 7465 common semop sys_semop
7566 64 semctl sys_semctl 7566 common semctl sys_semctl
7667 64 shmdt sys_shmdt 7667 common shmdt sys_shmdt
7768 64 msgget sys_msgget 7768 common msgget sys_msgget
7869 64 msgsnd sys_msgsnd 7869 common msgsnd sys_msgsnd
7970 64 msgrcv sys_msgrcv 7970 common msgrcv sys_msgrcv
8071 64 msgctl sys_msgctl 8071 common msgctl sys_msgctl
8172 64 fcntl sys_fcntl 8172 common fcntl sys_fcntl
8273 64 flock sys_flock 8273 common flock sys_flock
8374 64 fsync sys_fsync 8374 common fsync sys_fsync
8475 64 fdatasync sys_fdatasync 8475 common fdatasync sys_fdatasync
8576 64 truncate sys_truncate 8576 common truncate sys_truncate
8677 64 ftruncate sys_ftruncate 8677 common ftruncate sys_ftruncate
8778 64 getdents sys_getdents 8778 common getdents sys_getdents
8879 64 getcwd sys_getcwd 8879 common getcwd sys_getcwd
8980 64 chdir sys_chdir 8980 common chdir sys_chdir
9081 64 fchdir sys_fchdir 9081 common fchdir sys_fchdir
9182 64 rename sys_rename 9182 common rename sys_rename
9283 64 mkdir sys_mkdir 9283 common mkdir sys_mkdir
9384 64 rmdir sys_rmdir 9384 common rmdir sys_rmdir
9485 64 creat sys_creat 9485 common creat sys_creat
9586 64 link sys_link 9586 common link sys_link
9687 64 unlink sys_unlink 9687 common unlink sys_unlink
9788 64 symlink sys_symlink 9788 common symlink sys_symlink
9889 64 readlink sys_readlink 9889 common readlink sys_readlink
9990 64 chmod sys_chmod 9990 common chmod sys_chmod
10091 64 fchmod sys_fchmod 10091 common fchmod sys_fchmod
10192 64 chown sys_chown 10192 common chown sys_chown
10293 64 fchown sys_fchown 10293 common fchown sys_fchown
10394 64 lchown sys_lchown 10394 common lchown sys_lchown
10495 64 umask sys_umask 10495 common umask sys_umask
10596 64 gettimeofday sys_gettimeofday 10596 common gettimeofday sys_gettimeofday
10697 64 getrlimit sys_getrlimit 10697 common getrlimit sys_getrlimit
10798 64 getrusage sys_getrusage 10798 common getrusage sys_getrusage
10899 64 sysinfo sys_sysinfo 10899 common sysinfo sys_sysinfo
109100 64 times sys_times 109100 common times sys_times
110101 64 ptrace sys_ptrace 110101 64 ptrace sys_ptrace
111102 64 getuid sys_getuid 111102 common getuid sys_getuid
112103 64 syslog sys_syslog 112103 common syslog sys_syslog
113104 64 getgid sys_getgid 113104 common getgid sys_getgid
114105 64 setuid sys_setuid 114105 common setuid sys_setuid
115106 64 setgid sys_setgid 115106 common setgid sys_setgid
116107 64 geteuid sys_geteuid 116107 common geteuid sys_geteuid
117108 64 getegid sys_getegid 117108 common getegid sys_getegid
118109 64 setpgid sys_setpgid 118109 common setpgid sys_setpgid
119110 64 getppid sys_getppid 119110 common getppid sys_getppid
120111 64 getpgrp sys_getpgrp 120111 common getpgrp sys_getpgrp
121112 64 setsid sys_setsid 121112 common setsid sys_setsid
122113 64 setreuid sys_setreuid 122113 common setreuid sys_setreuid
123114 64 setregid sys_setregid 123114 common setregid sys_setregid
124115 64 getgroups sys_getgroups 124115 common getgroups sys_getgroups
125116 64 setgroups sys_setgroups 125116 common setgroups sys_setgroups
126117 64 setresuid sys_setresuid 126117 common setresuid sys_setresuid
127118 64 getresuid sys_getresuid 127118 common getresuid sys_getresuid
128119 64 setresgid sys_setresgid 128119 common setresgid sys_setresgid
129120 64 getresgid sys_getresgid 129120 common getresgid sys_getresgid
130121 64 getpgid sys_getpgid 130121 common getpgid sys_getpgid
131122 64 setfsuid sys_setfsuid 131122 common setfsuid sys_setfsuid
132123 64 setfsgid sys_setfsgid 132123 common setfsgid sys_setfsgid
133124 64 getsid sys_getsid 133124 common getsid sys_getsid
134125 64 capget sys_capget 134125 common capget sys_capget
135126 64 capset sys_capset 135126 common capset sys_capset
136127 64 rt_sigpending sys_rt_sigpending 136127 64 rt_sigpending sys_rt_sigpending
137128 64 rt_sigtimedwait sys_rt_sigtimedwait 137128 64 rt_sigtimedwait sys_rt_sigtimedwait
138129 64 rt_sigqueueinfo sys_rt_sigqueueinfo 138129 64 rt_sigqueueinfo sys_rt_sigqueueinfo
139130 64 rt_sigsuspend sys_rt_sigsuspend 139130 common rt_sigsuspend sys_rt_sigsuspend
140131 64 sigaltstack stub_sigaltstack 140131 64 sigaltstack stub_sigaltstack
141132 64 utime sys_utime 141132 common utime sys_utime
142133 64 mknod sys_mknod 142133 common mknod sys_mknod
143134 64 uselib 143134 64 uselib
144135 64 personality sys_personality 144135 common personality sys_personality
145136 64 ustat sys_ustat 145136 common ustat sys_ustat
146137 64 statfs sys_statfs 146137 common statfs sys_statfs
147138 64 fstatfs sys_fstatfs 147138 common fstatfs sys_fstatfs
148139 64 sysfs sys_sysfs 148139 common sysfs sys_sysfs
149140 64 getpriority sys_getpriority 149140 common getpriority sys_getpriority
150141 64 setpriority sys_setpriority 150141 common setpriority sys_setpriority
151142 64 sched_setparam sys_sched_setparam 151142 common sched_setparam sys_sched_setparam
152143 64 sched_getparam sys_sched_getparam 152143 common sched_getparam sys_sched_getparam
153144 64 sched_setscheduler sys_sched_setscheduler 153144 common sched_setscheduler sys_sched_setscheduler
154145 64 sched_getscheduler sys_sched_getscheduler 154145 common sched_getscheduler sys_sched_getscheduler
155146 64 sched_get_priority_max sys_sched_get_priority_max 155146 common sched_get_priority_max sys_sched_get_priority_max
156147 64 sched_get_priority_min sys_sched_get_priority_min 156147 common sched_get_priority_min sys_sched_get_priority_min
157148 64 sched_rr_get_interval sys_sched_rr_get_interval 157148 common sched_rr_get_interval sys_sched_rr_get_interval
158149 64 mlock sys_mlock 158149 common mlock sys_mlock
159150 64 munlock sys_munlock 159150 common munlock sys_munlock
160151 64 mlockall sys_mlockall 160151 common mlockall sys_mlockall
161152 64 munlockall sys_munlockall 161152 common munlockall sys_munlockall
162153 64 vhangup sys_vhangup 162153 common vhangup sys_vhangup
163154 64 modify_ldt sys_modify_ldt 163154 common modify_ldt sys_modify_ldt
164155 64 pivot_root sys_pivot_root 164155 common pivot_root sys_pivot_root
165156 64 _sysctl sys_sysctl 165156 64 _sysctl sys_sysctl
166157 64 prctl sys_prctl 166157 common prctl sys_prctl
167158 64 arch_prctl sys_arch_prctl 167158 common arch_prctl sys_arch_prctl
168159 64 adjtimex sys_adjtimex 168159 common adjtimex sys_adjtimex
169160 64 setrlimit sys_setrlimit 169160 common setrlimit sys_setrlimit
170161 64 chroot sys_chroot 170161 common chroot sys_chroot
171162 64 sync sys_sync 171162 common sync sys_sync
172163 64 acct sys_acct 172163 common acct sys_acct
173164 64 settimeofday sys_settimeofday 173164 common settimeofday sys_settimeofday
174165 64 mount sys_mount 174165 common mount sys_mount
175166 64 umount2 sys_umount 175166 common umount2 sys_umount
176167 64 swapon sys_swapon 176167 common swapon sys_swapon
177168 64 swapoff sys_swapoff 177168 common swapoff sys_swapoff
178169 64 reboot sys_reboot 178169 common reboot sys_reboot
179170 64 sethostname sys_sethostname 179170 common sethostname sys_sethostname
180171 64 setdomainname sys_setdomainname 180171 common setdomainname sys_setdomainname
181172 64 iopl stub_iopl 181172 common iopl stub_iopl
182173 64 ioperm sys_ioperm 182173 common ioperm sys_ioperm
183174 64 create_module 183174 64 create_module
184175 64 init_module sys_init_module 184175 common init_module sys_init_module
185176 64 delete_module sys_delete_module 185176 common delete_module sys_delete_module
186177 64 get_kernel_syms 186177 64 get_kernel_syms
187178 64 query_module 187178 64 query_module
188179 64 quotactl sys_quotactl 188179 common quotactl sys_quotactl
189180 64 nfsservctl 189180 64 nfsservctl
190181 64 getpmsg 190181 common getpmsg
191182 64 putpmsg 191182 common putpmsg
192183 64 afs_syscall 192183 common afs_syscall
193184 64 tuxcall 193184 common tuxcall
194185 64 security 194185 common security
195186 64 gettid sys_gettid 195186 common gettid sys_gettid
196187 64 readahead sys_readahead 196187 common readahead sys_readahead
197188 64 setxattr sys_setxattr 197188 common setxattr sys_setxattr
198189 64 lsetxattr sys_lsetxattr 198189 common lsetxattr sys_lsetxattr
199190 64 fsetxattr sys_fsetxattr 199190 common fsetxattr sys_fsetxattr
200191 64 getxattr sys_getxattr 200191 common getxattr sys_getxattr
201192 64 lgetxattr sys_lgetxattr 201192 common lgetxattr sys_lgetxattr
202193 64 fgetxattr sys_fgetxattr 202193 common fgetxattr sys_fgetxattr
203194 64 listxattr sys_listxattr 203194 common listxattr sys_listxattr
204195 64 llistxattr sys_llistxattr 204195 common llistxattr sys_llistxattr
205196 64 flistxattr sys_flistxattr 205196 common flistxattr sys_flistxattr
206197 64 removexattr sys_removexattr 206197 common removexattr sys_removexattr
207198 64 lremovexattr sys_lremovexattr 207198 common lremovexattr sys_lremovexattr
208199 64 fremovexattr sys_fremovexattr 208199 common fremovexattr sys_fremovexattr
209200 64 tkill sys_tkill 209200 common tkill sys_tkill
210201 64 time sys_time 210201 common time sys_time
211202 64 futex sys_futex 211202 common futex sys_futex
212203 64 sched_setaffinity sys_sched_setaffinity 212203 common sched_setaffinity sys_sched_setaffinity
213204 64 sched_getaffinity sys_sched_getaffinity 213204 common sched_getaffinity sys_sched_getaffinity
214205 64 set_thread_area 214205 64 set_thread_area
215206 64 io_setup sys_io_setup 215206 common io_setup sys_io_setup
216207 64 io_destroy sys_io_destroy 216207 common io_destroy sys_io_destroy
217208 64 io_getevents sys_io_getevents 217208 common io_getevents sys_io_getevents
218209 64 io_submit sys_io_submit 218209 common io_submit sys_io_submit
219210 64 io_cancel sys_io_cancel 219210 common io_cancel sys_io_cancel
220211 64 get_thread_area 220211 64 get_thread_area
221212 64 lookup_dcookie sys_lookup_dcookie 221212 common lookup_dcookie sys_lookup_dcookie
222213 64 epoll_create sys_epoll_create 222213 common epoll_create sys_epoll_create
223214 64 epoll_ctl_old 223214 64 epoll_ctl_old
224215 64 epoll_wait_old 224215 64 epoll_wait_old
225216 64 remap_file_pages sys_remap_file_pages 225216 common remap_file_pages sys_remap_file_pages
226217 64 getdents64 sys_getdents64 226217 common getdents64 sys_getdents64
227218 64 set_tid_address sys_set_tid_address 227218 common set_tid_address sys_set_tid_address
228219 64 restart_syscall sys_restart_syscall 228219 common restart_syscall sys_restart_syscall
229220 64 semtimedop sys_semtimedop 229220 common semtimedop sys_semtimedop
230221 64 fadvise64 sys_fadvise64 230221 common fadvise64 sys_fadvise64
231222 64 timer_create sys_timer_create 231222 64 timer_create sys_timer_create
232223 64 timer_settime sys_timer_settime 232223 common timer_settime sys_timer_settime
233224 64 timer_gettime sys_timer_gettime 233224 common timer_gettime sys_timer_gettime
234225 64 timer_getoverrun sys_timer_getoverrun 234225 common timer_getoverrun sys_timer_getoverrun
235226 64 timer_delete sys_timer_delete 235226 common timer_delete sys_timer_delete
236227 64 clock_settime sys_clock_settime 236227 common clock_settime sys_clock_settime
237228 64 clock_gettime sys_clock_gettime 237228 common clock_gettime sys_clock_gettime
238229 64 clock_getres sys_clock_getres 238229 common clock_getres sys_clock_getres
239230 64 clock_nanosleep sys_clock_nanosleep 239230 common clock_nanosleep sys_clock_nanosleep
240231 64 exit_group sys_exit_group 240231 common exit_group sys_exit_group
241232 64 epoll_wait sys_epoll_wait 241232 common epoll_wait sys_epoll_wait
242233 64 epoll_ctl sys_epoll_ctl 242233 common epoll_ctl sys_epoll_ctl
243234 64 tgkill sys_tgkill 243234 common tgkill sys_tgkill
244235 64 utimes sys_utimes 244235 common utimes sys_utimes
245236 64 vserver 245236 64 vserver
246237 64 mbind sys_mbind 246237 common mbind sys_mbind
247238 64 set_mempolicy sys_set_mempolicy 247238 common set_mempolicy sys_set_mempolicy
248239 64 get_mempolicy sys_get_mempolicy 248239 common get_mempolicy sys_get_mempolicy
249240 64 mq_open sys_mq_open 249240 common mq_open sys_mq_open
250241 64 mq_unlink sys_mq_unlink 250241 common mq_unlink sys_mq_unlink
251242 64 mq_timedsend sys_mq_timedsend 251242 common mq_timedsend sys_mq_timedsend
252243 64 mq_timedreceive sys_mq_timedreceive 252243 common mq_timedreceive sys_mq_timedreceive
253244 64 mq_notify sys_mq_notify 253244 64 mq_notify sys_mq_notify
254245 64 mq_getsetattr sys_mq_getsetattr 254245 common mq_getsetattr sys_mq_getsetattr
255246 64 kexec_load sys_kexec_load 255246 64 kexec_load sys_kexec_load
256247 64 waitid sys_waitid 256247 64 waitid sys_waitid
257248 64 add_key sys_add_key 257248 common add_key sys_add_key
258249 64 request_key sys_request_key 258249 common request_key sys_request_key
259250 64 keyctl sys_keyctl 259250 common keyctl sys_keyctl
260251 64 ioprio_set sys_ioprio_set 260251 common ioprio_set sys_ioprio_set
261252 64 ioprio_get sys_ioprio_get 261252 common ioprio_get sys_ioprio_get
262253 64 inotify_init sys_inotify_init 262253 common inotify_init sys_inotify_init
263254 64 inotify_add_watch sys_inotify_add_watch 263254 common inotify_add_watch sys_inotify_add_watch
264255 64 inotify_rm_watch sys_inotify_rm_watch 264255 common inotify_rm_watch sys_inotify_rm_watch
265256 64 migrate_pages sys_migrate_pages 265256 common migrate_pages sys_migrate_pages
266257 64 openat sys_openat 266257 common openat sys_openat
267258 64 mkdirat sys_mkdirat 267258 common mkdirat sys_mkdirat
268259 64 mknodat sys_mknodat 268259 common mknodat sys_mknodat
269260 64 fchownat sys_fchownat 269260 common fchownat sys_fchownat
270261 64 futimesat sys_futimesat 270261 common futimesat sys_futimesat
271262 64 newfstatat sys_newfstatat 271262 common newfstatat sys_newfstatat
272263 64 unlinkat sys_unlinkat 272263 common unlinkat sys_unlinkat
273264 64 renameat sys_renameat 273264 common renameat sys_renameat
274265 64 linkat sys_linkat 274265 common linkat sys_linkat
275266 64 symlinkat sys_symlinkat 275266 common symlinkat sys_symlinkat
276267 64 readlinkat sys_readlinkat 276267 common readlinkat sys_readlinkat
277268 64 fchmodat sys_fchmodat 277268 common fchmodat sys_fchmodat
278269 64 faccessat sys_faccessat 278269 common faccessat sys_faccessat
279270 64 pselect6 sys_pselect6 279270 common pselect6 sys_pselect6
280271 64 ppoll sys_ppoll 280271 common ppoll sys_ppoll
281272 64 unshare sys_unshare 281272 common unshare sys_unshare
282273 64 set_robust_list sys_set_robust_list 282273 64 set_robust_list sys_set_robust_list
283274 64 get_robust_list sys_get_robust_list 283274 64 get_robust_list sys_get_robust_list
284275 64 splice sys_splice 284275 common splice sys_splice
285276 64 tee sys_tee 285276 common tee sys_tee
286277 64 sync_file_range sys_sync_file_range 286277 common sync_file_range sys_sync_file_range
287278 64 vmsplice sys_vmsplice 287278 64 vmsplice sys_vmsplice
288279 64 move_pages sys_move_pages 288279 64 move_pages sys_move_pages
289280 64 utimensat sys_utimensat 289280 common utimensat sys_utimensat
290281 64 epoll_pwait sys_epoll_pwait 290281 common epoll_pwait sys_epoll_pwait
291282 64 signalfd sys_signalfd 291282 common signalfd sys_signalfd
292283 64 timerfd_create sys_timerfd_create 292283 common timerfd_create sys_timerfd_create
293284 64 eventfd sys_eventfd 293284 common eventfd sys_eventfd
294285 64 fallocate sys_fallocate 294285 common fallocate sys_fallocate
295286 64 timerfd_settime sys_timerfd_settime 295286 common timerfd_settime sys_timerfd_settime
296287 64 timerfd_gettime sys_timerfd_gettime 296287 common timerfd_gettime sys_timerfd_gettime
297288 64 accept4 sys_accept4 297288 common accept4 sys_accept4
298289 64 signalfd4 sys_signalfd4 298289 common signalfd4 sys_signalfd4
299290 64 eventfd2 sys_eventfd2 299290 common eventfd2 sys_eventfd2
300291 64 epoll_create1 sys_epoll_create1 300291 common epoll_create1 sys_epoll_create1
301292 64 dup3 sys_dup3 301292 common dup3 sys_dup3
302293 64 pipe2 sys_pipe2 302293 common pipe2 sys_pipe2
303294 64 inotify_init1 sys_inotify_init1 303294 common inotify_init1 sys_inotify_init1
304295 64 preadv sys_preadv 304295 64 preadv sys_preadv
305296 64 pwritev sys_pwritev 305296 64 pwritev sys_pwritev
306297 64 rt_tgsigqueueinfo sys_rt_tgsigqueueinfo 306297 64 rt_tgsigqueueinfo sys_rt_tgsigqueueinfo
307298 64 perf_event_open sys_perf_event_open 307298 common perf_event_open sys_perf_event_open
308299 64 recvmmsg sys_recvmmsg 308299 64 recvmmsg sys_recvmmsg
309300 64 fanotify_init sys_fanotify_init 309300 common fanotify_init sys_fanotify_init
310301 64 fanotify_mark sys_fanotify_mark 310301 common fanotify_mark sys_fanotify_mark
311302 64 prlimit64 sys_prlimit64 311302 common prlimit64 sys_prlimit64
312303 64 name_to_handle_at sys_name_to_handle_at 312303 common name_to_handle_at sys_name_to_handle_at
313304 64 open_by_handle_at sys_open_by_handle_at 313304 common open_by_handle_at sys_open_by_handle_at
314305 64 clock_adjtime sys_clock_adjtime 314305 common clock_adjtime sys_clock_adjtime
315306 64 syncfs sys_syncfs 315306 common syncfs sys_syncfs
316307 64 sendmmsg sys_sendmmsg 316307 64 sendmmsg sys_sendmmsg
317308 64 setns sys_setns 317308 common setns sys_setns
318309 64 getcpu sys_getcpu 318309 common getcpu sys_getcpu
319310 64 process_vm_readv sys_process_vm_readv 319310 64 process_vm_readv sys_process_vm_readv
320311 64 process_vm_writev sys_process_vm_writev 320311 64 process_vm_writev sys_process_vm_writev
321#
322# x32-specific system call numbers start at 512 to avoid cache impact
323# for native 64-bit operation.
324#
325512 x32 rt_sigaction sys32_rt_sigaction
326513 x32 rt_sigreturn stub_x32_rt_sigreturn
327514 x32 ioctl compat_sys_ioctl
328515 x32 readv compat_sys_readv
329516 x32 writev compat_sys_writev
330517 x32 recvfrom compat_sys_recvfrom
331518 x32 sendmsg compat_sys_sendmsg
332519 x32 recvmsg compat_sys_recvmsg
333520 x32 execve stub_x32_execve
334521 x32 ptrace compat_sys_ptrace
335522 x32 rt_sigpending sys32_rt_sigpending
336523 x32 rt_sigtimedwait compat_sys_rt_sigtimedwait
337524 x32 rt_sigqueueinfo sys32_rt_sigqueueinfo
338525 x32 sigaltstack stub_x32_sigaltstack
339526 x32 timer_create compat_sys_timer_create
340527 x32 mq_notify compat_sys_mq_notify
341528 x32 kexec_load compat_sys_kexec_load
342529 x32 waitid compat_sys_waitid
343530 x32 set_robust_list compat_sys_set_robust_list
344531 x32 get_robust_list compat_sys_get_robust_list
345532 x32 vmsplice compat_sys_vmsplice
346533 x32 move_pages compat_sys_move_pages
347534 x32 preadv compat_sys_preadv64
348535 x32 pwritev compat_sys_pwritev64
349536 x32 rt_tgsigqueueinfo compat_sys_rt_tgsigqueueinfo
350537 x32 recvmmsg compat_sys_recvmmsg
351538 x32 sendmmsg compat_sys_sendmmsg
352539 x32 process_vm_readv compat_sys_process_vm_readv
353540 x32 process_vm_writev compat_sys_process_vm_writev
diff --git a/arch/x86/um/sys_call_table_64.c b/arch/x86/um/sys_call_table_64.c
index fe626c3ba01b..9924776f4265 100644
--- a/arch/x86/um/sys_call_table_64.c
+++ b/arch/x86/um/sys_call_table_64.c
@@ -35,6 +35,9 @@
35#define stub_sigaltstack sys_sigaltstack 35#define stub_sigaltstack sys_sigaltstack
36#define stub_rt_sigreturn sys_rt_sigreturn 36#define stub_rt_sigreturn sys_rt_sigreturn
37 37
38#define __SYSCALL_COMMON(nr, sym, compat) __SYSCALL_64(nr, sym, compat)
39#define __SYSCALL_X32(nr, sym, compat) /* Not supported */
40
38#define __SYSCALL_64(nr, sym, compat) extern asmlinkage void sym(void) ; 41#define __SYSCALL_64(nr, sym, compat) extern asmlinkage void sym(void) ;
39#include <asm/syscalls_64.h> 42#include <asm/syscalls_64.h>
40 43
diff --git a/arch/x86/um/user-offsets.c b/arch/x86/um/user-offsets.c
index 5edf4f4bbf53..ce7e3607a870 100644
--- a/arch/x86/um/user-offsets.c
+++ b/arch/x86/um/user-offsets.c
@@ -15,6 +15,8 @@ static char syscalls[] = {
15}; 15};
16#else 16#else
17#define __SYSCALL_64(nr, sym, compat) [nr] = 1, 17#define __SYSCALL_64(nr, sym, compat) [nr] = 1,
18#define __SYSCALL_COMMON(nr, sym, compat) [nr] = 1,
19#define __SYSCALL_X32(nr, sym, compat) /* Not supported */
18static char syscalls[] = { 20static char syscalls[] = {
19#include <asm/syscalls_64.h> 21#include <asm/syscalls_64.h>
20}; 22};
diff --git a/arch/x86/vdso/.gitignore b/arch/x86/vdso/.gitignore
index 60274d5746e1..3282874bc61d 100644
--- a/arch/x86/vdso/.gitignore
+++ b/arch/x86/vdso/.gitignore
@@ -1,5 +1,7 @@
1vdso.lds 1vdso.lds
2vdso-syms.lds 2vdso-syms.lds
3vdsox32.lds
4vdsox32-syms.lds
3vdso32-syms.lds 5vdso32-syms.lds
4vdso32-syscall-syms.lds 6vdso32-syscall-syms.lds
5vdso32-sysenter-syms.lds 7vdso32-sysenter-syms.lds
diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
index 5d179502a52c..fd14be1d1472 100644
--- a/arch/x86/vdso/Makefile
+++ b/arch/x86/vdso/Makefile
@@ -3,21 +3,29 @@
3# 3#
4 4
5VDSO64-$(CONFIG_X86_64) := y 5VDSO64-$(CONFIG_X86_64) := y
6VDSOX32-$(CONFIG_X86_X32_ABI) := y
6VDSO32-$(CONFIG_X86_32) := y 7VDSO32-$(CONFIG_X86_32) := y
7VDSO32-$(CONFIG_COMPAT) := y 8VDSO32-$(CONFIG_COMPAT) := y
8 9
9vdso-install-$(VDSO64-y) += vdso.so 10vdso-install-$(VDSO64-y) += vdso.so
11vdso-install-$(VDSOX32-y) += vdsox32.so
10vdso-install-$(VDSO32-y) += $(vdso32-images) 12vdso-install-$(VDSO32-y) += $(vdso32-images)
11 13
12 14
13# files to link into the vdso 15# files to link into the vdso
14vobjs-y := vdso-note.o vclock_gettime.o vgetcpu.o 16vobjs-y := vdso-note.o vclock_gettime.o vgetcpu.o
15 17
18vobjs-$(VDSOX32-y) += $(vobjx32s-compat)
19
20# Filter out x32 objects.
21vobj64s := $(filter-out $(vobjx32s-compat),$(vobjs-y))
22
16# files to link into kernel 23# files to link into kernel
17obj-$(VDSO64-y) += vma.o vdso.o 24obj-$(VDSO64-y) += vma.o vdso.o
25obj-$(VDSOX32-y) += vdsox32.o
18obj-$(VDSO32-y) += vdso32.o vdso32-setup.o 26obj-$(VDSO32-y) += vdso32.o vdso32-setup.o
19 27
20vobjs := $(foreach F,$(vobjs-y),$(obj)/$F) 28vobjs := $(foreach F,$(vobj64s),$(obj)/$F)
21 29
22$(obj)/vdso.o: $(obj)/vdso.so 30$(obj)/vdso.o: $(obj)/vdso.so
23 31
@@ -73,6 +81,42 @@ $(obj)/%-syms.lds: $(obj)/%.so.dbg FORCE
73 $(call if_changed,vdsosym) 81 $(call if_changed,vdsosym)
74 82
75# 83#
84# X32 processes use x32 vDSO to access 64bit kernel data.
85#
86# Build x32 vDSO image:
87# 1. Compile x32 vDSO as 64bit.
88# 2. Convert object files to x32.
89# 3. Build x32 VDSO image with x32 objects, which contains 64bit codes
90# so that it can reach 64bit address space with 64bit pointers.
91#
92
93targets += vdsox32-syms.lds
94obj-$(VDSOX32-y) += vdsox32-syms.lds
95
96CPPFLAGS_vdsox32.lds = $(CPPFLAGS_vdso.lds)
97VDSO_LDFLAGS_vdsox32.lds = -Wl,-m,elf32_x86_64 \
98 -Wl,-soname=linux-vdso.so.1 \
99 -Wl,-z,max-page-size=4096 \
100 -Wl,-z,common-page-size=4096
101
102vobjx32s-y := $(vobj64s:.o=-x32.o)
103vobjx32s := $(foreach F,$(vobjx32s-y),$(obj)/$F)
104
105# Convert 64bit object file to x32 for x32 vDSO.
106quiet_cmd_x32 = X32 $@
107 cmd_x32 = $(OBJCOPY) -O elf32-x86-64 $< $@
108
109$(obj)/%-x32.o: $(obj)/%.o FORCE
110 $(call if_changed,x32)
111
112targets += vdsox32.so vdsox32.so.dbg vdsox32.lds $(vobjx32s-y)
113
114$(obj)/vdsox32.o: $(src)/vdsox32.S $(obj)/vdsox32.so
115
116$(obj)/vdsox32.so.dbg: $(src)/vdsox32.lds $(vobjx32s) FORCE
117 $(call if_changed,vdso)
118
119#
76# Build multiple 32-bit vDSO images to choose from at boot time. 120# Build multiple 32-bit vDSO images to choose from at boot time.
77# 121#
78obj-$(VDSO32-y) += vdso32-syms.lds 122obj-$(VDSO32-y) += vdso32-syms.lds
diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
index a944020fa859..66e6d9359826 100644
--- a/arch/x86/vdso/vdso32-setup.c
+++ b/arch/x86/vdso/vdso32-setup.c
@@ -311,6 +311,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
311 int ret = 0; 311 int ret = 0;
312 bool compat; 312 bool compat;
313 313
314#ifdef CONFIG_X86_X32_ABI
315 if (test_thread_flag(TIF_X32))
316 return x32_setup_additional_pages(bprm, uses_interp);
317#endif
318
314 if (vdso_enabled == VDSO_DISABLED) 319 if (vdso_enabled == VDSO_DISABLED)
315 return 0; 320 return 0;
316 321
diff --git a/arch/x86/vdso/vdsox32.S b/arch/x86/vdso/vdsox32.S
new file mode 100644
index 000000000000..d6b9a7f42a8a
--- /dev/null
+++ b/arch/x86/vdso/vdsox32.S
@@ -0,0 +1,22 @@
1#include <asm/page_types.h>
2#include <linux/linkage.h>
3#include <linux/init.h>
4
5__PAGE_ALIGNED_DATA
6
7 .globl vdsox32_start, vdsox32_end
8 .align PAGE_SIZE
9vdsox32_start:
10 .incbin "arch/x86/vdso/vdsox32.so"
11vdsox32_end:
12 .align PAGE_SIZE /* extra data here leaks to userspace. */
13
14.previous
15
16 .globl vdsox32_pages
17 .bss
18 .align 8
19 .type vdsox32_pages, @object
20vdsox32_pages:
21 .zero (vdsox32_end - vdsox32_start + PAGE_SIZE - 1) / PAGE_SIZE * 8
22 .size vdsox32_pages, .-vdsox32_pages
diff --git a/arch/x86/vdso/vdsox32.lds.S b/arch/x86/vdso/vdsox32.lds.S
new file mode 100644
index 000000000000..62272aa2ae0a
--- /dev/null
+++ b/arch/x86/vdso/vdsox32.lds.S
@@ -0,0 +1,28 @@
1/*
2 * Linker script for x32 vDSO.
3 * We #include the file to define the layout details.
4 * Here we only choose the prelinked virtual address.
5 *
6 * This file defines the version script giving the user-exported symbols in
7 * the DSO. We can define local symbols here called VDSO* to make their
8 * values visible using the asm-x86/vdso.h macros from the kernel proper.
9 */
10
11#define VDSO_PRELINK 0
12#include "vdso-layout.lds.S"
13
14/*
15 * This controls what userland symbols we export from the vDSO.
16 */
17VERSION {
18 LINUX_2.6 {
19 global:
20 __vdso_clock_gettime;
21 __vdso_gettimeofday;
22 __vdso_getcpu;
23 __vdso_time;
24 local: *;
25 };
26}
27
28VDSOX32_PRELINK = VDSO_PRELINK;
diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
index 17e18279649f..00aaf047b39f 100644
--- a/arch/x86/vdso/vma.c
+++ b/arch/x86/vdso/vma.c
@@ -24,7 +24,44 @@ extern unsigned short vdso_sync_cpuid;
24extern struct page *vdso_pages[]; 24extern struct page *vdso_pages[];
25static unsigned vdso_size; 25static unsigned vdso_size;
26 26
27static void __init patch_vdso(void *vdso, size_t len) 27#ifdef CONFIG_X86_X32_ABI
28extern char vdsox32_start[], vdsox32_end[];
29extern struct page *vdsox32_pages[];
30static unsigned vdsox32_size;
31
32static void __init patch_vdsox32(void *vdso, size_t len)
33{
34 Elf32_Ehdr *hdr = vdso;
35 Elf32_Shdr *sechdrs, *alt_sec = 0;
36 char *secstrings;
37 void *alt_data;
38 int i;
39
40 BUG_ON(len < sizeof(Elf32_Ehdr));
41 BUG_ON(memcmp(hdr->e_ident, ELFMAG, SELFMAG) != 0);
42
43 sechdrs = (void *)hdr + hdr->e_shoff;
44 secstrings = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
45
46 for (i = 1; i < hdr->e_shnum; i++) {
47 Elf32_Shdr *shdr = &sechdrs[i];
48 if (!strcmp(secstrings + shdr->sh_name, ".altinstructions")) {
49 alt_sec = shdr;
50 goto found;
51 }
52 }
53
54 /* If we get here, it's probably a bug. */
55 pr_warning("patch_vdsox32: .altinstructions not found\n");
56 return; /* nothing to patch */
57
58found:
59 alt_data = (void *)hdr + alt_sec->sh_offset;
60 apply_alternatives(alt_data, alt_data + alt_sec->sh_size);
61}
62#endif
63
64static void __init patch_vdso64(void *vdso, size_t len)
28{ 65{
29 Elf64_Ehdr *hdr = vdso; 66 Elf64_Ehdr *hdr = vdso;
30 Elf64_Shdr *sechdrs, *alt_sec = 0; 67 Elf64_Shdr *sechdrs, *alt_sec = 0;
@@ -47,7 +84,7 @@ static void __init patch_vdso(void *vdso, size_t len)
47 } 84 }
48 85
49 /* If we get here, it's probably a bug. */ 86 /* If we get here, it's probably a bug. */
50 pr_warning("patch_vdso: .altinstructions not found\n"); 87 pr_warning("patch_vdso64: .altinstructions not found\n");
51 return; /* nothing to patch */ 88 return; /* nothing to patch */
52 89
53found: 90found:
@@ -60,12 +97,20 @@ static int __init init_vdso(void)
60 int npages = (vdso_end - vdso_start + PAGE_SIZE - 1) / PAGE_SIZE; 97 int npages = (vdso_end - vdso_start + PAGE_SIZE - 1) / PAGE_SIZE;
61 int i; 98 int i;
62 99
63 patch_vdso(vdso_start, vdso_end - vdso_start); 100 patch_vdso64(vdso_start, vdso_end - vdso_start);
64 101
65 vdso_size = npages << PAGE_SHIFT; 102 vdso_size = npages << PAGE_SHIFT;
66 for (i = 0; i < npages; i++) 103 for (i = 0; i < npages; i++)
67 vdso_pages[i] = virt_to_page(vdso_start + i*PAGE_SIZE); 104 vdso_pages[i] = virt_to_page(vdso_start + i*PAGE_SIZE);
68 105
106#ifdef CONFIG_X86_X32_ABI
107 patch_vdsox32(vdsox32_start, vdsox32_end - vdsox32_start);
108 npages = (vdsox32_end - vdsox32_start + PAGE_SIZE - 1) / PAGE_SIZE;
109 vdsox32_size = npages << PAGE_SHIFT;
110 for (i = 0; i < npages; i++)
111 vdsox32_pages[i] = virt_to_page(vdsox32_start + i*PAGE_SIZE);
112#endif
113
69 return 0; 114 return 0;
70} 115}
71subsys_initcall(init_vdso); 116subsys_initcall(init_vdso);
@@ -103,7 +148,10 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
103 148
104/* Setup a VMA at program startup for the vsyscall page. 149/* Setup a VMA at program startup for the vsyscall page.
105 Not called for compat tasks */ 150 Not called for compat tasks */
106int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) 151static int setup_additional_pages(struct linux_binprm *bprm,
152 int uses_interp,
153 struct page **pages,
154 unsigned size)
107{ 155{
108 struct mm_struct *mm = current->mm; 156 struct mm_struct *mm = current->mm;
109 unsigned long addr; 157 unsigned long addr;
@@ -113,8 +161,8 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
113 return 0; 161 return 0;
114 162
115 down_write(&mm->mmap_sem); 163 down_write(&mm->mmap_sem);
116 addr = vdso_addr(mm->start_stack, vdso_size); 164 addr = vdso_addr(mm->start_stack, size);
117 addr = get_unmapped_area(NULL, addr, vdso_size, 0, 0); 165 addr = get_unmapped_area(NULL, addr, size, 0, 0);
118 if (IS_ERR_VALUE(addr)) { 166 if (IS_ERR_VALUE(addr)) {
119 ret = addr; 167 ret = addr;
120 goto up_fail; 168 goto up_fail;
@@ -122,10 +170,10 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
122 170
123 current->mm->context.vdso = (void *)addr; 171 current->mm->context.vdso = (void *)addr;
124 172
125 ret = install_special_mapping(mm, addr, vdso_size, 173 ret = install_special_mapping(mm, addr, size,
126 VM_READ|VM_EXEC| 174 VM_READ|VM_EXEC|
127 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC, 175 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
128 vdso_pages); 176 pages);
129 if (ret) { 177 if (ret) {
130 current->mm->context.vdso = NULL; 178 current->mm->context.vdso = NULL;
131 goto up_fail; 179 goto up_fail;
@@ -136,6 +184,20 @@ up_fail:
136 return ret; 184 return ret;
137} 185}
138 186
187int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
188{
189 return setup_additional_pages(bprm, uses_interp, vdso_pages,
190 vdso_size);
191}
192
193#ifdef CONFIG_X86_X32_ABI
194int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
195{
196 return setup_additional_pages(bprm, uses_interp, vdsox32_pages,
197 vdsox32_size);
198}
199#endif
200
139static __init int vdso_setup(char *s) 201static __init int vdso_setup(char *s)
140{ 202{
141 vdso_enabled = simple_strtoul(s, NULL, 0); 203 vdso_enabled = simple_strtoul(s, NULL, 0);
diff --git a/arch/xtensa/include/asm/posix_types.h b/arch/xtensa/include/asm/posix_types.h
index 6b2190c35882..6e96be0d02d3 100644
--- a/arch/xtensa/include/asm/posix_types.h
+++ b/arch/xtensa/include/asm/posix_types.h
@@ -19,104 +19,21 @@
19 * assume GCC is being used. 19 * assume GCC is being used.
20 */ 20 */
21 21
22typedef unsigned long __kernel_ino_t;
23typedef unsigned int __kernel_mode_t;
24typedef unsigned long __kernel_nlink_t;
25typedef long __kernel_off_t;
26typedef int __kernel_pid_t;
27typedef unsigned short __kernel_ipc_pid_t; 22typedef unsigned short __kernel_ipc_pid_t;
28typedef unsigned int __kernel_uid_t; 23#define __kernel_ipc_pid_t __kernel_ipc_pid_t
29typedef unsigned int __kernel_gid_t; 24
30typedef unsigned int __kernel_size_t; 25typedef unsigned int __kernel_size_t;
31typedef int __kernel_ssize_t; 26typedef int __kernel_ssize_t;
32typedef long __kernel_ptrdiff_t; 27typedef long __kernel_ptrdiff_t;
33typedef long __kernel_time_t; 28#define __kernel_size_t __kernel_size_t
34typedef long __kernel_suseconds_t;
35typedef long __kernel_clock_t;
36typedef int __kernel_timer_t;
37typedef int __kernel_clockid_t;
38typedef int __kernel_daddr_t;
39typedef char * __kernel_caddr_t;
40typedef unsigned short __kernel_uid16_t;
41typedef unsigned short __kernel_gid16_t;
42typedef unsigned int __kernel_uid32_t;
43typedef unsigned int __kernel_gid32_t;
44 29
45typedef unsigned short __kernel_old_uid_t; 30typedef unsigned short __kernel_old_uid_t;
46typedef unsigned short __kernel_old_gid_t; 31typedef unsigned short __kernel_old_gid_t;
47typedef unsigned short __kernel_old_dev_t; 32#define __kernel_old_uid_t __kernel_old_uid_t
48
49#ifdef __GNUC__
50typedef long long __kernel_loff_t;
51#endif
52
53typedef struct {
54 int val[2];
55} __kernel_fsid_t;
56
57#ifndef __GNUC__
58
59#define __FD_SET(d, set) ((set)->fds_bits[__FDELT(d)] |= __FDMASK(d))
60#define __FD_CLR(d, set) ((set)->fds_bits[__FDELT(d)] &= ~__FDMASK(d))
61#define __FD_ISSET(d, set) (!!((set)->fds_bits[__FDELT(d)] & __FDMASK(d)))
62#define __FD_ZERO(set) \
63 ((void) memset ((void *) (set), 0, sizeof (__kernel_fd_set)))
64
65#else /* __GNUC__ */
66 33
67#if defined(__KERNEL__) 34typedef unsigned short __kernel_old_dev_t;
68/* With GNU C, use inline functions instead so args are evaluated only once: */ 35#define __kernel_old_dev_t __kernel_old_dev_t
69
70#undef __FD_SET
71static __inline__ void __FD_SET(unsigned long fd, __kernel_fd_set *fdsetp)
72{
73 unsigned long _tmp = fd / __NFDBITS;
74 unsigned long _rem = fd % __NFDBITS;
75 fdsetp->fds_bits[_tmp] |= (1UL<<_rem);
76}
77
78#undef __FD_CLR
79static __inline__ void __FD_CLR(unsigned long fd, __kernel_fd_set *fdsetp)
80{
81 unsigned long _tmp = fd / __NFDBITS;
82 unsigned long _rem = fd % __NFDBITS;
83 fdsetp->fds_bits[_tmp] &= ~(1UL<<_rem);
84}
85
86#undef __FD_ISSET
87static __inline__ int __FD_ISSET(unsigned long fd, __kernel_fd_set *p)
88{
89 unsigned long _tmp = fd / __NFDBITS;
90 unsigned long _rem = fd % __NFDBITS;
91 return (p->fds_bits[_tmp] & (1UL<<_rem)) != 0;
92}
93
94/*
95 * This will unroll the loop for the normal constant case (8 ints,
96 * for a 256-bit fd_set)
97 */
98#undef __FD_ZERO
99static __inline__ void __FD_ZERO(__kernel_fd_set *p)
100{
101 unsigned int *tmp = (unsigned int *)p->fds_bits;
102 int i;
103 36
104 if (__builtin_constant_p(__FDSET_LONGS)) { 37#include <asm-generic/posix_types.h>
105 switch (__FDSET_LONGS) {
106 case 8:
107 tmp[0] = 0; tmp[1] = 0; tmp[2] = 0; tmp[3] = 0;
108 tmp[4] = 0; tmp[5] = 0; tmp[6] = 0; tmp[7] = 0;
109 return;
110 }
111 }
112 i = __FDSET_LONGS;
113 while (i) {
114 i--;
115 *tmp = 0;
116 tmp++;
117 }
118}
119 38
120#endif /* defined(__KERNEL__) */
121#endif /* __GNUC__ */
122#endif /* _XTENSA_POSIX_TYPES_H */ 39#endif /* _XTENSA_POSIX_TYPES_H */
diff --git a/drivers/char/lp.c b/drivers/char/lp.c
index 0fbf1a776b52..a741e418b456 100644
--- a/drivers/char/lp.c
+++ b/drivers/char/lp.c
@@ -705,16 +705,13 @@ static long lp_compat_ioctl(struct file *file, unsigned int cmd,
705{ 705{
706 unsigned int minor; 706 unsigned int minor;
707 struct timeval par_timeout; 707 struct timeval par_timeout;
708 struct compat_timeval __user *tc;
709 int ret; 708 int ret;
710 709
711 minor = iminor(file->f_path.dentry->d_inode); 710 minor = iminor(file->f_path.dentry->d_inode);
712 mutex_lock(&lp_mutex); 711 mutex_lock(&lp_mutex);
713 switch (cmd) { 712 switch (cmd) {
714 case LPSETTIMEOUT: 713 case LPSETTIMEOUT:
715 tc = compat_ptr(arg); 714 if (compat_get_timeval(&par_timeout, compat_ptr(arg))) {
716 if (get_user(par_timeout.tv_sec, &tc->tv_sec) ||
717 get_user(par_timeout.tv_usec, &tc->tv_usec)) {
718 ret = -EFAULT; 715 ret = -EFAULT;
719 break; 716 break;
720 } 717 }
diff --git a/drivers/input/input-compat.c b/drivers/input/input-compat.c
index e46a86776a6b..64ca7113ff28 100644
--- a/drivers/input/input-compat.c
+++ b/drivers/input/input-compat.c
@@ -17,7 +17,7 @@
17int input_event_from_user(const char __user *buffer, 17int input_event_from_user(const char __user *buffer,
18 struct input_event *event) 18 struct input_event *event)
19{ 19{
20 if (INPUT_COMPAT_TEST) { 20 if (INPUT_COMPAT_TEST && !COMPAT_USE_64BIT_TIME) {
21 struct input_event_compat compat_event; 21 struct input_event_compat compat_event;
22 22
23 if (copy_from_user(&compat_event, buffer, 23 if (copy_from_user(&compat_event, buffer,
@@ -41,7 +41,7 @@ int input_event_from_user(const char __user *buffer,
41int input_event_to_user(char __user *buffer, 41int input_event_to_user(char __user *buffer,
42 const struct input_event *event) 42 const struct input_event *event)
43{ 43{
44 if (INPUT_COMPAT_TEST) { 44 if (INPUT_COMPAT_TEST && !COMPAT_USE_64BIT_TIME) {
45 struct input_event_compat compat_event; 45 struct input_event_compat compat_event;
46 46
47 compat_event.time.tv_sec = event->time.tv_sec; 47 compat_event.time.tv_sec = event->time.tv_sec;
diff --git a/drivers/input/input-compat.h b/drivers/input/input-compat.h
index 22be27b424de..148f66fe3205 100644
--- a/drivers/input/input-compat.h
+++ b/drivers/input/input-compat.h
@@ -67,7 +67,7 @@ struct ff_effect_compat {
67 67
68static inline size_t input_event_size(void) 68static inline size_t input_event_size(void)
69{ 69{
70 return INPUT_COMPAT_TEST ? 70 return (INPUT_COMPAT_TEST && !COMPAT_USE_64BIT_TIME) ?
71 sizeof(struct input_event_compat) : sizeof(struct input_event); 71 sizeof(struct input_event_compat) : sizeof(struct input_event);
72} 72}
73 73
diff --git a/drivers/staging/android/binder.c b/drivers/staging/android/binder.c
index 59e095362c81..c2832124bb3e 100644
--- a/drivers/staging/android/binder.c
+++ b/drivers/staging/android/binder.c
@@ -381,8 +381,7 @@ int task_get_unused_fd_flags(struct binder_proc *proc, int flags)
381 381
382repeat: 382repeat:
383 fdt = files_fdtable(files); 383 fdt = files_fdtable(files);
384 fd = find_next_zero_bit(fdt->open_fds->fds_bits, fdt->max_fds, 384 fd = find_next_zero_bit(fdt->open_fds, fdt->max_fds, files->next_fd);
385 files->next_fd);
386 385
387 /* 386 /*
388 * N.B. For clone tasks sharing a files structure, this test 387 * N.B. For clone tasks sharing a files structure, this test
@@ -410,11 +409,11 @@ repeat:
410 goto repeat; 409 goto repeat;
411 } 410 }
412 411
413 FD_SET(fd, fdt->open_fds); 412 __set_open_fd(fd, fdt);
414 if (flags & O_CLOEXEC) 413 if (flags & O_CLOEXEC)
415 FD_SET(fd, fdt->close_on_exec); 414 __set_close_on_exec(fd, fdt);
416 else 415 else
417 FD_CLR(fd, fdt->close_on_exec); 416 __clear_close_on_exec(fd, fdt);
418 files->next_fd = fd + 1; 417 files->next_fd = fd + 1;
419#if 1 418#if 1
420 /* Sanity check */ 419 /* Sanity check */
@@ -455,7 +454,7 @@ static void task_fd_install(
455static void __put_unused_fd(struct files_struct *files, unsigned int fd) 454static void __put_unused_fd(struct files_struct *files, unsigned int fd)
456{ 455{
457 struct fdtable *fdt = files_fdtable(files); 456 struct fdtable *fdt = files_fdtable(files);
458 __FD_CLR(fd, fdt->open_fds); 457 __clear_open_fd(fd, fdt);
459 if (fd < files->next_fd) 458 if (fd < files->next_fd)
460 files->next_fd = fd; 459 files->next_fd = fd;
461} 460}
@@ -481,7 +480,7 @@ static long task_close_fd(struct binder_proc *proc, unsigned int fd)
481 if (!filp) 480 if (!filp)
482 goto out_unlock; 481 goto out_unlock;
483 rcu_assign_pointer(fdt->fd[fd], NULL); 482 rcu_assign_pointer(fdt->fd[fd], NULL);
484 FD_CLR(fd, fdt->close_on_exec); 483 __clear_close_on_exec(fd, fdt);
485 __put_unused_fd(files, fd); 484 __put_unused_fd(files, fd);
486 spin_unlock(&files->file_lock); 485 spin_unlock(&files->file_lock);
487 retval = filp_close(filp, files); 486 retval = filp_close(filp, files);
diff --git a/fs/autofs4/dev-ioctl.c b/fs/autofs4/dev-ioctl.c
index 85f1fcdb30e7..9dacb8586701 100644
--- a/fs/autofs4/dev-ioctl.c
+++ b/fs/autofs4/dev-ioctl.c
@@ -230,7 +230,7 @@ static void autofs_dev_ioctl_fd_install(unsigned int fd, struct file *file)
230 fdt = files_fdtable(files); 230 fdt = files_fdtable(files);
231 BUG_ON(fdt->fd[fd] != NULL); 231 BUG_ON(fdt->fd[fd] != NULL);
232 rcu_assign_pointer(fdt->fd[fd], file); 232 rcu_assign_pointer(fdt->fd[fd], file);
233 FD_SET(fd, fdt->close_on_exec); 233 __set_close_on_exec(fd, fdt);
234 spin_unlock(&files->file_lock); 234 spin_unlock(&files->file_lock);
235} 235}
236 236
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 7d7ff206cdcb..48ffb3dc610a 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -1415,6 +1415,22 @@ static void do_thread_regset_writeback(struct task_struct *task,
1415 regset->writeback(task, regset, 1); 1415 regset->writeback(task, regset, 1);
1416} 1416}
1417 1417
1418#ifndef PR_REG_SIZE
1419#define PR_REG_SIZE(S) sizeof(S)
1420#endif
1421
1422#ifndef PRSTATUS_SIZE
1423#define PRSTATUS_SIZE(S) sizeof(S)
1424#endif
1425
1426#ifndef PR_REG_PTR
1427#define PR_REG_PTR(S) (&((S)->pr_reg))
1428#endif
1429
1430#ifndef SET_PR_FPVALID
1431#define SET_PR_FPVALID(S, V) ((S)->pr_fpvalid = (V))
1432#endif
1433
1418static int fill_thread_core_info(struct elf_thread_core_info *t, 1434static int fill_thread_core_info(struct elf_thread_core_info *t,
1419 const struct user_regset_view *view, 1435 const struct user_regset_view *view,
1420 long signr, size_t *total) 1436 long signr, size_t *total)
@@ -1429,11 +1445,11 @@ static int fill_thread_core_info(struct elf_thread_core_info *t,
1429 */ 1445 */
1430 fill_prstatus(&t->prstatus, t->task, signr); 1446 fill_prstatus(&t->prstatus, t->task, signr);
1431 (void) view->regsets[0].get(t->task, &view->regsets[0], 1447 (void) view->regsets[0].get(t->task, &view->regsets[0],
1432 0, sizeof(t->prstatus.pr_reg), 1448 0, PR_REG_SIZE(t->prstatus.pr_reg),
1433 &t->prstatus.pr_reg, NULL); 1449 PR_REG_PTR(&t->prstatus), NULL);
1434 1450
1435 fill_note(&t->notes[0], "CORE", NT_PRSTATUS, 1451 fill_note(&t->notes[0], "CORE", NT_PRSTATUS,
1436 sizeof(t->prstatus), &t->prstatus); 1452 PRSTATUS_SIZE(t->prstatus), &t->prstatus);
1437 *total += notesize(&t->notes[0]); 1453 *total += notesize(&t->notes[0]);
1438 1454
1439 do_thread_regset_writeback(t->task, &view->regsets[0]); 1455 do_thread_regset_writeback(t->task, &view->regsets[0]);
@@ -1463,7 +1479,7 @@ static int fill_thread_core_info(struct elf_thread_core_info *t,
1463 regset->core_note_type, 1479 regset->core_note_type,
1464 size, data); 1480 size, data);
1465 else { 1481 else {
1466 t->prstatus.pr_fpvalid = 1; 1482 SET_PR_FPVALID(&t->prstatus, 1);
1467 fill_note(&t->notes[i], "CORE", 1483 fill_note(&t->notes[i], "CORE",
1468 NT_PRFPREG, size, data); 1484 NT_PRFPREG, size, data);
1469 } 1485 }
diff --git a/fs/compat.c b/fs/compat.c
index 14483a715bbb..f2944ace7a7b 100644
--- a/fs/compat.c
+++ b/fs/compat.c
@@ -1170,10 +1170,9 @@ compat_sys_readv(unsigned long fd, const struct compat_iovec __user *vec,
1170} 1170}
1171 1171
1172asmlinkage ssize_t 1172asmlinkage ssize_t
1173compat_sys_preadv(unsigned long fd, const struct compat_iovec __user *vec, 1173compat_sys_preadv64(unsigned long fd, const struct compat_iovec __user *vec,
1174 unsigned long vlen, u32 pos_low, u32 pos_high) 1174 unsigned long vlen, loff_t pos)
1175{ 1175{
1176 loff_t pos = ((loff_t)pos_high << 32) | pos_low;
1177 struct file *file; 1176 struct file *file;
1178 int fput_needed; 1177 int fput_needed;
1179 ssize_t ret; 1178 ssize_t ret;
@@ -1190,6 +1189,14 @@ compat_sys_preadv(unsigned long fd, const struct compat_iovec __user *vec,
1190 return ret; 1189 return ret;
1191} 1190}
1192 1191
1192asmlinkage ssize_t
1193compat_sys_preadv(unsigned long fd, const struct compat_iovec __user *vec,
1194 unsigned long vlen, u32 pos_low, u32 pos_high)
1195{
1196 loff_t pos = ((loff_t)pos_high << 32) | pos_low;
1197 return compat_sys_preadv64(fd, vec, vlen, pos);
1198}
1199
1193static size_t compat_writev(struct file *file, 1200static size_t compat_writev(struct file *file,
1194 const struct compat_iovec __user *vec, 1201 const struct compat_iovec __user *vec,
1195 unsigned long vlen, loff_t *pos) 1202 unsigned long vlen, loff_t *pos)
@@ -1229,10 +1236,9 @@ compat_sys_writev(unsigned long fd, const struct compat_iovec __user *vec,
1229} 1236}
1230 1237
1231asmlinkage ssize_t 1238asmlinkage ssize_t
1232compat_sys_pwritev(unsigned long fd, const struct compat_iovec __user *vec, 1239compat_sys_pwritev64(unsigned long fd, const struct compat_iovec __user *vec,
1233 unsigned long vlen, u32 pos_low, u32 pos_high) 1240 unsigned long vlen, loff_t pos)
1234{ 1241{
1235 loff_t pos = ((loff_t)pos_high << 32) | pos_low;
1236 struct file *file; 1242 struct file *file;
1237 int fput_needed; 1243 int fput_needed;
1238 ssize_t ret; 1244 ssize_t ret;
@@ -1249,6 +1255,14 @@ compat_sys_pwritev(unsigned long fd, const struct compat_iovec __user *vec,
1249 return ret; 1255 return ret;
1250} 1256}
1251 1257
1258asmlinkage ssize_t
1259compat_sys_pwritev(unsigned long fd, const struct compat_iovec __user *vec,
1260 unsigned long vlen, u32 pos_low, u32 pos_high)
1261{
1262 loff_t pos = ((loff_t)pos_high << 32) | pos_low;
1263 return compat_sys_pwritev64(fd, vec, vlen, pos);
1264}
1265
1252asmlinkage long 1266asmlinkage long
1253compat_sys_vmsplice(int fd, const struct compat_iovec __user *iov32, 1267compat_sys_vmsplice(int fd, const struct compat_iovec __user *iov32,
1254 unsigned int nr_segs, unsigned int flags) 1268 unsigned int nr_segs, unsigned int flags)
diff --git a/fs/exec.c b/fs/exec.c
index c8b63d14da85..9a1d9f0a60ab 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1028,10 +1028,10 @@ static void flush_old_files(struct files_struct * files)
1028 fdt = files_fdtable(files); 1028 fdt = files_fdtable(files);
1029 if (i >= fdt->max_fds) 1029 if (i >= fdt->max_fds)
1030 break; 1030 break;
1031 set = fdt->close_on_exec->fds_bits[j]; 1031 set = fdt->close_on_exec[j];
1032 if (!set) 1032 if (!set)
1033 continue; 1033 continue;
1034 fdt->close_on_exec->fds_bits[j] = 0; 1034 fdt->close_on_exec[j] = 0;
1035 spin_unlock(&files->file_lock); 1035 spin_unlock(&files->file_lock);
1036 for ( ; set ; i++,set >>= 1) { 1036 for ( ; set ; i++,set >>= 1) {
1037 if (set & 1) { 1037 if (set & 1) {
@@ -2067,8 +2067,8 @@ static int umh_pipe_setup(struct subprocess_info *info, struct cred *new)
2067 fd_install(0, rp); 2067 fd_install(0, rp);
2068 spin_lock(&cf->file_lock); 2068 spin_lock(&cf->file_lock);
2069 fdt = files_fdtable(cf); 2069 fdt = files_fdtable(cf);
2070 FD_SET(0, fdt->open_fds); 2070 __set_open_fd(0, fdt);
2071 FD_CLR(0, fdt->close_on_exec); 2071 __clear_close_on_exec(0, fdt);
2072 spin_unlock(&cf->file_lock); 2072 spin_unlock(&cf->file_lock);
2073 2073
2074 /* and disallow core files too */ 2074 /* and disallow core files too */
diff --git a/fs/fcntl.c b/fs/fcntl.c
index 22764c7c8382..75e7c1f3a080 100644
--- a/fs/fcntl.c
+++ b/fs/fcntl.c
@@ -32,20 +32,20 @@ void set_close_on_exec(unsigned int fd, int flag)
32 spin_lock(&files->file_lock); 32 spin_lock(&files->file_lock);
33 fdt = files_fdtable(files); 33 fdt = files_fdtable(files);
34 if (flag) 34 if (flag)
35 FD_SET(fd, fdt->close_on_exec); 35 __set_close_on_exec(fd, fdt);
36 else 36 else
37 FD_CLR(fd, fdt->close_on_exec); 37 __clear_close_on_exec(fd, fdt);
38 spin_unlock(&files->file_lock); 38 spin_unlock(&files->file_lock);
39} 39}
40 40
41static int get_close_on_exec(unsigned int fd) 41static bool get_close_on_exec(unsigned int fd)
42{ 42{
43 struct files_struct *files = current->files; 43 struct files_struct *files = current->files;
44 struct fdtable *fdt; 44 struct fdtable *fdt;
45 int res; 45 bool res;
46 rcu_read_lock(); 46 rcu_read_lock();
47 fdt = files_fdtable(files); 47 fdt = files_fdtable(files);
48 res = FD_ISSET(fd, fdt->close_on_exec); 48 res = close_on_exec(fd, fdt);
49 rcu_read_unlock(); 49 rcu_read_unlock();
50 return res; 50 return res;
51} 51}
@@ -90,15 +90,15 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
90 err = -EBUSY; 90 err = -EBUSY;
91 fdt = files_fdtable(files); 91 fdt = files_fdtable(files);
92 tofree = fdt->fd[newfd]; 92 tofree = fdt->fd[newfd];
93 if (!tofree && FD_ISSET(newfd, fdt->open_fds)) 93 if (!tofree && fd_is_open(newfd, fdt))
94 goto out_unlock; 94 goto out_unlock;
95 get_file(file); 95 get_file(file);
96 rcu_assign_pointer(fdt->fd[newfd], file); 96 rcu_assign_pointer(fdt->fd[newfd], file);
97 FD_SET(newfd, fdt->open_fds); 97 __set_open_fd(newfd, fdt);
98 if (flags & O_CLOEXEC) 98 if (flags & O_CLOEXEC)
99 FD_SET(newfd, fdt->close_on_exec); 99 __set_close_on_exec(newfd, fdt);
100 else 100 else
101 FD_CLR(newfd, fdt->close_on_exec); 101 __clear_close_on_exec(newfd, fdt);
102 spin_unlock(&files->file_lock); 102 spin_unlock(&files->file_lock);
103 103
104 if (tofree) 104 if (tofree)
diff --git a/fs/file.c b/fs/file.c
index 3c426de7203a..ba3f6053025c 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -40,7 +40,7 @@ int sysctl_nr_open_max = 1024 * 1024; /* raised later */
40 */ 40 */
41static DEFINE_PER_CPU(struct fdtable_defer, fdtable_defer_list); 41static DEFINE_PER_CPU(struct fdtable_defer, fdtable_defer_list);
42 42
43static void *alloc_fdmem(unsigned int size) 43static void *alloc_fdmem(size_t size)
44{ 44{
45 /* 45 /*
46 * Very large allocations can stress page reclaim, so fall back to 46 * Very large allocations can stress page reclaim, so fall back to
@@ -142,7 +142,7 @@ static void copy_fdtable(struct fdtable *nfdt, struct fdtable *ofdt)
142static struct fdtable * alloc_fdtable(unsigned int nr) 142static struct fdtable * alloc_fdtable(unsigned int nr)
143{ 143{
144 struct fdtable *fdt; 144 struct fdtable *fdt;
145 char *data; 145 void *data;
146 146
147 /* 147 /*
148 * Figure out how many fds we actually want to support in this fdtable. 148 * Figure out how many fds we actually want to support in this fdtable.
@@ -172,14 +172,15 @@ static struct fdtable * alloc_fdtable(unsigned int nr)
172 data = alloc_fdmem(nr * sizeof(struct file *)); 172 data = alloc_fdmem(nr * sizeof(struct file *));
173 if (!data) 173 if (!data)
174 goto out_fdt; 174 goto out_fdt;
175 fdt->fd = (struct file **)data; 175 fdt->fd = data;
176 data = alloc_fdmem(max_t(unsigned int, 176
177 data = alloc_fdmem(max_t(size_t,
177 2 * nr / BITS_PER_BYTE, L1_CACHE_BYTES)); 178 2 * nr / BITS_PER_BYTE, L1_CACHE_BYTES));
178 if (!data) 179 if (!data)
179 goto out_arr; 180 goto out_arr;
180 fdt->open_fds = (fd_set *)data; 181 fdt->open_fds = data;
181 data += nr / BITS_PER_BYTE; 182 data += nr / BITS_PER_BYTE;
182 fdt->close_on_exec = (fd_set *)data; 183 fdt->close_on_exec = data;
183 fdt->next = NULL; 184 fdt->next = NULL;
184 185
185 return fdt; 186 return fdt;
@@ -275,11 +276,11 @@ static int count_open_files(struct fdtable *fdt)
275 int i; 276 int i;
276 277
277 /* Find the last open fd */ 278 /* Find the last open fd */
278 for (i = size/(8*sizeof(long)); i > 0; ) { 279 for (i = size / BITS_PER_LONG; i > 0; ) {
279 if (fdt->open_fds->fds_bits[--i]) 280 if (fdt->open_fds[--i])
280 break; 281 break;
281 } 282 }
282 i = (i+1) * 8 * sizeof(long); 283 i = (i + 1) * BITS_PER_LONG;
283 return i; 284 return i;
284} 285}
285 286
@@ -306,8 +307,8 @@ struct files_struct *dup_fd(struct files_struct *oldf, int *errorp)
306 newf->next_fd = 0; 307 newf->next_fd = 0;
307 new_fdt = &newf->fdtab; 308 new_fdt = &newf->fdtab;
308 new_fdt->max_fds = NR_OPEN_DEFAULT; 309 new_fdt->max_fds = NR_OPEN_DEFAULT;
309 new_fdt->close_on_exec = (fd_set *)&newf->close_on_exec_init; 310 new_fdt->close_on_exec = newf->close_on_exec_init;
310 new_fdt->open_fds = (fd_set *)&newf->open_fds_init; 311 new_fdt->open_fds = newf->open_fds_init;
311 new_fdt->fd = &newf->fd_array[0]; 312 new_fdt->fd = &newf->fd_array[0];
312 new_fdt->next = NULL; 313 new_fdt->next = NULL;
313 314
@@ -350,10 +351,8 @@ struct files_struct *dup_fd(struct files_struct *oldf, int *errorp)
350 old_fds = old_fdt->fd; 351 old_fds = old_fdt->fd;
351 new_fds = new_fdt->fd; 352 new_fds = new_fdt->fd;
352 353
353 memcpy(new_fdt->open_fds->fds_bits, 354 memcpy(new_fdt->open_fds, old_fdt->open_fds, open_files / 8);
354 old_fdt->open_fds->fds_bits, open_files/8); 355 memcpy(new_fdt->close_on_exec, old_fdt->close_on_exec, open_files / 8);
355 memcpy(new_fdt->close_on_exec->fds_bits,
356 old_fdt->close_on_exec->fds_bits, open_files/8);
357 356
358 for (i = open_files; i != 0; i--) { 357 for (i = open_files; i != 0; i--) {
359 struct file *f = *old_fds++; 358 struct file *f = *old_fds++;
@@ -366,7 +365,7 @@ struct files_struct *dup_fd(struct files_struct *oldf, int *errorp)
366 * is partway through open(). So make sure that this 365 * is partway through open(). So make sure that this
367 * fd is available to the new process. 366 * fd is available to the new process.
368 */ 367 */
369 FD_CLR(open_files - i, new_fdt->open_fds); 368 __clear_open_fd(open_files - i, new_fdt);
370 } 369 }
371 rcu_assign_pointer(*new_fds++, f); 370 rcu_assign_pointer(*new_fds++, f);
372 } 371 }
@@ -379,11 +378,11 @@ struct files_struct *dup_fd(struct files_struct *oldf, int *errorp)
379 memset(new_fds, 0, size); 378 memset(new_fds, 0, size);
380 379
381 if (new_fdt->max_fds > open_files) { 380 if (new_fdt->max_fds > open_files) {
382 int left = (new_fdt->max_fds-open_files)/8; 381 int left = (new_fdt->max_fds - open_files) / 8;
383 int start = open_files / (8 * sizeof(unsigned long)); 382 int start = open_files / BITS_PER_LONG;
384 383
385 memset(&new_fdt->open_fds->fds_bits[start], 0, left); 384 memset(&new_fdt->open_fds[start], 0, left);
386 memset(&new_fdt->close_on_exec->fds_bits[start], 0, left); 385 memset(&new_fdt->close_on_exec[start], 0, left);
387 } 386 }
388 387
389 rcu_assign_pointer(newf->fdt, new_fdt); 388 rcu_assign_pointer(newf->fdt, new_fdt);
@@ -419,8 +418,8 @@ struct files_struct init_files = {
419 .fdtab = { 418 .fdtab = {
420 .max_fds = NR_OPEN_DEFAULT, 419 .max_fds = NR_OPEN_DEFAULT,
421 .fd = &init_files.fd_array[0], 420 .fd = &init_files.fd_array[0],
422 .close_on_exec = (fd_set *)&init_files.close_on_exec_init, 421 .close_on_exec = init_files.close_on_exec_init,
423 .open_fds = (fd_set *)&init_files.open_fds_init, 422 .open_fds = init_files.open_fds_init,
424 }, 423 },
425 .file_lock = __SPIN_LOCK_UNLOCKED(init_task.file_lock), 424 .file_lock = __SPIN_LOCK_UNLOCKED(init_task.file_lock),
426}; 425};
@@ -443,8 +442,7 @@ repeat:
443 fd = files->next_fd; 442 fd = files->next_fd;
444 443
445 if (fd < fdt->max_fds) 444 if (fd < fdt->max_fds)
446 fd = find_next_zero_bit(fdt->open_fds->fds_bits, 445 fd = find_next_zero_bit(fdt->open_fds, fdt->max_fds, fd);
447 fdt->max_fds, fd);
448 446
449 error = expand_files(files, fd); 447 error = expand_files(files, fd);
450 if (error < 0) 448 if (error < 0)
@@ -460,11 +458,11 @@ repeat:
460 if (start <= files->next_fd) 458 if (start <= files->next_fd)
461 files->next_fd = fd + 1; 459 files->next_fd = fd + 1;
462 460
463 FD_SET(fd, fdt->open_fds); 461 __set_open_fd(fd, fdt);
464 if (flags & O_CLOEXEC) 462 if (flags & O_CLOEXEC)
465 FD_SET(fd, fdt->close_on_exec); 463 __set_close_on_exec(fd, fdt);
466 else 464 else
467 FD_CLR(fd, fdt->close_on_exec); 465 __clear_close_on_exec(fd, fdt);
468 error = fd; 466 error = fd;
469#if 1 467#if 1
470 /* Sanity check */ 468 /* Sanity check */
diff --git a/fs/open.c b/fs/open.c
index 77becc041149..5720854156db 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -836,7 +836,7 @@ EXPORT_SYMBOL(dentry_open);
836static void __put_unused_fd(struct files_struct *files, unsigned int fd) 836static void __put_unused_fd(struct files_struct *files, unsigned int fd)
837{ 837{
838 struct fdtable *fdt = files_fdtable(files); 838 struct fdtable *fdt = files_fdtable(files);
839 __FD_CLR(fd, fdt->open_fds); 839 __clear_open_fd(fd, fdt);
840 if (fd < files->next_fd) 840 if (fd < files->next_fd)
841 files->next_fd = fd; 841 files->next_fd = fd;
842} 842}
@@ -1080,7 +1080,7 @@ SYSCALL_DEFINE1(close, unsigned int, fd)
1080 if (!filp) 1080 if (!filp)
1081 goto out_unlock; 1081 goto out_unlock;
1082 rcu_assign_pointer(fdt->fd[fd], NULL); 1082 rcu_assign_pointer(fdt->fd[fd], NULL);
1083 FD_CLR(fd, fdt->close_on_exec); 1083 __clear_close_on_exec(fd, fdt);
1084 __put_unused_fd(files, fd); 1084 __put_unused_fd(files, fd);
1085 spin_unlock(&files->file_lock); 1085 spin_unlock(&files->file_lock);
1086 retval = filp_close(filp, files); 1086 retval = filp_close(filp, files);
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 3b42c1418f31..1c8b280146d7 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -1753,7 +1753,7 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
1753 1753
1754 fdt = files_fdtable(files); 1754 fdt = files_fdtable(files);
1755 f_flags = file->f_flags & ~O_CLOEXEC; 1755 f_flags = file->f_flags & ~O_CLOEXEC;
1756 if (FD_ISSET(fd, fdt->close_on_exec)) 1756 if (close_on_exec(fd, fdt))
1757 f_flags |= O_CLOEXEC; 1757 f_flags |= O_CLOEXEC;
1758 1758
1759 if (path) { 1759 if (path) {
diff --git a/fs/select.c b/fs/select.c
index 6fb8943d580b..17d33d09fc16 100644
--- a/fs/select.c
+++ b/fs/select.c
@@ -348,7 +348,7 @@ static int max_select_fd(unsigned long n, fd_set_bits *fds)
348 set = ~(~0UL << (n & (__NFDBITS-1))); 348 set = ~(~0UL << (n & (__NFDBITS-1)));
349 n /= __NFDBITS; 349 n /= __NFDBITS;
350 fdt = files_fdtable(current->files); 350 fdt = files_fdtable(current->files);
351 open_fds = fdt->open_fds->fds_bits+n; 351 open_fds = fdt->open_fds + n;
352 max = 0; 352 max = 0;
353 if (set) { 353 if (set) {
354 set &= BITS(fds, n); 354 set &= BITS(fds, n);
diff --git a/include/asm-generic/posix_types.h b/include/asm-generic/posix_types.h
index 3dab00860e71..91d44bd4dde3 100644
--- a/include/asm-generic/posix_types.h
+++ b/include/asm-generic/posix_types.h
@@ -10,8 +10,13 @@
10 * architectures, so that you can override them. 10 * architectures, so that you can override them.
11 */ 11 */
12 12
13#ifndef __kernel_long_t
14typedef long __kernel_long_t;
15typedef unsigned long __kernel_ulong_t;
16#endif
17
13#ifndef __kernel_ino_t 18#ifndef __kernel_ino_t
14typedef unsigned long __kernel_ino_t; 19typedef __kernel_ulong_t __kernel_ino_t;
15#endif 20#endif
16 21
17#ifndef __kernel_mode_t 22#ifndef __kernel_mode_t
@@ -19,7 +24,7 @@ typedef unsigned int __kernel_mode_t;
19#endif 24#endif
20 25
21#ifndef __kernel_nlink_t 26#ifndef __kernel_nlink_t
22typedef unsigned long __kernel_nlink_t; 27typedef __kernel_ulong_t __kernel_nlink_t;
23#endif 28#endif
24 29
25#ifndef __kernel_pid_t 30#ifndef __kernel_pid_t
@@ -36,7 +41,7 @@ typedef unsigned int __kernel_gid_t;
36#endif 41#endif
37 42
38#ifndef __kernel_suseconds_t 43#ifndef __kernel_suseconds_t
39typedef long __kernel_suseconds_t; 44typedef __kernel_long_t __kernel_suseconds_t;
40#endif 45#endif
41 46
42#ifndef __kernel_daddr_t 47#ifndef __kernel_daddr_t
@@ -44,8 +49,8 @@ typedef int __kernel_daddr_t;
44#endif 49#endif
45 50
46#ifndef __kernel_uid32_t 51#ifndef __kernel_uid32_t
47typedef __kernel_uid_t __kernel_uid32_t; 52typedef unsigned int __kernel_uid32_t;
48typedef __kernel_gid_t __kernel_gid32_t; 53typedef unsigned int __kernel_gid32_t;
49#endif 54#endif
50 55
51#ifndef __kernel_old_uid_t 56#ifndef __kernel_old_uid_t
@@ -67,99 +72,29 @@ typedef unsigned int __kernel_size_t;
67typedef int __kernel_ssize_t; 72typedef int __kernel_ssize_t;
68typedef int __kernel_ptrdiff_t; 73typedef int __kernel_ptrdiff_t;
69#else 74#else
70typedef unsigned long __kernel_size_t; 75typedef __kernel_ulong_t __kernel_size_t;
71typedef long __kernel_ssize_t; 76typedef __kernel_long_t __kernel_ssize_t;
72typedef long __kernel_ptrdiff_t; 77typedef __kernel_long_t __kernel_ptrdiff_t;
73#endif 78#endif
74#endif 79#endif
75 80
81#ifndef __kernel_fsid_t
82typedef struct {
83 int val[2];
84} __kernel_fsid_t;
85#endif
86
76/* 87/*
77 * anything below here should be completely generic 88 * anything below here should be completely generic
78 */ 89 */
79typedef long __kernel_off_t; 90typedef __kernel_long_t __kernel_off_t;
80typedef long long __kernel_loff_t; 91typedef long long __kernel_loff_t;
81typedef long __kernel_time_t; 92typedef __kernel_long_t __kernel_time_t;
82typedef long __kernel_clock_t; 93typedef __kernel_long_t __kernel_clock_t;
83typedef int __kernel_timer_t; 94typedef int __kernel_timer_t;
84typedef int __kernel_clockid_t; 95typedef int __kernel_clockid_t;
85typedef char * __kernel_caddr_t; 96typedef char * __kernel_caddr_t;
86typedef unsigned short __kernel_uid16_t; 97typedef unsigned short __kernel_uid16_t;
87typedef unsigned short __kernel_gid16_t; 98typedef unsigned short __kernel_gid16_t;
88 99
89typedef struct {
90 int val[2];
91} __kernel_fsid_t;
92
93#ifdef __KERNEL__
94
95#undef __FD_SET
96static inline void __FD_SET(unsigned long __fd, __kernel_fd_set *__fdsetp)
97{
98 unsigned long __tmp = __fd / __NFDBITS;
99 unsigned long __rem = __fd % __NFDBITS;
100 __fdsetp->fds_bits[__tmp] |= (1UL<<__rem);
101}
102
103#undef __FD_CLR
104static inline void __FD_CLR(unsigned long __fd, __kernel_fd_set *__fdsetp)
105{
106 unsigned long __tmp = __fd / __NFDBITS;
107 unsigned long __rem = __fd % __NFDBITS;
108 __fdsetp->fds_bits[__tmp] &= ~(1UL<<__rem);
109}
110
111#undef __FD_ISSET
112static inline int __FD_ISSET(unsigned long __fd, const __kernel_fd_set *__p)
113{
114 unsigned long __tmp = __fd / __NFDBITS;
115 unsigned long __rem = __fd % __NFDBITS;
116 return (__p->fds_bits[__tmp] & (1UL<<__rem)) != 0;
117}
118
119/*
120 * This will unroll the loop for the normal constant case (8 ints,
121 * for a 256-bit fd_set)
122 */
123#undef __FD_ZERO
124static inline void __FD_ZERO(__kernel_fd_set *__p)
125{
126 unsigned long *__tmp = __p->fds_bits;
127 int __i;
128
129 if (__builtin_constant_p(__FDSET_LONGS)) {
130 switch (__FDSET_LONGS) {
131 case 16:
132 __tmp[ 0] = 0; __tmp[ 1] = 0;
133 __tmp[ 2] = 0; __tmp[ 3] = 0;
134 __tmp[ 4] = 0; __tmp[ 5] = 0;
135 __tmp[ 6] = 0; __tmp[ 7] = 0;
136 __tmp[ 8] = 0; __tmp[ 9] = 0;
137 __tmp[10] = 0; __tmp[11] = 0;
138 __tmp[12] = 0; __tmp[13] = 0;
139 __tmp[14] = 0; __tmp[15] = 0;
140 return;
141
142 case 8:
143 __tmp[ 0] = 0; __tmp[ 1] = 0;
144 __tmp[ 2] = 0; __tmp[ 3] = 0;
145 __tmp[ 4] = 0; __tmp[ 5] = 0;
146 __tmp[ 6] = 0; __tmp[ 7] = 0;
147 return;
148
149 case 4:
150 __tmp[ 0] = 0; __tmp[ 1] = 0;
151 __tmp[ 2] = 0; __tmp[ 3] = 0;
152 return;
153 }
154 }
155 __i = __FDSET_LONGS;
156 while (__i) {
157 __i--;
158 *__tmp = 0;
159 __tmp++;
160 }
161}
162
163#endif /* __KERNEL__ */
164
165#endif /* __ASM_GENERIC_POSIX_TYPES_H */ 100#endif /* __ASM_GENERIC_POSIX_TYPES_H */
diff --git a/include/linux/Kbuild b/include/linux/Kbuild
index a25555381097..a4b5da2b83f5 100644
--- a/include/linux/Kbuild
+++ b/include/linux/Kbuild
@@ -357,6 +357,7 @@ header-y += suspend_ioctls.h
357header-y += swab.h 357header-y += swab.h
358header-y += synclink.h 358header-y += synclink.h
359header-y += sysctl.h 359header-y += sysctl.h
360header-y += sysinfo.h
360header-y += taskstats.h 361header-y += taskstats.h
361header-y += tcp.h 362header-y += tcp.h
362header-y += telephony.h 363header-y += telephony.h
diff --git a/include/linux/aio_abi.h b/include/linux/aio_abi.h
index 2c8731664180..86fa7a71336a 100644
--- a/include/linux/aio_abi.h
+++ b/include/linux/aio_abi.h
@@ -30,7 +30,7 @@
30#include <linux/types.h> 30#include <linux/types.h>
31#include <asm/byteorder.h> 31#include <asm/byteorder.h>
32 32
33typedef unsigned long aio_context_t; 33typedef __kernel_ulong_t aio_context_t;
34 34
35enum { 35enum {
36 IOCB_CMD_PREAD = 0, 36 IOCB_CMD_PREAD = 0,
diff --git a/include/linux/compat.h b/include/linux/compat.h
index 35c2dbf2448a..5d46217f84ad 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -19,6 +19,10 @@
19#include <asm/siginfo.h> 19#include <asm/siginfo.h>
20#include <asm/signal.h> 20#include <asm/signal.h>
21 21
22#ifndef COMPAT_USE_64BIT_TIME
23#define COMPAT_USE_64BIT_TIME 0
24#endif
25
22#define compat_jiffies_to_clock_t(x) \ 26#define compat_jiffies_to_clock_t(x) \
23 (((unsigned long)(x) * COMPAT_USER_HZ) / HZ) 27 (((unsigned long)(x) * COMPAT_USER_HZ) / HZ)
24 28
@@ -83,10 +87,26 @@ typedef struct {
83 compat_sigset_word sig[_COMPAT_NSIG_WORDS]; 87 compat_sigset_word sig[_COMPAT_NSIG_WORDS];
84} compat_sigset_t; 88} compat_sigset_t;
85 89
90/*
91 * These functions operate strictly on struct compat_time*
92 */
86extern int get_compat_timespec(struct timespec *, 93extern int get_compat_timespec(struct timespec *,
87 const struct compat_timespec __user *); 94 const struct compat_timespec __user *);
88extern int put_compat_timespec(const struct timespec *, 95extern int put_compat_timespec(const struct timespec *,
89 struct compat_timespec __user *); 96 struct compat_timespec __user *);
97extern int get_compat_timeval(struct timeval *,
98 const struct compat_timeval __user *);
99extern int put_compat_timeval(const struct timeval *,
100 struct compat_timeval __user *);
101/*
102 * These functions operate on 32- or 64-bit specs depending on
103 * COMPAT_USE_64BIT_TIME, hence the void user pointer arguments and the
104 * naming as compat_get/put_ rather than get/put_compat_.
105 */
106extern int compat_get_timespec(struct timespec *, const void __user *);
107extern int compat_put_timespec(const struct timespec *, void __user *);
108extern int compat_get_timeval(struct timeval *, const void __user *);
109extern int compat_put_timeval(const struct timeval *, void __user *);
90 110
91struct compat_iovec { 111struct compat_iovec {
92 compat_uptr_t iov_base; 112 compat_uptr_t iov_base;
diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
index 82163c4b32c9..158a41eed314 100644
--- a/include/linux/fdtable.h
+++ b/include/linux/fdtable.h
@@ -21,23 +21,45 @@
21 */ 21 */
22#define NR_OPEN_DEFAULT BITS_PER_LONG 22#define NR_OPEN_DEFAULT BITS_PER_LONG
23 23
24/*
25 * The embedded_fd_set is a small fd_set,
26 * suitable for most tasks (which open <= BITS_PER_LONG files)
27 */
28struct embedded_fd_set {
29 unsigned long fds_bits[1];
30};
31
32struct fdtable { 24struct fdtable {
33 unsigned int max_fds; 25 unsigned int max_fds;
34 struct file __rcu **fd; /* current fd array */ 26 struct file __rcu **fd; /* current fd array */
35 fd_set *close_on_exec; 27 unsigned long *close_on_exec;
36 fd_set *open_fds; 28 unsigned long *open_fds;
37 struct rcu_head rcu; 29 struct rcu_head rcu;
38 struct fdtable *next; 30 struct fdtable *next;
39}; 31};
40 32
33static inline void __set_close_on_exec(int fd, struct fdtable *fdt)
34{
35 __set_bit(fd, fdt->close_on_exec);
36}
37
38static inline void __clear_close_on_exec(int fd, struct fdtable *fdt)
39{
40 __clear_bit(fd, fdt->close_on_exec);
41}
42
43static inline bool close_on_exec(int fd, const struct fdtable *fdt)
44{
45 return test_bit(fd, fdt->close_on_exec);
46}
47
48static inline void __set_open_fd(int fd, struct fdtable *fdt)
49{
50 __set_bit(fd, fdt->open_fds);
51}
52
53static inline void __clear_open_fd(int fd, struct fdtable *fdt)
54{
55 __clear_bit(fd, fdt->open_fds);
56}
57
58static inline bool fd_is_open(int fd, const struct fdtable *fdt)
59{
60 return test_bit(fd, fdt->open_fds);
61}
62
41/* 63/*
42 * Open file table structure 64 * Open file table structure
43 */ 65 */
@@ -53,8 +75,8 @@ struct files_struct {
53 */ 75 */
54 spinlock_t file_lock ____cacheline_aligned_in_smp; 76 spinlock_t file_lock ____cacheline_aligned_in_smp;
55 int next_fd; 77 int next_fd;
56 struct embedded_fd_set close_on_exec_init; 78 unsigned long close_on_exec_init[1];
57 struct embedded_fd_set open_fds_init; 79 unsigned long open_fds_init[1];
58 struct file __rcu * fd_array[NR_OPEN_DEFAULT]; 80 struct file __rcu * fd_array[NR_OPEN_DEFAULT];
59}; 81};
60 82
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 5db52d0ff1d4..a5375e7f3fea 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -1,6 +1,8 @@
1#ifndef _LINUX_KERNEL_H 1#ifndef _LINUX_KERNEL_H
2#define _LINUX_KERNEL_H 2#define _LINUX_KERNEL_H
3 3
4#include <linux/sysinfo.h>
5
4/* 6/*
5 * 'kernel.h' contains some often-used function prototypes etc 7 * 'kernel.h' contains some often-used function prototypes etc
6 */ 8 */
@@ -698,27 +700,8 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
698# define REBUILD_DUE_TO_FTRACE_MCOUNT_RECORD 700# define REBUILD_DUE_TO_FTRACE_MCOUNT_RECORD
699#endif 701#endif
700 702
701struct sysinfo;
702extern int do_sysinfo(struct sysinfo *info); 703extern int do_sysinfo(struct sysinfo *info);
703 704
704#endif /* __KERNEL__ */ 705#endif /* __KERNEL__ */
705 706
706#define SI_LOAD_SHIFT 16
707struct sysinfo {
708 long uptime; /* Seconds since boot */
709 unsigned long loads[3]; /* 1, 5, and 15 minute load averages */
710 unsigned long totalram; /* Total usable main memory size */
711 unsigned long freeram; /* Available memory size */
712 unsigned long sharedram; /* Amount of shared memory */
713 unsigned long bufferram; /* Memory used by buffers */
714 unsigned long totalswap; /* Total swap space size */
715 unsigned long freeswap; /* swap space still available */
716 unsigned short procs; /* Number of current processes */
717 unsigned short pad; /* explicit padding for m68k */
718 unsigned long totalhigh; /* Total high memory size */
719 unsigned long freehigh; /* Available high memory size */
720 unsigned int mem_unit; /* Memory unit size in bytes */
721 char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */
722};
723
724#endif 707#endif
diff --git a/include/linux/sysinfo.h b/include/linux/sysinfo.h
new file mode 100644
index 000000000000..934335a22522
--- /dev/null
+++ b/include/linux/sysinfo.h
@@ -0,0 +1,24 @@
1#ifndef _LINUX_SYSINFO_H
2#define _LINUX_SYSINFO_H
3
4#include <linux/types.h>
5
6#define SI_LOAD_SHIFT 16
7struct sysinfo {
8 __kernel_long_t uptime; /* Seconds since boot */
9 __kernel_ulong_t loads[3]; /* 1, 5, and 15 minute load averages */
10 __kernel_ulong_t totalram; /* Total usable main memory size */
11 __kernel_ulong_t freeram; /* Available memory size */
12 __kernel_ulong_t sharedram; /* Amount of shared memory */
13 __kernel_ulong_t bufferram; /* Memory used by buffers */
14 __kernel_ulong_t totalswap; /* Total swap space size */
15 __kernel_ulong_t freeswap; /* swap space still available */
16 __u16 procs; /* Number of current processes */
17 __u16 pad; /* Explicit padding for m68k */
18 __kernel_ulong_t totalhigh; /* Total high memory size */
19 __kernel_ulong_t freehigh; /* Available high memory size */
20 __u32 mem_unit; /* Memory unit size in bytes */
21 char _f[20-2*sizeof(__kernel_ulong_t)-sizeof(__u32)]; /* Padding: libc5 uses this.. */
22};
23
24#endif /* _LINUX_SYSINFO_H */
diff --git a/include/linux/time.h b/include/linux/time.h
index 97734e9409c6..33a92ead4d88 100644
--- a/include/linux/time.h
+++ b/include/linux/time.h
@@ -255,6 +255,7 @@ static __always_inline void timespec_add_ns(struct timespec *a, u64 ns)
255 a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns); 255 a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns);
256 a->tv_nsec = ns; 256 a->tv_nsec = ns;
257} 257}
258
258#endif /* __KERNEL__ */ 259#endif /* __KERNEL__ */
259 260
260#define NFDBITS __NFDBITS 261#define NFDBITS __NFDBITS
diff --git a/kernel/compat.c b/kernel/compat.c
index f346cedfe24d..74ff8498809a 100644
--- a/kernel/compat.c
+++ b/kernel/compat.c
@@ -31,11 +31,10 @@
31#include <asm/uaccess.h> 31#include <asm/uaccess.h>
32 32
33/* 33/*
34 * Note that the native side is already converted to a timespec, because 34 * Get/set struct timeval with struct timespec on the native side
35 * that's what we want anyway.
36 */ 35 */
37static int compat_get_timeval(struct timespec *o, 36static int compat_get_timeval_convert(struct timespec *o,
38 struct compat_timeval __user *i) 37 struct compat_timeval __user *i)
39{ 38{
40 long usec; 39 long usec;
41 40
@@ -46,8 +45,8 @@ static int compat_get_timeval(struct timespec *o,
46 return 0; 45 return 0;
47} 46}
48 47
49static int compat_put_timeval(struct compat_timeval __user *o, 48static int compat_put_timeval_convert(struct compat_timeval __user *o,
50 struct timeval *i) 49 struct timeval *i)
51{ 50{
52 return (put_user(i->tv_sec, &o->tv_sec) || 51 return (put_user(i->tv_sec, &o->tv_sec) ||
53 put_user(i->tv_usec, &o->tv_usec)) ? -EFAULT : 0; 52 put_user(i->tv_usec, &o->tv_usec)) ? -EFAULT : 0;
@@ -117,7 +116,7 @@ asmlinkage long compat_sys_gettimeofday(struct compat_timeval __user *tv,
117 if (tv) { 116 if (tv) {
118 struct timeval ktv; 117 struct timeval ktv;
119 do_gettimeofday(&ktv); 118 do_gettimeofday(&ktv);
120 if (compat_put_timeval(tv, &ktv)) 119 if (compat_put_timeval_convert(tv, &ktv))
121 return -EFAULT; 120 return -EFAULT;
122 } 121 }
123 if (tz) { 122 if (tz) {
@@ -135,7 +134,7 @@ asmlinkage long compat_sys_settimeofday(struct compat_timeval __user *tv,
135 struct timezone ktz; 134 struct timezone ktz;
136 135
137 if (tv) { 136 if (tv) {
138 if (compat_get_timeval(&kts, tv)) 137 if (compat_get_timeval_convert(&kts, tv))
139 return -EFAULT; 138 return -EFAULT;
140 } 139 }
141 if (tz) { 140 if (tz) {
@@ -146,12 +145,29 @@ asmlinkage long compat_sys_settimeofday(struct compat_timeval __user *tv,
146 return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL); 145 return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
147} 146}
148 147
148int get_compat_timeval(struct timeval *tv, const struct compat_timeval __user *ctv)
149{
150 return (!access_ok(VERIFY_READ, ctv, sizeof(*ctv)) ||
151 __get_user(tv->tv_sec, &ctv->tv_sec) ||
152 __get_user(tv->tv_usec, &ctv->tv_usec)) ? -EFAULT : 0;
153}
154EXPORT_SYMBOL_GPL(get_compat_timeval);
155
156int put_compat_timeval(const struct timeval *tv, struct compat_timeval __user *ctv)
157{
158 return (!access_ok(VERIFY_WRITE, ctv, sizeof(*ctv)) ||
159 __put_user(tv->tv_sec, &ctv->tv_sec) ||
160 __put_user(tv->tv_usec, &ctv->tv_usec)) ? -EFAULT : 0;
161}
162EXPORT_SYMBOL_GPL(put_compat_timeval);
163
149int get_compat_timespec(struct timespec *ts, const struct compat_timespec __user *cts) 164int get_compat_timespec(struct timespec *ts, const struct compat_timespec __user *cts)
150{ 165{
151 return (!access_ok(VERIFY_READ, cts, sizeof(*cts)) || 166 return (!access_ok(VERIFY_READ, cts, sizeof(*cts)) ||
152 __get_user(ts->tv_sec, &cts->tv_sec) || 167 __get_user(ts->tv_sec, &cts->tv_sec) ||
153 __get_user(ts->tv_nsec, &cts->tv_nsec)) ? -EFAULT : 0; 168 __get_user(ts->tv_nsec, &cts->tv_nsec)) ? -EFAULT : 0;
154} 169}
170EXPORT_SYMBOL_GPL(get_compat_timespec);
155 171
156int put_compat_timespec(const struct timespec *ts, struct compat_timespec __user *cts) 172int put_compat_timespec(const struct timespec *ts, struct compat_timespec __user *cts)
157{ 173{
@@ -161,6 +177,42 @@ int put_compat_timespec(const struct timespec *ts, struct compat_timespec __user
161} 177}
162EXPORT_SYMBOL_GPL(put_compat_timespec); 178EXPORT_SYMBOL_GPL(put_compat_timespec);
163 179
180int compat_get_timeval(struct timeval *tv, const void __user *utv)
181{
182 if (COMPAT_USE_64BIT_TIME)
183 return copy_from_user(tv, utv, sizeof *tv) ? -EFAULT : 0;
184 else
185 return get_compat_timeval(tv, utv);
186}
187EXPORT_SYMBOL_GPL(compat_get_timeval);
188
189int compat_put_timeval(const struct timeval *tv, void __user *utv)
190{
191 if (COMPAT_USE_64BIT_TIME)
192 return copy_to_user(utv, tv, sizeof *tv) ? -EFAULT : 0;
193 else
194 return put_compat_timeval(tv, utv);
195}
196EXPORT_SYMBOL_GPL(compat_put_timeval);
197
198int compat_get_timespec(struct timespec *ts, const void __user *uts)
199{
200 if (COMPAT_USE_64BIT_TIME)
201 return copy_from_user(ts, uts, sizeof *ts) ? -EFAULT : 0;
202 else
203 return get_compat_timespec(ts, uts);
204}
205EXPORT_SYMBOL_GPL(compat_get_timespec);
206
207int compat_put_timespec(const struct timespec *ts, void __user *uts)
208{
209 if (COMPAT_USE_64BIT_TIME)
210 return copy_to_user(uts, ts, sizeof *ts) ? -EFAULT : 0;
211 else
212 return put_compat_timespec(ts, uts);
213}
214EXPORT_SYMBOL_GPL(compat_put_timespec);
215
164static long compat_nanosleep_restart(struct restart_block *restart) 216static long compat_nanosleep_restart(struct restart_block *restart)
165{ 217{
166 struct compat_timespec __user *rmtp; 218 struct compat_timespec __user *rmtp;
diff --git a/kernel/exit.c b/kernel/exit.c
index 3db1909faed9..d8bd3b425fa7 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -474,7 +474,7 @@ static void close_files(struct files_struct * files)
474 i = j * __NFDBITS; 474 i = j * __NFDBITS;
475 if (i >= fdt->max_fds) 475 if (i >= fdt->max_fds)
476 break; 476 break;
477 set = fdt->open_fds->fds_bits[j++]; 477 set = fdt->open_fds[j++];
478 while (set) { 478 while (set) {
479 if (set & 1) { 479 if (set & 1) {
480 struct file * file = xchg(&fdt->fd[i], NULL); 480 struct file * file = xchg(&fdt->fd[i], NULL);
diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
index 49142612916e..5914623f426a 100644
--- a/net/bluetooth/hci_sock.c
+++ b/net/bluetooth/hci_sock.c
@@ -733,7 +733,8 @@ static inline void hci_sock_cmsg(struct sock *sk, struct msghdr *msg, struct sk_
733 data = &tv; 733 data = &tv;
734 len = sizeof(tv); 734 len = sizeof(tv);
735#ifdef CONFIG_COMPAT 735#ifdef CONFIG_COMPAT
736 if (msg->msg_flags & MSG_CMSG_COMPAT) { 736 if (!COMPAT_USE_64BIT_TIME &&
737 (msg->msg_flags & MSG_CMSG_COMPAT)) {
737 ctv.tv_sec = tv.tv_sec; 738 ctv.tv_sec = tv.tv_sec;
738 ctv.tv_usec = tv.tv_usec; 739 ctv.tv_usec = tv.tv_usec;
739 data = &ctv; 740 data = &ctv;
diff --git a/net/compat.c b/net/compat.c
index 64b4515a64e6..e055708b8ec9 100644
--- a/net/compat.c
+++ b/net/compat.c
@@ -219,8 +219,6 @@ Efault:
219 219
220int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data) 220int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
221{ 221{
222 struct compat_timeval ctv;
223 struct compat_timespec cts[3];
224 struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control; 222 struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
225 struct compat_cmsghdr cmhdr; 223 struct compat_cmsghdr cmhdr;
226 int cmlen; 224 int cmlen;
@@ -230,24 +228,28 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
230 return 0; /* XXX: return error? check spec. */ 228 return 0; /* XXX: return error? check spec. */
231 } 229 }
232 230
233 if (level == SOL_SOCKET && type == SCM_TIMESTAMP) { 231 if (!COMPAT_USE_64BIT_TIME) {
234 struct timeval *tv = (struct timeval *)data; 232 struct compat_timeval ctv;
235 ctv.tv_sec = tv->tv_sec; 233 struct compat_timespec cts[3];
236 ctv.tv_usec = tv->tv_usec; 234 if (level == SOL_SOCKET && type == SCM_TIMESTAMP) {
237 data = &ctv; 235 struct timeval *tv = (struct timeval *)data;
238 len = sizeof(ctv); 236 ctv.tv_sec = tv->tv_sec;
239 } 237 ctv.tv_usec = tv->tv_usec;
240 if (level == SOL_SOCKET && 238 data = &ctv;
241 (type == SCM_TIMESTAMPNS || type == SCM_TIMESTAMPING)) { 239 len = sizeof(ctv);
242 int count = type == SCM_TIMESTAMPNS ? 1 : 3; 240 }
243 int i; 241 if (level == SOL_SOCKET &&
244 struct timespec *ts = (struct timespec *)data; 242 (type == SCM_TIMESTAMPNS || type == SCM_TIMESTAMPING)) {
245 for (i = 0; i < count; i++) { 243 int count = type == SCM_TIMESTAMPNS ? 1 : 3;
246 cts[i].tv_sec = ts[i].tv_sec; 244 int i;
247 cts[i].tv_nsec = ts[i].tv_nsec; 245 struct timespec *ts = (struct timespec *)data;
246 for (i = 0; i < count; i++) {
247 cts[i].tv_sec = ts[i].tv_sec;
248 cts[i].tv_nsec = ts[i].tv_nsec;
249 }
250 data = &cts;
251 len = sizeof(cts[0]) * count;
248 } 252 }
249 data = &cts;
250 len = sizeof(cts[0]) * count;
251 } 253 }
252 254
253 cmlen = CMSG_COMPAT_LEN(len); 255 cmlen = CMSG_COMPAT_LEN(len);
@@ -454,11 +456,15 @@ static int compat_sock_getsockopt(struct socket *sock, int level, int optname,
454 456
455int compat_sock_get_timestamp(struct sock *sk, struct timeval __user *userstamp) 457int compat_sock_get_timestamp(struct sock *sk, struct timeval __user *userstamp)
456{ 458{
457 struct compat_timeval __user *ctv = 459 struct compat_timeval __user *ctv;
458 (struct compat_timeval __user *) userstamp; 460 int err;
459 int err = -ENOENT;
460 struct timeval tv; 461 struct timeval tv;
461 462
463 if (COMPAT_USE_64BIT_TIME)
464 return sock_get_timestamp(sk, userstamp);
465
466 ctv = (struct compat_timeval __user *) userstamp;
467 err = -ENOENT;
462 if (!sock_flag(sk, SOCK_TIMESTAMP)) 468 if (!sock_flag(sk, SOCK_TIMESTAMP))
463 sock_enable_timestamp(sk, SOCK_TIMESTAMP); 469 sock_enable_timestamp(sk, SOCK_TIMESTAMP);
464 tv = ktime_to_timeval(sk->sk_stamp); 470 tv = ktime_to_timeval(sk->sk_stamp);
@@ -478,11 +484,15 @@ EXPORT_SYMBOL(compat_sock_get_timestamp);
478 484
479int compat_sock_get_timestampns(struct sock *sk, struct timespec __user *userstamp) 485int compat_sock_get_timestampns(struct sock *sk, struct timespec __user *userstamp)
480{ 486{
481 struct compat_timespec __user *ctv = 487 struct compat_timespec __user *ctv;
482 (struct compat_timespec __user *) userstamp; 488 int err;
483 int err = -ENOENT;
484 struct timespec ts; 489 struct timespec ts;
485 490
491 if (COMPAT_USE_64BIT_TIME)
492 return sock_get_timestampns (sk, userstamp);
493
494 ctv = (struct compat_timespec __user *) userstamp;
495 err = -ENOENT;
486 if (!sock_flag(sk, SOCK_TIMESTAMP)) 496 if (!sock_flag(sk, SOCK_TIMESTAMP))
487 sock_enable_timestamp(sk, SOCK_TIMESTAMP); 497 sock_enable_timestamp(sk, SOCK_TIMESTAMP);
488 ts = ktime_to_timespec(sk->sk_stamp); 498 ts = ktime_to_timespec(sk->sk_stamp);
@@ -767,6 +777,11 @@ asmlinkage long compat_sys_recvmmsg(int fd, struct compat_mmsghdr __user *mmsg,
767 int datagrams; 777 int datagrams;
768 struct timespec ktspec; 778 struct timespec ktspec;
769 779
780 if (COMPAT_USE_64BIT_TIME)
781 return __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen,
782 flags | MSG_CMSG_COMPAT,
783 (struct timespec *) timeout);
784
770 if (timeout == NULL) 785 if (timeout == NULL)
771 return __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen, 786 return __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen,
772 flags | MSG_CMSG_COMPAT, NULL); 787 flags | MSG_CMSG_COMPAT, NULL);
diff --git a/net/socket.c b/net/socket.c
index 12a48d846223..484cc6953fc6 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -2592,7 +2592,7 @@ void socket_seq_show(struct seq_file *seq)
2592 2592
2593#ifdef CONFIG_COMPAT 2593#ifdef CONFIG_COMPAT
2594static int do_siocgstamp(struct net *net, struct socket *sock, 2594static int do_siocgstamp(struct net *net, struct socket *sock,
2595 unsigned int cmd, struct compat_timeval __user *up) 2595 unsigned int cmd, void __user *up)
2596{ 2596{
2597 mm_segment_t old_fs = get_fs(); 2597 mm_segment_t old_fs = get_fs();
2598 struct timeval ktv; 2598 struct timeval ktv;
@@ -2601,15 +2601,14 @@ static int do_siocgstamp(struct net *net, struct socket *sock,
2601 set_fs(KERNEL_DS); 2601 set_fs(KERNEL_DS);
2602 err = sock_do_ioctl(net, sock, cmd, (unsigned long)&ktv); 2602 err = sock_do_ioctl(net, sock, cmd, (unsigned long)&ktv);
2603 set_fs(old_fs); 2603 set_fs(old_fs);
2604 if (!err) { 2604 if (!err)
2605 err = put_user(ktv.tv_sec, &up->tv_sec); 2605 err = compat_put_timeval(up, &ktv);
2606 err |= __put_user(ktv.tv_usec, &up->tv_usec); 2606
2607 }
2608 return err; 2607 return err;
2609} 2608}
2610 2609
2611static int do_siocgstampns(struct net *net, struct socket *sock, 2610static int do_siocgstampns(struct net *net, struct socket *sock,
2612 unsigned int cmd, struct compat_timespec __user *up) 2611 unsigned int cmd, void __user *up)
2613{ 2612{
2614 mm_segment_t old_fs = get_fs(); 2613 mm_segment_t old_fs = get_fs();
2615 struct timespec kts; 2614 struct timespec kts;
@@ -2618,10 +2617,9 @@ static int do_siocgstampns(struct net *net, struct socket *sock,
2618 set_fs(KERNEL_DS); 2617 set_fs(KERNEL_DS);
2619 err = sock_do_ioctl(net, sock, cmd, (unsigned long)&kts); 2618 err = sock_do_ioctl(net, sock, cmd, (unsigned long)&kts);
2620 set_fs(old_fs); 2619 set_fs(old_fs);
2621 if (!err) { 2620 if (!err)
2622 err = put_user(kts.tv_sec, &up->tv_sec); 2621 err = compat_put_timespec(up, &kts);
2623 err |= __put_user(kts.tv_nsec, &up->tv_nsec); 2622
2624 }
2625 return err; 2623 return err;
2626} 2624}
2627 2625
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 304929909375..15c6c567468b 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -2147,7 +2147,7 @@ static inline void flush_unauthorized_files(const struct cred *cred,
2147 fdt = files_fdtable(files); 2147 fdt = files_fdtable(files);
2148 if (i >= fdt->max_fds) 2148 if (i >= fdt->max_fds)
2149 break; 2149 break;
2150 set = fdt->open_fds->fds_bits[j]; 2150 set = fdt->open_fds[j];
2151 if (!set) 2151 if (!set)
2152 continue; 2152 continue;
2153 spin_unlock(&files->file_lock); 2153 spin_unlock(&files->file_lock);