bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Linux syscalls |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3 | * |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 4 | * Copyright (c) 2003 Fabrice Bellard |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
Blue Swirl | 8167ee8 | 2009-07-16 20:47:01 +0000 | [diff] [blame] | 17 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 18 | */ |
Eduardo Habkost | d5b3a9b | 2009-06-09 18:26:31 -0300 | [diff] [blame] | 19 | #define _ATFILE_SOURCE |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 20 | #include <stdlib.h> |
| 21 | #include <stdio.h> |
| 22 | #include <stdarg.h> |
bellard | 04369ff | 2003-03-20 22:33:23 +0000 | [diff] [blame] | 23 | #include <string.h> |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 24 | #include <elf.h> |
| 25 | #include <endian.h> |
| 26 | #include <errno.h> |
| 27 | #include <unistd.h> |
| 28 | #include <fcntl.h> |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 29 | #include <time.h> |
pbrook | 82e671d | 2008-06-09 12:10:22 +0000 | [diff] [blame] | 30 | #include <limits.h> |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 31 | #include <sys/types.h> |
ths | d08d3bb | 2007-03-19 13:09:22 +0000 | [diff] [blame] | 32 | #include <sys/ipc.h> |
| 33 | #include <sys/msg.h> |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 34 | #include <sys/wait.h> |
| 35 | #include <sys/time.h> |
| 36 | #include <sys/stat.h> |
| 37 | #include <sys/mount.h> |
ths | 39b9aae | 2007-02-11 18:36:44 +0000 | [diff] [blame] | 38 | #include <sys/prctl.h> |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 39 | #include <sys/resource.h> |
| 40 | #include <sys/mman.h> |
| 41 | #include <sys/swap.h> |
| 42 | #include <signal.h> |
| 43 | #include <sched.h> |
Aurelien Jarno | 60e9924 | 2010-03-29 02:12:51 +0200 | [diff] [blame] | 44 | #ifdef __ia64__ |
| 45 | int __clone2(int (*fn)(void *), void *child_stack_base, |
| 46 | size_t stack_size, int flags, void *arg, ...); |
| 47 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 48 | #include <sys/socket.h> |
aurel32 | 607175e | 2009-04-15 16:11:59 +0000 | [diff] [blame] | 49 | #include <sys/un.h> |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 50 | #include <sys/uio.h> |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 51 | #include <sys/poll.h> |
bellard | 32f36bc | 2003-03-30 21:29:48 +0000 | [diff] [blame] | 52 | #include <sys/times.h> |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 53 | #include <sys/shm.h> |
ths | fa29481 | 2007-02-02 22:05:00 +0000 | [diff] [blame] | 54 | #include <sys/sem.h> |
bellard | 56c8f68 | 2005-11-28 22:28:41 +0000 | [diff] [blame] | 55 | #include <sys/statfs.h> |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 56 | #include <utime.h> |
bellard | a5448a7 | 2004-06-19 16:59:03 +0000 | [diff] [blame] | 57 | #include <sys/sysinfo.h> |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 58 | #include <sys/utsname.h> |
bellard | 72f0390 | 2003-02-18 23:33:18 +0000 | [diff] [blame] | 59 | //#include <sys/user.h> |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 60 | #include <netinet/ip.h> |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 61 | #include <netinet/tcp.h> |
Laurent Vivier | 86fcd94 | 2011-03-30 01:35:23 +0200 | [diff] [blame] | 62 | #include <linux/wireless.h> |
Jing Huang | 920394d | 2012-07-24 13:59:23 +0000 | [diff] [blame] | 63 | #include <linux/icmp.h> |
Stefan Weil | 5a61cb6 | 2011-09-08 17:55:32 +0200 | [diff] [blame] | 64 | #include "qemu-common.h" |
Juan Quintela | 9788c9c | 2009-07-27 16:13:02 +0200 | [diff] [blame] | 65 | #ifdef TARGET_GPROF |
aurel32 | 6d946cd | 2008-11-06 16:15:18 +0000 | [diff] [blame] | 66 | #include <sys/gmon.h> |
| 67 | #endif |
Riku Voipio | c2882b9 | 2009-08-12 15:08:24 +0300 | [diff] [blame] | 68 | #ifdef CONFIG_EVENTFD |
| 69 | #include <sys/eventfd.h> |
| 70 | #endif |
Peter Maydell | 3b6edd1 | 2011-02-15 18:35:05 +0000 | [diff] [blame] | 71 | #ifdef CONFIG_EPOLL |
| 72 | #include <sys/epoll.h> |
| 73 | #endif |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 74 | #ifdef CONFIG_ATTR |
Avi Kivity | 4f26f2b | 2011-11-09 14:44:52 +0200 | [diff] [blame] | 75 | #include "qemu-xattr.h" |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 76 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 77 | |
| 78 | #define termios host_termios |
| 79 | #define winsize host_winsize |
| 80 | #define termio host_termio |
bellard | 04369ff | 2003-03-20 22:33:23 +0000 | [diff] [blame] | 81 | #define sgttyb host_sgttyb /* same as target */ |
| 82 | #define tchars host_tchars /* same as target */ |
| 83 | #define ltchars host_ltchars /* same as target */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 84 | |
| 85 | #include <linux/termios.h> |
| 86 | #include <linux/unistd.h> |
| 87 | #include <linux/utsname.h> |
| 88 | #include <linux/cdrom.h> |
| 89 | #include <linux/hdreg.h> |
| 90 | #include <linux/soundcard.h> |
bellard | 19b84f3 | 2003-05-08 15:41:49 +0000 | [diff] [blame] | 91 | #include <linux/kd.h> |
balrog | 8fbd6b5 | 2008-09-20 03:03:09 +0000 | [diff] [blame] | 92 | #include <linux/mtio.h> |
Martin Mohring | 350d177 | 2009-05-04 21:21:41 +0300 | [diff] [blame] | 93 | #include <linux/fs.h> |
Peter Maydell | dace20d | 2011-01-10 13:11:24 +0000 | [diff] [blame] | 94 | #if defined(CONFIG_FIEMAP) |
Peter Maydell | 285da2b | 2011-01-06 15:04:18 +0000 | [diff] [blame] | 95 | #include <linux/fiemap.h> |
Peter Maydell | dace20d | 2011-01-10 13:11:24 +0000 | [diff] [blame] | 96 | #endif |
Ulrich Hecht | f7680a5 | 2009-10-16 17:00:44 +0200 | [diff] [blame] | 97 | #include <linux/fb.h> |
| 98 | #include <linux/vt.h> |
Alexander Graf | 56e904e | 2012-01-31 18:42:06 +0100 | [diff] [blame] | 99 | #include <linux/dm-ioctl.h> |
pbrook | d7e4036 | 2008-05-23 16:06:43 +0000 | [diff] [blame] | 100 | #include "linux_loop.h" |
Loïc Minier | da79030 | 2009-12-29 22:06:13 +0100 | [diff] [blame] | 101 | #include "cpu-uname.h" |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 102 | |
bellard | 3ef693a | 2003-03-23 20:17:16 +0000 | [diff] [blame] | 103 | #include "qemu.h" |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 104 | |
Juan Quintela | 2f7bb87 | 2009-07-27 16:13:24 +0200 | [diff] [blame] | 105 | #if defined(CONFIG_USE_NPTL) |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 106 | #define CLONE_NPTL_FLAGS2 (CLONE_SETTLS | \ |
| 107 | CLONE_PARENT_SETTID | CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID) |
| 108 | #else |
| 109 | /* XXX: Hardcode the above values. */ |
| 110 | #define CLONE_NPTL_FLAGS2 0 |
pbrook | 30813ce | 2008-06-02 15:45:44 +0000 | [diff] [blame] | 111 | #endif |
| 112 | |
bellard | 72f0390 | 2003-02-18 23:33:18 +0000 | [diff] [blame] | 113 | //#define DEBUG |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 114 | |
bellard | 1a9353d | 2003-03-16 20:28:50 +0000 | [diff] [blame] | 115 | //#include <linux/msdos_fs.h> |
aurel32 | 6556a83 | 2008-10-13 21:08:17 +0000 | [diff] [blame] | 116 | #define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, struct linux_dirent [2]) |
| 117 | #define VFAT_IOCTL_READDIR_SHORT _IOR('r', 2, struct linux_dirent [2]) |
bellard | 1a9353d | 2003-03-16 20:28:50 +0000 | [diff] [blame] | 118 | |
bellard | 70a194b | 2003-08-11 22:20:16 +0000 | [diff] [blame] | 119 | |
bellard | 70a194b | 2003-08-11 22:20:16 +0000 | [diff] [blame] | 120 | #undef _syscall0 |
| 121 | #undef _syscall1 |
| 122 | #undef _syscall2 |
| 123 | #undef _syscall3 |
| 124 | #undef _syscall4 |
| 125 | #undef _syscall5 |
bellard | 83fcb51 | 2006-06-14 13:37:16 +0000 | [diff] [blame] | 126 | #undef _syscall6 |
bellard | 70a194b | 2003-08-11 22:20:16 +0000 | [diff] [blame] | 127 | |
bellard | 83fcb51 | 2006-06-14 13:37:16 +0000 | [diff] [blame] | 128 | #define _syscall0(type,name) \ |
blueswir1 | 8fcd369 | 2008-08-17 20:26:25 +0000 | [diff] [blame] | 129 | static type name (void) \ |
bellard | 83fcb51 | 2006-06-14 13:37:16 +0000 | [diff] [blame] | 130 | { \ |
| 131 | return syscall(__NR_##name); \ |
bellard | 70a194b | 2003-08-11 22:20:16 +0000 | [diff] [blame] | 132 | } |
| 133 | |
bellard | 83fcb51 | 2006-06-14 13:37:16 +0000 | [diff] [blame] | 134 | #define _syscall1(type,name,type1,arg1) \ |
blueswir1 | 8fcd369 | 2008-08-17 20:26:25 +0000 | [diff] [blame] | 135 | static type name (type1 arg1) \ |
bellard | 83fcb51 | 2006-06-14 13:37:16 +0000 | [diff] [blame] | 136 | { \ |
| 137 | return syscall(__NR_##name, arg1); \ |
bellard | 70a194b | 2003-08-11 22:20:16 +0000 | [diff] [blame] | 138 | } |
| 139 | |
bellard | 83fcb51 | 2006-06-14 13:37:16 +0000 | [diff] [blame] | 140 | #define _syscall2(type,name,type1,arg1,type2,arg2) \ |
blueswir1 | 8fcd369 | 2008-08-17 20:26:25 +0000 | [diff] [blame] | 141 | static type name (type1 arg1,type2 arg2) \ |
bellard | 83fcb51 | 2006-06-14 13:37:16 +0000 | [diff] [blame] | 142 | { \ |
| 143 | return syscall(__NR_##name, arg1, arg2); \ |
bellard | 70a194b | 2003-08-11 22:20:16 +0000 | [diff] [blame] | 144 | } |
| 145 | |
bellard | 83fcb51 | 2006-06-14 13:37:16 +0000 | [diff] [blame] | 146 | #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \ |
blueswir1 | 8fcd369 | 2008-08-17 20:26:25 +0000 | [diff] [blame] | 147 | static type name (type1 arg1,type2 arg2,type3 arg3) \ |
bellard | 83fcb51 | 2006-06-14 13:37:16 +0000 | [diff] [blame] | 148 | { \ |
| 149 | return syscall(__NR_##name, arg1, arg2, arg3); \ |
bellard | 70a194b | 2003-08-11 22:20:16 +0000 | [diff] [blame] | 150 | } |
| 151 | |
bellard | 83fcb51 | 2006-06-14 13:37:16 +0000 | [diff] [blame] | 152 | #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ |
blueswir1 | 8fcd369 | 2008-08-17 20:26:25 +0000 | [diff] [blame] | 153 | static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4) \ |
bellard | 83fcb51 | 2006-06-14 13:37:16 +0000 | [diff] [blame] | 154 | { \ |
| 155 | return syscall(__NR_##name, arg1, arg2, arg3, arg4); \ |
bellard | 70a194b | 2003-08-11 22:20:16 +0000 | [diff] [blame] | 156 | } |
| 157 | |
bellard | 83fcb51 | 2006-06-14 13:37:16 +0000 | [diff] [blame] | 158 | #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ |
| 159 | type5,arg5) \ |
blueswir1 | 8fcd369 | 2008-08-17 20:26:25 +0000 | [diff] [blame] | 160 | static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \ |
bellard | 83fcb51 | 2006-06-14 13:37:16 +0000 | [diff] [blame] | 161 | { \ |
| 162 | return syscall(__NR_##name, arg1, arg2, arg3, arg4, arg5); \ |
bellard | 70a194b | 2003-08-11 22:20:16 +0000 | [diff] [blame] | 163 | } |
bellard | 83fcb51 | 2006-06-14 13:37:16 +0000 | [diff] [blame] | 164 | |
| 165 | |
| 166 | #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ |
| 167 | type5,arg5,type6,arg6) \ |
blueswir1 | 8fcd369 | 2008-08-17 20:26:25 +0000 | [diff] [blame] | 168 | static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5, \ |
| 169 | type6 arg6) \ |
bellard | 83fcb51 | 2006-06-14 13:37:16 +0000 | [diff] [blame] | 170 | { \ |
| 171 | return syscall(__NR_##name, arg1, arg2, arg3, arg4, arg5, arg6); \ |
| 172 | } |
| 173 | |
bellard | 70a194b | 2003-08-11 22:20:16 +0000 | [diff] [blame] | 174 | |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 175 | #define __NR_sys_uname __NR_uname |
ths | 92a34c1 | 2007-09-24 09:27:49 +0000 | [diff] [blame] | 176 | #define __NR_sys_faccessat __NR_faccessat |
ths | 814d797 | 2007-09-24 09:26:51 +0000 | [diff] [blame] | 177 | #define __NR_sys_fchmodat __NR_fchmodat |
ths | ccfa72b | 2007-09-24 09:23:34 +0000 | [diff] [blame] | 178 | #define __NR_sys_fchownat __NR_fchownat |
balrog | 6a24a77 | 2008-09-20 02:23:36 +0000 | [diff] [blame] | 179 | #define __NR_sys_fstatat64 __NR_fstatat64 |
balrog | ac8a655 | 2008-09-20 02:25:39 +0000 | [diff] [blame] | 180 | #define __NR_sys_futimesat __NR_futimesat |
bellard | 72f0390 | 2003-02-18 23:33:18 +0000 | [diff] [blame] | 181 | #define __NR_sys_getcwd1 __NR_getcwd |
bellard | 72f0390 | 2003-02-18 23:33:18 +0000 | [diff] [blame] | 182 | #define __NR_sys_getdents __NR_getdents |
bellard | dab2ed9 | 2003-03-22 15:23:14 +0000 | [diff] [blame] | 183 | #define __NR_sys_getdents64 __NR_getdents64 |
ths | c6cda17 | 2007-10-09 03:42:34 +0000 | [diff] [blame] | 184 | #define __NR_sys_getpriority __NR_getpriority |
ths | 64f0ce4 | 2007-09-24 09:25:06 +0000 | [diff] [blame] | 185 | #define __NR_sys_linkat __NR_linkat |
ths | 4472ad0 | 2007-09-24 09:22:32 +0000 | [diff] [blame] | 186 | #define __NR_sys_mkdirat __NR_mkdirat |
ths | 75ac37a | 2007-09-24 09:23:05 +0000 | [diff] [blame] | 187 | #define __NR_sys_mknodat __NR_mknodat |
aurel32 | 9d33b76 | 2009-04-08 23:07:05 +0000 | [diff] [blame] | 188 | #define __NR_sys_newfstatat __NR_newfstatat |
ths | 8242483 | 2007-09-24 09:21:55 +0000 | [diff] [blame] | 189 | #define __NR_sys_openat __NR_openat |
ths | 5e0ccb1 | 2007-09-24 09:26:10 +0000 | [diff] [blame] | 190 | #define __NR_sys_readlinkat __NR_readlinkat |
ths | 722183f | 2007-09-24 09:24:37 +0000 | [diff] [blame] | 191 | #define __NR_sys_renameat __NR_renameat |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 192 | #define __NR_sys_rt_sigqueueinfo __NR_rt_sigqueueinfo |
ths | f0b6243 | 2007-09-24 09:25:40 +0000 | [diff] [blame] | 193 | #define __NR_sys_symlinkat __NR_symlinkat |
ths | 7494b0f | 2007-02-11 18:26:53 +0000 | [diff] [blame] | 194 | #define __NR_sys_syslog __NR_syslog |
ths | 7145557 | 2007-06-21 21:45:30 +0000 | [diff] [blame] | 195 | #define __NR_sys_tgkill __NR_tgkill |
ths | 4cae1d1 | 2007-07-12 11:06:53 +0000 | [diff] [blame] | 196 | #define __NR_sys_tkill __NR_tkill |
ths | 8170f56 | 2007-09-24 09:24:11 +0000 | [diff] [blame] | 197 | #define __NR_sys_unlinkat __NR_unlinkat |
ths | 9007f0e | 2007-09-25 17:50:37 +0000 | [diff] [blame] | 198 | #define __NR_sys_utimensat __NR_utimensat |
pbrook | bd0c566 | 2008-05-29 14:34:11 +0000 | [diff] [blame] | 199 | #define __NR_sys_futex __NR_futex |
aurel32 | 39b5976 | 2008-10-01 21:46:50 +0000 | [diff] [blame] | 200 | #define __NR_sys_inotify_init __NR_inotify_init |
| 201 | #define __NR_sys_inotify_add_watch __NR_inotify_add_watch |
| 202 | #define __NR_sys_inotify_rm_watch __NR_inotify_rm_watch |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 203 | |
Alexander Graf | 42a39fb | 2011-04-15 17:32:45 +0200 | [diff] [blame] | 204 | #if defined(__alpha__) || defined (__ia64__) || defined(__x86_64__) || \ |
| 205 | defined(__s390x__) |
bellard | 9af9eaa | 2003-04-07 21:34:41 +0000 | [diff] [blame] | 206 | #define __NR__llseek __NR_lseek |
| 207 | #endif |
| 208 | |
bellard | 72f0390 | 2003-02-18 23:33:18 +0000 | [diff] [blame] | 209 | #ifdef __NR_gettid |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 210 | _syscall0(int, gettid) |
bellard | 72f0390 | 2003-02-18 23:33:18 +0000 | [diff] [blame] | 211 | #else |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 212 | /* This is a replacement for the host gettid() and must return a host |
| 213 | errno. */ |
bellard | 72f0390 | 2003-02-18 23:33:18 +0000 | [diff] [blame] | 214 | static int gettid(void) { |
| 215 | return -ENOSYS; |
| 216 | } |
| 217 | #endif |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 218 | _syscall3(int, sys_getdents, uint, fd, struct linux_dirent *, dirp, uint, count); |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 219 | #if defined(TARGET_NR_getdents64) && defined(__NR_getdents64) |
| 220 | _syscall3(int, sys_getdents64, uint, fd, struct linux_dirent64 *, dirp, uint, count); |
| 221 | #endif |
Richard Henderson | d35b261 | 2010-06-04 12:14:10 -0700 | [diff] [blame] | 222 | #if defined(TARGET_NR__llseek) && defined(__NR_llseek) |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 223 | _syscall5(int, _llseek, uint, fd, ulong, hi, ulong, lo, |
| 224 | loff_t *, res, uint, wh); |
| 225 | #endif |
| 226 | _syscall3(int,sys_rt_sigqueueinfo,int,pid,int,sig,siginfo_t *,uinfo) |
| 227 | _syscall3(int,sys_syslog,int,type,char*,bufp,int,len) |
| 228 | #if defined(TARGET_NR_tgkill) && defined(__NR_tgkill) |
| 229 | _syscall3(int,sys_tgkill,int,tgid,int,pid,int,sig) |
| 230 | #endif |
| 231 | #if defined(TARGET_NR_tkill) && defined(__NR_tkill) |
| 232 | _syscall2(int,sys_tkill,int,tid,int,sig) |
| 233 | #endif |
| 234 | #ifdef __NR_exit_group |
| 235 | _syscall1(int,exit_group,int,error_code) |
| 236 | #endif |
| 237 | #if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address) |
| 238 | _syscall1(int,set_tid_address,int *,tidptr) |
| 239 | #endif |
Juan Quintela | 2f7bb87 | 2009-07-27 16:13:24 +0200 | [diff] [blame] | 240 | #if defined(CONFIG_USE_NPTL) |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 241 | #if defined(TARGET_NR_futex) && defined(__NR_futex) |
| 242 | _syscall6(int,sys_futex,int *,uaddr,int,op,int,val, |
| 243 | const struct timespec *,timeout,int *,uaddr2,int,val3) |
| 244 | #endif |
| 245 | #endif |
Mike Frysinger | 737de1d | 2011-02-07 01:05:55 -0500 | [diff] [blame] | 246 | #define __NR_sys_sched_getaffinity __NR_sched_getaffinity |
| 247 | _syscall3(int, sys_sched_getaffinity, pid_t, pid, unsigned int, len, |
| 248 | unsigned long *, user_mask_ptr); |
| 249 | #define __NR_sys_sched_setaffinity __NR_sched_setaffinity |
| 250 | _syscall3(int, sys_sched_setaffinity, pid_t, pid, unsigned int, len, |
| 251 | unsigned long *, user_mask_ptr); |
Alexander Graf | 0f6b4d2 | 2011-09-27 14:39:42 +0200 | [diff] [blame] | 252 | _syscall4(int, reboot, int, magic1, int, magic2, unsigned int, cmd, |
| 253 | void *, arg); |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 254 | |
| 255 | static bitmask_transtbl fcntl_flags_tbl[] = { |
| 256 | { TARGET_O_ACCMODE, TARGET_O_WRONLY, O_ACCMODE, O_WRONLY, }, |
| 257 | { TARGET_O_ACCMODE, TARGET_O_RDWR, O_ACCMODE, O_RDWR, }, |
| 258 | { TARGET_O_CREAT, TARGET_O_CREAT, O_CREAT, O_CREAT, }, |
| 259 | { TARGET_O_EXCL, TARGET_O_EXCL, O_EXCL, O_EXCL, }, |
| 260 | { TARGET_O_NOCTTY, TARGET_O_NOCTTY, O_NOCTTY, O_NOCTTY, }, |
| 261 | { TARGET_O_TRUNC, TARGET_O_TRUNC, O_TRUNC, O_TRUNC, }, |
| 262 | { TARGET_O_APPEND, TARGET_O_APPEND, O_APPEND, O_APPEND, }, |
| 263 | { TARGET_O_NONBLOCK, TARGET_O_NONBLOCK, O_NONBLOCK, O_NONBLOCK, }, |
Richard Henderson | afc8763 | 2012-07-25 14:30:34 -0700 | [diff] [blame] | 264 | { TARGET_O_SYNC, TARGET_O_DSYNC, O_SYNC, O_DSYNC, }, |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 265 | { TARGET_O_SYNC, TARGET_O_SYNC, O_SYNC, O_SYNC, }, |
| 266 | { TARGET_FASYNC, TARGET_FASYNC, FASYNC, FASYNC, }, |
| 267 | { TARGET_O_DIRECTORY, TARGET_O_DIRECTORY, O_DIRECTORY, O_DIRECTORY, }, |
| 268 | { TARGET_O_NOFOLLOW, TARGET_O_NOFOLLOW, O_NOFOLLOW, O_NOFOLLOW, }, |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 269 | #if defined(O_DIRECT) |
| 270 | { TARGET_O_DIRECT, TARGET_O_DIRECT, O_DIRECT, O_DIRECT, }, |
| 271 | #endif |
Richard Henderson | afc8763 | 2012-07-25 14:30:34 -0700 | [diff] [blame] | 272 | #if defined(O_NOATIME) |
| 273 | { TARGET_O_NOATIME, TARGET_O_NOATIME, O_NOATIME, O_NOATIME }, |
| 274 | #endif |
| 275 | #if defined(O_CLOEXEC) |
| 276 | { TARGET_O_CLOEXEC, TARGET_O_CLOEXEC, O_CLOEXEC, O_CLOEXEC }, |
| 277 | #endif |
| 278 | #if defined(O_PATH) |
| 279 | { TARGET_O_PATH, TARGET_O_PATH, O_PATH, O_PATH }, |
| 280 | #endif |
| 281 | /* Don't terminate the list prematurely on 64-bit host+guest. */ |
| 282 | #if TARGET_O_LARGEFILE != 0 || O_LARGEFILE != 0 |
| 283 | { TARGET_O_LARGEFILE, TARGET_O_LARGEFILE, O_LARGEFILE, O_LARGEFILE, }, |
| 284 | #endif |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 285 | { 0, 0, 0, 0 } |
| 286 | }; |
| 287 | |
| 288 | #define COPY_UTSNAME_FIELD(dest, src) \ |
| 289 | do { \ |
| 290 | /* __NEW_UTS_LEN doesn't include terminating null */ \ |
| 291 | (void) strncpy((dest), (src), __NEW_UTS_LEN); \ |
| 292 | (dest)[__NEW_UTS_LEN] = '\0'; \ |
| 293 | } while (0) |
| 294 | |
| 295 | static int sys_uname(struct new_utsname *buf) |
| 296 | { |
| 297 | struct utsname uts_buf; |
| 298 | |
| 299 | if (uname(&uts_buf) < 0) |
| 300 | return (-1); |
| 301 | |
| 302 | /* |
| 303 | * Just in case these have some differences, we |
| 304 | * translate utsname to new_utsname (which is the |
| 305 | * struct linux kernel uses). |
| 306 | */ |
| 307 | |
Stefan Weil | 67bd9ed | 2011-05-07 22:32:25 +0200 | [diff] [blame] | 308 | memset(buf, 0, sizeof(*buf)); |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 309 | COPY_UTSNAME_FIELD(buf->sysname, uts_buf.sysname); |
| 310 | COPY_UTSNAME_FIELD(buf->nodename, uts_buf.nodename); |
| 311 | COPY_UTSNAME_FIELD(buf->release, uts_buf.release); |
| 312 | COPY_UTSNAME_FIELD(buf->version, uts_buf.version); |
| 313 | COPY_UTSNAME_FIELD(buf->machine, uts_buf.machine); |
| 314 | #ifdef _GNU_SOURCE |
| 315 | COPY_UTSNAME_FIELD(buf->domainname, uts_buf.domainname); |
| 316 | #endif |
| 317 | return (0); |
| 318 | |
| 319 | #undef COPY_UTSNAME_FIELD |
| 320 | } |
| 321 | |
| 322 | static int sys_getcwd1(char *buf, size_t size) |
| 323 | { |
| 324 | if (getcwd(buf, size) == NULL) { |
| 325 | /* getcwd() sets errno */ |
| 326 | return (-1); |
| 327 | } |
aurel32 | aaf4ad3 | 2009-04-16 14:17:14 +0000 | [diff] [blame] | 328 | return strlen(buf)+1; |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | #ifdef CONFIG_ATFILE |
| 332 | /* |
| 333 | * Host system seems to have atfile syscall stubs available. We |
| 334 | * now enable them one by one as specified by target syscall_nr.h. |
| 335 | */ |
| 336 | |
| 337 | #ifdef TARGET_NR_faccessat |
aurel32 | 465c9f0 | 2009-04-19 08:52:17 +0000 | [diff] [blame] | 338 | static int sys_faccessat(int dirfd, const char *pathname, int mode) |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 339 | { |
aurel32 | 465c9f0 | 2009-04-19 08:52:17 +0000 | [diff] [blame] | 340 | return (faccessat(dirfd, pathname, mode, 0)); |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 341 | } |
| 342 | #endif |
| 343 | #ifdef TARGET_NR_fchmodat |
aurel32 | 465c9f0 | 2009-04-19 08:52:17 +0000 | [diff] [blame] | 344 | static int sys_fchmodat(int dirfd, const char *pathname, mode_t mode) |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 345 | { |
aurel32 | 465c9f0 | 2009-04-19 08:52:17 +0000 | [diff] [blame] | 346 | return (fchmodat(dirfd, pathname, mode, 0)); |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 347 | } |
| 348 | #endif |
Riku Voipio | 0c866a7 | 2011-04-18 15:23:06 +0300 | [diff] [blame] | 349 | #if defined(TARGET_NR_fchownat) |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 350 | static int sys_fchownat(int dirfd, const char *pathname, uid_t owner, |
| 351 | gid_t group, int flags) |
| 352 | { |
| 353 | return (fchownat(dirfd, pathname, owner, group, flags)); |
| 354 | } |
| 355 | #endif |
| 356 | #ifdef __NR_fstatat64 |
| 357 | static int sys_fstatat64(int dirfd, const char *pathname, struct stat *buf, |
| 358 | int flags) |
| 359 | { |
| 360 | return (fstatat(dirfd, pathname, buf, flags)); |
| 361 | } |
| 362 | #endif |
| 363 | #ifdef __NR_newfstatat |
| 364 | static int sys_newfstatat(int dirfd, const char *pathname, struct stat *buf, |
| 365 | int flags) |
| 366 | { |
| 367 | return (fstatat(dirfd, pathname, buf, flags)); |
| 368 | } |
| 369 | #endif |
| 370 | #ifdef TARGET_NR_futimesat |
| 371 | static int sys_futimesat(int dirfd, const char *pathname, |
| 372 | const struct timeval times[2]) |
| 373 | { |
| 374 | return (futimesat(dirfd, pathname, times)); |
| 375 | } |
| 376 | #endif |
| 377 | #ifdef TARGET_NR_linkat |
| 378 | static int sys_linkat(int olddirfd, const char *oldpath, |
| 379 | int newdirfd, const char *newpath, int flags) |
| 380 | { |
| 381 | return (linkat(olddirfd, oldpath, newdirfd, newpath, flags)); |
| 382 | } |
| 383 | #endif |
| 384 | #ifdef TARGET_NR_mkdirat |
| 385 | static int sys_mkdirat(int dirfd, const char *pathname, mode_t mode) |
| 386 | { |
| 387 | return (mkdirat(dirfd, pathname, mode)); |
| 388 | } |
| 389 | #endif |
| 390 | #ifdef TARGET_NR_mknodat |
| 391 | static int sys_mknodat(int dirfd, const char *pathname, mode_t mode, |
| 392 | dev_t dev) |
| 393 | { |
| 394 | return (mknodat(dirfd, pathname, mode, dev)); |
| 395 | } |
| 396 | #endif |
| 397 | #ifdef TARGET_NR_openat |
Alexander Graf | f4c6901 | 2011-09-25 06:25:35 +0200 | [diff] [blame] | 398 | static int sys_openat(int dirfd, const char *pathname, int flags, mode_t mode) |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 399 | { |
| 400 | /* |
| 401 | * open(2) has extra parameter 'mode' when called with |
| 402 | * flag O_CREAT. |
| 403 | */ |
| 404 | if ((flags & O_CREAT) != 0) { |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 405 | return (openat(dirfd, pathname, flags, mode)); |
| 406 | } |
| 407 | return (openat(dirfd, pathname, flags)); |
| 408 | } |
| 409 | #endif |
| 410 | #ifdef TARGET_NR_readlinkat |
| 411 | static int sys_readlinkat(int dirfd, const char *pathname, char *buf, size_t bufsiz) |
| 412 | { |
| 413 | return (readlinkat(dirfd, pathname, buf, bufsiz)); |
| 414 | } |
| 415 | #endif |
| 416 | #ifdef TARGET_NR_renameat |
| 417 | static int sys_renameat(int olddirfd, const char *oldpath, |
| 418 | int newdirfd, const char *newpath) |
| 419 | { |
| 420 | return (renameat(olddirfd, oldpath, newdirfd, newpath)); |
| 421 | } |
| 422 | #endif |
| 423 | #ifdef TARGET_NR_symlinkat |
| 424 | static int sys_symlinkat(const char *oldpath, int newdirfd, const char *newpath) |
| 425 | { |
| 426 | return (symlinkat(oldpath, newdirfd, newpath)); |
| 427 | } |
| 428 | #endif |
| 429 | #ifdef TARGET_NR_unlinkat |
| 430 | static int sys_unlinkat(int dirfd, const char *pathname, int flags) |
| 431 | { |
| 432 | return (unlinkat(dirfd, pathname, flags)); |
| 433 | } |
| 434 | #endif |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 435 | #else /* !CONFIG_ATFILE */ |
| 436 | |
| 437 | /* |
| 438 | * Try direct syscalls instead |
| 439 | */ |
ths | 92a34c1 | 2007-09-24 09:27:49 +0000 | [diff] [blame] | 440 | #if defined(TARGET_NR_faccessat) && defined(__NR_faccessat) |
aurel32 | 465c9f0 | 2009-04-19 08:52:17 +0000 | [diff] [blame] | 441 | _syscall3(int,sys_faccessat,int,dirfd,const char *,pathname,int,mode) |
ths | 92a34c1 | 2007-09-24 09:27:49 +0000 | [diff] [blame] | 442 | #endif |
ths | 814d797 | 2007-09-24 09:26:51 +0000 | [diff] [blame] | 443 | #if defined(TARGET_NR_fchmodat) && defined(__NR_fchmodat) |
aurel32 | 465c9f0 | 2009-04-19 08:52:17 +0000 | [diff] [blame] | 444 | _syscall3(int,sys_fchmodat,int,dirfd,const char *,pathname, mode_t,mode) |
ths | 814d797 | 2007-09-24 09:26:51 +0000 | [diff] [blame] | 445 | #endif |
Riku Voipio | 0c866a7 | 2011-04-18 15:23:06 +0300 | [diff] [blame] | 446 | #if defined(TARGET_NR_fchownat) && defined(__NR_fchownat) |
ths | ccfa72b | 2007-09-24 09:23:34 +0000 | [diff] [blame] | 447 | _syscall5(int,sys_fchownat,int,dirfd,const char *,pathname, |
| 448 | uid_t,owner,gid_t,group,int,flags) |
| 449 | #endif |
aurel32 | 9d33b76 | 2009-04-08 23:07:05 +0000 | [diff] [blame] | 450 | #if (defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)) && \ |
| 451 | defined(__NR_fstatat64) |
balrog | 6a24a77 | 2008-09-20 02:23:36 +0000 | [diff] [blame] | 452 | _syscall4(int,sys_fstatat64,int,dirfd,const char *,pathname, |
| 453 | struct stat *,buf,int,flags) |
| 454 | #endif |
balrog | ac8a655 | 2008-09-20 02:25:39 +0000 | [diff] [blame] | 455 | #if defined(TARGET_NR_futimesat) && defined(__NR_futimesat) |
| 456 | _syscall3(int,sys_futimesat,int,dirfd,const char *,pathname, |
| 457 | const struct timeval *,times) |
| 458 | #endif |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 459 | #if (defined(TARGET_NR_newfstatat) || defined(TARGET_NR_fstatat64) ) && \ |
| 460 | defined(__NR_newfstatat) |
| 461 | _syscall4(int,sys_newfstatat,int,dirfd,const char *,pathname, |
| 462 | struct stat *,buf,int,flags) |
blueswir1 | 8fcd369 | 2008-08-17 20:26:25 +0000 | [diff] [blame] | 463 | #endif |
ths | 64f0ce4 | 2007-09-24 09:25:06 +0000 | [diff] [blame] | 464 | #if defined(TARGET_NR_linkat) && defined(__NR_linkat) |
| 465 | _syscall5(int,sys_linkat,int,olddirfd,const char *,oldpath, |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 466 | int,newdirfd,const char *,newpath,int,flags) |
ths | 64f0ce4 | 2007-09-24 09:25:06 +0000 | [diff] [blame] | 467 | #endif |
ths | 4472ad0 | 2007-09-24 09:22:32 +0000 | [diff] [blame] | 468 | #if defined(TARGET_NR_mkdirat) && defined(__NR_mkdirat) |
| 469 | _syscall3(int,sys_mkdirat,int,dirfd,const char *,pathname,mode_t,mode) |
| 470 | #endif |
ths | 75ac37a | 2007-09-24 09:23:05 +0000 | [diff] [blame] | 471 | #if defined(TARGET_NR_mknodat) && defined(__NR_mknodat) |
| 472 | _syscall4(int,sys_mknodat,int,dirfd,const char *,pathname, |
| 473 | mode_t,mode,dev_t,dev) |
| 474 | #endif |
ths | 8242483 | 2007-09-24 09:21:55 +0000 | [diff] [blame] | 475 | #if defined(TARGET_NR_openat) && defined(__NR_openat) |
| 476 | _syscall4(int,sys_openat,int,dirfd,const char *,pathname,int,flags,mode_t,mode) |
| 477 | #endif |
ths | 5e0ccb1 | 2007-09-24 09:26:10 +0000 | [diff] [blame] | 478 | #if defined(TARGET_NR_readlinkat) && defined(__NR_readlinkat) |
| 479 | _syscall4(int,sys_readlinkat,int,dirfd,const char *,pathname, |
| 480 | char *,buf,size_t,bufsize) |
| 481 | #endif |
ths | 722183f | 2007-09-24 09:24:37 +0000 | [diff] [blame] | 482 | #if defined(TARGET_NR_renameat) && defined(__NR_renameat) |
| 483 | _syscall4(int,sys_renameat,int,olddirfd,const char *,oldpath, |
| 484 | int,newdirfd,const char *,newpath) |
| 485 | #endif |
ths | b51eaa8 | 2007-09-25 16:09:22 +0000 | [diff] [blame] | 486 | #if defined(TARGET_NR_symlinkat) && defined(__NR_symlinkat) |
ths | f0b6243 | 2007-09-24 09:25:40 +0000 | [diff] [blame] | 487 | _syscall3(int,sys_symlinkat,const char *,oldpath, |
| 488 | int,newdirfd,const char *,newpath) |
| 489 | #endif |
ths | 8170f56 | 2007-09-24 09:24:11 +0000 | [diff] [blame] | 490 | #if defined(TARGET_NR_unlinkat) && defined(__NR_unlinkat) |
| 491 | _syscall3(int,sys_unlinkat,int,dirfd,const char *,pathname,int,flags) |
| 492 | #endif |
Riku Voipio | ebc996f | 2009-04-21 15:01:51 +0300 | [diff] [blame] | 493 | |
| 494 | #endif /* CONFIG_ATFILE */ |
| 495 | |
| 496 | #ifdef CONFIG_UTIMENSAT |
| 497 | static int sys_utimensat(int dirfd, const char *pathname, |
| 498 | const struct timespec times[2], int flags) |
| 499 | { |
| 500 | if (pathname == NULL) |
| 501 | return futimens(dirfd, times); |
| 502 | else |
| 503 | return utimensat(dirfd, pathname, times, flags); |
| 504 | } |
| 505 | #else |
ths | 9007f0e | 2007-09-25 17:50:37 +0000 | [diff] [blame] | 506 | #if defined(TARGET_NR_utimensat) && defined(__NR_utimensat) |
| 507 | _syscall4(int,sys_utimensat,int,dirfd,const char *,pathname, |
| 508 | const struct timespec *,tsp,int,flags) |
| 509 | #endif |
Riku Voipio | ebc996f | 2009-04-21 15:01:51 +0300 | [diff] [blame] | 510 | #endif /* CONFIG_UTIMENSAT */ |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 511 | |
| 512 | #ifdef CONFIG_INOTIFY |
aurel32 | 8690e42 | 2009-04-17 13:50:32 +0000 | [diff] [blame] | 513 | #include <sys/inotify.h> |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 514 | |
aurel32 | 39b5976 | 2008-10-01 21:46:50 +0000 | [diff] [blame] | 515 | #if defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init) |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 516 | static int sys_inotify_init(void) |
| 517 | { |
| 518 | return (inotify_init()); |
| 519 | } |
aurel32 | 39b5976 | 2008-10-01 21:46:50 +0000 | [diff] [blame] | 520 | #endif |
| 521 | #if defined(TARGET_NR_inotify_add_watch) && defined(__NR_inotify_add_watch) |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 522 | static int sys_inotify_add_watch(int fd,const char *pathname, int32_t mask) |
| 523 | { |
| 524 | return (inotify_add_watch(fd, pathname, mask)); |
| 525 | } |
aurel32 | 39b5976 | 2008-10-01 21:46:50 +0000 | [diff] [blame] | 526 | #endif |
| 527 | #if defined(TARGET_NR_inotify_rm_watch) && defined(__NR_inotify_rm_watch) |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 528 | static int sys_inotify_rm_watch(int fd, int32_t wd) |
| 529 | { |
aurel32 | 8690e42 | 2009-04-17 13:50:32 +0000 | [diff] [blame] | 530 | return (inotify_rm_watch(fd, wd)); |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 531 | } |
aurel32 | 39b5976 | 2008-10-01 21:46:50 +0000 | [diff] [blame] | 532 | #endif |
Riku Voipio | c05c7a7 | 2010-03-26 15:25:11 +0000 | [diff] [blame] | 533 | #ifdef CONFIG_INOTIFY1 |
| 534 | #if defined(TARGET_NR_inotify_init1) && defined(__NR_inotify_init1) |
| 535 | static int sys_inotify_init1(int flags) |
| 536 | { |
| 537 | return (inotify_init1(flags)); |
| 538 | } |
| 539 | #endif |
| 540 | #endif |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 541 | #else |
| 542 | /* Userspace can usually survive runtime without inotify */ |
| 543 | #undef TARGET_NR_inotify_init |
Riku Voipio | c05c7a7 | 2010-03-26 15:25:11 +0000 | [diff] [blame] | 544 | #undef TARGET_NR_inotify_init1 |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 545 | #undef TARGET_NR_inotify_add_watch |
| 546 | #undef TARGET_NR_inotify_rm_watch |
| 547 | #endif /* CONFIG_INOTIFY */ |
| 548 | |
Mike Frysinger | d8035d4 | 2011-02-07 01:05:51 -0500 | [diff] [blame] | 549 | #if defined(TARGET_NR_ppoll) |
| 550 | #ifndef __NR_ppoll |
| 551 | # define __NR_ppoll -1 |
| 552 | #endif |
| 553 | #define __NR_sys_ppoll __NR_ppoll |
| 554 | _syscall5(int, sys_ppoll, struct pollfd *, fds, nfds_t, nfds, |
| 555 | struct timespec *, timeout, const __sigset_t *, sigmask, |
| 556 | size_t, sigsetsize) |
| 557 | #endif |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 558 | |
Mike Frysinger | 055e090 | 2011-06-03 17:01:49 -0400 | [diff] [blame] | 559 | #if defined(TARGET_NR_pselect6) |
| 560 | #ifndef __NR_pselect6 |
| 561 | # define __NR_pselect6 -1 |
| 562 | #endif |
| 563 | #define __NR_sys_pselect6 __NR_pselect6 |
| 564 | _syscall6(int, sys_pselect6, int, nfds, fd_set *, readfds, fd_set *, writefds, |
| 565 | fd_set *, exceptfds, struct timespec *, timeout, void *, sig); |
| 566 | #endif |
| 567 | |
Peter Maydell | 163a05a | 2011-06-27 17:44:52 +0100 | [diff] [blame] | 568 | #if defined(TARGET_NR_prlimit64) |
| 569 | #ifndef __NR_prlimit64 |
| 570 | # define __NR_prlimit64 -1 |
| 571 | #endif |
| 572 | #define __NR_sys_prlimit64 __NR_prlimit64 |
| 573 | /* The glibc rlimit structure may not be that used by the underlying syscall */ |
| 574 | struct host_rlimit64 { |
| 575 | uint64_t rlim_cur; |
| 576 | uint64_t rlim_max; |
| 577 | }; |
| 578 | _syscall4(int, sys_prlimit64, pid_t, pid, int, resource, |
| 579 | const struct host_rlimit64 *, new_limit, |
| 580 | struct host_rlimit64 *, old_limit) |
| 581 | #endif |
| 582 | |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 583 | extern int personality(int); |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 584 | extern int flock(int, int); |
| 585 | extern int setfsuid(int); |
| 586 | extern int setfsgid(int); |
bellard | 19b84f3 | 2003-05-08 15:41:49 +0000 | [diff] [blame] | 587 | extern int setgroups(int, gid_t *); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 588 | |
Riku Voipio | 48e515d | 2011-07-12 15:40:51 +0300 | [diff] [blame] | 589 | /* ARM EABI and MIPS expect 64bit types aligned even on pairs or registers */ |
Alexander Graf | 4a1def4 | 2012-09-29 15:32:38 +0000 | [diff] [blame] | 590 | #ifdef TARGET_ARM |
Riku Voipio | 48e515d | 2011-07-12 15:40:51 +0300 | [diff] [blame] | 591 | static inline int regpairs_aligned(void *cpu_env) { |
| 592 | return ((((CPUARMState *)cpu_env)->eabi) == 1) ; |
| 593 | } |
| 594 | #elif defined(TARGET_MIPS) |
| 595 | static inline int regpairs_aligned(void *cpu_env) { return 1; } |
Alexander Graf | 4a1def4 | 2012-09-29 15:32:38 +0000 | [diff] [blame] | 596 | #elif defined(TARGET_PPC) && !defined(TARGET_PPC64) |
| 597 | /* SysV AVI for PPC32 expects 64bit parameters to be passed on odd/even pairs |
| 598 | * of registers which translates to the same as ARM/MIPS, because we start with |
| 599 | * r3 as arg1 */ |
| 600 | static inline int regpairs_aligned(void *cpu_env) { return 1; } |
Riku Voipio | 48e515d | 2011-07-12 15:40:51 +0300 | [diff] [blame] | 601 | #else |
| 602 | static inline int regpairs_aligned(void *cpu_env) { return 0; } |
| 603 | #endif |
| 604 | |
ths | b92c47c | 2007-11-01 00:07:38 +0000 | [diff] [blame] | 605 | #define ERRNO_TABLE_SIZE 1200 |
| 606 | |
| 607 | /* target_to_host_errno_table[] is initialized from |
| 608 | * host_to_target_errno_table[] in syscall_init(). */ |
| 609 | static uint16_t target_to_host_errno_table[ERRNO_TABLE_SIZE] = { |
| 610 | }; |
| 611 | |
ths | 637947f | 2007-06-01 12:09:19 +0000 | [diff] [blame] | 612 | /* |
ths | fe8f096 | 2007-07-12 10:59:21 +0000 | [diff] [blame] | 613 | * This list is the union of errno values overridden in asm-<arch>/errno.h |
ths | 637947f | 2007-06-01 12:09:19 +0000 | [diff] [blame] | 614 | * minus the errnos that are not actually generic to all archs. |
| 615 | */ |
ths | b92c47c | 2007-11-01 00:07:38 +0000 | [diff] [blame] | 616 | static uint16_t host_to_target_errno_table[ERRNO_TABLE_SIZE] = { |
ths | 637947f | 2007-06-01 12:09:19 +0000 | [diff] [blame] | 617 | [EIDRM] = TARGET_EIDRM, |
| 618 | [ECHRNG] = TARGET_ECHRNG, |
| 619 | [EL2NSYNC] = TARGET_EL2NSYNC, |
| 620 | [EL3HLT] = TARGET_EL3HLT, |
| 621 | [EL3RST] = TARGET_EL3RST, |
| 622 | [ELNRNG] = TARGET_ELNRNG, |
| 623 | [EUNATCH] = TARGET_EUNATCH, |
| 624 | [ENOCSI] = TARGET_ENOCSI, |
| 625 | [EL2HLT] = TARGET_EL2HLT, |
| 626 | [EDEADLK] = TARGET_EDEADLK, |
| 627 | [ENOLCK] = TARGET_ENOLCK, |
| 628 | [EBADE] = TARGET_EBADE, |
| 629 | [EBADR] = TARGET_EBADR, |
| 630 | [EXFULL] = TARGET_EXFULL, |
| 631 | [ENOANO] = TARGET_ENOANO, |
| 632 | [EBADRQC] = TARGET_EBADRQC, |
| 633 | [EBADSLT] = TARGET_EBADSLT, |
| 634 | [EBFONT] = TARGET_EBFONT, |
| 635 | [ENOSTR] = TARGET_ENOSTR, |
| 636 | [ENODATA] = TARGET_ENODATA, |
| 637 | [ETIME] = TARGET_ETIME, |
| 638 | [ENOSR] = TARGET_ENOSR, |
| 639 | [ENONET] = TARGET_ENONET, |
| 640 | [ENOPKG] = TARGET_ENOPKG, |
| 641 | [EREMOTE] = TARGET_EREMOTE, |
| 642 | [ENOLINK] = TARGET_ENOLINK, |
| 643 | [EADV] = TARGET_EADV, |
| 644 | [ESRMNT] = TARGET_ESRMNT, |
| 645 | [ECOMM] = TARGET_ECOMM, |
| 646 | [EPROTO] = TARGET_EPROTO, |
| 647 | [EDOTDOT] = TARGET_EDOTDOT, |
| 648 | [EMULTIHOP] = TARGET_EMULTIHOP, |
| 649 | [EBADMSG] = TARGET_EBADMSG, |
| 650 | [ENAMETOOLONG] = TARGET_ENAMETOOLONG, |
| 651 | [EOVERFLOW] = TARGET_EOVERFLOW, |
| 652 | [ENOTUNIQ] = TARGET_ENOTUNIQ, |
| 653 | [EBADFD] = TARGET_EBADFD, |
| 654 | [EREMCHG] = TARGET_EREMCHG, |
| 655 | [ELIBACC] = TARGET_ELIBACC, |
| 656 | [ELIBBAD] = TARGET_ELIBBAD, |
| 657 | [ELIBSCN] = TARGET_ELIBSCN, |
| 658 | [ELIBMAX] = TARGET_ELIBMAX, |
| 659 | [ELIBEXEC] = TARGET_ELIBEXEC, |
| 660 | [EILSEQ] = TARGET_EILSEQ, |
| 661 | [ENOSYS] = TARGET_ENOSYS, |
| 662 | [ELOOP] = TARGET_ELOOP, |
| 663 | [ERESTART] = TARGET_ERESTART, |
| 664 | [ESTRPIPE] = TARGET_ESTRPIPE, |
| 665 | [ENOTEMPTY] = TARGET_ENOTEMPTY, |
| 666 | [EUSERS] = TARGET_EUSERS, |
| 667 | [ENOTSOCK] = TARGET_ENOTSOCK, |
| 668 | [EDESTADDRREQ] = TARGET_EDESTADDRREQ, |
| 669 | [EMSGSIZE] = TARGET_EMSGSIZE, |
| 670 | [EPROTOTYPE] = TARGET_EPROTOTYPE, |
| 671 | [ENOPROTOOPT] = TARGET_ENOPROTOOPT, |
| 672 | [EPROTONOSUPPORT] = TARGET_EPROTONOSUPPORT, |
| 673 | [ESOCKTNOSUPPORT] = TARGET_ESOCKTNOSUPPORT, |
| 674 | [EOPNOTSUPP] = TARGET_EOPNOTSUPP, |
| 675 | [EPFNOSUPPORT] = TARGET_EPFNOSUPPORT, |
| 676 | [EAFNOSUPPORT] = TARGET_EAFNOSUPPORT, |
| 677 | [EADDRINUSE] = TARGET_EADDRINUSE, |
| 678 | [EADDRNOTAVAIL] = TARGET_EADDRNOTAVAIL, |
| 679 | [ENETDOWN] = TARGET_ENETDOWN, |
| 680 | [ENETUNREACH] = TARGET_ENETUNREACH, |
| 681 | [ENETRESET] = TARGET_ENETRESET, |
| 682 | [ECONNABORTED] = TARGET_ECONNABORTED, |
| 683 | [ECONNRESET] = TARGET_ECONNRESET, |
| 684 | [ENOBUFS] = TARGET_ENOBUFS, |
| 685 | [EISCONN] = TARGET_EISCONN, |
| 686 | [ENOTCONN] = TARGET_ENOTCONN, |
| 687 | [EUCLEAN] = TARGET_EUCLEAN, |
| 688 | [ENOTNAM] = TARGET_ENOTNAM, |
| 689 | [ENAVAIL] = TARGET_ENAVAIL, |
| 690 | [EISNAM] = TARGET_EISNAM, |
| 691 | [EREMOTEIO] = TARGET_EREMOTEIO, |
| 692 | [ESHUTDOWN] = TARGET_ESHUTDOWN, |
| 693 | [ETOOMANYREFS] = TARGET_ETOOMANYREFS, |
| 694 | [ETIMEDOUT] = TARGET_ETIMEDOUT, |
| 695 | [ECONNREFUSED] = TARGET_ECONNREFUSED, |
| 696 | [EHOSTDOWN] = TARGET_EHOSTDOWN, |
| 697 | [EHOSTUNREACH] = TARGET_EHOSTUNREACH, |
| 698 | [EALREADY] = TARGET_EALREADY, |
| 699 | [EINPROGRESS] = TARGET_EINPROGRESS, |
| 700 | [ESTALE] = TARGET_ESTALE, |
| 701 | [ECANCELED] = TARGET_ECANCELED, |
| 702 | [ENOMEDIUM] = TARGET_ENOMEDIUM, |
| 703 | [EMEDIUMTYPE] = TARGET_EMEDIUMTYPE, |
ths | b7fe5db | 2007-07-23 15:37:46 +0000 | [diff] [blame] | 704 | #ifdef ENOKEY |
ths | 637947f | 2007-06-01 12:09:19 +0000 | [diff] [blame] | 705 | [ENOKEY] = TARGET_ENOKEY, |
ths | b7fe5db | 2007-07-23 15:37:46 +0000 | [diff] [blame] | 706 | #endif |
| 707 | #ifdef EKEYEXPIRED |
ths | 637947f | 2007-06-01 12:09:19 +0000 | [diff] [blame] | 708 | [EKEYEXPIRED] = TARGET_EKEYEXPIRED, |
ths | b7fe5db | 2007-07-23 15:37:46 +0000 | [diff] [blame] | 709 | #endif |
| 710 | #ifdef EKEYREVOKED |
ths | 637947f | 2007-06-01 12:09:19 +0000 | [diff] [blame] | 711 | [EKEYREVOKED] = TARGET_EKEYREVOKED, |
ths | b7fe5db | 2007-07-23 15:37:46 +0000 | [diff] [blame] | 712 | #endif |
| 713 | #ifdef EKEYREJECTED |
ths | 637947f | 2007-06-01 12:09:19 +0000 | [diff] [blame] | 714 | [EKEYREJECTED] = TARGET_EKEYREJECTED, |
ths | b7fe5db | 2007-07-23 15:37:46 +0000 | [diff] [blame] | 715 | #endif |
| 716 | #ifdef EOWNERDEAD |
ths | 637947f | 2007-06-01 12:09:19 +0000 | [diff] [blame] | 717 | [EOWNERDEAD] = TARGET_EOWNERDEAD, |
ths | b7fe5db | 2007-07-23 15:37:46 +0000 | [diff] [blame] | 718 | #endif |
| 719 | #ifdef ENOTRECOVERABLE |
ths | 637947f | 2007-06-01 12:09:19 +0000 | [diff] [blame] | 720 | [ENOTRECOVERABLE] = TARGET_ENOTRECOVERABLE, |
ths | b7fe5db | 2007-07-23 15:37:46 +0000 | [diff] [blame] | 721 | #endif |
ths | b92c47c | 2007-11-01 00:07:38 +0000 | [diff] [blame] | 722 | }; |
ths | 637947f | 2007-06-01 12:09:19 +0000 | [diff] [blame] | 723 | |
| 724 | static inline int host_to_target_errno(int err) |
| 725 | { |
| 726 | if(host_to_target_errno_table[err]) |
| 727 | return host_to_target_errno_table[err]; |
| 728 | return err; |
| 729 | } |
| 730 | |
ths | b92c47c | 2007-11-01 00:07:38 +0000 | [diff] [blame] | 731 | static inline int target_to_host_errno(int err) |
| 732 | { |
| 733 | if (target_to_host_errno_table[err]) |
| 734 | return target_to_host_errno_table[err]; |
| 735 | return err; |
| 736 | } |
| 737 | |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 738 | static inline abi_long get_errno(abi_long ret) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 739 | { |
| 740 | if (ret == -1) |
ths | 637947f | 2007-06-01 12:09:19 +0000 | [diff] [blame] | 741 | return -host_to_target_errno(errno); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 742 | else |
| 743 | return ret; |
| 744 | } |
| 745 | |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 746 | static inline int is_error(abi_long ret) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 747 | { |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 748 | return (abi_ulong)ret >= (abi_ulong)(-4096); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 749 | } |
| 750 | |
ths | b92c47c | 2007-11-01 00:07:38 +0000 | [diff] [blame] | 751 | char *target_strerror(int err) |
| 752 | { |
Alexander Graf | 962b289 | 2011-11-21 12:04:07 +0100 | [diff] [blame] | 753 | if ((err >= ERRNO_TABLE_SIZE) || (err < 0)) { |
| 754 | return NULL; |
| 755 | } |
ths | b92c47c | 2007-11-01 00:07:38 +0000 | [diff] [blame] | 756 | return strerror(target_to_host_errno(err)); |
| 757 | } |
| 758 | |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 759 | static abi_ulong target_brk; |
| 760 | static abi_ulong target_original_brk; |
vincent | 4d1de87 | 2011-06-14 21:56:33 +0000 | [diff] [blame] | 761 | static abi_ulong brk_page; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 762 | |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 763 | void target_set_brk(abi_ulong new_brk) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 764 | { |
blueswir1 | 4c1de73 | 2007-07-07 20:45:44 +0000 | [diff] [blame] | 765 | target_original_brk = target_brk = HOST_PAGE_ALIGN(new_brk); |
vincent | 4d1de87 | 2011-06-14 21:56:33 +0000 | [diff] [blame] | 766 | brk_page = HOST_PAGE_ALIGN(target_brk); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 767 | } |
| 768 | |
vincent | 4d1de87 | 2011-06-14 21:56:33 +0000 | [diff] [blame] | 769 | //#define DEBUGF_BRK(message, args...) do { fprintf(stderr, (message), ## args); } while (0) |
| 770 | #define DEBUGF_BRK(message, args...) |
| 771 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 772 | /* do_brk() must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 773 | abi_long do_brk(abi_ulong new_brk) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 774 | { |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 775 | abi_long mapped_addr; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 776 | int new_alloc_size; |
| 777 | |
Paul Brook | 3a0c6c4 | 2012-02-09 19:04:27 +0000 | [diff] [blame] | 778 | DEBUGF_BRK("do_brk(" TARGET_ABI_FMT_lx ") -> ", new_brk); |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 779 | |
vincent | 4d1de87 | 2011-06-14 21:56:33 +0000 | [diff] [blame] | 780 | if (!new_brk) { |
Paul Brook | 3a0c6c4 | 2012-02-09 19:04:27 +0000 | [diff] [blame] | 781 | DEBUGF_BRK(TARGET_ABI_FMT_lx " (!new_brk)\n", target_brk); |
vincent | 4d1de87 | 2011-06-14 21:56:33 +0000 | [diff] [blame] | 782 | return target_brk; |
| 783 | } |
| 784 | if (new_brk < target_original_brk) { |
Paul Brook | 3a0c6c4 | 2012-02-09 19:04:27 +0000 | [diff] [blame] | 785 | DEBUGF_BRK(TARGET_ABI_FMT_lx " (new_brk < target_original_brk)\n", |
| 786 | target_brk); |
vincent | 4d1de87 | 2011-06-14 21:56:33 +0000 | [diff] [blame] | 787 | return target_brk; |
| 788 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 789 | |
vincent | 4d1de87 | 2011-06-14 21:56:33 +0000 | [diff] [blame] | 790 | /* If the new brk is less than the highest page reserved to the |
| 791 | * target heap allocation, set it and we're almost done... */ |
| 792 | if (new_brk <= brk_page) { |
| 793 | /* Heap contents are initialized to zero, as for anonymous |
| 794 | * mapped pages. */ |
| 795 | if (new_brk > target_brk) { |
| 796 | memset(g2h(target_brk), 0, new_brk - target_brk); |
| 797 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 798 | target_brk = new_brk; |
Paul Brook | 3a0c6c4 | 2012-02-09 19:04:27 +0000 | [diff] [blame] | 799 | DEBUGF_BRK(TARGET_ABI_FMT_lx " (new_brk <= brk_page)\n", target_brk); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 800 | return target_brk; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 801 | } |
| 802 | |
Peter Maydell | 00faf08 | 2011-04-18 16:34:24 +0100 | [diff] [blame] | 803 | /* We need to allocate more memory after the brk... Note that |
| 804 | * we don't use MAP_FIXED because that will map over the top of |
| 805 | * any existing mapping (like the one with the host libc or qemu |
| 806 | * itself); instead we treat "mapped but at wrong address" as |
| 807 | * a failure and unmap again. |
| 808 | */ |
vincent | 4d1de87 | 2011-06-14 21:56:33 +0000 | [diff] [blame] | 809 | new_alloc_size = HOST_PAGE_ALIGN(new_brk - brk_page); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 810 | mapped_addr = get_errno(target_mmap(brk_page, new_alloc_size, |
bellard | 5493600 | 2003-05-13 00:25:15 +0000 | [diff] [blame] | 811 | PROT_READ|PROT_WRITE, |
Peter Maydell | 00faf08 | 2011-04-18 16:34:24 +0100 | [diff] [blame] | 812 | MAP_ANON|MAP_PRIVATE, 0, 0)); |
| 813 | |
| 814 | if (mapped_addr == brk_page) { |
Cédric VINCENT | 70afc34 | 2011-08-26 10:56:50 +0200 | [diff] [blame] | 815 | /* Heap contents are initialized to zero, as for anonymous |
| 816 | * mapped pages. Technically the new pages are already |
| 817 | * initialized to zero since they *are* anonymous mapped |
| 818 | * pages, however we have to take care with the contents that |
| 819 | * come from the remaining part of the previous page: it may |
| 820 | * contains garbage data due to a previous heap usage (grown |
| 821 | * then shrunken). */ |
| 822 | memset(g2h(target_brk), 0, brk_page - target_brk); |
| 823 | |
Peter Maydell | 00faf08 | 2011-04-18 16:34:24 +0100 | [diff] [blame] | 824 | target_brk = new_brk; |
vincent | 4d1de87 | 2011-06-14 21:56:33 +0000 | [diff] [blame] | 825 | brk_page = HOST_PAGE_ALIGN(target_brk); |
Paul Brook | 3a0c6c4 | 2012-02-09 19:04:27 +0000 | [diff] [blame] | 826 | DEBUGF_BRK(TARGET_ABI_FMT_lx " (mapped_addr == brk_page)\n", |
| 827 | target_brk); |
Peter Maydell | 00faf08 | 2011-04-18 16:34:24 +0100 | [diff] [blame] | 828 | return target_brk; |
| 829 | } else if (mapped_addr != -1) { |
| 830 | /* Mapped but at wrong address, meaning there wasn't actually |
| 831 | * enough space for this brk. |
| 832 | */ |
| 833 | target_munmap(mapped_addr, new_alloc_size); |
| 834 | mapped_addr = -1; |
Paul Brook | 3a0c6c4 | 2012-02-09 19:04:27 +0000 | [diff] [blame] | 835 | DEBUGF_BRK(TARGET_ABI_FMT_lx " (mapped_addr != -1)\n", target_brk); |
vincent | 4d1de87 | 2011-06-14 21:56:33 +0000 | [diff] [blame] | 836 | } |
| 837 | else { |
Paul Brook | 3a0c6c4 | 2012-02-09 19:04:27 +0000 | [diff] [blame] | 838 | DEBUGF_BRK(TARGET_ABI_FMT_lx " (otherwise)\n", target_brk); |
Peter Maydell | 00faf08 | 2011-04-18 16:34:24 +0100 | [diff] [blame] | 839 | } |
balrog | 7ab240a | 2008-04-26 12:17:34 +0000 | [diff] [blame] | 840 | |
Richard Henderson | 7dd46c0 | 2010-05-03 10:07:49 -0700 | [diff] [blame] | 841 | #if defined(TARGET_ALPHA) |
| 842 | /* We (partially) emulate OSF/1 on Alpha, which requires we |
| 843 | return a proper errno, not an unchanged brk value. */ |
Peter Maydell | 00faf08 | 2011-04-18 16:34:24 +0100 | [diff] [blame] | 844 | return -TARGET_ENOMEM; |
Richard Henderson | 7dd46c0 | 2010-05-03 10:07:49 -0700 | [diff] [blame] | 845 | #endif |
Peter Maydell | 00faf08 | 2011-04-18 16:34:24 +0100 | [diff] [blame] | 846 | /* For everything else, return the previous break. */ |
balrog | 7ab240a | 2008-04-26 12:17:34 +0000 | [diff] [blame] | 847 | return target_brk; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 848 | } |
| 849 | |
ths | 26edcf4 | 2007-12-09 02:25:24 +0000 | [diff] [blame] | 850 | static inline abi_long copy_from_user_fdset(fd_set *fds, |
| 851 | abi_ulong target_fds_addr, |
| 852 | int n) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 853 | { |
ths | 26edcf4 | 2007-12-09 02:25:24 +0000 | [diff] [blame] | 854 | int i, nw, j, k; |
| 855 | abi_ulong b, *target_fds; |
| 856 | |
| 857 | nw = (n + TARGET_ABI_BITS - 1) / TARGET_ABI_BITS; |
| 858 | if (!(target_fds = lock_user(VERIFY_READ, |
| 859 | target_fds_addr, |
| 860 | sizeof(abi_ulong) * nw, |
| 861 | 1))) |
| 862 | return -TARGET_EFAULT; |
| 863 | |
| 864 | FD_ZERO(fds); |
| 865 | k = 0; |
| 866 | for (i = 0; i < nw; i++) { |
| 867 | /* grab the abi_ulong */ |
| 868 | __get_user(b, &target_fds[i]); |
| 869 | for (j = 0; j < TARGET_ABI_BITS; j++) { |
| 870 | /* check the bit inside the abi_ulong */ |
| 871 | if ((b >> j) & 1) |
| 872 | FD_SET(k, fds); |
| 873 | k++; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 874 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 875 | } |
ths | 26edcf4 | 2007-12-09 02:25:24 +0000 | [diff] [blame] | 876 | |
| 877 | unlock_user(target_fds, target_fds_addr, 0); |
| 878 | |
| 879 | return 0; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 880 | } |
| 881 | |
Mike Frysinger | 055e090 | 2011-06-03 17:01:49 -0400 | [diff] [blame] | 882 | static inline abi_ulong copy_from_user_fdset_ptr(fd_set *fds, fd_set **fds_ptr, |
| 883 | abi_ulong target_fds_addr, |
| 884 | int n) |
| 885 | { |
| 886 | if (target_fds_addr) { |
| 887 | if (copy_from_user_fdset(fds, target_fds_addr, n)) |
| 888 | return -TARGET_EFAULT; |
| 889 | *fds_ptr = fds; |
| 890 | } else { |
| 891 | *fds_ptr = NULL; |
| 892 | } |
| 893 | return 0; |
| 894 | } |
| 895 | |
ths | 26edcf4 | 2007-12-09 02:25:24 +0000 | [diff] [blame] | 896 | static inline abi_long copy_to_user_fdset(abi_ulong target_fds_addr, |
| 897 | const fd_set *fds, |
| 898 | int n) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 899 | { |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 900 | int i, nw, j, k; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 901 | abi_long v; |
ths | 26edcf4 | 2007-12-09 02:25:24 +0000 | [diff] [blame] | 902 | abi_ulong *target_fds; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 903 | |
ths | 26edcf4 | 2007-12-09 02:25:24 +0000 | [diff] [blame] | 904 | nw = (n + TARGET_ABI_BITS - 1) / TARGET_ABI_BITS; |
| 905 | if (!(target_fds = lock_user(VERIFY_WRITE, |
| 906 | target_fds_addr, |
| 907 | sizeof(abi_ulong) * nw, |
| 908 | 0))) |
| 909 | return -TARGET_EFAULT; |
| 910 | |
| 911 | k = 0; |
| 912 | for (i = 0; i < nw; i++) { |
| 913 | v = 0; |
| 914 | for (j = 0; j < TARGET_ABI_BITS; j++) { |
| 915 | v |= ((FD_ISSET(k, fds) != 0) << j); |
| 916 | k++; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 917 | } |
ths | 26edcf4 | 2007-12-09 02:25:24 +0000 | [diff] [blame] | 918 | __put_user(v, &target_fds[i]); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 919 | } |
ths | 26edcf4 | 2007-12-09 02:25:24 +0000 | [diff] [blame] | 920 | |
| 921 | unlock_user(target_fds, target_fds_addr, sizeof(abi_ulong) * nw); |
| 922 | |
| 923 | return 0; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 924 | } |
| 925 | |
bellard | c596ed1 | 2003-07-13 17:32:31 +0000 | [diff] [blame] | 926 | #if defined(__alpha__) |
| 927 | #define HOST_HZ 1024 |
| 928 | #else |
| 929 | #define HOST_HZ 100 |
| 930 | #endif |
| 931 | |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 932 | static inline abi_long host_to_target_clock_t(long ticks) |
bellard | c596ed1 | 2003-07-13 17:32:31 +0000 | [diff] [blame] | 933 | { |
| 934 | #if HOST_HZ == TARGET_HZ |
| 935 | return ticks; |
| 936 | #else |
| 937 | return ((int64_t)ticks * TARGET_HZ) / HOST_HZ; |
| 938 | #endif |
| 939 | } |
| 940 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 941 | static inline abi_long host_to_target_rusage(abi_ulong target_addr, |
| 942 | const struct rusage *rusage) |
bellard | b409186 | 2003-05-16 15:39:34 +0000 | [diff] [blame] | 943 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 944 | struct target_rusage *target_rusage; |
| 945 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 946 | if (!lock_user_struct(VERIFY_WRITE, target_rusage, target_addr, 0)) |
| 947 | return -TARGET_EFAULT; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 948 | target_rusage->ru_utime.tv_sec = tswapal(rusage->ru_utime.tv_sec); |
| 949 | target_rusage->ru_utime.tv_usec = tswapal(rusage->ru_utime.tv_usec); |
| 950 | target_rusage->ru_stime.tv_sec = tswapal(rusage->ru_stime.tv_sec); |
| 951 | target_rusage->ru_stime.tv_usec = tswapal(rusage->ru_stime.tv_usec); |
| 952 | target_rusage->ru_maxrss = tswapal(rusage->ru_maxrss); |
| 953 | target_rusage->ru_ixrss = tswapal(rusage->ru_ixrss); |
| 954 | target_rusage->ru_idrss = tswapal(rusage->ru_idrss); |
| 955 | target_rusage->ru_isrss = tswapal(rusage->ru_isrss); |
| 956 | target_rusage->ru_minflt = tswapal(rusage->ru_minflt); |
| 957 | target_rusage->ru_majflt = tswapal(rusage->ru_majflt); |
| 958 | target_rusage->ru_nswap = tswapal(rusage->ru_nswap); |
| 959 | target_rusage->ru_inblock = tswapal(rusage->ru_inblock); |
| 960 | target_rusage->ru_oublock = tswapal(rusage->ru_oublock); |
| 961 | target_rusage->ru_msgsnd = tswapal(rusage->ru_msgsnd); |
| 962 | target_rusage->ru_msgrcv = tswapal(rusage->ru_msgrcv); |
| 963 | target_rusage->ru_nsignals = tswapal(rusage->ru_nsignals); |
| 964 | target_rusage->ru_nvcsw = tswapal(rusage->ru_nvcsw); |
| 965 | target_rusage->ru_nivcsw = tswapal(rusage->ru_nivcsw); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 966 | unlock_user_struct(target_rusage, target_addr, 1); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 967 | |
| 968 | return 0; |
bellard | b409186 | 2003-05-16 15:39:34 +0000 | [diff] [blame] | 969 | } |
| 970 | |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 971 | static inline rlim_t target_to_host_rlim(abi_ulong target_rlim) |
takasi-y@ops.dti.ne.jp | 81bbe90 | 2010-04-12 04:07:35 +0900 | [diff] [blame] | 972 | { |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 973 | abi_ulong target_rlim_swap; |
Wesley W. Terpstra | 95b33b2 | 2011-07-12 14:38:22 +0300 | [diff] [blame] | 974 | rlim_t result; |
| 975 | |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 976 | target_rlim_swap = tswapal(target_rlim); |
| 977 | if (target_rlim_swap == TARGET_RLIM_INFINITY) |
| 978 | return RLIM_INFINITY; |
| 979 | |
| 980 | result = target_rlim_swap; |
| 981 | if (target_rlim_swap != (rlim_t)result) |
| 982 | return RLIM_INFINITY; |
Wesley W. Terpstra | 95b33b2 | 2011-07-12 14:38:22 +0300 | [diff] [blame] | 983 | |
| 984 | return result; |
takasi-y@ops.dti.ne.jp | 81bbe90 | 2010-04-12 04:07:35 +0900 | [diff] [blame] | 985 | } |
| 986 | |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 987 | static inline abi_ulong host_to_target_rlim(rlim_t rlim) |
takasi-y@ops.dti.ne.jp | 81bbe90 | 2010-04-12 04:07:35 +0900 | [diff] [blame] | 988 | { |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 989 | abi_ulong target_rlim_swap; |
| 990 | abi_ulong result; |
Wesley W. Terpstra | 95b33b2 | 2011-07-12 14:38:22 +0300 | [diff] [blame] | 991 | |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 992 | if (rlim == RLIM_INFINITY || rlim != (abi_long)rlim) |
Wesley W. Terpstra | 95b33b2 | 2011-07-12 14:38:22 +0300 | [diff] [blame] | 993 | target_rlim_swap = TARGET_RLIM_INFINITY; |
takasi-y@ops.dti.ne.jp | 81bbe90 | 2010-04-12 04:07:35 +0900 | [diff] [blame] | 994 | else |
Wesley W. Terpstra | 95b33b2 | 2011-07-12 14:38:22 +0300 | [diff] [blame] | 995 | target_rlim_swap = rlim; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 996 | result = tswapal(target_rlim_swap); |
Wesley W. Terpstra | 95b33b2 | 2011-07-12 14:38:22 +0300 | [diff] [blame] | 997 | |
| 998 | return result; |
takasi-y@ops.dti.ne.jp | 81bbe90 | 2010-04-12 04:07:35 +0900 | [diff] [blame] | 999 | } |
| 1000 | |
Wesley W. Terpstra | e22b701 | 2011-07-12 14:42:00 +0300 | [diff] [blame] | 1001 | static inline int target_to_host_resource(int code) |
| 1002 | { |
| 1003 | switch (code) { |
| 1004 | case TARGET_RLIMIT_AS: |
| 1005 | return RLIMIT_AS; |
| 1006 | case TARGET_RLIMIT_CORE: |
| 1007 | return RLIMIT_CORE; |
| 1008 | case TARGET_RLIMIT_CPU: |
| 1009 | return RLIMIT_CPU; |
| 1010 | case TARGET_RLIMIT_DATA: |
| 1011 | return RLIMIT_DATA; |
| 1012 | case TARGET_RLIMIT_FSIZE: |
| 1013 | return RLIMIT_FSIZE; |
| 1014 | case TARGET_RLIMIT_LOCKS: |
| 1015 | return RLIMIT_LOCKS; |
| 1016 | case TARGET_RLIMIT_MEMLOCK: |
| 1017 | return RLIMIT_MEMLOCK; |
| 1018 | case TARGET_RLIMIT_MSGQUEUE: |
| 1019 | return RLIMIT_MSGQUEUE; |
| 1020 | case TARGET_RLIMIT_NICE: |
| 1021 | return RLIMIT_NICE; |
| 1022 | case TARGET_RLIMIT_NOFILE: |
| 1023 | return RLIMIT_NOFILE; |
| 1024 | case TARGET_RLIMIT_NPROC: |
| 1025 | return RLIMIT_NPROC; |
| 1026 | case TARGET_RLIMIT_RSS: |
| 1027 | return RLIMIT_RSS; |
| 1028 | case TARGET_RLIMIT_RTPRIO: |
| 1029 | return RLIMIT_RTPRIO; |
| 1030 | case TARGET_RLIMIT_SIGPENDING: |
| 1031 | return RLIMIT_SIGPENDING; |
| 1032 | case TARGET_RLIMIT_STACK: |
| 1033 | return RLIMIT_STACK; |
| 1034 | default: |
| 1035 | return code; |
| 1036 | } |
| 1037 | } |
| 1038 | |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 1039 | static inline abi_long copy_from_user_timeval(struct timeval *tv, |
| 1040 | abi_ulong target_tv_addr) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 1041 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1042 | struct target_timeval *target_tv; |
| 1043 | |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 1044 | if (!lock_user_struct(VERIFY_READ, target_tv, target_tv_addr, 1)) |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1045 | return -TARGET_EFAULT; |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 1046 | |
| 1047 | __get_user(tv->tv_sec, &target_tv->tv_sec); |
| 1048 | __get_user(tv->tv_usec, &target_tv->tv_usec); |
| 1049 | |
| 1050 | unlock_user_struct(target_tv, target_tv_addr, 0); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1051 | |
| 1052 | return 0; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 1053 | } |
| 1054 | |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 1055 | static inline abi_long copy_to_user_timeval(abi_ulong target_tv_addr, |
| 1056 | const struct timeval *tv) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 1057 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1058 | struct target_timeval *target_tv; |
| 1059 | |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 1060 | if (!lock_user_struct(VERIFY_WRITE, target_tv, target_tv_addr, 0)) |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1061 | return -TARGET_EFAULT; |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 1062 | |
| 1063 | __put_user(tv->tv_sec, &target_tv->tv_sec); |
| 1064 | __put_user(tv->tv_usec, &target_tv->tv_usec); |
| 1065 | |
| 1066 | unlock_user_struct(target_tv, target_tv_addr, 1); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1067 | |
| 1068 | return 0; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 1069 | } |
| 1070 | |
Nathan Froyd | 8ec9cf8 | 2009-07-22 09:14:36 -0700 | [diff] [blame] | 1071 | #if defined(TARGET_NR_mq_open) && defined(__NR_mq_open) |
| 1072 | #include <mqueue.h> |
| 1073 | |
aurel32 | 24e1003 | 2009-04-15 16:11:43 +0000 | [diff] [blame] | 1074 | static inline abi_long copy_from_user_mq_attr(struct mq_attr *attr, |
| 1075 | abi_ulong target_mq_attr_addr) |
| 1076 | { |
| 1077 | struct target_mq_attr *target_mq_attr; |
| 1078 | |
| 1079 | if (!lock_user_struct(VERIFY_READ, target_mq_attr, |
| 1080 | target_mq_attr_addr, 1)) |
| 1081 | return -TARGET_EFAULT; |
| 1082 | |
| 1083 | __get_user(attr->mq_flags, &target_mq_attr->mq_flags); |
| 1084 | __get_user(attr->mq_maxmsg, &target_mq_attr->mq_maxmsg); |
| 1085 | __get_user(attr->mq_msgsize, &target_mq_attr->mq_msgsize); |
| 1086 | __get_user(attr->mq_curmsgs, &target_mq_attr->mq_curmsgs); |
| 1087 | |
| 1088 | unlock_user_struct(target_mq_attr, target_mq_attr_addr, 0); |
| 1089 | |
| 1090 | return 0; |
| 1091 | } |
| 1092 | |
| 1093 | static inline abi_long copy_to_user_mq_attr(abi_ulong target_mq_attr_addr, |
| 1094 | const struct mq_attr *attr) |
| 1095 | { |
| 1096 | struct target_mq_attr *target_mq_attr; |
| 1097 | |
| 1098 | if (!lock_user_struct(VERIFY_WRITE, target_mq_attr, |
| 1099 | target_mq_attr_addr, 0)) |
| 1100 | return -TARGET_EFAULT; |
| 1101 | |
| 1102 | __put_user(attr->mq_flags, &target_mq_attr->mq_flags); |
| 1103 | __put_user(attr->mq_maxmsg, &target_mq_attr->mq_maxmsg); |
| 1104 | __put_user(attr->mq_msgsize, &target_mq_attr->mq_msgsize); |
| 1105 | __put_user(attr->mq_curmsgs, &target_mq_attr->mq_curmsgs); |
| 1106 | |
| 1107 | unlock_user_struct(target_mq_attr, target_mq_attr_addr, 1); |
| 1108 | |
| 1109 | return 0; |
| 1110 | } |
Nathan Froyd | 8ec9cf8 | 2009-07-22 09:14:36 -0700 | [diff] [blame] | 1111 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 1112 | |
Mike Frysinger | 055e090 | 2011-06-03 17:01:49 -0400 | [diff] [blame] | 1113 | #if defined(TARGET_NR_select) || defined(TARGET_NR__newselect) |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 1114 | /* do_select() must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 1115 | static abi_long do_select(int n, |
ths | 26edcf4 | 2007-12-09 02:25:24 +0000 | [diff] [blame] | 1116 | abi_ulong rfd_addr, abi_ulong wfd_addr, |
| 1117 | abi_ulong efd_addr, abi_ulong target_tv_addr) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 1118 | { |
| 1119 | fd_set rfds, wfds, efds; |
| 1120 | fd_set *rfds_ptr, *wfds_ptr, *efds_ptr; |
| 1121 | struct timeval tv, *tv_ptr; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 1122 | abi_long ret; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 1123 | |
Mike Frysinger | 055e090 | 2011-06-03 17:01:49 -0400 | [diff] [blame] | 1124 | ret = copy_from_user_fdset_ptr(&rfds, &rfds_ptr, rfd_addr, n); |
| 1125 | if (ret) { |
| 1126 | return ret; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1127 | } |
Mike Frysinger | 055e090 | 2011-06-03 17:01:49 -0400 | [diff] [blame] | 1128 | ret = copy_from_user_fdset_ptr(&wfds, &wfds_ptr, wfd_addr, n); |
| 1129 | if (ret) { |
| 1130 | return ret; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1131 | } |
Mike Frysinger | 055e090 | 2011-06-03 17:01:49 -0400 | [diff] [blame] | 1132 | ret = copy_from_user_fdset_ptr(&efds, &efds_ptr, efd_addr, n); |
| 1133 | if (ret) { |
| 1134 | return ret; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1135 | } |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1136 | |
ths | 26edcf4 | 2007-12-09 02:25:24 +0000 | [diff] [blame] | 1137 | if (target_tv_addr) { |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 1138 | if (copy_from_user_timeval(&tv, target_tv_addr)) |
| 1139 | return -TARGET_EFAULT; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 1140 | tv_ptr = &tv; |
| 1141 | } else { |
| 1142 | tv_ptr = NULL; |
| 1143 | } |
ths | 26edcf4 | 2007-12-09 02:25:24 +0000 | [diff] [blame] | 1144 | |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 1145 | ret = get_errno(select(n, rfds_ptr, wfds_ptr, efds_ptr, tv_ptr)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1146 | |
ths | 26edcf4 | 2007-12-09 02:25:24 +0000 | [diff] [blame] | 1147 | if (!is_error(ret)) { |
| 1148 | if (rfd_addr && copy_to_user_fdset(rfd_addr, &rfds, n)) |
| 1149 | return -TARGET_EFAULT; |
| 1150 | if (wfd_addr && copy_to_user_fdset(wfd_addr, &wfds, n)) |
| 1151 | return -TARGET_EFAULT; |
| 1152 | if (efd_addr && copy_to_user_fdset(efd_addr, &efds, n)) |
| 1153 | return -TARGET_EFAULT; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 1154 | |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 1155 | if (target_tv_addr && copy_to_user_timeval(target_tv_addr, &tv)) |
| 1156 | return -TARGET_EFAULT; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 1157 | } |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1158 | |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 1159 | return ret; |
| 1160 | } |
Mike Frysinger | 055e090 | 2011-06-03 17:01:49 -0400 | [diff] [blame] | 1161 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 1162 | |
Riku Voipio | 099d6b0 | 2009-05-05 12:10:04 +0300 | [diff] [blame] | 1163 | static abi_long do_pipe2(int host_pipe[], int flags) |
| 1164 | { |
| 1165 | #ifdef CONFIG_PIPE2 |
| 1166 | return pipe2(host_pipe, flags); |
| 1167 | #else |
| 1168 | return -ENOSYS; |
| 1169 | #endif |
| 1170 | } |
| 1171 | |
Richard Henderson | fb41a66 | 2010-05-03 10:07:52 -0700 | [diff] [blame] | 1172 | static abi_long do_pipe(void *cpu_env, abi_ulong pipedes, |
| 1173 | int flags, int is_pipe2) |
Riku Voipio | 099d6b0 | 2009-05-05 12:10:04 +0300 | [diff] [blame] | 1174 | { |
| 1175 | int host_pipe[2]; |
| 1176 | abi_long ret; |
| 1177 | ret = flags ? do_pipe2(host_pipe, flags) : pipe(host_pipe); |
| 1178 | |
| 1179 | if (is_error(ret)) |
| 1180 | return get_errno(ret); |
Richard Henderson | fb41a66 | 2010-05-03 10:07:52 -0700 | [diff] [blame] | 1181 | |
| 1182 | /* Several targets have special calling conventions for the original |
| 1183 | pipe syscall, but didn't replicate this into the pipe2 syscall. */ |
| 1184 | if (!is_pipe2) { |
| 1185 | #if defined(TARGET_ALPHA) |
| 1186 | ((CPUAlphaState *)cpu_env)->ir[IR_A4] = host_pipe[1]; |
| 1187 | return host_pipe[0]; |
| 1188 | #elif defined(TARGET_MIPS) |
| 1189 | ((CPUMIPSState*)cpu_env)->active_tc.gpr[3] = host_pipe[1]; |
| 1190 | return host_pipe[0]; |
| 1191 | #elif defined(TARGET_SH4) |
takasi-y@ops.dti.ne.jp | 597c021 | 2010-02-18 00:35:03 +0900 | [diff] [blame] | 1192 | ((CPUSH4State*)cpu_env)->gregs[1] = host_pipe[1]; |
Richard Henderson | fb41a66 | 2010-05-03 10:07:52 -0700 | [diff] [blame] | 1193 | return host_pipe[0]; |
takasi-y@ops.dti.ne.jp | 597c021 | 2010-02-18 00:35:03 +0900 | [diff] [blame] | 1194 | #endif |
Richard Henderson | fb41a66 | 2010-05-03 10:07:52 -0700 | [diff] [blame] | 1195 | } |
| 1196 | |
Riku Voipio | 099d6b0 | 2009-05-05 12:10:04 +0300 | [diff] [blame] | 1197 | if (put_user_s32(host_pipe[0], pipedes) |
| 1198 | || put_user_s32(host_pipe[1], pipedes + sizeof(host_pipe[0]))) |
| 1199 | return -TARGET_EFAULT; |
Riku Voipio | 099d6b0 | 2009-05-05 12:10:04 +0300 | [diff] [blame] | 1200 | return get_errno(ret); |
| 1201 | } |
| 1202 | |
Lionel Landwerlin | b975b83 | 2009-04-25 23:30:19 +0200 | [diff] [blame] | 1203 | static inline abi_long target_to_host_ip_mreq(struct ip_mreqn *mreqn, |
| 1204 | abi_ulong target_addr, |
| 1205 | socklen_t len) |
| 1206 | { |
| 1207 | struct target_ip_mreqn *target_smreqn; |
| 1208 | |
| 1209 | target_smreqn = lock_user(VERIFY_READ, target_addr, len, 1); |
| 1210 | if (!target_smreqn) |
| 1211 | return -TARGET_EFAULT; |
| 1212 | mreqn->imr_multiaddr.s_addr = target_smreqn->imr_multiaddr.s_addr; |
| 1213 | mreqn->imr_address.s_addr = target_smreqn->imr_address.s_addr; |
| 1214 | if (len == sizeof(struct target_ip_mreqn)) |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 1215 | mreqn->imr_ifindex = tswapal(target_smreqn->imr_ifindex); |
Lionel Landwerlin | b975b83 | 2009-04-25 23:30:19 +0200 | [diff] [blame] | 1216 | unlock_user(target_smreqn, target_addr, 0); |
| 1217 | |
| 1218 | return 0; |
| 1219 | } |
| 1220 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1221 | static inline abi_long target_to_host_sockaddr(struct sockaddr *addr, |
| 1222 | abi_ulong target_addr, |
| 1223 | socklen_t len) |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1224 | { |
aurel32 | 607175e | 2009-04-15 16:11:59 +0000 | [diff] [blame] | 1225 | const socklen_t unix_maxlen = sizeof (struct sockaddr_un); |
| 1226 | sa_family_t sa_family; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1227 | struct target_sockaddr *target_saddr; |
| 1228 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1229 | target_saddr = lock_user(VERIFY_READ, target_addr, len, 1); |
| 1230 | if (!target_saddr) |
| 1231 | return -TARGET_EFAULT; |
aurel32 | 607175e | 2009-04-15 16:11:59 +0000 | [diff] [blame] | 1232 | |
| 1233 | sa_family = tswap16(target_saddr->sa_family); |
| 1234 | |
| 1235 | /* Oops. The caller might send a incomplete sun_path; sun_path |
| 1236 | * must be terminated by \0 (see the manual page), but |
| 1237 | * unfortunately it is quite common to specify sockaddr_un |
| 1238 | * length as "strlen(x->sun_path)" while it should be |
| 1239 | * "strlen(...) + 1". We'll fix that here if needed. |
| 1240 | * Linux kernel has a similar feature. |
| 1241 | */ |
| 1242 | |
| 1243 | if (sa_family == AF_UNIX) { |
| 1244 | if (len < unix_maxlen && len > 0) { |
| 1245 | char *cp = (char*)target_saddr; |
| 1246 | |
| 1247 | if ( cp[len-1] && !cp[len] ) |
| 1248 | len++; |
| 1249 | } |
| 1250 | if (len > unix_maxlen) |
| 1251 | len = unix_maxlen; |
| 1252 | } |
| 1253 | |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1254 | memcpy(addr, target_saddr, len); |
aurel32 | 607175e | 2009-04-15 16:11:59 +0000 | [diff] [blame] | 1255 | addr->sa_family = sa_family; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1256 | unlock_user(target_saddr, target_addr, 0); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1257 | |
| 1258 | return 0; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1259 | } |
| 1260 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1261 | static inline abi_long host_to_target_sockaddr(abi_ulong target_addr, |
| 1262 | struct sockaddr *addr, |
| 1263 | socklen_t len) |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1264 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1265 | struct target_sockaddr *target_saddr; |
| 1266 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1267 | target_saddr = lock_user(VERIFY_WRITE, target_addr, len, 0); |
| 1268 | if (!target_saddr) |
| 1269 | return -TARGET_EFAULT; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1270 | memcpy(target_saddr, addr, len); |
| 1271 | target_saddr->sa_family = tswap16(addr->sa_family); |
| 1272 | unlock_user(target_saddr, target_addr, len); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1273 | |
| 1274 | return 0; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1275 | } |
| 1276 | |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1277 | static inline abi_long target_to_host_cmsg(struct msghdr *msgh, |
| 1278 | struct target_msghdr *target_msgh) |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1279 | { |
| 1280 | struct cmsghdr *cmsg = CMSG_FIRSTHDR(msgh); |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1281 | abi_long msg_controllen; |
| 1282 | abi_ulong target_cmsg_addr; |
| 1283 | struct target_cmsghdr *target_cmsg; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1284 | socklen_t space = 0; |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1285 | |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 1286 | msg_controllen = tswapal(target_msgh->msg_controllen); |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1287 | if (msg_controllen < sizeof (struct target_cmsghdr)) |
| 1288 | goto the_end; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 1289 | target_cmsg_addr = tswapal(target_msgh->msg_control); |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1290 | target_cmsg = lock_user(VERIFY_READ, target_cmsg_addr, msg_controllen, 1); |
| 1291 | if (!target_cmsg) |
| 1292 | return -TARGET_EFAULT; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1293 | |
| 1294 | while (cmsg && target_cmsg) { |
| 1295 | void *data = CMSG_DATA(cmsg); |
| 1296 | void *target_data = TARGET_CMSG_DATA(target_cmsg); |
| 1297 | |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 1298 | int len = tswapal(target_cmsg->cmsg_len) |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1299 | - TARGET_CMSG_ALIGN(sizeof (struct target_cmsghdr)); |
| 1300 | |
| 1301 | space += CMSG_SPACE(len); |
| 1302 | if (space > msgh->msg_controllen) { |
| 1303 | space -= CMSG_SPACE(len); |
bellard | 31febb7 | 2005-12-18 20:03:27 +0000 | [diff] [blame] | 1304 | gemu_log("Host cmsg overflow\n"); |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1305 | break; |
| 1306 | } |
| 1307 | |
| 1308 | cmsg->cmsg_level = tswap32(target_cmsg->cmsg_level); |
| 1309 | cmsg->cmsg_type = tswap32(target_cmsg->cmsg_type); |
| 1310 | cmsg->cmsg_len = CMSG_LEN(len); |
| 1311 | |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1312 | if (cmsg->cmsg_level != TARGET_SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) { |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1313 | gemu_log("Unsupported ancillary data: %d/%d\n", cmsg->cmsg_level, cmsg->cmsg_type); |
| 1314 | memcpy(data, target_data, len); |
| 1315 | } else { |
| 1316 | int *fd = (int *)data; |
| 1317 | int *target_fd = (int *)target_data; |
| 1318 | int i, numfds = len / sizeof(int); |
| 1319 | |
| 1320 | for (i = 0; i < numfds; i++) |
| 1321 | fd[i] = tswap32(target_fd[i]); |
| 1322 | } |
| 1323 | |
| 1324 | cmsg = CMSG_NXTHDR(msgh, cmsg); |
| 1325 | target_cmsg = TARGET_CMSG_NXTHDR(target_msgh, target_cmsg); |
| 1326 | } |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1327 | unlock_user(target_cmsg, target_cmsg_addr, 0); |
| 1328 | the_end: |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1329 | msgh->msg_controllen = space; |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1330 | return 0; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1331 | } |
| 1332 | |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1333 | static inline abi_long host_to_target_cmsg(struct target_msghdr *target_msgh, |
| 1334 | struct msghdr *msgh) |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1335 | { |
| 1336 | struct cmsghdr *cmsg = CMSG_FIRSTHDR(msgh); |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1337 | abi_long msg_controllen; |
| 1338 | abi_ulong target_cmsg_addr; |
| 1339 | struct target_cmsghdr *target_cmsg; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1340 | socklen_t space = 0; |
| 1341 | |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 1342 | msg_controllen = tswapal(target_msgh->msg_controllen); |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1343 | if (msg_controllen < sizeof (struct target_cmsghdr)) |
| 1344 | goto the_end; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 1345 | target_cmsg_addr = tswapal(target_msgh->msg_control); |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1346 | target_cmsg = lock_user(VERIFY_WRITE, target_cmsg_addr, msg_controllen, 0); |
| 1347 | if (!target_cmsg) |
| 1348 | return -TARGET_EFAULT; |
| 1349 | |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1350 | while (cmsg && target_cmsg) { |
| 1351 | void *data = CMSG_DATA(cmsg); |
| 1352 | void *target_data = TARGET_CMSG_DATA(target_cmsg); |
| 1353 | |
| 1354 | int len = cmsg->cmsg_len - CMSG_ALIGN(sizeof (struct cmsghdr)); |
| 1355 | |
| 1356 | space += TARGET_CMSG_SPACE(len); |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1357 | if (space > msg_controllen) { |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1358 | space -= TARGET_CMSG_SPACE(len); |
bellard | 31febb7 | 2005-12-18 20:03:27 +0000 | [diff] [blame] | 1359 | gemu_log("Target cmsg overflow\n"); |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1360 | break; |
| 1361 | } |
| 1362 | |
| 1363 | target_cmsg->cmsg_level = tswap32(cmsg->cmsg_level); |
| 1364 | target_cmsg->cmsg_type = tswap32(cmsg->cmsg_type); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 1365 | target_cmsg->cmsg_len = tswapal(TARGET_CMSG_LEN(len)); |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1366 | |
Jing Huang | aebf5bc | 2012-07-24 14:01:42 +0000 | [diff] [blame] | 1367 | if ((cmsg->cmsg_level == TARGET_SOL_SOCKET) && |
| 1368 | (cmsg->cmsg_type == SCM_RIGHTS)) { |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1369 | int *fd = (int *)data; |
| 1370 | int *target_fd = (int *)target_data; |
| 1371 | int i, numfds = len / sizeof(int); |
| 1372 | |
| 1373 | for (i = 0; i < numfds; i++) |
| 1374 | target_fd[i] = tswap32(fd[i]); |
Jing Huang | aebf5bc | 2012-07-24 14:01:42 +0000 | [diff] [blame] | 1375 | } else if ((cmsg->cmsg_level == TARGET_SOL_SOCKET) && |
| 1376 | (cmsg->cmsg_type == SO_TIMESTAMP) && |
| 1377 | (len == sizeof(struct timeval))) { |
| 1378 | /* copy struct timeval to target */ |
| 1379 | struct timeval *tv = (struct timeval *)data; |
| 1380 | struct target_timeval *target_tv = |
| 1381 | (struct target_timeval *)target_data; |
| 1382 | |
| 1383 | target_tv->tv_sec = tswapal(tv->tv_sec); |
| 1384 | target_tv->tv_usec = tswapal(tv->tv_usec); |
| 1385 | } else { |
| 1386 | gemu_log("Unsupported ancillary data: %d/%d\n", |
| 1387 | cmsg->cmsg_level, cmsg->cmsg_type); |
| 1388 | memcpy(target_data, data, len); |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1389 | } |
| 1390 | |
| 1391 | cmsg = CMSG_NXTHDR(msgh, cmsg); |
| 1392 | target_cmsg = TARGET_CMSG_NXTHDR(target_msgh, target_cmsg); |
| 1393 | } |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1394 | unlock_user(target_cmsg, target_cmsg_addr, space); |
| 1395 | the_end: |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 1396 | target_msgh->msg_controllen = tswapal(space); |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1397 | return 0; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1398 | } |
| 1399 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 1400 | /* do_setsockopt() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 1401 | static abi_long do_setsockopt(int sockfd, int level, int optname, |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1402 | abi_ulong optval_addr, socklen_t optlen) |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1403 | { |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 1404 | abi_long ret; |
j_mayer | 3240710 | 2007-09-26 23:01:49 +0000 | [diff] [blame] | 1405 | int val; |
Lionel Landwerlin | b975b83 | 2009-04-25 23:30:19 +0200 | [diff] [blame] | 1406 | struct ip_mreqn *ip_mreq; |
Lionel Landwerlin | 6e3cb58 | 2009-04-25 23:31:18 +0200 | [diff] [blame] | 1407 | struct ip_mreq_source *ip_mreq_source; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1408 | |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1409 | switch(level) { |
| 1410 | case SOL_TCP: |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1411 | /* TCP options all take an 'int' value. */ |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1412 | if (optlen < sizeof(uint32_t)) |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 1413 | return -TARGET_EINVAL; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1414 | |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1415 | if (get_user_u32(val, optval_addr)) |
| 1416 | return -TARGET_EFAULT; |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1417 | ret = get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val))); |
| 1418 | break; |
| 1419 | case SOL_IP: |
| 1420 | switch(optname) { |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1421 | case IP_TOS: |
| 1422 | case IP_TTL: |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1423 | case IP_HDRINCL: |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1424 | case IP_ROUTER_ALERT: |
| 1425 | case IP_RECVOPTS: |
| 1426 | case IP_RETOPTS: |
| 1427 | case IP_PKTINFO: |
| 1428 | case IP_MTU_DISCOVER: |
| 1429 | case IP_RECVERR: |
| 1430 | case IP_RECVTOS: |
| 1431 | #ifdef IP_FREEBIND |
| 1432 | case IP_FREEBIND: |
| 1433 | #endif |
| 1434 | case IP_MULTICAST_TTL: |
| 1435 | case IP_MULTICAST_LOOP: |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1436 | val = 0; |
| 1437 | if (optlen >= sizeof(uint32_t)) { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1438 | if (get_user_u32(val, optval_addr)) |
| 1439 | return -TARGET_EFAULT; |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1440 | } else if (optlen >= 1) { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1441 | if (get_user_u8(val, optval_addr)) |
| 1442 | return -TARGET_EFAULT; |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1443 | } |
| 1444 | ret = get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val))); |
| 1445 | break; |
Lionel Landwerlin | b975b83 | 2009-04-25 23:30:19 +0200 | [diff] [blame] | 1446 | case IP_ADD_MEMBERSHIP: |
| 1447 | case IP_DROP_MEMBERSHIP: |
| 1448 | if (optlen < sizeof (struct target_ip_mreq) || |
| 1449 | optlen > sizeof (struct target_ip_mreqn)) |
| 1450 | return -TARGET_EINVAL; |
| 1451 | |
| 1452 | ip_mreq = (struct ip_mreqn *) alloca(optlen); |
| 1453 | target_to_host_ip_mreq(ip_mreq, optval_addr, optlen); |
| 1454 | ret = get_errno(setsockopt(sockfd, level, optname, ip_mreq, optlen)); |
| 1455 | break; |
| 1456 | |
Lionel Landwerlin | 6e3cb58 | 2009-04-25 23:31:18 +0200 | [diff] [blame] | 1457 | case IP_BLOCK_SOURCE: |
| 1458 | case IP_UNBLOCK_SOURCE: |
| 1459 | case IP_ADD_SOURCE_MEMBERSHIP: |
| 1460 | case IP_DROP_SOURCE_MEMBERSHIP: |
| 1461 | if (optlen != sizeof (struct target_ip_mreq_source)) |
| 1462 | return -TARGET_EINVAL; |
| 1463 | |
| 1464 | ip_mreq_source = lock_user(VERIFY_READ, optval_addr, optlen, 1); |
| 1465 | ret = get_errno(setsockopt(sockfd, level, optname, ip_mreq_source, optlen)); |
| 1466 | unlock_user (ip_mreq_source, optval_addr, 0); |
| 1467 | break; |
| 1468 | |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1469 | default: |
| 1470 | goto unimplemented; |
| 1471 | } |
| 1472 | break; |
Jing Huang | 920394d | 2012-07-24 13:59:23 +0000 | [diff] [blame] | 1473 | case SOL_RAW: |
| 1474 | switch (optname) { |
| 1475 | case ICMP_FILTER: |
| 1476 | /* struct icmp_filter takes an u32 value */ |
| 1477 | if (optlen < sizeof(uint32_t)) { |
| 1478 | return -TARGET_EINVAL; |
| 1479 | } |
| 1480 | |
| 1481 | if (get_user_u32(val, optval_addr)) { |
| 1482 | return -TARGET_EFAULT; |
| 1483 | } |
| 1484 | ret = get_errno(setsockopt(sockfd, level, optname, |
| 1485 | &val, sizeof(val))); |
| 1486 | break; |
| 1487 | |
| 1488 | default: |
| 1489 | goto unimplemented; |
| 1490 | } |
| 1491 | break; |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1492 | case TARGET_SOL_SOCKET: |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1493 | switch (optname) { |
| 1494 | /* Options with 'int' argument. */ |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1495 | case TARGET_SO_DEBUG: |
| 1496 | optname = SO_DEBUG; |
| 1497 | break; |
| 1498 | case TARGET_SO_REUSEADDR: |
| 1499 | optname = SO_REUSEADDR; |
| 1500 | break; |
| 1501 | case TARGET_SO_TYPE: |
| 1502 | optname = SO_TYPE; |
| 1503 | break; |
| 1504 | case TARGET_SO_ERROR: |
| 1505 | optname = SO_ERROR; |
| 1506 | break; |
| 1507 | case TARGET_SO_DONTROUTE: |
| 1508 | optname = SO_DONTROUTE; |
| 1509 | break; |
| 1510 | case TARGET_SO_BROADCAST: |
| 1511 | optname = SO_BROADCAST; |
| 1512 | break; |
| 1513 | case TARGET_SO_SNDBUF: |
| 1514 | optname = SO_SNDBUF; |
| 1515 | break; |
| 1516 | case TARGET_SO_RCVBUF: |
| 1517 | optname = SO_RCVBUF; |
| 1518 | break; |
| 1519 | case TARGET_SO_KEEPALIVE: |
| 1520 | optname = SO_KEEPALIVE; |
| 1521 | break; |
| 1522 | case TARGET_SO_OOBINLINE: |
| 1523 | optname = SO_OOBINLINE; |
| 1524 | break; |
| 1525 | case TARGET_SO_NO_CHECK: |
| 1526 | optname = SO_NO_CHECK; |
| 1527 | break; |
| 1528 | case TARGET_SO_PRIORITY: |
| 1529 | optname = SO_PRIORITY; |
| 1530 | break; |
bellard | 5e83e8e | 2005-03-01 22:32:06 +0000 | [diff] [blame] | 1531 | #ifdef SO_BSDCOMPAT |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1532 | case TARGET_SO_BSDCOMPAT: |
| 1533 | optname = SO_BSDCOMPAT; |
| 1534 | break; |
bellard | 5e83e8e | 2005-03-01 22:32:06 +0000 | [diff] [blame] | 1535 | #endif |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1536 | case TARGET_SO_PASSCRED: |
| 1537 | optname = SO_PASSCRED; |
| 1538 | break; |
| 1539 | case TARGET_SO_TIMESTAMP: |
| 1540 | optname = SO_TIMESTAMP; |
| 1541 | break; |
| 1542 | case TARGET_SO_RCVLOWAT: |
| 1543 | optname = SO_RCVLOWAT; |
| 1544 | break; |
| 1545 | case TARGET_SO_RCVTIMEO: |
| 1546 | optname = SO_RCVTIMEO; |
| 1547 | break; |
| 1548 | case TARGET_SO_SNDTIMEO: |
| 1549 | optname = SO_SNDTIMEO; |
| 1550 | break; |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1551 | break; |
| 1552 | default: |
| 1553 | goto unimplemented; |
| 1554 | } |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1555 | if (optlen < sizeof(uint32_t)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1556 | return -TARGET_EINVAL; |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1557 | |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1558 | if (get_user_u32(val, optval_addr)) |
| 1559 | return -TARGET_EFAULT; |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1560 | ret = get_errno(setsockopt(sockfd, SOL_SOCKET, optname, &val, sizeof(val))); |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1561 | break; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1562 | default: |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1563 | unimplemented: |
Stefan Weil | b2bedb2 | 2011-09-12 22:33:01 +0200 | [diff] [blame] | 1564 | gemu_log("Unsupported setsockopt level=%d optname=%d\n", level, optname); |
ths | 6fa13c1 | 2007-12-18 02:41:04 +0000 | [diff] [blame] | 1565 | ret = -TARGET_ENOPROTOOPT; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1566 | } |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1567 | return ret; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1568 | } |
| 1569 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 1570 | /* do_getsockopt() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 1571 | static abi_long do_getsockopt(int sockfd, int level, int optname, |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1572 | abi_ulong optval_addr, abi_ulong optlen) |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1573 | { |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 1574 | abi_long ret; |
blueswir1 | b55266b | 2008-09-20 08:07:15 +0000 | [diff] [blame] | 1575 | int len, val; |
| 1576 | socklen_t lv; |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1577 | |
| 1578 | switch(level) { |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1579 | case TARGET_SOL_SOCKET: |
Jamie Lentin | f3b974c | 2010-11-26 15:04:08 +0200 | [diff] [blame] | 1580 | level = SOL_SOCKET; |
| 1581 | switch (optname) { |
| 1582 | /* These don't just return a single integer */ |
| 1583 | case TARGET_SO_LINGER: |
| 1584 | case TARGET_SO_RCVTIMEO: |
| 1585 | case TARGET_SO_SNDTIMEO: |
Jamie Lentin | f3b974c | 2010-11-26 15:04:08 +0200 | [diff] [blame] | 1586 | case TARGET_SO_PEERNAME: |
| 1587 | goto unimplemented; |
Akos PASZTORY | 583359a | 2011-11-14 15:09:49 +0200 | [diff] [blame] | 1588 | case TARGET_SO_PEERCRED: { |
| 1589 | struct ucred cr; |
| 1590 | socklen_t crlen; |
| 1591 | struct target_ucred *tcr; |
| 1592 | |
| 1593 | if (get_user_u32(len, optlen)) { |
| 1594 | return -TARGET_EFAULT; |
| 1595 | } |
| 1596 | if (len < 0) { |
| 1597 | return -TARGET_EINVAL; |
| 1598 | } |
| 1599 | |
| 1600 | crlen = sizeof(cr); |
| 1601 | ret = get_errno(getsockopt(sockfd, level, SO_PEERCRED, |
| 1602 | &cr, &crlen)); |
| 1603 | if (ret < 0) { |
| 1604 | return ret; |
| 1605 | } |
| 1606 | if (len > crlen) { |
| 1607 | len = crlen; |
| 1608 | } |
| 1609 | if (!lock_user_struct(VERIFY_WRITE, tcr, optval_addr, 0)) { |
| 1610 | return -TARGET_EFAULT; |
| 1611 | } |
| 1612 | __put_user(cr.pid, &tcr->pid); |
| 1613 | __put_user(cr.uid, &tcr->uid); |
| 1614 | __put_user(cr.gid, &tcr->gid); |
| 1615 | unlock_user_struct(tcr, optval_addr, 1); |
| 1616 | if (put_user_u32(len, optlen)) { |
| 1617 | return -TARGET_EFAULT; |
| 1618 | } |
| 1619 | break; |
| 1620 | } |
Jamie Lentin | f3b974c | 2010-11-26 15:04:08 +0200 | [diff] [blame] | 1621 | /* Options with 'int' argument. */ |
| 1622 | case TARGET_SO_DEBUG: |
| 1623 | optname = SO_DEBUG; |
| 1624 | goto int_case; |
| 1625 | case TARGET_SO_REUSEADDR: |
| 1626 | optname = SO_REUSEADDR; |
| 1627 | goto int_case; |
| 1628 | case TARGET_SO_TYPE: |
| 1629 | optname = SO_TYPE; |
| 1630 | goto int_case; |
| 1631 | case TARGET_SO_ERROR: |
| 1632 | optname = SO_ERROR; |
| 1633 | goto int_case; |
| 1634 | case TARGET_SO_DONTROUTE: |
| 1635 | optname = SO_DONTROUTE; |
| 1636 | goto int_case; |
| 1637 | case TARGET_SO_BROADCAST: |
| 1638 | optname = SO_BROADCAST; |
| 1639 | goto int_case; |
| 1640 | case TARGET_SO_SNDBUF: |
| 1641 | optname = SO_SNDBUF; |
| 1642 | goto int_case; |
| 1643 | case TARGET_SO_RCVBUF: |
| 1644 | optname = SO_RCVBUF; |
| 1645 | goto int_case; |
| 1646 | case TARGET_SO_KEEPALIVE: |
| 1647 | optname = SO_KEEPALIVE; |
| 1648 | goto int_case; |
| 1649 | case TARGET_SO_OOBINLINE: |
| 1650 | optname = SO_OOBINLINE; |
| 1651 | goto int_case; |
| 1652 | case TARGET_SO_NO_CHECK: |
| 1653 | optname = SO_NO_CHECK; |
| 1654 | goto int_case; |
| 1655 | case TARGET_SO_PRIORITY: |
| 1656 | optname = SO_PRIORITY; |
| 1657 | goto int_case; |
| 1658 | #ifdef SO_BSDCOMPAT |
| 1659 | case TARGET_SO_BSDCOMPAT: |
| 1660 | optname = SO_BSDCOMPAT; |
| 1661 | goto int_case; |
| 1662 | #endif |
| 1663 | case TARGET_SO_PASSCRED: |
| 1664 | optname = SO_PASSCRED; |
| 1665 | goto int_case; |
| 1666 | case TARGET_SO_TIMESTAMP: |
| 1667 | optname = SO_TIMESTAMP; |
| 1668 | goto int_case; |
| 1669 | case TARGET_SO_RCVLOWAT: |
| 1670 | optname = SO_RCVLOWAT; |
| 1671 | goto int_case; |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1672 | default: |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1673 | goto int_case; |
| 1674 | } |
| 1675 | break; |
| 1676 | case SOL_TCP: |
| 1677 | /* TCP options all take an 'int' value. */ |
| 1678 | int_case: |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1679 | if (get_user_u32(len, optlen)) |
| 1680 | return -TARGET_EFAULT; |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1681 | if (len < 0) |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 1682 | return -TARGET_EINVAL; |
Mike Frysinger | 73160d9 | 2011-02-07 01:05:49 -0500 | [diff] [blame] | 1683 | lv = sizeof(lv); |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1684 | ret = get_errno(getsockopt(sockfd, level, optname, &val, &lv)); |
| 1685 | if (ret < 0) |
| 1686 | return ret; |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1687 | if (len > lv) |
| 1688 | len = lv; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1689 | if (len == 4) { |
| 1690 | if (put_user_u32(val, optval_addr)) |
| 1691 | return -TARGET_EFAULT; |
| 1692 | } else { |
| 1693 | if (put_user_u8(val, optval_addr)) |
| 1694 | return -TARGET_EFAULT; |
Jamie Lentin | f3b974c | 2010-11-26 15:04:08 +0200 | [diff] [blame] | 1695 | } |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1696 | if (put_user_u32(len, optlen)) |
| 1697 | return -TARGET_EFAULT; |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1698 | break; |
| 1699 | case SOL_IP: |
| 1700 | switch(optname) { |
| 1701 | case IP_TOS: |
| 1702 | case IP_TTL: |
| 1703 | case IP_HDRINCL: |
| 1704 | case IP_ROUTER_ALERT: |
| 1705 | case IP_RECVOPTS: |
| 1706 | case IP_RETOPTS: |
| 1707 | case IP_PKTINFO: |
| 1708 | case IP_MTU_DISCOVER: |
| 1709 | case IP_RECVERR: |
| 1710 | case IP_RECVTOS: |
| 1711 | #ifdef IP_FREEBIND |
| 1712 | case IP_FREEBIND: |
| 1713 | #endif |
| 1714 | case IP_MULTICAST_TTL: |
| 1715 | case IP_MULTICAST_LOOP: |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1716 | if (get_user_u32(len, optlen)) |
| 1717 | return -TARGET_EFAULT; |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1718 | if (len < 0) |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 1719 | return -TARGET_EINVAL; |
Mike Frysinger | 73160d9 | 2011-02-07 01:05:49 -0500 | [diff] [blame] | 1720 | lv = sizeof(lv); |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1721 | ret = get_errno(getsockopt(sockfd, level, optname, &val, &lv)); |
| 1722 | if (ret < 0) |
| 1723 | return ret; |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1724 | if (len < sizeof(int) && len > 0 && val >= 0 && val < 255) { |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1725 | len = 1; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1726 | if (put_user_u32(len, optlen) |
| 1727 | || put_user_u8(val, optval_addr)) |
| 1728 | return -TARGET_EFAULT; |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1729 | } else { |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1730 | if (len > sizeof(int)) |
| 1731 | len = sizeof(int); |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1732 | if (put_user_u32(len, optlen) |
| 1733 | || put_user_u32(val, optval_addr)) |
| 1734 | return -TARGET_EFAULT; |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1735 | } |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1736 | break; |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1737 | default: |
ths | c02f499 | 2007-12-18 02:39:59 +0000 | [diff] [blame] | 1738 | ret = -TARGET_ENOPROTOOPT; |
| 1739 | break; |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1740 | } |
| 1741 | break; |
| 1742 | default: |
| 1743 | unimplemented: |
| 1744 | gemu_log("getsockopt level=%d optname=%d not yet supported\n", |
| 1745 | level, optname); |
ths | c02f499 | 2007-12-18 02:39:59 +0000 | [diff] [blame] | 1746 | ret = -TARGET_EOPNOTSUPP; |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1747 | break; |
| 1748 | } |
| 1749 | return ret; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1750 | } |
| 1751 | |
Richard Henderson | f287b2c | 2012-09-15 13:20:25 -0700 | [diff] [blame] | 1752 | static struct iovec *lock_iovec(int type, abi_ulong target_addr, |
| 1753 | int count, int copy) |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1754 | { |
| 1755 | struct target_iovec *target_vec; |
Richard Henderson | f287b2c | 2012-09-15 13:20:25 -0700 | [diff] [blame] | 1756 | struct iovec *vec; |
| 1757 | abi_ulong total_len, max_len; |
balrog | d732dcb | 2008-10-28 10:21:03 +0000 | [diff] [blame] | 1758 | int i; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1759 | |
Richard Henderson | f287b2c | 2012-09-15 13:20:25 -0700 | [diff] [blame] | 1760 | if (count == 0) { |
| 1761 | errno = 0; |
| 1762 | return NULL; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1763 | } |
Richard Henderson | f287b2c | 2012-09-15 13:20:25 -0700 | [diff] [blame] | 1764 | if (count > IOV_MAX) { |
| 1765 | errno = EINVAL; |
| 1766 | return NULL; |
| 1767 | } |
| 1768 | |
| 1769 | vec = calloc(count, sizeof(struct iovec)); |
| 1770 | if (vec == NULL) { |
| 1771 | errno = ENOMEM; |
| 1772 | return NULL; |
| 1773 | } |
| 1774 | |
| 1775 | target_vec = lock_user(VERIFY_READ, target_addr, |
| 1776 | count * sizeof(struct target_iovec), 1); |
| 1777 | if (target_vec == NULL) { |
| 1778 | errno = EFAULT; |
| 1779 | goto fail2; |
| 1780 | } |
| 1781 | |
| 1782 | /* ??? If host page size > target page size, this will result in a |
| 1783 | value larger than what we can actually support. */ |
| 1784 | max_len = 0x7fffffff & TARGET_PAGE_MASK; |
| 1785 | total_len = 0; |
| 1786 | |
| 1787 | for (i = 0; i < count; i++) { |
| 1788 | abi_ulong base = tswapal(target_vec[i].iov_base); |
| 1789 | abi_long len = tswapal(target_vec[i].iov_len); |
| 1790 | |
| 1791 | if (len < 0) { |
| 1792 | errno = EINVAL; |
| 1793 | goto fail; |
| 1794 | } else if (len == 0) { |
| 1795 | /* Zero length pointer is ignored. */ |
| 1796 | vec[i].iov_base = 0; |
| 1797 | } else { |
| 1798 | vec[i].iov_base = lock_user(type, base, len, copy); |
| 1799 | if (!vec[i].iov_base) { |
| 1800 | errno = EFAULT; |
| 1801 | goto fail; |
| 1802 | } |
| 1803 | if (len > max_len - total_len) { |
| 1804 | len = max_len - total_len; |
| 1805 | } |
| 1806 | } |
| 1807 | vec[i].iov_len = len; |
| 1808 | total_len += len; |
| 1809 | } |
| 1810 | |
| 1811 | unlock_user(target_vec, target_addr, 0); |
| 1812 | return vec; |
| 1813 | |
| 1814 | fail: |
| 1815 | free(vec); |
| 1816 | fail2: |
| 1817 | unlock_user(target_vec, target_addr, 0); |
| 1818 | return NULL; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1819 | } |
| 1820 | |
Richard Henderson | f287b2c | 2012-09-15 13:20:25 -0700 | [diff] [blame] | 1821 | static void unlock_iovec(struct iovec *vec, abi_ulong target_addr, |
| 1822 | int count, int copy) |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1823 | { |
| 1824 | struct target_iovec *target_vec; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1825 | int i; |
| 1826 | |
Richard Henderson | f287b2c | 2012-09-15 13:20:25 -0700 | [diff] [blame] | 1827 | target_vec = lock_user(VERIFY_READ, target_addr, |
| 1828 | count * sizeof(struct target_iovec), 1); |
| 1829 | if (target_vec) { |
| 1830 | for (i = 0; i < count; i++) { |
| 1831 | abi_ulong base = tswapal(target_vec[i].iov_base); |
| 1832 | abi_long len = tswapal(target_vec[i].iov_base); |
| 1833 | if (len < 0) { |
| 1834 | break; |
| 1835 | } |
balrog | d732dcb | 2008-10-28 10:21:03 +0000 | [diff] [blame] | 1836 | unlock_user(vec[i].iov_base, base, copy ? vec[i].iov_len : 0); |
| 1837 | } |
Richard Henderson | f287b2c | 2012-09-15 13:20:25 -0700 | [diff] [blame] | 1838 | unlock_user(target_vec, target_addr, 0); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1839 | } |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1840 | |
Richard Henderson | f287b2c | 2012-09-15 13:20:25 -0700 | [diff] [blame] | 1841 | free(vec); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1842 | } |
| 1843 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 1844 | /* do_socket() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 1845 | static abi_long do_socket(int domain, int type, int protocol) |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1846 | { |
| 1847 | #if defined(TARGET_MIPS) |
| 1848 | switch(type) { |
| 1849 | case TARGET_SOCK_DGRAM: |
| 1850 | type = SOCK_DGRAM; |
| 1851 | break; |
| 1852 | case TARGET_SOCK_STREAM: |
| 1853 | type = SOCK_STREAM; |
| 1854 | break; |
| 1855 | case TARGET_SOCK_RAW: |
| 1856 | type = SOCK_RAW; |
| 1857 | break; |
| 1858 | case TARGET_SOCK_RDM: |
| 1859 | type = SOCK_RDM; |
| 1860 | break; |
| 1861 | case TARGET_SOCK_SEQPACKET: |
| 1862 | type = SOCK_SEQPACKET; |
| 1863 | break; |
| 1864 | case TARGET_SOCK_PACKET: |
| 1865 | type = SOCK_PACKET; |
| 1866 | break; |
| 1867 | } |
| 1868 | #endif |
balrog | 12bc92a | 2007-10-30 21:06:14 +0000 | [diff] [blame] | 1869 | if (domain == PF_NETLINK) |
| 1870 | return -EAFNOSUPPORT; /* do not NETLINK socket connections possible */ |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1871 | return get_errno(socket(domain, type, protocol)); |
| 1872 | } |
| 1873 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 1874 | /* do_bind() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 1875 | static abi_long do_bind(int sockfd, abi_ulong target_addr, |
| 1876 | socklen_t addrlen) |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1877 | { |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 1878 | void *addr; |
Arnaud Patard | 917507b | 2009-06-19 10:44:45 +0300 | [diff] [blame] | 1879 | abi_long ret; |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 1880 | |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 1881 | if ((int)addrlen < 0) { |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 1882 | return -TARGET_EINVAL; |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 1883 | } |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 1884 | |
aurel32 | 607175e | 2009-04-15 16:11:59 +0000 | [diff] [blame] | 1885 | addr = alloca(addrlen+1); |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1886 | |
Arnaud Patard | 917507b | 2009-06-19 10:44:45 +0300 | [diff] [blame] | 1887 | ret = target_to_host_sockaddr(addr, target_addr, addrlen); |
| 1888 | if (ret) |
| 1889 | return ret; |
| 1890 | |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1891 | return get_errno(bind(sockfd, addr, addrlen)); |
| 1892 | } |
| 1893 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 1894 | /* do_connect() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 1895 | static abi_long do_connect(int sockfd, abi_ulong target_addr, |
| 1896 | socklen_t addrlen) |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1897 | { |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 1898 | void *addr; |
Arnaud Patard | 917507b | 2009-06-19 10:44:45 +0300 | [diff] [blame] | 1899 | abi_long ret; |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 1900 | |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 1901 | if ((int)addrlen < 0) { |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 1902 | return -TARGET_EINVAL; |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 1903 | } |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 1904 | |
| 1905 | addr = alloca(addrlen); |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1906 | |
Arnaud Patard | 917507b | 2009-06-19 10:44:45 +0300 | [diff] [blame] | 1907 | ret = target_to_host_sockaddr(addr, target_addr, addrlen); |
| 1908 | if (ret) |
| 1909 | return ret; |
| 1910 | |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1911 | return get_errno(connect(sockfd, addr, addrlen)); |
| 1912 | } |
| 1913 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 1914 | /* do_sendrecvmsg() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 1915 | static abi_long do_sendrecvmsg(int fd, abi_ulong target_msg, |
| 1916 | int flags, int send) |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1917 | { |
balrog | 6de645c | 2008-10-28 10:26:29 +0000 | [diff] [blame] | 1918 | abi_long ret, len; |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1919 | struct target_msghdr *msgp; |
| 1920 | struct msghdr msg; |
| 1921 | int count; |
| 1922 | struct iovec *vec; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 1923 | abi_ulong target_vec; |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1924 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1925 | /* FIXME */ |
| 1926 | if (!lock_user_struct(send ? VERIFY_READ : VERIFY_WRITE, |
| 1927 | msgp, |
| 1928 | target_msg, |
| 1929 | send ? 1 : 0)) |
| 1930 | return -TARGET_EFAULT; |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1931 | if (msgp->msg_name) { |
| 1932 | msg.msg_namelen = tswap32(msgp->msg_namelen); |
| 1933 | msg.msg_name = alloca(msg.msg_namelen); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 1934 | ret = target_to_host_sockaddr(msg.msg_name, tswapal(msgp->msg_name), |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1935 | msg.msg_namelen); |
Arnaud Patard | 917507b | 2009-06-19 10:44:45 +0300 | [diff] [blame] | 1936 | if (ret) { |
Richard Henderson | f287b2c | 2012-09-15 13:20:25 -0700 | [diff] [blame] | 1937 | goto out2; |
Arnaud Patard | 917507b | 2009-06-19 10:44:45 +0300 | [diff] [blame] | 1938 | } |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1939 | } else { |
| 1940 | msg.msg_name = NULL; |
| 1941 | msg.msg_namelen = 0; |
| 1942 | } |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 1943 | msg.msg_controllen = 2 * tswapal(msgp->msg_controllen); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1944 | msg.msg_control = alloca(msg.msg_controllen); |
| 1945 | msg.msg_flags = tswap32(msgp->msg_flags); |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1946 | |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 1947 | count = tswapal(msgp->msg_iovlen); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 1948 | target_vec = tswapal(msgp->msg_iov); |
Richard Henderson | f287b2c | 2012-09-15 13:20:25 -0700 | [diff] [blame] | 1949 | vec = lock_iovec(send ? VERIFY_READ : VERIFY_WRITE, |
| 1950 | target_vec, count, send); |
| 1951 | if (vec == NULL) { |
| 1952 | ret = -host_to_target_errno(errno); |
| 1953 | goto out2; |
| 1954 | } |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1955 | msg.msg_iovlen = count; |
| 1956 | msg.msg_iov = vec; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1957 | |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1958 | if (send) { |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1959 | ret = target_to_host_cmsg(&msg, msgp); |
| 1960 | if (ret == 0) |
| 1961 | ret = get_errno(sendmsg(fd, &msg, flags)); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1962 | } else { |
| 1963 | ret = get_errno(recvmsg(fd, &msg, flags)); |
balrog | 6de645c | 2008-10-28 10:26:29 +0000 | [diff] [blame] | 1964 | if (!is_error(ret)) { |
| 1965 | len = ret; |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1966 | ret = host_to_target_cmsg(msgp, &msg); |
Jing Huang | ca61906 | 2012-07-24 13:58:02 +0000 | [diff] [blame] | 1967 | if (!is_error(ret)) { |
| 1968 | msgp->msg_namelen = tswap32(msg.msg_namelen); |
| 1969 | if (msg.msg_name != NULL) { |
| 1970 | ret = host_to_target_sockaddr(tswapal(msgp->msg_name), |
| 1971 | msg.msg_name, msg.msg_namelen); |
| 1972 | if (ret) { |
| 1973 | goto out; |
| 1974 | } |
| 1975 | } |
| 1976 | |
balrog | 6de645c | 2008-10-28 10:26:29 +0000 | [diff] [blame] | 1977 | ret = len; |
Jing Huang | ca61906 | 2012-07-24 13:58:02 +0000 | [diff] [blame] | 1978 | } |
balrog | 6de645c | 2008-10-28 10:26:29 +0000 | [diff] [blame] | 1979 | } |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1980 | } |
Jing Huang | ca61906 | 2012-07-24 13:58:02 +0000 | [diff] [blame] | 1981 | |
| 1982 | out: |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1983 | unlock_iovec(vec, target_vec, count, !send); |
Richard Henderson | f287b2c | 2012-09-15 13:20:25 -0700 | [diff] [blame] | 1984 | out2: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1985 | unlock_user_struct(msgp, target_msg, send ? 0 : 1); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1986 | return ret; |
| 1987 | } |
| 1988 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 1989 | /* do_accept() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 1990 | static abi_long do_accept(int fd, abi_ulong target_addr, |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1991 | abi_ulong target_addrlen_addr) |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 1992 | { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1993 | socklen_t addrlen; |
| 1994 | void *addr; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 1995 | abi_long ret; |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 1996 | |
Arnaud Patard | 917507b | 2009-06-19 10:44:45 +0300 | [diff] [blame] | 1997 | if (target_addr == 0) |
| 1998 | return get_errno(accept(fd, NULL, NULL)); |
| 1999 | |
| 2000 | /* linux returns EINVAL if addrlen pointer is invalid */ |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2001 | if (get_user_u32(addrlen, target_addrlen_addr)) |
Arnaud Patard | 917507b | 2009-06-19 10:44:45 +0300 | [diff] [blame] | 2002 | return -TARGET_EINVAL; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2003 | |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 2004 | if ((int)addrlen < 0) { |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 2005 | return -TARGET_EINVAL; |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 2006 | } |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 2007 | |
Arnaud Patard | 917507b | 2009-06-19 10:44:45 +0300 | [diff] [blame] | 2008 | if (!access_ok(VERIFY_WRITE, target_addr, addrlen)) |
| 2009 | return -TARGET_EINVAL; |
| 2010 | |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2011 | addr = alloca(addrlen); |
| 2012 | |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2013 | ret = get_errno(accept(fd, addr, &addrlen)); |
| 2014 | if (!is_error(ret)) { |
| 2015 | host_to_target_sockaddr(target_addr, addr, addrlen); |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2016 | if (put_user_u32(addrlen, target_addrlen_addr)) |
| 2017 | ret = -TARGET_EFAULT; |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2018 | } |
| 2019 | return ret; |
| 2020 | } |
| 2021 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 2022 | /* do_getpeername() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2023 | static abi_long do_getpeername(int fd, abi_ulong target_addr, |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2024 | abi_ulong target_addrlen_addr) |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2025 | { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2026 | socklen_t addrlen; |
| 2027 | void *addr; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2028 | abi_long ret; |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2029 | |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2030 | if (get_user_u32(addrlen, target_addrlen_addr)) |
| 2031 | return -TARGET_EFAULT; |
| 2032 | |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 2033 | if ((int)addrlen < 0) { |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 2034 | return -TARGET_EINVAL; |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 2035 | } |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 2036 | |
Arnaud Patard | 917507b | 2009-06-19 10:44:45 +0300 | [diff] [blame] | 2037 | if (!access_ok(VERIFY_WRITE, target_addr, addrlen)) |
| 2038 | return -TARGET_EFAULT; |
| 2039 | |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2040 | addr = alloca(addrlen); |
| 2041 | |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2042 | ret = get_errno(getpeername(fd, addr, &addrlen)); |
| 2043 | if (!is_error(ret)) { |
| 2044 | host_to_target_sockaddr(target_addr, addr, addrlen); |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2045 | if (put_user_u32(addrlen, target_addrlen_addr)) |
| 2046 | ret = -TARGET_EFAULT; |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2047 | } |
| 2048 | return ret; |
| 2049 | } |
| 2050 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 2051 | /* do_getsockname() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2052 | static abi_long do_getsockname(int fd, abi_ulong target_addr, |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2053 | abi_ulong target_addrlen_addr) |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2054 | { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2055 | socklen_t addrlen; |
| 2056 | void *addr; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2057 | abi_long ret; |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2058 | |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2059 | if (get_user_u32(addrlen, target_addrlen_addr)) |
| 2060 | return -TARGET_EFAULT; |
| 2061 | |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 2062 | if ((int)addrlen < 0) { |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 2063 | return -TARGET_EINVAL; |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 2064 | } |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 2065 | |
Arnaud Patard | 917507b | 2009-06-19 10:44:45 +0300 | [diff] [blame] | 2066 | if (!access_ok(VERIFY_WRITE, target_addr, addrlen)) |
| 2067 | return -TARGET_EFAULT; |
| 2068 | |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2069 | addr = alloca(addrlen); |
| 2070 | |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2071 | ret = get_errno(getsockname(fd, addr, &addrlen)); |
| 2072 | if (!is_error(ret)) { |
| 2073 | host_to_target_sockaddr(target_addr, addr, addrlen); |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2074 | if (put_user_u32(addrlen, target_addrlen_addr)) |
| 2075 | ret = -TARGET_EFAULT; |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2076 | } |
| 2077 | return ret; |
| 2078 | } |
| 2079 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 2080 | /* do_socketpair() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2081 | static abi_long do_socketpair(int domain, int type, int protocol, |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2082 | abi_ulong target_tab_addr) |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2083 | { |
| 2084 | int tab[2]; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2085 | abi_long ret; |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2086 | |
| 2087 | ret = get_errno(socketpair(domain, type, protocol, tab)); |
| 2088 | if (!is_error(ret)) { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2089 | if (put_user_s32(tab[0], target_tab_addr) |
| 2090 | || put_user_s32(tab[1], target_tab_addr + sizeof(tab[0]))) |
| 2091 | ret = -TARGET_EFAULT; |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2092 | } |
| 2093 | return ret; |
| 2094 | } |
| 2095 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 2096 | /* do_sendto() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2097 | static abi_long do_sendto(int fd, abi_ulong msg, size_t len, int flags, |
| 2098 | abi_ulong target_addr, socklen_t addrlen) |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2099 | { |
| 2100 | void *addr; |
| 2101 | void *host_msg; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2102 | abi_long ret; |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2103 | |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 2104 | if ((int)addrlen < 0) { |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 2105 | return -TARGET_EINVAL; |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 2106 | } |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 2107 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2108 | host_msg = lock_user(VERIFY_READ, msg, len, 1); |
| 2109 | if (!host_msg) |
| 2110 | return -TARGET_EFAULT; |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2111 | if (target_addr) { |
| 2112 | addr = alloca(addrlen); |
Arnaud Patard | 917507b | 2009-06-19 10:44:45 +0300 | [diff] [blame] | 2113 | ret = target_to_host_sockaddr(addr, target_addr, addrlen); |
| 2114 | if (ret) { |
| 2115 | unlock_user(host_msg, msg, 0); |
| 2116 | return ret; |
| 2117 | } |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2118 | ret = get_errno(sendto(fd, host_msg, len, flags, addr, addrlen)); |
| 2119 | } else { |
| 2120 | ret = get_errno(send(fd, host_msg, len, flags)); |
| 2121 | } |
| 2122 | unlock_user(host_msg, msg, 0); |
| 2123 | return ret; |
| 2124 | } |
| 2125 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 2126 | /* do_recvfrom() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2127 | static abi_long do_recvfrom(int fd, abi_ulong msg, size_t len, int flags, |
| 2128 | abi_ulong target_addr, |
| 2129 | abi_ulong target_addrlen) |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2130 | { |
| 2131 | socklen_t addrlen; |
| 2132 | void *addr; |
| 2133 | void *host_msg; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2134 | abi_long ret; |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2135 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2136 | host_msg = lock_user(VERIFY_WRITE, msg, len, 0); |
| 2137 | if (!host_msg) |
| 2138 | return -TARGET_EFAULT; |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2139 | if (target_addr) { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2140 | if (get_user_u32(addrlen, target_addrlen)) { |
| 2141 | ret = -TARGET_EFAULT; |
| 2142 | goto fail; |
| 2143 | } |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 2144 | if ((int)addrlen < 0) { |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 2145 | ret = -TARGET_EINVAL; |
| 2146 | goto fail; |
| 2147 | } |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2148 | addr = alloca(addrlen); |
| 2149 | ret = get_errno(recvfrom(fd, host_msg, len, flags, addr, &addrlen)); |
| 2150 | } else { |
| 2151 | addr = NULL; /* To keep compiler quiet. */ |
Blue Swirl | 00aa004 | 2011-07-23 20:04:29 +0000 | [diff] [blame] | 2152 | ret = get_errno(qemu_recv(fd, host_msg, len, flags)); |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2153 | } |
| 2154 | if (!is_error(ret)) { |
| 2155 | if (target_addr) { |
| 2156 | host_to_target_sockaddr(target_addr, addr, addrlen); |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2157 | if (put_user_u32(addrlen, target_addrlen)) { |
| 2158 | ret = -TARGET_EFAULT; |
| 2159 | goto fail; |
| 2160 | } |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2161 | } |
| 2162 | unlock_user(host_msg, msg, len); |
| 2163 | } else { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2164 | fail: |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2165 | unlock_user(host_msg, msg, 0); |
| 2166 | } |
| 2167 | return ret; |
| 2168 | } |
| 2169 | |
j_mayer | 3240710 | 2007-09-26 23:01:49 +0000 | [diff] [blame] | 2170 | #ifdef TARGET_NR_socketcall |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 2171 | /* do_socketcall() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2172 | static abi_long do_socketcall(int num, abi_ulong vptr) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2173 | { |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2174 | abi_long ret; |
| 2175 | const int n = sizeof(abi_ulong); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2176 | |
| 2177 | switch(num) { |
| 2178 | case SOCKOP_socket: |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2179 | { |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2180 | abi_ulong domain, type, protocol; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2181 | |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2182 | if (get_user_ual(domain, vptr) |
| 2183 | || get_user_ual(type, vptr + n) |
| 2184 | || get_user_ual(protocol, vptr + 2 * n)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2185 | return -TARGET_EFAULT; |
| 2186 | |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 2187 | ret = do_socket(domain, type, protocol); |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2188 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2189 | break; |
| 2190 | case SOCKOP_bind: |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2191 | { |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2192 | abi_ulong sockfd; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2193 | abi_ulong target_addr; |
| 2194 | socklen_t addrlen; |
| 2195 | |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2196 | if (get_user_ual(sockfd, vptr) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2197 | || get_user_ual(target_addr, vptr + n) |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2198 | || get_user_ual(addrlen, vptr + 2 * n)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2199 | return -TARGET_EFAULT; |
| 2200 | |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 2201 | ret = do_bind(sockfd, target_addr, addrlen); |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2202 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2203 | break; |
| 2204 | case SOCKOP_connect: |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2205 | { |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2206 | abi_ulong sockfd; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2207 | abi_ulong target_addr; |
| 2208 | socklen_t addrlen; |
| 2209 | |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2210 | if (get_user_ual(sockfd, vptr) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2211 | || get_user_ual(target_addr, vptr + n) |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2212 | || get_user_ual(addrlen, vptr + 2 * n)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2213 | return -TARGET_EFAULT; |
| 2214 | |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 2215 | ret = do_connect(sockfd, target_addr, addrlen); |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2216 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2217 | break; |
| 2218 | case SOCKOP_listen: |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2219 | { |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2220 | abi_ulong sockfd, backlog; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2221 | |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2222 | if (get_user_ual(sockfd, vptr) |
| 2223 | || get_user_ual(backlog, vptr + n)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2224 | return -TARGET_EFAULT; |
| 2225 | |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2226 | ret = get_errno(listen(sockfd, backlog)); |
| 2227 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2228 | break; |
| 2229 | case SOCKOP_accept: |
| 2230 | { |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2231 | abi_ulong sockfd; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2232 | abi_ulong target_addr, target_addrlen; |
| 2233 | |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2234 | if (get_user_ual(sockfd, vptr) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2235 | || get_user_ual(target_addr, vptr + n) |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2236 | || get_user_ual(target_addrlen, vptr + 2 * n)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2237 | return -TARGET_EFAULT; |
| 2238 | |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2239 | ret = do_accept(sockfd, target_addr, target_addrlen); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2240 | } |
| 2241 | break; |
| 2242 | case SOCKOP_getsockname: |
| 2243 | { |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2244 | abi_ulong sockfd; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2245 | abi_ulong target_addr, target_addrlen; |
| 2246 | |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2247 | if (get_user_ual(sockfd, vptr) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2248 | || get_user_ual(target_addr, vptr + n) |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2249 | || get_user_ual(target_addrlen, vptr + 2 * n)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2250 | return -TARGET_EFAULT; |
| 2251 | |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2252 | ret = do_getsockname(sockfd, target_addr, target_addrlen); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2253 | } |
| 2254 | break; |
| 2255 | case SOCKOP_getpeername: |
| 2256 | { |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2257 | abi_ulong sockfd; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2258 | abi_ulong target_addr, target_addrlen; |
| 2259 | |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2260 | if (get_user_ual(sockfd, vptr) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2261 | || get_user_ual(target_addr, vptr + n) |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2262 | || get_user_ual(target_addrlen, vptr + 2 * n)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2263 | return -TARGET_EFAULT; |
| 2264 | |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2265 | ret = do_getpeername(sockfd, target_addr, target_addrlen); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2266 | } |
| 2267 | break; |
| 2268 | case SOCKOP_socketpair: |
| 2269 | { |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2270 | abi_ulong domain, type, protocol; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2271 | abi_ulong tab; |
| 2272 | |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2273 | if (get_user_ual(domain, vptr) |
| 2274 | || get_user_ual(type, vptr + n) |
| 2275 | || get_user_ual(protocol, vptr + 2 * n) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2276 | || get_user_ual(tab, vptr + 3 * n)) |
| 2277 | return -TARGET_EFAULT; |
| 2278 | |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2279 | ret = do_socketpair(domain, type, protocol, tab); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2280 | } |
| 2281 | break; |
| 2282 | case SOCKOP_send: |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2283 | { |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2284 | abi_ulong sockfd; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2285 | abi_ulong msg; |
| 2286 | size_t len; |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2287 | abi_ulong flags; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2288 | |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2289 | if (get_user_ual(sockfd, vptr) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2290 | || get_user_ual(msg, vptr + n) |
| 2291 | || get_user_ual(len, vptr + 2 * n) |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2292 | || get_user_ual(flags, vptr + 3 * n)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2293 | return -TARGET_EFAULT; |
| 2294 | |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2295 | ret = do_sendto(sockfd, msg, len, flags, 0, 0); |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2296 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2297 | break; |
| 2298 | case SOCKOP_recv: |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2299 | { |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2300 | abi_ulong sockfd; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2301 | abi_ulong msg; |
| 2302 | size_t len; |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2303 | abi_ulong flags; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2304 | |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2305 | if (get_user_ual(sockfd, vptr) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2306 | || get_user_ual(msg, vptr + n) |
| 2307 | || get_user_ual(len, vptr + 2 * n) |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2308 | || get_user_ual(flags, vptr + 3 * n)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2309 | return -TARGET_EFAULT; |
| 2310 | |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2311 | ret = do_recvfrom(sockfd, msg, len, flags, 0, 0); |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2312 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2313 | break; |
| 2314 | case SOCKOP_sendto: |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2315 | { |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2316 | abi_ulong sockfd; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2317 | abi_ulong msg; |
| 2318 | size_t len; |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2319 | abi_ulong flags; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2320 | abi_ulong addr; |
| 2321 | socklen_t addrlen; |
| 2322 | |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2323 | if (get_user_ual(sockfd, vptr) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2324 | || get_user_ual(msg, vptr + n) |
| 2325 | || get_user_ual(len, vptr + 2 * n) |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2326 | || get_user_ual(flags, vptr + 3 * n) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2327 | || get_user_ual(addr, vptr + 4 * n) |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2328 | || get_user_ual(addrlen, vptr + 5 * n)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2329 | return -TARGET_EFAULT; |
| 2330 | |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2331 | ret = do_sendto(sockfd, msg, len, flags, addr, addrlen); |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2332 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2333 | break; |
| 2334 | case SOCKOP_recvfrom: |
| 2335 | { |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2336 | abi_ulong sockfd; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2337 | abi_ulong msg; |
| 2338 | size_t len; |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2339 | abi_ulong flags; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2340 | abi_ulong addr; |
| 2341 | socklen_t addrlen; |
| 2342 | |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2343 | if (get_user_ual(sockfd, vptr) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2344 | || get_user_ual(msg, vptr + n) |
| 2345 | || get_user_ual(len, vptr + 2 * n) |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2346 | || get_user_ual(flags, vptr + 3 * n) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2347 | || get_user_ual(addr, vptr + 4 * n) |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2348 | || get_user_ual(addrlen, vptr + 5 * n)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2349 | return -TARGET_EFAULT; |
| 2350 | |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2351 | ret = do_recvfrom(sockfd, msg, len, flags, addr, addrlen); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2352 | } |
| 2353 | break; |
| 2354 | case SOCKOP_shutdown: |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2355 | { |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2356 | abi_ulong sockfd, how; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2357 | |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2358 | if (get_user_ual(sockfd, vptr) |
| 2359 | || get_user_ual(how, vptr + n)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2360 | return -TARGET_EFAULT; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2361 | |
| 2362 | ret = get_errno(shutdown(sockfd, how)); |
| 2363 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2364 | break; |
| 2365 | case SOCKOP_sendmsg: |
| 2366 | case SOCKOP_recvmsg: |
bellard | 1a9353d | 2003-03-16 20:28:50 +0000 | [diff] [blame] | 2367 | { |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2368 | abi_ulong fd; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2369 | abi_ulong target_msg; |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2370 | abi_ulong flags; |
bellard | 1a9353d | 2003-03-16 20:28:50 +0000 | [diff] [blame] | 2371 | |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2372 | if (get_user_ual(fd, vptr) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2373 | || get_user_ual(target_msg, vptr + n) |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2374 | || get_user_ual(flags, vptr + 2 * n)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2375 | return -TARGET_EFAULT; |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 2376 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 2377 | ret = do_sendrecvmsg(fd, target_msg, flags, |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 2378 | (num == SOCKOP_sendmsg)); |
bellard | 1a9353d | 2003-03-16 20:28:50 +0000 | [diff] [blame] | 2379 | } |
| 2380 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2381 | case SOCKOP_setsockopt: |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2382 | { |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2383 | abi_ulong sockfd; |
| 2384 | abi_ulong level; |
| 2385 | abi_ulong optname; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2386 | abi_ulong optval; |
| 2387 | socklen_t optlen; |
| 2388 | |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2389 | if (get_user_ual(sockfd, vptr) |
| 2390 | || get_user_ual(level, vptr + n) |
| 2391 | || get_user_ual(optname, vptr + 2 * n) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2392 | || get_user_ual(optval, vptr + 3 * n) |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2393 | || get_user_ual(optlen, vptr + 4 * n)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2394 | return -TARGET_EFAULT; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2395 | |
| 2396 | ret = do_setsockopt(sockfd, level, optname, optval, optlen); |
| 2397 | } |
| 2398 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2399 | case SOCKOP_getsockopt: |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2400 | { |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2401 | abi_ulong sockfd; |
| 2402 | abi_ulong level; |
| 2403 | abi_ulong optname; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2404 | abi_ulong optval; |
| 2405 | socklen_t optlen; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2406 | |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2407 | if (get_user_ual(sockfd, vptr) |
| 2408 | || get_user_ual(level, vptr + n) |
| 2409 | || get_user_ual(optname, vptr + 2 * n) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2410 | || get_user_ual(optval, vptr + 3 * n) |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2411 | || get_user_ual(optlen, vptr + 4 * n)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2412 | return -TARGET_EFAULT; |
| 2413 | |
| 2414 | ret = do_getsockopt(sockfd, level, optname, optval, optlen); |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2415 | } |
| 2416 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2417 | default: |
| 2418 | gemu_log("Unsupported socketcall: %d\n", num); |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 2419 | ret = -TARGET_ENOSYS; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2420 | break; |
| 2421 | } |
| 2422 | return ret; |
| 2423 | } |
j_mayer | 3240710 | 2007-09-26 23:01:49 +0000 | [diff] [blame] | 2424 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2425 | |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 2426 | #define N_SHM_REGIONS 32 |
| 2427 | |
| 2428 | static struct shm_region { |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 2429 | abi_ulong start; |
| 2430 | abi_ulong size; |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 2431 | } shm_regions[N_SHM_REGIONS]; |
| 2432 | |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2433 | struct target_ipc_perm |
| 2434 | { |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2435 | abi_long __key; |
| 2436 | abi_ulong uid; |
| 2437 | abi_ulong gid; |
| 2438 | abi_ulong cuid; |
| 2439 | abi_ulong cgid; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2440 | unsigned short int mode; |
| 2441 | unsigned short int __pad1; |
| 2442 | unsigned short int __seq; |
| 2443 | unsigned short int __pad2; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2444 | abi_ulong __unused1; |
| 2445 | abi_ulong __unused2; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2446 | }; |
| 2447 | |
| 2448 | struct target_semid_ds |
| 2449 | { |
| 2450 | struct target_ipc_perm sem_perm; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2451 | abi_ulong sem_otime; |
| 2452 | abi_ulong __unused1; |
| 2453 | abi_ulong sem_ctime; |
| 2454 | abi_ulong __unused2; |
| 2455 | abi_ulong sem_nsems; |
| 2456 | abi_ulong __unused3; |
| 2457 | abi_ulong __unused4; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2458 | }; |
| 2459 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2460 | static inline abi_long target_to_host_ipc_perm(struct ipc_perm *host_ip, |
| 2461 | abi_ulong target_addr) |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2462 | { |
| 2463 | struct target_ipc_perm *target_ip; |
| 2464 | struct target_semid_ds *target_sd; |
| 2465 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2466 | if (!lock_user_struct(VERIFY_READ, target_sd, target_addr, 1)) |
| 2467 | return -TARGET_EFAULT; |
Michael S. Tsirkin | e8bbe36 | 2009-09-30 18:56:44 +0000 | [diff] [blame] | 2468 | target_ip = &(target_sd->sem_perm); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 2469 | host_ip->__key = tswapal(target_ip->__key); |
| 2470 | host_ip->uid = tswapal(target_ip->uid); |
| 2471 | host_ip->gid = tswapal(target_ip->gid); |
| 2472 | host_ip->cuid = tswapal(target_ip->cuid); |
| 2473 | host_ip->cgid = tswapal(target_ip->cgid); |
| 2474 | host_ip->mode = tswap16(target_ip->mode); |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2475 | unlock_user_struct(target_sd, target_addr, 0); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2476 | return 0; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2477 | } |
| 2478 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2479 | static inline abi_long host_to_target_ipc_perm(abi_ulong target_addr, |
| 2480 | struct ipc_perm *host_ip) |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2481 | { |
| 2482 | struct target_ipc_perm *target_ip; |
| 2483 | struct target_semid_ds *target_sd; |
| 2484 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2485 | if (!lock_user_struct(VERIFY_WRITE, target_sd, target_addr, 0)) |
| 2486 | return -TARGET_EFAULT; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2487 | target_ip = &(target_sd->sem_perm); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 2488 | target_ip->__key = tswapal(host_ip->__key); |
| 2489 | target_ip->uid = tswapal(host_ip->uid); |
| 2490 | target_ip->gid = tswapal(host_ip->gid); |
| 2491 | target_ip->cuid = tswapal(host_ip->cuid); |
| 2492 | target_ip->cgid = tswapal(host_ip->cgid); |
| 2493 | target_ip->mode = tswap16(host_ip->mode); |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2494 | unlock_user_struct(target_sd, target_addr, 1); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2495 | return 0; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2496 | } |
| 2497 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2498 | static inline abi_long target_to_host_semid_ds(struct semid_ds *host_sd, |
| 2499 | abi_ulong target_addr) |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2500 | { |
| 2501 | struct target_semid_ds *target_sd; |
| 2502 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2503 | if (!lock_user_struct(VERIFY_READ, target_sd, target_addr, 1)) |
| 2504 | return -TARGET_EFAULT; |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2505 | if (target_to_host_ipc_perm(&(host_sd->sem_perm),target_addr)) |
| 2506 | return -TARGET_EFAULT; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 2507 | host_sd->sem_nsems = tswapal(target_sd->sem_nsems); |
| 2508 | host_sd->sem_otime = tswapal(target_sd->sem_otime); |
| 2509 | host_sd->sem_ctime = tswapal(target_sd->sem_ctime); |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2510 | unlock_user_struct(target_sd, target_addr, 0); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2511 | return 0; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2512 | } |
| 2513 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2514 | static inline abi_long host_to_target_semid_ds(abi_ulong target_addr, |
| 2515 | struct semid_ds *host_sd) |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2516 | { |
| 2517 | struct target_semid_ds *target_sd; |
| 2518 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2519 | if (!lock_user_struct(VERIFY_WRITE, target_sd, target_addr, 0)) |
| 2520 | return -TARGET_EFAULT; |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2521 | if (host_to_target_ipc_perm(target_addr,&(host_sd->sem_perm))) |
Dong Xu Wang | 3a93113 | 2011-11-29 16:52:38 +0800 | [diff] [blame] | 2522 | return -TARGET_EFAULT; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 2523 | target_sd->sem_nsems = tswapal(host_sd->sem_nsems); |
| 2524 | target_sd->sem_otime = tswapal(host_sd->sem_otime); |
| 2525 | target_sd->sem_ctime = tswapal(host_sd->sem_ctime); |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2526 | unlock_user_struct(target_sd, target_addr, 1); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2527 | return 0; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2528 | } |
| 2529 | |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2530 | struct target_seminfo { |
| 2531 | int semmap; |
| 2532 | int semmni; |
| 2533 | int semmns; |
| 2534 | int semmnu; |
| 2535 | int semmsl; |
| 2536 | int semopm; |
| 2537 | int semume; |
| 2538 | int semusz; |
| 2539 | int semvmx; |
| 2540 | int semaem; |
| 2541 | }; |
| 2542 | |
| 2543 | static inline abi_long host_to_target_seminfo(abi_ulong target_addr, |
| 2544 | struct seminfo *host_seminfo) |
| 2545 | { |
| 2546 | struct target_seminfo *target_seminfo; |
| 2547 | if (!lock_user_struct(VERIFY_WRITE, target_seminfo, target_addr, 0)) |
| 2548 | return -TARGET_EFAULT; |
| 2549 | __put_user(host_seminfo->semmap, &target_seminfo->semmap); |
| 2550 | __put_user(host_seminfo->semmni, &target_seminfo->semmni); |
| 2551 | __put_user(host_seminfo->semmns, &target_seminfo->semmns); |
| 2552 | __put_user(host_seminfo->semmnu, &target_seminfo->semmnu); |
| 2553 | __put_user(host_seminfo->semmsl, &target_seminfo->semmsl); |
| 2554 | __put_user(host_seminfo->semopm, &target_seminfo->semopm); |
| 2555 | __put_user(host_seminfo->semume, &target_seminfo->semume); |
| 2556 | __put_user(host_seminfo->semusz, &target_seminfo->semusz); |
| 2557 | __put_user(host_seminfo->semvmx, &target_seminfo->semvmx); |
| 2558 | __put_user(host_seminfo->semaem, &target_seminfo->semaem); |
| 2559 | unlock_user_struct(target_seminfo, target_addr, 1); |
| 2560 | return 0; |
| 2561 | } |
| 2562 | |
ths | fa29481 | 2007-02-02 22:05:00 +0000 | [diff] [blame] | 2563 | union semun { |
| 2564 | int val; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2565 | struct semid_ds *buf; |
ths | fa29481 | 2007-02-02 22:05:00 +0000 | [diff] [blame] | 2566 | unsigned short *array; |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2567 | struct seminfo *__buf; |
ths | fa29481 | 2007-02-02 22:05:00 +0000 | [diff] [blame] | 2568 | }; |
| 2569 | |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2570 | union target_semun { |
| 2571 | int val; |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2572 | abi_ulong buf; |
| 2573 | abi_ulong array; |
| 2574 | abi_ulong __buf; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2575 | }; |
| 2576 | |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2577 | static inline abi_long target_to_host_semarray(int semid, unsigned short **host_array, |
| 2578 | abi_ulong target_addr) |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2579 | { |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2580 | int nsems; |
| 2581 | unsigned short *array; |
| 2582 | union semun semun; |
| 2583 | struct semid_ds semid_ds; |
| 2584 | int i, ret; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2585 | |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2586 | semun.buf = &semid_ds; |
| 2587 | |
| 2588 | ret = semctl(semid, 0, IPC_STAT, semun); |
| 2589 | if (ret == -1) |
| 2590 | return get_errno(ret); |
| 2591 | |
| 2592 | nsems = semid_ds.sem_nsems; |
| 2593 | |
| 2594 | *host_array = malloc(nsems*sizeof(unsigned short)); |
| 2595 | array = lock_user(VERIFY_READ, target_addr, |
| 2596 | nsems*sizeof(unsigned short), 1); |
| 2597 | if (!array) |
| 2598 | return -TARGET_EFAULT; |
| 2599 | |
| 2600 | for(i=0; i<nsems; i++) { |
| 2601 | __get_user((*host_array)[i], &array[i]); |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2602 | } |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2603 | unlock_user(array, target_addr, 0); |
| 2604 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2605 | return 0; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2606 | } |
| 2607 | |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2608 | static inline abi_long host_to_target_semarray(int semid, abi_ulong target_addr, |
| 2609 | unsigned short **host_array) |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2610 | { |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2611 | int nsems; |
| 2612 | unsigned short *array; |
| 2613 | union semun semun; |
| 2614 | struct semid_ds semid_ds; |
| 2615 | int i, ret; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2616 | |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2617 | semun.buf = &semid_ds; |
| 2618 | |
| 2619 | ret = semctl(semid, 0, IPC_STAT, semun); |
| 2620 | if (ret == -1) |
| 2621 | return get_errno(ret); |
| 2622 | |
| 2623 | nsems = semid_ds.sem_nsems; |
| 2624 | |
| 2625 | array = lock_user(VERIFY_WRITE, target_addr, |
| 2626 | nsems*sizeof(unsigned short), 0); |
| 2627 | if (!array) |
| 2628 | return -TARGET_EFAULT; |
| 2629 | |
| 2630 | for(i=0; i<nsems; i++) { |
| 2631 | __put_user((*host_array)[i], &array[i]); |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2632 | } |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2633 | free(*host_array); |
| 2634 | unlock_user(array, target_addr, 1); |
| 2635 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2636 | return 0; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2637 | } |
| 2638 | |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2639 | static inline abi_long do_semctl(int semid, int semnum, int cmd, |
| 2640 | union target_semun target_su) |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2641 | { |
| 2642 | union semun arg; |
| 2643 | struct semid_ds dsarg; |
vibi sreenivasan | 7b8118e | 2009-06-19 13:34:39 +0530 | [diff] [blame] | 2644 | unsigned short *array = NULL; |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2645 | struct seminfo seminfo; |
| 2646 | abi_long ret = -TARGET_EINVAL; |
| 2647 | abi_long err; |
| 2648 | cmd &= 0xff; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2649 | |
| 2650 | switch( cmd ) { |
| 2651 | case GETVAL: |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2652 | case SETVAL: |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 2653 | arg.val = tswap32(target_su.val); |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2654 | ret = get_errno(semctl(semid, semnum, cmd, arg)); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 2655 | target_su.val = tswap32(arg.val); |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2656 | break; |
| 2657 | case GETALL: |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2658 | case SETALL: |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2659 | err = target_to_host_semarray(semid, &array, target_su.array); |
| 2660 | if (err) |
| 2661 | return err; |
| 2662 | arg.array = array; |
| 2663 | ret = get_errno(semctl(semid, semnum, cmd, arg)); |
| 2664 | err = host_to_target_semarray(semid, target_su.array, &array); |
| 2665 | if (err) |
| 2666 | return err; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2667 | break; |
| 2668 | case IPC_STAT: |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2669 | case IPC_SET: |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2670 | case SEM_STAT: |
| 2671 | err = target_to_host_semid_ds(&dsarg, target_su.buf); |
| 2672 | if (err) |
| 2673 | return err; |
| 2674 | arg.buf = &dsarg; |
| 2675 | ret = get_errno(semctl(semid, semnum, cmd, arg)); |
| 2676 | err = host_to_target_semid_ds(target_su.buf, &dsarg); |
| 2677 | if (err) |
| 2678 | return err; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2679 | break; |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2680 | case IPC_INFO: |
| 2681 | case SEM_INFO: |
| 2682 | arg.__buf = &seminfo; |
| 2683 | ret = get_errno(semctl(semid, semnum, cmd, arg)); |
| 2684 | err = host_to_target_seminfo(target_su.__buf, &seminfo); |
| 2685 | if (err) |
| 2686 | return err; |
| 2687 | break; |
| 2688 | case IPC_RMID: |
| 2689 | case GETPID: |
| 2690 | case GETNCNT: |
| 2691 | case GETZCNT: |
| 2692 | ret = get_errno(semctl(semid, semnum, cmd, NULL)); |
| 2693 | break; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2694 | } |
| 2695 | |
| 2696 | return ret; |
| 2697 | } |
| 2698 | |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2699 | struct target_sembuf { |
| 2700 | unsigned short sem_num; |
| 2701 | short sem_op; |
| 2702 | short sem_flg; |
| 2703 | }; |
| 2704 | |
| 2705 | static inline abi_long target_to_host_sembuf(struct sembuf *host_sembuf, |
| 2706 | abi_ulong target_addr, |
| 2707 | unsigned nsops) |
| 2708 | { |
| 2709 | struct target_sembuf *target_sembuf; |
| 2710 | int i; |
| 2711 | |
| 2712 | target_sembuf = lock_user(VERIFY_READ, target_addr, |
| 2713 | nsops*sizeof(struct target_sembuf), 1); |
| 2714 | if (!target_sembuf) |
| 2715 | return -TARGET_EFAULT; |
| 2716 | |
| 2717 | for(i=0; i<nsops; i++) { |
| 2718 | __get_user(host_sembuf[i].sem_num, &target_sembuf[i].sem_num); |
| 2719 | __get_user(host_sembuf[i].sem_op, &target_sembuf[i].sem_op); |
| 2720 | __get_user(host_sembuf[i].sem_flg, &target_sembuf[i].sem_flg); |
| 2721 | } |
| 2722 | |
| 2723 | unlock_user(target_sembuf, target_addr, 0); |
| 2724 | |
| 2725 | return 0; |
| 2726 | } |
| 2727 | |
| 2728 | static inline abi_long do_semop(int semid, abi_long ptr, unsigned nsops) |
| 2729 | { |
| 2730 | struct sembuf sops[nsops]; |
| 2731 | |
| 2732 | if (target_to_host_sembuf(sops, ptr, nsops)) |
| 2733 | return -TARGET_EFAULT; |
| 2734 | |
| 2735 | return semop(semid, sops, nsops); |
| 2736 | } |
| 2737 | |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2738 | struct target_msqid_ds |
| 2739 | { |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 2740 | struct target_ipc_perm msg_perm; |
| 2741 | abi_ulong msg_stime; |
| 2742 | #if TARGET_ABI_BITS == 32 |
| 2743 | abi_ulong __unused1; |
| 2744 | #endif |
| 2745 | abi_ulong msg_rtime; |
| 2746 | #if TARGET_ABI_BITS == 32 |
| 2747 | abi_ulong __unused2; |
| 2748 | #endif |
| 2749 | abi_ulong msg_ctime; |
| 2750 | #if TARGET_ABI_BITS == 32 |
| 2751 | abi_ulong __unused3; |
| 2752 | #endif |
| 2753 | abi_ulong __msg_cbytes; |
| 2754 | abi_ulong msg_qnum; |
| 2755 | abi_ulong msg_qbytes; |
| 2756 | abi_ulong msg_lspid; |
| 2757 | abi_ulong msg_lrpid; |
| 2758 | abi_ulong __unused4; |
| 2759 | abi_ulong __unused5; |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2760 | }; |
| 2761 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2762 | static inline abi_long target_to_host_msqid_ds(struct msqid_ds *host_md, |
| 2763 | abi_ulong target_addr) |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2764 | { |
| 2765 | struct target_msqid_ds *target_md; |
| 2766 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2767 | if (!lock_user_struct(VERIFY_READ, target_md, target_addr, 1)) |
| 2768 | return -TARGET_EFAULT; |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 2769 | if (target_to_host_ipc_perm(&(host_md->msg_perm),target_addr)) |
| 2770 | return -TARGET_EFAULT; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 2771 | host_md->msg_stime = tswapal(target_md->msg_stime); |
| 2772 | host_md->msg_rtime = tswapal(target_md->msg_rtime); |
| 2773 | host_md->msg_ctime = tswapal(target_md->msg_ctime); |
| 2774 | host_md->__msg_cbytes = tswapal(target_md->__msg_cbytes); |
| 2775 | host_md->msg_qnum = tswapal(target_md->msg_qnum); |
| 2776 | host_md->msg_qbytes = tswapal(target_md->msg_qbytes); |
| 2777 | host_md->msg_lspid = tswapal(target_md->msg_lspid); |
| 2778 | host_md->msg_lrpid = tswapal(target_md->msg_lrpid); |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2779 | unlock_user_struct(target_md, target_addr, 0); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2780 | return 0; |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2781 | } |
| 2782 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2783 | static inline abi_long host_to_target_msqid_ds(abi_ulong target_addr, |
| 2784 | struct msqid_ds *host_md) |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2785 | { |
| 2786 | struct target_msqid_ds *target_md; |
| 2787 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2788 | if (!lock_user_struct(VERIFY_WRITE, target_md, target_addr, 0)) |
| 2789 | return -TARGET_EFAULT; |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 2790 | if (host_to_target_ipc_perm(target_addr,&(host_md->msg_perm))) |
| 2791 | return -TARGET_EFAULT; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 2792 | target_md->msg_stime = tswapal(host_md->msg_stime); |
| 2793 | target_md->msg_rtime = tswapal(host_md->msg_rtime); |
| 2794 | target_md->msg_ctime = tswapal(host_md->msg_ctime); |
| 2795 | target_md->__msg_cbytes = tswapal(host_md->__msg_cbytes); |
| 2796 | target_md->msg_qnum = tswapal(host_md->msg_qnum); |
| 2797 | target_md->msg_qbytes = tswapal(host_md->msg_qbytes); |
| 2798 | target_md->msg_lspid = tswapal(host_md->msg_lspid); |
| 2799 | target_md->msg_lrpid = tswapal(host_md->msg_lrpid); |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2800 | unlock_user_struct(target_md, target_addr, 1); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2801 | return 0; |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2802 | } |
| 2803 | |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 2804 | struct target_msginfo { |
| 2805 | int msgpool; |
| 2806 | int msgmap; |
| 2807 | int msgmax; |
| 2808 | int msgmnb; |
| 2809 | int msgmni; |
| 2810 | int msgssz; |
| 2811 | int msgtql; |
| 2812 | unsigned short int msgseg; |
| 2813 | }; |
| 2814 | |
| 2815 | static inline abi_long host_to_target_msginfo(abi_ulong target_addr, |
| 2816 | struct msginfo *host_msginfo) |
| 2817 | { |
| 2818 | struct target_msginfo *target_msginfo; |
| 2819 | if (!lock_user_struct(VERIFY_WRITE, target_msginfo, target_addr, 0)) |
| 2820 | return -TARGET_EFAULT; |
| 2821 | __put_user(host_msginfo->msgpool, &target_msginfo->msgpool); |
| 2822 | __put_user(host_msginfo->msgmap, &target_msginfo->msgmap); |
| 2823 | __put_user(host_msginfo->msgmax, &target_msginfo->msgmax); |
| 2824 | __put_user(host_msginfo->msgmnb, &target_msginfo->msgmnb); |
| 2825 | __put_user(host_msginfo->msgmni, &target_msginfo->msgmni); |
| 2826 | __put_user(host_msginfo->msgssz, &target_msginfo->msgssz); |
| 2827 | __put_user(host_msginfo->msgtql, &target_msginfo->msgtql); |
| 2828 | __put_user(host_msginfo->msgseg, &target_msginfo->msgseg); |
| 2829 | unlock_user_struct(target_msginfo, target_addr, 1); |
aurel32 | 00b229a | 2008-10-24 13:12:52 +0000 | [diff] [blame] | 2830 | return 0; |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 2831 | } |
| 2832 | |
| 2833 | static inline abi_long do_msgctl(int msgid, int cmd, abi_long ptr) |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2834 | { |
| 2835 | struct msqid_ds dsarg; |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 2836 | struct msginfo msginfo; |
| 2837 | abi_long ret = -TARGET_EINVAL; |
| 2838 | |
| 2839 | cmd &= 0xff; |
| 2840 | |
| 2841 | switch (cmd) { |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2842 | case IPC_STAT: |
| 2843 | case IPC_SET: |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 2844 | case MSG_STAT: |
| 2845 | if (target_to_host_msqid_ds(&dsarg,ptr)) |
| 2846 | return -TARGET_EFAULT; |
| 2847 | ret = get_errno(msgctl(msgid, cmd, &dsarg)); |
| 2848 | if (host_to_target_msqid_ds(ptr,&dsarg)) |
| 2849 | return -TARGET_EFAULT; |
| 2850 | break; |
| 2851 | case IPC_RMID: |
| 2852 | ret = get_errno(msgctl(msgid, cmd, NULL)); |
| 2853 | break; |
| 2854 | case IPC_INFO: |
| 2855 | case MSG_INFO: |
| 2856 | ret = get_errno(msgctl(msgid, cmd, (struct msqid_ds *)&msginfo)); |
| 2857 | if (host_to_target_msginfo(ptr, &msginfo)) |
| 2858 | return -TARGET_EFAULT; |
| 2859 | break; |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2860 | } |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 2861 | |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2862 | return ret; |
| 2863 | } |
| 2864 | |
| 2865 | struct target_msgbuf { |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 2866 | abi_long mtype; |
| 2867 | char mtext[1]; |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2868 | }; |
| 2869 | |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2870 | static inline abi_long do_msgsnd(int msqid, abi_long msgp, |
| 2871 | unsigned int msgsz, int msgflg) |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2872 | { |
| 2873 | struct target_msgbuf *target_mb; |
| 2874 | struct msgbuf *host_mb; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2875 | abi_long ret = 0; |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2876 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2877 | if (!lock_user_struct(VERIFY_READ, target_mb, msgp, 0)) |
| 2878 | return -TARGET_EFAULT; |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2879 | host_mb = malloc(msgsz+sizeof(long)); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 2880 | host_mb->mtype = (abi_long) tswapal(target_mb->mtype); |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 2881 | memcpy(host_mb->mtext, target_mb->mtext, msgsz); |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2882 | ret = get_errno(msgsnd(msqid, host_mb, msgsz, msgflg)); |
| 2883 | free(host_mb); |
| 2884 | unlock_user_struct(target_mb, msgp, 0); |
| 2885 | |
| 2886 | return ret; |
| 2887 | } |
| 2888 | |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2889 | static inline abi_long do_msgrcv(int msqid, abi_long msgp, |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 2890 | unsigned int msgsz, abi_long msgtyp, |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2891 | int msgflg) |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2892 | { |
| 2893 | struct target_msgbuf *target_mb; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2894 | char *target_mtext; |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2895 | struct msgbuf *host_mb; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2896 | abi_long ret = 0; |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2897 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2898 | if (!lock_user_struct(VERIFY_WRITE, target_mb, msgp, 0)) |
| 2899 | return -TARGET_EFAULT; |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 2900 | |
Jim Meyering | 0d07fe4 | 2012-08-22 13:55:53 +0200 | [diff] [blame] | 2901 | host_mb = g_malloc(msgsz+sizeof(long)); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 2902 | ret = get_errno(msgrcv(msqid, host_mb, msgsz, tswapal(msgtyp), msgflg)); |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 2903 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2904 | if (ret > 0) { |
| 2905 | abi_ulong target_mtext_addr = msgp + sizeof(abi_ulong); |
| 2906 | target_mtext = lock_user(VERIFY_WRITE, target_mtext_addr, ret, 0); |
| 2907 | if (!target_mtext) { |
| 2908 | ret = -TARGET_EFAULT; |
| 2909 | goto end; |
| 2910 | } |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 2911 | memcpy(target_mb->mtext, host_mb->mtext, ret); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2912 | unlock_user(target_mtext, target_mtext_addr, ret); |
| 2913 | } |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 2914 | |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 2915 | target_mb->mtype = tswapal(host_mb->mtype); |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2916 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2917 | end: |
| 2918 | if (target_mb) |
| 2919 | unlock_user_struct(target_mb, msgp, 1); |
Jim Meyering | 0d07fe4 | 2012-08-22 13:55:53 +0200 | [diff] [blame] | 2920 | g_free(host_mb); |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2921 | return ret; |
| 2922 | } |
| 2923 | |
Riku Voipio | 88a8c98 | 2009-04-03 10:42:00 +0300 | [diff] [blame] | 2924 | struct target_shmid_ds |
| 2925 | { |
| 2926 | struct target_ipc_perm shm_perm; |
| 2927 | abi_ulong shm_segsz; |
| 2928 | abi_ulong shm_atime; |
| 2929 | #if TARGET_ABI_BITS == 32 |
| 2930 | abi_ulong __unused1; |
| 2931 | #endif |
| 2932 | abi_ulong shm_dtime; |
| 2933 | #if TARGET_ABI_BITS == 32 |
| 2934 | abi_ulong __unused2; |
| 2935 | #endif |
| 2936 | abi_ulong shm_ctime; |
| 2937 | #if TARGET_ABI_BITS == 32 |
| 2938 | abi_ulong __unused3; |
| 2939 | #endif |
| 2940 | int shm_cpid; |
| 2941 | int shm_lpid; |
| 2942 | abi_ulong shm_nattch; |
| 2943 | unsigned long int __unused4; |
| 2944 | unsigned long int __unused5; |
| 2945 | }; |
| 2946 | |
| 2947 | static inline abi_long target_to_host_shmid_ds(struct shmid_ds *host_sd, |
| 2948 | abi_ulong target_addr) |
| 2949 | { |
| 2950 | struct target_shmid_ds *target_sd; |
| 2951 | |
| 2952 | if (!lock_user_struct(VERIFY_READ, target_sd, target_addr, 1)) |
| 2953 | return -TARGET_EFAULT; |
| 2954 | if (target_to_host_ipc_perm(&(host_sd->shm_perm), target_addr)) |
| 2955 | return -TARGET_EFAULT; |
| 2956 | __get_user(host_sd->shm_segsz, &target_sd->shm_segsz); |
| 2957 | __get_user(host_sd->shm_atime, &target_sd->shm_atime); |
| 2958 | __get_user(host_sd->shm_dtime, &target_sd->shm_dtime); |
| 2959 | __get_user(host_sd->shm_ctime, &target_sd->shm_ctime); |
| 2960 | __get_user(host_sd->shm_cpid, &target_sd->shm_cpid); |
| 2961 | __get_user(host_sd->shm_lpid, &target_sd->shm_lpid); |
| 2962 | __get_user(host_sd->shm_nattch, &target_sd->shm_nattch); |
| 2963 | unlock_user_struct(target_sd, target_addr, 0); |
| 2964 | return 0; |
| 2965 | } |
| 2966 | |
| 2967 | static inline abi_long host_to_target_shmid_ds(abi_ulong target_addr, |
| 2968 | struct shmid_ds *host_sd) |
| 2969 | { |
| 2970 | struct target_shmid_ds *target_sd; |
| 2971 | |
| 2972 | if (!lock_user_struct(VERIFY_WRITE, target_sd, target_addr, 0)) |
| 2973 | return -TARGET_EFAULT; |
| 2974 | if (host_to_target_ipc_perm(target_addr, &(host_sd->shm_perm))) |
| 2975 | return -TARGET_EFAULT; |
| 2976 | __put_user(host_sd->shm_segsz, &target_sd->shm_segsz); |
| 2977 | __put_user(host_sd->shm_atime, &target_sd->shm_atime); |
| 2978 | __put_user(host_sd->shm_dtime, &target_sd->shm_dtime); |
| 2979 | __put_user(host_sd->shm_ctime, &target_sd->shm_ctime); |
| 2980 | __put_user(host_sd->shm_cpid, &target_sd->shm_cpid); |
| 2981 | __put_user(host_sd->shm_lpid, &target_sd->shm_lpid); |
| 2982 | __put_user(host_sd->shm_nattch, &target_sd->shm_nattch); |
| 2983 | unlock_user_struct(target_sd, target_addr, 1); |
| 2984 | return 0; |
| 2985 | } |
| 2986 | |
| 2987 | struct target_shminfo { |
| 2988 | abi_ulong shmmax; |
| 2989 | abi_ulong shmmin; |
| 2990 | abi_ulong shmmni; |
| 2991 | abi_ulong shmseg; |
| 2992 | abi_ulong shmall; |
| 2993 | }; |
| 2994 | |
| 2995 | static inline abi_long host_to_target_shminfo(abi_ulong target_addr, |
| 2996 | struct shminfo *host_shminfo) |
| 2997 | { |
| 2998 | struct target_shminfo *target_shminfo; |
| 2999 | if (!lock_user_struct(VERIFY_WRITE, target_shminfo, target_addr, 0)) |
| 3000 | return -TARGET_EFAULT; |
| 3001 | __put_user(host_shminfo->shmmax, &target_shminfo->shmmax); |
| 3002 | __put_user(host_shminfo->shmmin, &target_shminfo->shmmin); |
| 3003 | __put_user(host_shminfo->shmmni, &target_shminfo->shmmni); |
| 3004 | __put_user(host_shminfo->shmseg, &target_shminfo->shmseg); |
| 3005 | __put_user(host_shminfo->shmall, &target_shminfo->shmall); |
| 3006 | unlock_user_struct(target_shminfo, target_addr, 1); |
| 3007 | return 0; |
| 3008 | } |
| 3009 | |
| 3010 | struct target_shm_info { |
| 3011 | int used_ids; |
| 3012 | abi_ulong shm_tot; |
| 3013 | abi_ulong shm_rss; |
| 3014 | abi_ulong shm_swp; |
| 3015 | abi_ulong swap_attempts; |
| 3016 | abi_ulong swap_successes; |
| 3017 | }; |
| 3018 | |
| 3019 | static inline abi_long host_to_target_shm_info(abi_ulong target_addr, |
| 3020 | struct shm_info *host_shm_info) |
| 3021 | { |
| 3022 | struct target_shm_info *target_shm_info; |
| 3023 | if (!lock_user_struct(VERIFY_WRITE, target_shm_info, target_addr, 0)) |
| 3024 | return -TARGET_EFAULT; |
| 3025 | __put_user(host_shm_info->used_ids, &target_shm_info->used_ids); |
| 3026 | __put_user(host_shm_info->shm_tot, &target_shm_info->shm_tot); |
| 3027 | __put_user(host_shm_info->shm_rss, &target_shm_info->shm_rss); |
| 3028 | __put_user(host_shm_info->shm_swp, &target_shm_info->shm_swp); |
| 3029 | __put_user(host_shm_info->swap_attempts, &target_shm_info->swap_attempts); |
| 3030 | __put_user(host_shm_info->swap_successes, &target_shm_info->swap_successes); |
| 3031 | unlock_user_struct(target_shm_info, target_addr, 1); |
| 3032 | return 0; |
| 3033 | } |
| 3034 | |
| 3035 | static inline abi_long do_shmctl(int shmid, int cmd, abi_long buf) |
| 3036 | { |
| 3037 | struct shmid_ds dsarg; |
| 3038 | struct shminfo shminfo; |
| 3039 | struct shm_info shm_info; |
| 3040 | abi_long ret = -TARGET_EINVAL; |
| 3041 | |
| 3042 | cmd &= 0xff; |
| 3043 | |
| 3044 | switch(cmd) { |
| 3045 | case IPC_STAT: |
| 3046 | case IPC_SET: |
| 3047 | case SHM_STAT: |
| 3048 | if (target_to_host_shmid_ds(&dsarg, buf)) |
| 3049 | return -TARGET_EFAULT; |
| 3050 | ret = get_errno(shmctl(shmid, cmd, &dsarg)); |
| 3051 | if (host_to_target_shmid_ds(buf, &dsarg)) |
| 3052 | return -TARGET_EFAULT; |
| 3053 | break; |
| 3054 | case IPC_INFO: |
| 3055 | ret = get_errno(shmctl(shmid, cmd, (struct shmid_ds *)&shminfo)); |
| 3056 | if (host_to_target_shminfo(buf, &shminfo)) |
| 3057 | return -TARGET_EFAULT; |
| 3058 | break; |
| 3059 | case SHM_INFO: |
| 3060 | ret = get_errno(shmctl(shmid, cmd, (struct shmid_ds *)&shm_info)); |
| 3061 | if (host_to_target_shm_info(buf, &shm_info)) |
| 3062 | return -TARGET_EFAULT; |
| 3063 | break; |
| 3064 | case IPC_RMID: |
| 3065 | case SHM_LOCK: |
| 3066 | case SHM_UNLOCK: |
| 3067 | ret = get_errno(shmctl(shmid, cmd, NULL)); |
| 3068 | break; |
| 3069 | } |
| 3070 | |
| 3071 | return ret; |
| 3072 | } |
| 3073 | |
| 3074 | static inline abi_ulong do_shmat(int shmid, abi_ulong shmaddr, int shmflg) |
| 3075 | { |
| 3076 | abi_long raddr; |
| 3077 | void *host_raddr; |
| 3078 | struct shmid_ds shm_info; |
| 3079 | int i,ret; |
| 3080 | |
| 3081 | /* find out the length of the shared memory segment */ |
| 3082 | ret = get_errno(shmctl(shmid, IPC_STAT, &shm_info)); |
| 3083 | if (is_error(ret)) { |
| 3084 | /* can't get length, bail out */ |
| 3085 | return ret; |
| 3086 | } |
| 3087 | |
| 3088 | mmap_lock(); |
| 3089 | |
| 3090 | if (shmaddr) |
| 3091 | host_raddr = shmat(shmid, (void *)g2h(shmaddr), shmflg); |
| 3092 | else { |
| 3093 | abi_ulong mmap_start; |
| 3094 | |
| 3095 | mmap_start = mmap_find_vma(0, shm_info.shm_segsz); |
| 3096 | |
| 3097 | if (mmap_start == -1) { |
| 3098 | errno = ENOMEM; |
| 3099 | host_raddr = (void *)-1; |
| 3100 | } else |
| 3101 | host_raddr = shmat(shmid, g2h(mmap_start), shmflg | SHM_REMAP); |
| 3102 | } |
| 3103 | |
| 3104 | if (host_raddr == (void *)-1) { |
| 3105 | mmap_unlock(); |
| 3106 | return get_errno((long)host_raddr); |
| 3107 | } |
| 3108 | raddr=h2g((unsigned long)host_raddr); |
| 3109 | |
| 3110 | page_set_flags(raddr, raddr + shm_info.shm_segsz, |
| 3111 | PAGE_VALID | PAGE_READ | |
| 3112 | ((shmflg & SHM_RDONLY)? 0 : PAGE_WRITE)); |
| 3113 | |
| 3114 | for (i = 0; i < N_SHM_REGIONS; i++) { |
| 3115 | if (shm_regions[i].start == 0) { |
| 3116 | shm_regions[i].start = raddr; |
| 3117 | shm_regions[i].size = shm_info.shm_segsz; |
| 3118 | break; |
| 3119 | } |
| 3120 | } |
| 3121 | |
| 3122 | mmap_unlock(); |
| 3123 | return raddr; |
| 3124 | |
| 3125 | } |
| 3126 | |
| 3127 | static inline abi_long do_shmdt(abi_ulong shmaddr) |
| 3128 | { |
| 3129 | int i; |
| 3130 | |
| 3131 | for (i = 0; i < N_SHM_REGIONS; ++i) { |
| 3132 | if (shm_regions[i].start == shmaddr) { |
| 3133 | shm_regions[i].start = 0; |
takasi-y@ops.dti.ne.jp | e00ac24 | 2010-04-11 02:09:57 +0900 | [diff] [blame] | 3134 | page_set_flags(shmaddr, shmaddr + shm_regions[i].size, 0); |
Riku Voipio | 88a8c98 | 2009-04-03 10:42:00 +0300 | [diff] [blame] | 3135 | break; |
| 3136 | } |
| 3137 | } |
| 3138 | |
| 3139 | return get_errno(shmdt(g2h(shmaddr))); |
| 3140 | } |
| 3141 | |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 3142 | #ifdef TARGET_NR_ipc |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 3143 | /* ??? This only works with linear mappings. */ |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 3144 | /* do_ipc() must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 3145 | static abi_long do_ipc(unsigned int call, int first, |
| 3146 | int second, int third, |
| 3147 | abi_long ptr, abi_long fifth) |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 3148 | { |
| 3149 | int version; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 3150 | abi_long ret = 0; |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 3151 | |
| 3152 | version = call >> 16; |
| 3153 | call &= 0xffff; |
| 3154 | |
| 3155 | switch (call) { |
ths | fa29481 | 2007-02-02 22:05:00 +0000 | [diff] [blame] | 3156 | case IPCOP_semop: |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 3157 | ret = do_semop(first, ptr, second); |
ths | fa29481 | 2007-02-02 22:05:00 +0000 | [diff] [blame] | 3158 | break; |
| 3159 | |
| 3160 | case IPCOP_semget: |
| 3161 | ret = get_errno(semget(first, second, third)); |
| 3162 | break; |
| 3163 | |
| 3164 | case IPCOP_semctl: |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 3165 | ret = do_semctl(first, second, third, (union target_semun)(abi_ulong) ptr); |
ths | fa29481 | 2007-02-02 22:05:00 +0000 | [diff] [blame] | 3166 | break; |
ths | d96372e | 2007-02-02 22:05:44 +0000 | [diff] [blame] | 3167 | |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 3168 | case IPCOP_msgget: |
| 3169 | ret = get_errno(msgget(first, second)); |
| 3170 | break; |
ths | d96372e | 2007-02-02 22:05:44 +0000 | [diff] [blame] | 3171 | |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 3172 | case IPCOP_msgsnd: |
| 3173 | ret = do_msgsnd(first, ptr, second, third); |
| 3174 | break; |
ths | d96372e | 2007-02-02 22:05:44 +0000 | [diff] [blame] | 3175 | |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 3176 | case IPCOP_msgctl: |
| 3177 | ret = do_msgctl(first, second, ptr); |
| 3178 | break; |
ths | d96372e | 2007-02-02 22:05:44 +0000 | [diff] [blame] | 3179 | |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 3180 | case IPCOP_msgrcv: |
| 3181 | switch (version) { |
| 3182 | case 0: |
| 3183 | { |
| 3184 | struct target_ipc_kludge { |
| 3185 | abi_long msgp; |
| 3186 | abi_long msgtyp; |
| 3187 | } *tmp; |
ths | d96372e | 2007-02-02 22:05:44 +0000 | [diff] [blame] | 3188 | |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 3189 | if (!lock_user_struct(VERIFY_READ, tmp, ptr, 1)) { |
| 3190 | ret = -TARGET_EFAULT; |
| 3191 | break; |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 3192 | } |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 3193 | |
| 3194 | ret = do_msgrcv(first, tmp->msgp, second, tmp->msgtyp, third); |
| 3195 | |
| 3196 | unlock_user_struct(tmp, ptr, 0); |
| 3197 | break; |
| 3198 | } |
| 3199 | default: |
| 3200 | ret = do_msgrcv(first, ptr, second, fifth, third); |
| 3201 | } |
| 3202 | break; |
ths | d96372e | 2007-02-02 22:05:44 +0000 | [diff] [blame] | 3203 | |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 3204 | case IPCOP_shmat: |
Riku Voipio | 88a8c98 | 2009-04-03 10:42:00 +0300 | [diff] [blame] | 3205 | switch (version) { |
| 3206 | default: |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 3207 | { |
| 3208 | abi_ulong raddr; |
Riku Voipio | 88a8c98 | 2009-04-03 10:42:00 +0300 | [diff] [blame] | 3209 | raddr = do_shmat(first, ptr, second); |
| 3210 | if (is_error(raddr)) |
| 3211 | return get_errno(raddr); |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 3212 | if (put_user_ual(raddr, third)) |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 3213 | return -TARGET_EFAULT; |
Riku Voipio | 88a8c98 | 2009-04-03 10:42:00 +0300 | [diff] [blame] | 3214 | break; |
| 3215 | } |
| 3216 | case 1: |
| 3217 | ret = -TARGET_EINVAL; |
| 3218 | break; |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 3219 | } |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 3220 | break; |
| 3221 | case IPCOP_shmdt: |
Riku Voipio | 88a8c98 | 2009-04-03 10:42:00 +0300 | [diff] [blame] | 3222 | ret = do_shmdt(ptr); |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 3223 | break; |
| 3224 | |
| 3225 | case IPCOP_shmget: |
| 3226 | /* IPC_* flag values are the same on all linux platforms */ |
| 3227 | ret = get_errno(shmget(first, second, third)); |
| 3228 | break; |
| 3229 | |
| 3230 | /* IPC_* and SHM_* command values are the same on all linux platforms */ |
| 3231 | case IPCOP_shmctl: |
Riku Voipio | 88a8c98 | 2009-04-03 10:42:00 +0300 | [diff] [blame] | 3232 | ret = do_shmctl(first, second, third); |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 3233 | break; |
| 3234 | default: |
j_mayer | 3240710 | 2007-09-26 23:01:49 +0000 | [diff] [blame] | 3235 | gemu_log("Unsupported ipc call: %d (version %d)\n", call, version); |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 3236 | ret = -TARGET_ENOSYS; |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 3237 | break; |
| 3238 | } |
| 3239 | return ret; |
| 3240 | } |
j_mayer | 3240710 | 2007-09-26 23:01:49 +0000 | [diff] [blame] | 3241 | #endif |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 3242 | |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3243 | /* kernel structure types definitions */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3244 | |
Blue Swirl | 001faf3 | 2009-05-13 17:53:17 +0000 | [diff] [blame] | 3245 | #define STRUCT(name, ...) STRUCT_ ## name, |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3246 | #define STRUCT_SPECIAL(name) STRUCT_ ## name, |
| 3247 | enum { |
| 3248 | #include "syscall_types.h" |
| 3249 | }; |
| 3250 | #undef STRUCT |
| 3251 | #undef STRUCT_SPECIAL |
| 3252 | |
Blue Swirl | 001faf3 | 2009-05-13 17:53:17 +0000 | [diff] [blame] | 3253 | #define STRUCT(name, ...) static const argtype struct_ ## name ## _def[] = { __VA_ARGS__, TYPE_NULL }; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3254 | #define STRUCT_SPECIAL(name) |
| 3255 | #include "syscall_types.h" |
| 3256 | #undef STRUCT |
| 3257 | #undef STRUCT_SPECIAL |
| 3258 | |
Peter Maydell | d2ef05b | 2011-01-06 15:04:17 +0000 | [diff] [blame] | 3259 | typedef struct IOCTLEntry IOCTLEntry; |
| 3260 | |
| 3261 | typedef abi_long do_ioctl_fn(const IOCTLEntry *ie, uint8_t *buf_temp, |
| 3262 | int fd, abi_long cmd, abi_long arg); |
| 3263 | |
| 3264 | struct IOCTLEntry { |
bellard | 2ab83ea | 2003-06-15 19:56:46 +0000 | [diff] [blame] | 3265 | unsigned int target_cmd; |
| 3266 | unsigned int host_cmd; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3267 | const char *name; |
| 3268 | int access; |
Peter Maydell | d2ef05b | 2011-01-06 15:04:17 +0000 | [diff] [blame] | 3269 | do_ioctl_fn *do_ioctl; |
bellard | 1a9353d | 2003-03-16 20:28:50 +0000 | [diff] [blame] | 3270 | const argtype arg_type[5]; |
Peter Maydell | d2ef05b | 2011-01-06 15:04:17 +0000 | [diff] [blame] | 3271 | }; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3272 | |
| 3273 | #define IOC_R 0x0001 |
| 3274 | #define IOC_W 0x0002 |
| 3275 | #define IOC_RW (IOC_R | IOC_W) |
| 3276 | |
| 3277 | #define MAX_STRUCT_SIZE 4096 |
| 3278 | |
Peter Maydell | dace20d | 2011-01-10 13:11:24 +0000 | [diff] [blame] | 3279 | #ifdef CONFIG_FIEMAP |
Peter Maydell | 285da2b | 2011-01-06 15:04:18 +0000 | [diff] [blame] | 3280 | /* So fiemap access checks don't overflow on 32 bit systems. |
| 3281 | * This is very slightly smaller than the limit imposed by |
| 3282 | * the underlying kernel. |
| 3283 | */ |
| 3284 | #define FIEMAP_MAX_EXTENTS ((UINT_MAX - sizeof(struct fiemap)) \ |
| 3285 | / sizeof(struct fiemap_extent)) |
| 3286 | |
| 3287 | static abi_long do_ioctl_fs_ioc_fiemap(const IOCTLEntry *ie, uint8_t *buf_temp, |
| 3288 | int fd, abi_long cmd, abi_long arg) |
| 3289 | { |
| 3290 | /* The parameter for this ioctl is a struct fiemap followed |
| 3291 | * by an array of struct fiemap_extent whose size is set |
| 3292 | * in fiemap->fm_extent_count. The array is filled in by the |
| 3293 | * ioctl. |
| 3294 | */ |
| 3295 | int target_size_in, target_size_out; |
| 3296 | struct fiemap *fm; |
| 3297 | const argtype *arg_type = ie->arg_type; |
| 3298 | const argtype extent_arg_type[] = { MK_STRUCT(STRUCT_fiemap_extent) }; |
| 3299 | void *argptr, *p; |
| 3300 | abi_long ret; |
| 3301 | int i, extent_size = thunk_type_size(extent_arg_type, 0); |
| 3302 | uint32_t outbufsz; |
| 3303 | int free_fm = 0; |
| 3304 | |
| 3305 | assert(arg_type[0] == TYPE_PTR); |
| 3306 | assert(ie->access == IOC_RW); |
| 3307 | arg_type++; |
| 3308 | target_size_in = thunk_type_size(arg_type, 0); |
| 3309 | argptr = lock_user(VERIFY_READ, arg, target_size_in, 1); |
| 3310 | if (!argptr) { |
| 3311 | return -TARGET_EFAULT; |
| 3312 | } |
| 3313 | thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST); |
| 3314 | unlock_user(argptr, arg, 0); |
| 3315 | fm = (struct fiemap *)buf_temp; |
| 3316 | if (fm->fm_extent_count > FIEMAP_MAX_EXTENTS) { |
| 3317 | return -TARGET_EINVAL; |
| 3318 | } |
| 3319 | |
| 3320 | outbufsz = sizeof (*fm) + |
| 3321 | (sizeof(struct fiemap_extent) * fm->fm_extent_count); |
| 3322 | |
| 3323 | if (outbufsz > MAX_STRUCT_SIZE) { |
| 3324 | /* We can't fit all the extents into the fixed size buffer. |
| 3325 | * Allocate one that is large enough and use it instead. |
| 3326 | */ |
| 3327 | fm = malloc(outbufsz); |
| 3328 | if (!fm) { |
| 3329 | return -TARGET_ENOMEM; |
| 3330 | } |
| 3331 | memcpy(fm, buf_temp, sizeof(struct fiemap)); |
| 3332 | free_fm = 1; |
| 3333 | } |
| 3334 | ret = get_errno(ioctl(fd, ie->host_cmd, fm)); |
| 3335 | if (!is_error(ret)) { |
| 3336 | target_size_out = target_size_in; |
| 3337 | /* An extent_count of 0 means we were only counting the extents |
| 3338 | * so there are no structs to copy |
| 3339 | */ |
| 3340 | if (fm->fm_extent_count != 0) { |
| 3341 | target_size_out += fm->fm_mapped_extents * extent_size; |
| 3342 | } |
| 3343 | argptr = lock_user(VERIFY_WRITE, arg, target_size_out, 0); |
| 3344 | if (!argptr) { |
| 3345 | ret = -TARGET_EFAULT; |
| 3346 | } else { |
| 3347 | /* Convert the struct fiemap */ |
| 3348 | thunk_convert(argptr, fm, arg_type, THUNK_TARGET); |
| 3349 | if (fm->fm_extent_count != 0) { |
| 3350 | p = argptr + target_size_in; |
| 3351 | /* ...and then all the struct fiemap_extents */ |
| 3352 | for (i = 0; i < fm->fm_mapped_extents; i++) { |
| 3353 | thunk_convert(p, &fm->fm_extents[i], extent_arg_type, |
| 3354 | THUNK_TARGET); |
| 3355 | p += extent_size; |
| 3356 | } |
| 3357 | } |
| 3358 | unlock_user(argptr, arg, target_size_out); |
| 3359 | } |
| 3360 | } |
| 3361 | if (free_fm) { |
| 3362 | free(fm); |
| 3363 | } |
| 3364 | return ret; |
| 3365 | } |
Peter Maydell | dace20d | 2011-01-10 13:11:24 +0000 | [diff] [blame] | 3366 | #endif |
Peter Maydell | 285da2b | 2011-01-06 15:04:18 +0000 | [diff] [blame] | 3367 | |
Laurent Vivier | 059c2f2 | 2011-03-30 00:12:12 +0200 | [diff] [blame] | 3368 | static abi_long do_ioctl_ifconf(const IOCTLEntry *ie, uint8_t *buf_temp, |
| 3369 | int fd, abi_long cmd, abi_long arg) |
| 3370 | { |
| 3371 | const argtype *arg_type = ie->arg_type; |
| 3372 | int target_size; |
| 3373 | void *argptr; |
| 3374 | int ret; |
| 3375 | struct ifconf *host_ifconf; |
| 3376 | uint32_t outbufsz; |
| 3377 | const argtype ifreq_arg_type[] = { MK_STRUCT(STRUCT_sockaddr_ifreq) }; |
| 3378 | int target_ifreq_size; |
| 3379 | int nb_ifreq; |
| 3380 | int free_buf = 0; |
| 3381 | int i; |
| 3382 | int target_ifc_len; |
| 3383 | abi_long target_ifc_buf; |
| 3384 | int host_ifc_len; |
| 3385 | char *host_ifc_buf; |
| 3386 | |
| 3387 | assert(arg_type[0] == TYPE_PTR); |
| 3388 | assert(ie->access == IOC_RW); |
| 3389 | |
| 3390 | arg_type++; |
| 3391 | target_size = thunk_type_size(arg_type, 0); |
| 3392 | |
| 3393 | argptr = lock_user(VERIFY_READ, arg, target_size, 1); |
| 3394 | if (!argptr) |
| 3395 | return -TARGET_EFAULT; |
| 3396 | thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST); |
| 3397 | unlock_user(argptr, arg, 0); |
| 3398 | |
| 3399 | host_ifconf = (struct ifconf *)(unsigned long)buf_temp; |
| 3400 | target_ifc_len = host_ifconf->ifc_len; |
| 3401 | target_ifc_buf = (abi_long)(unsigned long)host_ifconf->ifc_buf; |
| 3402 | |
| 3403 | target_ifreq_size = thunk_type_size(ifreq_arg_type, 0); |
| 3404 | nb_ifreq = target_ifc_len / target_ifreq_size; |
| 3405 | host_ifc_len = nb_ifreq * sizeof(struct ifreq); |
| 3406 | |
| 3407 | outbufsz = sizeof(*host_ifconf) + host_ifc_len; |
| 3408 | if (outbufsz > MAX_STRUCT_SIZE) { |
| 3409 | /* We can't fit all the extents into the fixed size buffer. |
| 3410 | * Allocate one that is large enough and use it instead. |
| 3411 | */ |
| 3412 | host_ifconf = malloc(outbufsz); |
| 3413 | if (!host_ifconf) { |
| 3414 | return -TARGET_ENOMEM; |
| 3415 | } |
| 3416 | memcpy(host_ifconf, buf_temp, sizeof(*host_ifconf)); |
| 3417 | free_buf = 1; |
| 3418 | } |
| 3419 | host_ifc_buf = (char*)host_ifconf + sizeof(*host_ifconf); |
| 3420 | |
| 3421 | host_ifconf->ifc_len = host_ifc_len; |
| 3422 | host_ifconf->ifc_buf = host_ifc_buf; |
| 3423 | |
| 3424 | ret = get_errno(ioctl(fd, ie->host_cmd, host_ifconf)); |
| 3425 | if (!is_error(ret)) { |
| 3426 | /* convert host ifc_len to target ifc_len */ |
| 3427 | |
| 3428 | nb_ifreq = host_ifconf->ifc_len / sizeof(struct ifreq); |
| 3429 | target_ifc_len = nb_ifreq * target_ifreq_size; |
| 3430 | host_ifconf->ifc_len = target_ifc_len; |
| 3431 | |
| 3432 | /* restore target ifc_buf */ |
| 3433 | |
| 3434 | host_ifconf->ifc_buf = (char *)(unsigned long)target_ifc_buf; |
| 3435 | |
| 3436 | /* copy struct ifconf to target user */ |
| 3437 | |
| 3438 | argptr = lock_user(VERIFY_WRITE, arg, target_size, 0); |
| 3439 | if (!argptr) |
| 3440 | return -TARGET_EFAULT; |
| 3441 | thunk_convert(argptr, host_ifconf, arg_type, THUNK_TARGET); |
| 3442 | unlock_user(argptr, arg, target_size); |
| 3443 | |
| 3444 | /* copy ifreq[] to target user */ |
| 3445 | |
| 3446 | argptr = lock_user(VERIFY_WRITE, target_ifc_buf, target_ifc_len, 0); |
| 3447 | for (i = 0; i < nb_ifreq ; i++) { |
| 3448 | thunk_convert(argptr + i * target_ifreq_size, |
| 3449 | host_ifc_buf + i * sizeof(struct ifreq), |
| 3450 | ifreq_arg_type, THUNK_TARGET); |
| 3451 | } |
| 3452 | unlock_user(argptr, target_ifc_buf, target_ifc_len); |
| 3453 | } |
| 3454 | |
| 3455 | if (free_buf) { |
| 3456 | free(host_ifconf); |
| 3457 | } |
| 3458 | |
| 3459 | return ret; |
| 3460 | } |
| 3461 | |
Alexander Graf | 56e904e | 2012-01-31 18:42:06 +0100 | [diff] [blame] | 3462 | static abi_long do_ioctl_dm(const IOCTLEntry *ie, uint8_t *buf_temp, int fd, |
| 3463 | abi_long cmd, abi_long arg) |
| 3464 | { |
| 3465 | void *argptr; |
| 3466 | struct dm_ioctl *host_dm; |
| 3467 | abi_long guest_data; |
| 3468 | uint32_t guest_data_size; |
| 3469 | int target_size; |
| 3470 | const argtype *arg_type = ie->arg_type; |
| 3471 | abi_long ret; |
| 3472 | void *big_buf = NULL; |
| 3473 | char *host_data; |
| 3474 | |
| 3475 | arg_type++; |
| 3476 | target_size = thunk_type_size(arg_type, 0); |
| 3477 | argptr = lock_user(VERIFY_READ, arg, target_size, 1); |
| 3478 | if (!argptr) { |
| 3479 | ret = -TARGET_EFAULT; |
| 3480 | goto out; |
| 3481 | } |
| 3482 | thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST); |
| 3483 | unlock_user(argptr, arg, 0); |
| 3484 | |
| 3485 | /* buf_temp is too small, so fetch things into a bigger buffer */ |
| 3486 | big_buf = g_malloc0(((struct dm_ioctl*)buf_temp)->data_size * 2); |
| 3487 | memcpy(big_buf, buf_temp, target_size); |
| 3488 | buf_temp = big_buf; |
| 3489 | host_dm = big_buf; |
| 3490 | |
| 3491 | guest_data = arg + host_dm->data_start; |
| 3492 | if ((guest_data - arg) < 0) { |
| 3493 | ret = -EINVAL; |
| 3494 | goto out; |
| 3495 | } |
| 3496 | guest_data_size = host_dm->data_size - host_dm->data_start; |
| 3497 | host_data = (char*)host_dm + host_dm->data_start; |
| 3498 | |
| 3499 | argptr = lock_user(VERIFY_READ, guest_data, guest_data_size, 1); |
| 3500 | switch (ie->host_cmd) { |
| 3501 | case DM_REMOVE_ALL: |
| 3502 | case DM_LIST_DEVICES: |
| 3503 | case DM_DEV_CREATE: |
| 3504 | case DM_DEV_REMOVE: |
| 3505 | case DM_DEV_SUSPEND: |
| 3506 | case DM_DEV_STATUS: |
| 3507 | case DM_DEV_WAIT: |
| 3508 | case DM_TABLE_STATUS: |
| 3509 | case DM_TABLE_CLEAR: |
| 3510 | case DM_TABLE_DEPS: |
| 3511 | case DM_LIST_VERSIONS: |
| 3512 | /* no input data */ |
| 3513 | break; |
| 3514 | case DM_DEV_RENAME: |
| 3515 | case DM_DEV_SET_GEOMETRY: |
| 3516 | /* data contains only strings */ |
| 3517 | memcpy(host_data, argptr, guest_data_size); |
| 3518 | break; |
| 3519 | case DM_TARGET_MSG: |
| 3520 | memcpy(host_data, argptr, guest_data_size); |
| 3521 | *(uint64_t*)host_data = tswap64(*(uint64_t*)argptr); |
| 3522 | break; |
| 3523 | case DM_TABLE_LOAD: |
| 3524 | { |
| 3525 | void *gspec = argptr; |
| 3526 | void *cur_data = host_data; |
| 3527 | const argtype arg_type[] = { MK_STRUCT(STRUCT_dm_target_spec) }; |
| 3528 | int spec_size = thunk_type_size(arg_type, 0); |
| 3529 | int i; |
| 3530 | |
| 3531 | for (i = 0; i < host_dm->target_count; i++) { |
| 3532 | struct dm_target_spec *spec = cur_data; |
| 3533 | uint32_t next; |
| 3534 | int slen; |
| 3535 | |
| 3536 | thunk_convert(spec, gspec, arg_type, THUNK_HOST); |
| 3537 | slen = strlen((char*)gspec + spec_size) + 1; |
| 3538 | next = spec->next; |
| 3539 | spec->next = sizeof(*spec) + slen; |
| 3540 | strcpy((char*)&spec[1], gspec + spec_size); |
| 3541 | gspec += next; |
| 3542 | cur_data += spec->next; |
| 3543 | } |
| 3544 | break; |
| 3545 | } |
| 3546 | default: |
| 3547 | ret = -TARGET_EINVAL; |
| 3548 | goto out; |
| 3549 | } |
| 3550 | unlock_user(argptr, guest_data, 0); |
| 3551 | |
| 3552 | ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp)); |
| 3553 | if (!is_error(ret)) { |
| 3554 | guest_data = arg + host_dm->data_start; |
| 3555 | guest_data_size = host_dm->data_size - host_dm->data_start; |
| 3556 | argptr = lock_user(VERIFY_WRITE, guest_data, guest_data_size, 0); |
| 3557 | switch (ie->host_cmd) { |
| 3558 | case DM_REMOVE_ALL: |
| 3559 | case DM_DEV_CREATE: |
| 3560 | case DM_DEV_REMOVE: |
| 3561 | case DM_DEV_RENAME: |
| 3562 | case DM_DEV_SUSPEND: |
| 3563 | case DM_DEV_STATUS: |
| 3564 | case DM_TABLE_LOAD: |
| 3565 | case DM_TABLE_CLEAR: |
| 3566 | case DM_TARGET_MSG: |
| 3567 | case DM_DEV_SET_GEOMETRY: |
| 3568 | /* no return data */ |
| 3569 | break; |
| 3570 | case DM_LIST_DEVICES: |
| 3571 | { |
| 3572 | struct dm_name_list *nl = (void*)host_dm + host_dm->data_start; |
| 3573 | uint32_t remaining_data = guest_data_size; |
| 3574 | void *cur_data = argptr; |
| 3575 | const argtype arg_type[] = { MK_STRUCT(STRUCT_dm_name_list) }; |
| 3576 | int nl_size = 12; /* can't use thunk_size due to alignment */ |
| 3577 | |
| 3578 | while (1) { |
| 3579 | uint32_t next = nl->next; |
| 3580 | if (next) { |
| 3581 | nl->next = nl_size + (strlen(nl->name) + 1); |
| 3582 | } |
| 3583 | if (remaining_data < nl->next) { |
| 3584 | host_dm->flags |= DM_BUFFER_FULL_FLAG; |
| 3585 | break; |
| 3586 | } |
| 3587 | thunk_convert(cur_data, nl, arg_type, THUNK_TARGET); |
| 3588 | strcpy(cur_data + nl_size, nl->name); |
| 3589 | cur_data += nl->next; |
| 3590 | remaining_data -= nl->next; |
| 3591 | if (!next) { |
| 3592 | break; |
| 3593 | } |
| 3594 | nl = (void*)nl + next; |
| 3595 | } |
| 3596 | break; |
| 3597 | } |
| 3598 | case DM_DEV_WAIT: |
| 3599 | case DM_TABLE_STATUS: |
| 3600 | { |
| 3601 | struct dm_target_spec *spec = (void*)host_dm + host_dm->data_start; |
| 3602 | void *cur_data = argptr; |
| 3603 | const argtype arg_type[] = { MK_STRUCT(STRUCT_dm_target_spec) }; |
| 3604 | int spec_size = thunk_type_size(arg_type, 0); |
| 3605 | int i; |
| 3606 | |
| 3607 | for (i = 0; i < host_dm->target_count; i++) { |
| 3608 | uint32_t next = spec->next; |
| 3609 | int slen = strlen((char*)&spec[1]) + 1; |
| 3610 | spec->next = (cur_data - argptr) + spec_size + slen; |
| 3611 | if (guest_data_size < spec->next) { |
| 3612 | host_dm->flags |= DM_BUFFER_FULL_FLAG; |
| 3613 | break; |
| 3614 | } |
| 3615 | thunk_convert(cur_data, spec, arg_type, THUNK_TARGET); |
| 3616 | strcpy(cur_data + spec_size, (char*)&spec[1]); |
| 3617 | cur_data = argptr + spec->next; |
| 3618 | spec = (void*)host_dm + host_dm->data_start + next; |
| 3619 | } |
| 3620 | break; |
| 3621 | } |
| 3622 | case DM_TABLE_DEPS: |
| 3623 | { |
| 3624 | void *hdata = (void*)host_dm + host_dm->data_start; |
| 3625 | int count = *(uint32_t*)hdata; |
| 3626 | uint64_t *hdev = hdata + 8; |
| 3627 | uint64_t *gdev = argptr + 8; |
| 3628 | int i; |
| 3629 | |
| 3630 | *(uint32_t*)argptr = tswap32(count); |
| 3631 | for (i = 0; i < count; i++) { |
| 3632 | *gdev = tswap64(*hdev); |
| 3633 | gdev++; |
| 3634 | hdev++; |
| 3635 | } |
| 3636 | break; |
| 3637 | } |
| 3638 | case DM_LIST_VERSIONS: |
| 3639 | { |
| 3640 | struct dm_target_versions *vers = (void*)host_dm + host_dm->data_start; |
| 3641 | uint32_t remaining_data = guest_data_size; |
| 3642 | void *cur_data = argptr; |
| 3643 | const argtype arg_type[] = { MK_STRUCT(STRUCT_dm_target_versions) }; |
| 3644 | int vers_size = thunk_type_size(arg_type, 0); |
| 3645 | |
| 3646 | while (1) { |
| 3647 | uint32_t next = vers->next; |
| 3648 | if (next) { |
| 3649 | vers->next = vers_size + (strlen(vers->name) + 1); |
| 3650 | } |
| 3651 | if (remaining_data < vers->next) { |
| 3652 | host_dm->flags |= DM_BUFFER_FULL_FLAG; |
| 3653 | break; |
| 3654 | } |
| 3655 | thunk_convert(cur_data, vers, arg_type, THUNK_TARGET); |
| 3656 | strcpy(cur_data + vers_size, vers->name); |
| 3657 | cur_data += vers->next; |
| 3658 | remaining_data -= vers->next; |
| 3659 | if (!next) { |
| 3660 | break; |
| 3661 | } |
| 3662 | vers = (void*)vers + next; |
| 3663 | } |
| 3664 | break; |
| 3665 | } |
| 3666 | default: |
| 3667 | ret = -TARGET_EINVAL; |
| 3668 | goto out; |
| 3669 | } |
| 3670 | unlock_user(argptr, guest_data, guest_data_size); |
| 3671 | |
| 3672 | argptr = lock_user(VERIFY_WRITE, arg, target_size, 0); |
| 3673 | if (!argptr) { |
| 3674 | ret = -TARGET_EFAULT; |
| 3675 | goto out; |
| 3676 | } |
| 3677 | thunk_convert(argptr, buf_temp, arg_type, THUNK_TARGET); |
| 3678 | unlock_user(argptr, arg, target_size); |
| 3679 | } |
| 3680 | out: |
Stefan Weil | ad11ad7 | 2012-09-04 22:14:19 +0200 | [diff] [blame] | 3681 | g_free(big_buf); |
Alexander Graf | 56e904e | 2012-01-31 18:42:06 +0100 | [diff] [blame] | 3682 | return ret; |
| 3683 | } |
| 3684 | |
blueswir1 | 9f106a7 | 2008-10-05 10:52:52 +0000 | [diff] [blame] | 3685 | static IOCTLEntry ioctl_entries[] = { |
Blue Swirl | 001faf3 | 2009-05-13 17:53:17 +0000 | [diff] [blame] | 3686 | #define IOCTL(cmd, access, ...) \ |
Peter Maydell | d2ef05b | 2011-01-06 15:04:17 +0000 | [diff] [blame] | 3687 | { TARGET_ ## cmd, cmd, #cmd, access, 0, { __VA_ARGS__ } }, |
| 3688 | #define IOCTL_SPECIAL(cmd, access, dofn, ...) \ |
| 3689 | { TARGET_ ## cmd, cmd, #cmd, access, dofn, { __VA_ARGS__ } }, |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3690 | #include "ioctls.h" |
| 3691 | { 0, 0, }, |
| 3692 | }; |
| 3693 | |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 3694 | /* ??? Implement proper locking for ioctls. */ |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 3695 | /* do_ioctl() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 3696 | static abi_long do_ioctl(int fd, abi_long cmd, abi_long arg) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3697 | { |
| 3698 | const IOCTLEntry *ie; |
| 3699 | const argtype *arg_type; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 3700 | abi_long ret; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3701 | uint8_t buf_temp[MAX_STRUCT_SIZE]; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 3702 | int target_size; |
| 3703 | void *argptr; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3704 | |
| 3705 | ie = ioctl_entries; |
| 3706 | for(;;) { |
| 3707 | if (ie->target_cmd == 0) { |
j_mayer | 3240710 | 2007-09-26 23:01:49 +0000 | [diff] [blame] | 3708 | gemu_log("Unsupported ioctl: cmd=0x%04lx\n", (long)cmd); |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 3709 | return -TARGET_ENOSYS; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3710 | } |
| 3711 | if (ie->target_cmd == cmd) |
| 3712 | break; |
| 3713 | ie++; |
| 3714 | } |
| 3715 | arg_type = ie->arg_type; |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 3716 | #if defined(DEBUG) |
j_mayer | 3240710 | 2007-09-26 23:01:49 +0000 | [diff] [blame] | 3717 | gemu_log("ioctl: cmd=0x%04lx (%s)\n", (long)cmd, ie->name); |
bellard | 72f0390 | 2003-02-18 23:33:18 +0000 | [diff] [blame] | 3718 | #endif |
Peter Maydell | d2ef05b | 2011-01-06 15:04:17 +0000 | [diff] [blame] | 3719 | if (ie->do_ioctl) { |
| 3720 | return ie->do_ioctl(ie, buf_temp, fd, cmd, arg); |
| 3721 | } |
| 3722 | |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3723 | switch(arg_type[0]) { |
| 3724 | case TYPE_NULL: |
| 3725 | /* no argument */ |
| 3726 | ret = get_errno(ioctl(fd, ie->host_cmd)); |
| 3727 | break; |
| 3728 | case TYPE_PTRVOID: |
| 3729 | case TYPE_INT: |
| 3730 | /* int argment */ |
| 3731 | ret = get_errno(ioctl(fd, ie->host_cmd, arg)); |
| 3732 | break; |
| 3733 | case TYPE_PTR: |
| 3734 | arg_type++; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 3735 | target_size = thunk_type_size(arg_type, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3736 | switch(ie->access) { |
| 3737 | case IOC_R: |
| 3738 | ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp)); |
| 3739 | if (!is_error(ret)) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 3740 | argptr = lock_user(VERIFY_WRITE, arg, target_size, 0); |
| 3741 | if (!argptr) |
| 3742 | return -TARGET_EFAULT; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 3743 | thunk_convert(argptr, buf_temp, arg_type, THUNK_TARGET); |
| 3744 | unlock_user(argptr, arg, target_size); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3745 | } |
| 3746 | break; |
| 3747 | case IOC_W: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 3748 | argptr = lock_user(VERIFY_READ, arg, target_size, 1); |
| 3749 | if (!argptr) |
| 3750 | return -TARGET_EFAULT; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 3751 | thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST); |
| 3752 | unlock_user(argptr, arg, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3753 | ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp)); |
| 3754 | break; |
| 3755 | default: |
| 3756 | case IOC_RW: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 3757 | argptr = lock_user(VERIFY_READ, arg, target_size, 1); |
| 3758 | if (!argptr) |
| 3759 | return -TARGET_EFAULT; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 3760 | thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST); |
| 3761 | unlock_user(argptr, arg, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3762 | ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp)); |
| 3763 | if (!is_error(ret)) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 3764 | argptr = lock_user(VERIFY_WRITE, arg, target_size, 0); |
| 3765 | if (!argptr) |
| 3766 | return -TARGET_EFAULT; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 3767 | thunk_convert(argptr, buf_temp, arg_type, THUNK_TARGET); |
| 3768 | unlock_user(argptr, arg, target_size); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3769 | } |
| 3770 | break; |
| 3771 | } |
| 3772 | break; |
| 3773 | default: |
j_mayer | 3240710 | 2007-09-26 23:01:49 +0000 | [diff] [blame] | 3774 | gemu_log("Unsupported ioctl type: cmd=0x%04lx type=%d\n", |
| 3775 | (long)cmd, arg_type[0]); |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 3776 | ret = -TARGET_ENOSYS; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3777 | break; |
| 3778 | } |
| 3779 | return ret; |
| 3780 | } |
| 3781 | |
blueswir1 | b39bc50 | 2008-10-05 10:51:10 +0000 | [diff] [blame] | 3782 | static const bitmask_transtbl iflag_tbl[] = { |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3783 | { TARGET_IGNBRK, TARGET_IGNBRK, IGNBRK, IGNBRK }, |
| 3784 | { TARGET_BRKINT, TARGET_BRKINT, BRKINT, BRKINT }, |
| 3785 | { TARGET_IGNPAR, TARGET_IGNPAR, IGNPAR, IGNPAR }, |
| 3786 | { TARGET_PARMRK, TARGET_PARMRK, PARMRK, PARMRK }, |
| 3787 | { TARGET_INPCK, TARGET_INPCK, INPCK, INPCK }, |
| 3788 | { TARGET_ISTRIP, TARGET_ISTRIP, ISTRIP, ISTRIP }, |
| 3789 | { TARGET_INLCR, TARGET_INLCR, INLCR, INLCR }, |
| 3790 | { TARGET_IGNCR, TARGET_IGNCR, IGNCR, IGNCR }, |
| 3791 | { TARGET_ICRNL, TARGET_ICRNL, ICRNL, ICRNL }, |
| 3792 | { TARGET_IUCLC, TARGET_IUCLC, IUCLC, IUCLC }, |
| 3793 | { TARGET_IXON, TARGET_IXON, IXON, IXON }, |
| 3794 | { TARGET_IXANY, TARGET_IXANY, IXANY, IXANY }, |
| 3795 | { TARGET_IXOFF, TARGET_IXOFF, IXOFF, IXOFF }, |
| 3796 | { TARGET_IMAXBEL, TARGET_IMAXBEL, IMAXBEL, IMAXBEL }, |
| 3797 | { 0, 0, 0, 0 } |
| 3798 | }; |
| 3799 | |
blueswir1 | b39bc50 | 2008-10-05 10:51:10 +0000 | [diff] [blame] | 3800 | static const bitmask_transtbl oflag_tbl[] = { |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3801 | { TARGET_OPOST, TARGET_OPOST, OPOST, OPOST }, |
| 3802 | { TARGET_OLCUC, TARGET_OLCUC, OLCUC, OLCUC }, |
| 3803 | { TARGET_ONLCR, TARGET_ONLCR, ONLCR, ONLCR }, |
| 3804 | { TARGET_OCRNL, TARGET_OCRNL, OCRNL, OCRNL }, |
| 3805 | { TARGET_ONOCR, TARGET_ONOCR, ONOCR, ONOCR }, |
| 3806 | { TARGET_ONLRET, TARGET_ONLRET, ONLRET, ONLRET }, |
| 3807 | { TARGET_OFILL, TARGET_OFILL, OFILL, OFILL }, |
| 3808 | { TARGET_OFDEL, TARGET_OFDEL, OFDEL, OFDEL }, |
| 3809 | { TARGET_NLDLY, TARGET_NL0, NLDLY, NL0 }, |
| 3810 | { TARGET_NLDLY, TARGET_NL1, NLDLY, NL1 }, |
| 3811 | { TARGET_CRDLY, TARGET_CR0, CRDLY, CR0 }, |
| 3812 | { TARGET_CRDLY, TARGET_CR1, CRDLY, CR1 }, |
| 3813 | { TARGET_CRDLY, TARGET_CR2, CRDLY, CR2 }, |
| 3814 | { TARGET_CRDLY, TARGET_CR3, CRDLY, CR3 }, |
| 3815 | { TARGET_TABDLY, TARGET_TAB0, TABDLY, TAB0 }, |
| 3816 | { TARGET_TABDLY, TARGET_TAB1, TABDLY, TAB1 }, |
| 3817 | { TARGET_TABDLY, TARGET_TAB2, TABDLY, TAB2 }, |
| 3818 | { TARGET_TABDLY, TARGET_TAB3, TABDLY, TAB3 }, |
| 3819 | { TARGET_BSDLY, TARGET_BS0, BSDLY, BS0 }, |
| 3820 | { TARGET_BSDLY, TARGET_BS1, BSDLY, BS1 }, |
| 3821 | { TARGET_VTDLY, TARGET_VT0, VTDLY, VT0 }, |
| 3822 | { TARGET_VTDLY, TARGET_VT1, VTDLY, VT1 }, |
| 3823 | { TARGET_FFDLY, TARGET_FF0, FFDLY, FF0 }, |
| 3824 | { TARGET_FFDLY, TARGET_FF1, FFDLY, FF1 }, |
| 3825 | { 0, 0, 0, 0 } |
| 3826 | }; |
| 3827 | |
blueswir1 | b39bc50 | 2008-10-05 10:51:10 +0000 | [diff] [blame] | 3828 | static const bitmask_transtbl cflag_tbl[] = { |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3829 | { TARGET_CBAUD, TARGET_B0, CBAUD, B0 }, |
| 3830 | { TARGET_CBAUD, TARGET_B50, CBAUD, B50 }, |
| 3831 | { TARGET_CBAUD, TARGET_B75, CBAUD, B75 }, |
| 3832 | { TARGET_CBAUD, TARGET_B110, CBAUD, B110 }, |
| 3833 | { TARGET_CBAUD, TARGET_B134, CBAUD, B134 }, |
| 3834 | { TARGET_CBAUD, TARGET_B150, CBAUD, B150 }, |
| 3835 | { TARGET_CBAUD, TARGET_B200, CBAUD, B200 }, |
| 3836 | { TARGET_CBAUD, TARGET_B300, CBAUD, B300 }, |
| 3837 | { TARGET_CBAUD, TARGET_B600, CBAUD, B600 }, |
| 3838 | { TARGET_CBAUD, TARGET_B1200, CBAUD, B1200 }, |
| 3839 | { TARGET_CBAUD, TARGET_B1800, CBAUD, B1800 }, |
| 3840 | { TARGET_CBAUD, TARGET_B2400, CBAUD, B2400 }, |
| 3841 | { TARGET_CBAUD, TARGET_B4800, CBAUD, B4800 }, |
| 3842 | { TARGET_CBAUD, TARGET_B9600, CBAUD, B9600 }, |
| 3843 | { TARGET_CBAUD, TARGET_B19200, CBAUD, B19200 }, |
| 3844 | { TARGET_CBAUD, TARGET_B38400, CBAUD, B38400 }, |
| 3845 | { TARGET_CBAUD, TARGET_B57600, CBAUD, B57600 }, |
| 3846 | { TARGET_CBAUD, TARGET_B115200, CBAUD, B115200 }, |
| 3847 | { TARGET_CBAUD, TARGET_B230400, CBAUD, B230400 }, |
| 3848 | { TARGET_CBAUD, TARGET_B460800, CBAUD, B460800 }, |
| 3849 | { TARGET_CSIZE, TARGET_CS5, CSIZE, CS5 }, |
| 3850 | { TARGET_CSIZE, TARGET_CS6, CSIZE, CS6 }, |
| 3851 | { TARGET_CSIZE, TARGET_CS7, CSIZE, CS7 }, |
| 3852 | { TARGET_CSIZE, TARGET_CS8, CSIZE, CS8 }, |
| 3853 | { TARGET_CSTOPB, TARGET_CSTOPB, CSTOPB, CSTOPB }, |
| 3854 | { TARGET_CREAD, TARGET_CREAD, CREAD, CREAD }, |
| 3855 | { TARGET_PARENB, TARGET_PARENB, PARENB, PARENB }, |
| 3856 | { TARGET_PARODD, TARGET_PARODD, PARODD, PARODD }, |
| 3857 | { TARGET_HUPCL, TARGET_HUPCL, HUPCL, HUPCL }, |
| 3858 | { TARGET_CLOCAL, TARGET_CLOCAL, CLOCAL, CLOCAL }, |
| 3859 | { TARGET_CRTSCTS, TARGET_CRTSCTS, CRTSCTS, CRTSCTS }, |
| 3860 | { 0, 0, 0, 0 } |
| 3861 | }; |
| 3862 | |
blueswir1 | b39bc50 | 2008-10-05 10:51:10 +0000 | [diff] [blame] | 3863 | static const bitmask_transtbl lflag_tbl[] = { |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3864 | { TARGET_ISIG, TARGET_ISIG, ISIG, ISIG }, |
| 3865 | { TARGET_ICANON, TARGET_ICANON, ICANON, ICANON }, |
| 3866 | { TARGET_XCASE, TARGET_XCASE, XCASE, XCASE }, |
| 3867 | { TARGET_ECHO, TARGET_ECHO, ECHO, ECHO }, |
| 3868 | { TARGET_ECHOE, TARGET_ECHOE, ECHOE, ECHOE }, |
| 3869 | { TARGET_ECHOK, TARGET_ECHOK, ECHOK, ECHOK }, |
| 3870 | { TARGET_ECHONL, TARGET_ECHONL, ECHONL, ECHONL }, |
| 3871 | { TARGET_NOFLSH, TARGET_NOFLSH, NOFLSH, NOFLSH }, |
| 3872 | { TARGET_TOSTOP, TARGET_TOSTOP, TOSTOP, TOSTOP }, |
| 3873 | { TARGET_ECHOCTL, TARGET_ECHOCTL, ECHOCTL, ECHOCTL }, |
| 3874 | { TARGET_ECHOPRT, TARGET_ECHOPRT, ECHOPRT, ECHOPRT }, |
| 3875 | { TARGET_ECHOKE, TARGET_ECHOKE, ECHOKE, ECHOKE }, |
| 3876 | { TARGET_FLUSHO, TARGET_FLUSHO, FLUSHO, FLUSHO }, |
| 3877 | { TARGET_PENDIN, TARGET_PENDIN, PENDIN, PENDIN }, |
| 3878 | { TARGET_IEXTEN, TARGET_IEXTEN, IEXTEN, IEXTEN }, |
| 3879 | { 0, 0, 0, 0 } |
| 3880 | }; |
| 3881 | |
| 3882 | static void target_to_host_termios (void *dst, const void *src) |
| 3883 | { |
| 3884 | struct host_termios *host = dst; |
| 3885 | const struct target_termios *target = src; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 3886 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3887 | host->c_iflag = |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3888 | target_to_host_bitmask(tswap32(target->c_iflag), iflag_tbl); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3889 | host->c_oflag = |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3890 | target_to_host_bitmask(tswap32(target->c_oflag), oflag_tbl); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3891 | host->c_cflag = |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3892 | target_to_host_bitmask(tswap32(target->c_cflag), cflag_tbl); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3893 | host->c_lflag = |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3894 | target_to_host_bitmask(tswap32(target->c_lflag), lflag_tbl); |
| 3895 | host->c_line = target->c_line; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 3896 | |
Arnaud Patard | 4460712 | 2009-04-21 17:39:08 +0300 | [diff] [blame] | 3897 | memset(host->c_cc, 0, sizeof(host->c_cc)); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3898 | host->c_cc[VINTR] = target->c_cc[TARGET_VINTR]; |
| 3899 | host->c_cc[VQUIT] = target->c_cc[TARGET_VQUIT]; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 3900 | host->c_cc[VERASE] = target->c_cc[TARGET_VERASE]; |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3901 | host->c_cc[VKILL] = target->c_cc[TARGET_VKILL]; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 3902 | host->c_cc[VEOF] = target->c_cc[TARGET_VEOF]; |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3903 | host->c_cc[VTIME] = target->c_cc[TARGET_VTIME]; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 3904 | host->c_cc[VMIN] = target->c_cc[TARGET_VMIN]; |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3905 | host->c_cc[VSWTC] = target->c_cc[TARGET_VSWTC]; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 3906 | host->c_cc[VSTART] = target->c_cc[TARGET_VSTART]; |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3907 | host->c_cc[VSTOP] = target->c_cc[TARGET_VSTOP]; |
| 3908 | host->c_cc[VSUSP] = target->c_cc[TARGET_VSUSP]; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 3909 | host->c_cc[VEOL] = target->c_cc[TARGET_VEOL]; |
| 3910 | host->c_cc[VREPRINT] = target->c_cc[TARGET_VREPRINT]; |
| 3911 | host->c_cc[VDISCARD] = target->c_cc[TARGET_VDISCARD]; |
| 3912 | host->c_cc[VWERASE] = target->c_cc[TARGET_VWERASE]; |
| 3913 | host->c_cc[VLNEXT] = target->c_cc[TARGET_VLNEXT]; |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3914 | host->c_cc[VEOL2] = target->c_cc[TARGET_VEOL2]; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3915 | } |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 3916 | |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3917 | static void host_to_target_termios (void *dst, const void *src) |
| 3918 | { |
| 3919 | struct target_termios *target = dst; |
| 3920 | const struct host_termios *host = src; |
| 3921 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3922 | target->c_iflag = |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3923 | tswap32(host_to_target_bitmask(host->c_iflag, iflag_tbl)); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3924 | target->c_oflag = |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3925 | tswap32(host_to_target_bitmask(host->c_oflag, oflag_tbl)); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3926 | target->c_cflag = |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3927 | tswap32(host_to_target_bitmask(host->c_cflag, cflag_tbl)); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3928 | target->c_lflag = |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3929 | tswap32(host_to_target_bitmask(host->c_lflag, lflag_tbl)); |
| 3930 | target->c_line = host->c_line; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 3931 | |
Arnaud Patard | 4460712 | 2009-04-21 17:39:08 +0300 | [diff] [blame] | 3932 | memset(target->c_cc, 0, sizeof(target->c_cc)); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3933 | target->c_cc[TARGET_VINTR] = host->c_cc[VINTR]; |
| 3934 | target->c_cc[TARGET_VQUIT] = host->c_cc[VQUIT]; |
| 3935 | target->c_cc[TARGET_VERASE] = host->c_cc[VERASE]; |
| 3936 | target->c_cc[TARGET_VKILL] = host->c_cc[VKILL]; |
| 3937 | target->c_cc[TARGET_VEOF] = host->c_cc[VEOF]; |
| 3938 | target->c_cc[TARGET_VTIME] = host->c_cc[VTIME]; |
| 3939 | target->c_cc[TARGET_VMIN] = host->c_cc[VMIN]; |
| 3940 | target->c_cc[TARGET_VSWTC] = host->c_cc[VSWTC]; |
| 3941 | target->c_cc[TARGET_VSTART] = host->c_cc[VSTART]; |
| 3942 | target->c_cc[TARGET_VSTOP] = host->c_cc[VSTOP]; |
| 3943 | target->c_cc[TARGET_VSUSP] = host->c_cc[VSUSP]; |
| 3944 | target->c_cc[TARGET_VEOL] = host->c_cc[VEOL]; |
| 3945 | target->c_cc[TARGET_VREPRINT] = host->c_cc[VREPRINT]; |
| 3946 | target->c_cc[TARGET_VDISCARD] = host->c_cc[VDISCARD]; |
| 3947 | target->c_cc[TARGET_VWERASE] = host->c_cc[VWERASE]; |
| 3948 | target->c_cc[TARGET_VLNEXT] = host->c_cc[VLNEXT]; |
| 3949 | target->c_cc[TARGET_VEOL2] = host->c_cc[VEOL2]; |
| 3950 | } |
| 3951 | |
blueswir1 | 8e853dc | 2008-10-05 10:49:32 +0000 | [diff] [blame] | 3952 | static const StructEntry struct_termios_def = { |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3953 | .convert = { host_to_target_termios, target_to_host_termios }, |
| 3954 | .size = { sizeof(struct target_termios), sizeof(struct host_termios) }, |
| 3955 | .align = { __alignof__(struct target_termios), __alignof__(struct host_termios) }, |
| 3956 | }; |
| 3957 | |
bellard | 5286db7 | 2003-06-05 00:57:30 +0000 | [diff] [blame] | 3958 | static bitmask_transtbl mmap_flags_tbl[] = { |
| 3959 | { TARGET_MAP_SHARED, TARGET_MAP_SHARED, MAP_SHARED, MAP_SHARED }, |
| 3960 | { TARGET_MAP_PRIVATE, TARGET_MAP_PRIVATE, MAP_PRIVATE, MAP_PRIVATE }, |
| 3961 | { TARGET_MAP_FIXED, TARGET_MAP_FIXED, MAP_FIXED, MAP_FIXED }, |
| 3962 | { TARGET_MAP_ANONYMOUS, TARGET_MAP_ANONYMOUS, MAP_ANONYMOUS, MAP_ANONYMOUS }, |
| 3963 | { TARGET_MAP_GROWSDOWN, TARGET_MAP_GROWSDOWN, MAP_GROWSDOWN, MAP_GROWSDOWN }, |
| 3964 | { TARGET_MAP_DENYWRITE, TARGET_MAP_DENYWRITE, MAP_DENYWRITE, MAP_DENYWRITE }, |
| 3965 | { TARGET_MAP_EXECUTABLE, TARGET_MAP_EXECUTABLE, MAP_EXECUTABLE, MAP_EXECUTABLE }, |
| 3966 | { TARGET_MAP_LOCKED, TARGET_MAP_LOCKED, MAP_LOCKED, MAP_LOCKED }, |
| 3967 | { 0, 0, 0, 0 } |
| 3968 | }; |
| 3969 | |
bellard | 2ab83ea | 2003-06-15 19:56:46 +0000 | [diff] [blame] | 3970 | #if defined(TARGET_I386) |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 3971 | |
| 3972 | /* NOTE: there is really one LDT for all the threads */ |
blueswir1 | b1d8e52 | 2008-10-26 13:43:07 +0000 | [diff] [blame] | 3973 | static uint8_t *ldt_table; |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 3974 | |
bellard | 03acab6 | 2007-11-11 14:57:14 +0000 | [diff] [blame] | 3975 | static abi_long read_ldt(abi_ulong ptr, unsigned long bytecount) |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 3976 | { |
| 3977 | int size; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 3978 | void *p; |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 3979 | |
| 3980 | if (!ldt_table) |
| 3981 | return 0; |
| 3982 | size = TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE; |
| 3983 | if (size > bytecount) |
| 3984 | size = bytecount; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 3985 | p = lock_user(VERIFY_WRITE, ptr, size, 0); |
| 3986 | if (!p) |
bellard | 03acab6 | 2007-11-11 14:57:14 +0000 | [diff] [blame] | 3987 | return -TARGET_EFAULT; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 3988 | /* ??? Should this by byteswapped? */ |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 3989 | memcpy(p, ldt_table, size); |
| 3990 | unlock_user(p, ptr, size); |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 3991 | return size; |
| 3992 | } |
| 3993 | |
| 3994 | /* XXX: add locking support */ |
bellard | 03acab6 | 2007-11-11 14:57:14 +0000 | [diff] [blame] | 3995 | static abi_long write_ldt(CPUX86State *env, |
| 3996 | abi_ulong ptr, unsigned long bytecount, int oldmode) |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 3997 | { |
| 3998 | struct target_modify_ldt_ldt_s ldt_info; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 3999 | struct target_modify_ldt_ldt_s *target_ldt_info; |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4000 | int seg_32bit, contents, read_exec_only, limit_in_pages; |
bellard | 8d18e89 | 2007-11-14 15:18:40 +0000 | [diff] [blame] | 4001 | int seg_not_present, useable, lm; |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4002 | uint32_t *lp, entry_1, entry_2; |
| 4003 | |
| 4004 | if (bytecount != sizeof(ldt_info)) |
bellard | 03acab6 | 2007-11-11 14:57:14 +0000 | [diff] [blame] | 4005 | return -TARGET_EINVAL; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 4006 | if (!lock_user_struct(VERIFY_READ, target_ldt_info, ptr, 1)) |
bellard | 03acab6 | 2007-11-11 14:57:14 +0000 | [diff] [blame] | 4007 | return -TARGET_EFAULT; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 4008 | ldt_info.entry_number = tswap32(target_ldt_info->entry_number); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 4009 | ldt_info.base_addr = tswapal(target_ldt_info->base_addr); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 4010 | ldt_info.limit = tswap32(target_ldt_info->limit); |
| 4011 | ldt_info.flags = tswap32(target_ldt_info->flags); |
| 4012 | unlock_user_struct(target_ldt_info, ptr, 0); |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 4013 | |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4014 | if (ldt_info.entry_number >= TARGET_LDT_ENTRIES) |
bellard | 03acab6 | 2007-11-11 14:57:14 +0000 | [diff] [blame] | 4015 | return -TARGET_EINVAL; |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4016 | seg_32bit = ldt_info.flags & 1; |
| 4017 | contents = (ldt_info.flags >> 1) & 3; |
| 4018 | read_exec_only = (ldt_info.flags >> 3) & 1; |
| 4019 | limit_in_pages = (ldt_info.flags >> 4) & 1; |
| 4020 | seg_not_present = (ldt_info.flags >> 5) & 1; |
| 4021 | useable = (ldt_info.flags >> 6) & 1; |
bellard | 8d18e89 | 2007-11-14 15:18:40 +0000 | [diff] [blame] | 4022 | #ifdef TARGET_ABI32 |
| 4023 | lm = 0; |
| 4024 | #else |
| 4025 | lm = (ldt_info.flags >> 7) & 1; |
| 4026 | #endif |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4027 | if (contents == 3) { |
| 4028 | if (oldmode) |
bellard | 03acab6 | 2007-11-11 14:57:14 +0000 | [diff] [blame] | 4029 | return -TARGET_EINVAL; |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4030 | if (seg_not_present == 0) |
bellard | 03acab6 | 2007-11-11 14:57:14 +0000 | [diff] [blame] | 4031 | return -TARGET_EINVAL; |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4032 | } |
| 4033 | /* allocate the LDT */ |
| 4034 | if (!ldt_table) { |
balrog | e441570 | 2008-11-10 02:55:33 +0000 | [diff] [blame] | 4035 | env->ldt.base = target_mmap(0, |
| 4036 | TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE, |
| 4037 | PROT_READ|PROT_WRITE, |
| 4038 | MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); |
| 4039 | if (env->ldt.base == -1) |
bellard | 03acab6 | 2007-11-11 14:57:14 +0000 | [diff] [blame] | 4040 | return -TARGET_ENOMEM; |
balrog | e441570 | 2008-11-10 02:55:33 +0000 | [diff] [blame] | 4041 | memset(g2h(env->ldt.base), 0, |
| 4042 | TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE); |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4043 | env->ldt.limit = 0xffff; |
balrog | e441570 | 2008-11-10 02:55:33 +0000 | [diff] [blame] | 4044 | ldt_table = g2h(env->ldt.base); |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4045 | } |
| 4046 | |
| 4047 | /* NOTE: same code as Linux kernel */ |
| 4048 | /* Allow LDTs to be cleared by the user. */ |
| 4049 | if (ldt_info.base_addr == 0 && ldt_info.limit == 0) { |
| 4050 | if (oldmode || |
| 4051 | (contents == 0 && |
| 4052 | read_exec_only == 1 && |
| 4053 | seg_32bit == 0 && |
| 4054 | limit_in_pages == 0 && |
| 4055 | seg_not_present == 1 && |
| 4056 | useable == 0 )) { |
| 4057 | entry_1 = 0; |
| 4058 | entry_2 = 0; |
| 4059 | goto install; |
| 4060 | } |
| 4061 | } |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 4062 | |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4063 | entry_1 = ((ldt_info.base_addr & 0x0000ffff) << 16) | |
| 4064 | (ldt_info.limit & 0x0ffff); |
| 4065 | entry_2 = (ldt_info.base_addr & 0xff000000) | |
| 4066 | ((ldt_info.base_addr & 0x00ff0000) >> 16) | |
| 4067 | (ldt_info.limit & 0xf0000) | |
| 4068 | ((read_exec_only ^ 1) << 9) | |
| 4069 | (contents << 10) | |
| 4070 | ((seg_not_present ^ 1) << 15) | |
| 4071 | (seg_32bit << 22) | |
| 4072 | (limit_in_pages << 23) | |
bellard | 8d18e89 | 2007-11-14 15:18:40 +0000 | [diff] [blame] | 4073 | (lm << 21) | |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4074 | 0x7000; |
| 4075 | if (!oldmode) |
| 4076 | entry_2 |= (useable << 20); |
bellard | 14ae3ba | 2003-05-27 23:25:06 +0000 | [diff] [blame] | 4077 | |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4078 | /* Install the new entry ... */ |
| 4079 | install: |
| 4080 | lp = (uint32_t *)(ldt_table + (ldt_info.entry_number << 3)); |
| 4081 | lp[0] = tswap32(entry_1); |
| 4082 | lp[1] = tswap32(entry_2); |
| 4083 | return 0; |
| 4084 | } |
| 4085 | |
| 4086 | /* specific and weird i386 syscalls */ |
blueswir1 | 8fcd369 | 2008-08-17 20:26:25 +0000 | [diff] [blame] | 4087 | static abi_long do_modify_ldt(CPUX86State *env, int func, abi_ulong ptr, |
| 4088 | unsigned long bytecount) |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4089 | { |
bellard | 03acab6 | 2007-11-11 14:57:14 +0000 | [diff] [blame] | 4090 | abi_long ret; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 4091 | |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4092 | switch (func) { |
| 4093 | case 0: |
| 4094 | ret = read_ldt(ptr, bytecount); |
| 4095 | break; |
| 4096 | case 1: |
| 4097 | ret = write_ldt(env, ptr, bytecount, 1); |
| 4098 | break; |
| 4099 | case 0x11: |
| 4100 | ret = write_ldt(env, ptr, bytecount, 0); |
| 4101 | break; |
bellard | 03acab6 | 2007-11-11 14:57:14 +0000 | [diff] [blame] | 4102 | default: |
| 4103 | ret = -TARGET_ENOSYS; |
| 4104 | break; |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4105 | } |
| 4106 | return ret; |
| 4107 | } |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 4108 | |
blueswir1 | 4583f58 | 2008-08-24 10:35:55 +0000 | [diff] [blame] | 4109 | #if defined(TARGET_I386) && defined(TARGET_ABI32) |
blueswir1 | 8fcd369 | 2008-08-17 20:26:25 +0000 | [diff] [blame] | 4110 | static abi_long do_set_thread_area(CPUX86State *env, abi_ulong ptr) |
bellard | 8d18e89 | 2007-11-14 15:18:40 +0000 | [diff] [blame] | 4111 | { |
| 4112 | uint64_t *gdt_table = g2h(env->gdt.base); |
| 4113 | struct target_modify_ldt_ldt_s ldt_info; |
| 4114 | struct target_modify_ldt_ldt_s *target_ldt_info; |
| 4115 | int seg_32bit, contents, read_exec_only, limit_in_pages; |
| 4116 | int seg_not_present, useable, lm; |
| 4117 | uint32_t *lp, entry_1, entry_2; |
| 4118 | int i; |
| 4119 | |
| 4120 | lock_user_struct(VERIFY_WRITE, target_ldt_info, ptr, 1); |
| 4121 | if (!target_ldt_info) |
| 4122 | return -TARGET_EFAULT; |
| 4123 | ldt_info.entry_number = tswap32(target_ldt_info->entry_number); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 4124 | ldt_info.base_addr = tswapal(target_ldt_info->base_addr); |
bellard | 8d18e89 | 2007-11-14 15:18:40 +0000 | [diff] [blame] | 4125 | ldt_info.limit = tswap32(target_ldt_info->limit); |
| 4126 | ldt_info.flags = tswap32(target_ldt_info->flags); |
| 4127 | if (ldt_info.entry_number == -1) { |
| 4128 | for (i=TARGET_GDT_ENTRY_TLS_MIN; i<=TARGET_GDT_ENTRY_TLS_MAX; i++) { |
| 4129 | if (gdt_table[i] == 0) { |
| 4130 | ldt_info.entry_number = i; |
| 4131 | target_ldt_info->entry_number = tswap32(i); |
| 4132 | break; |
| 4133 | } |
| 4134 | } |
| 4135 | } |
| 4136 | unlock_user_struct(target_ldt_info, ptr, 1); |
| 4137 | |
| 4138 | if (ldt_info.entry_number < TARGET_GDT_ENTRY_TLS_MIN || |
| 4139 | ldt_info.entry_number > TARGET_GDT_ENTRY_TLS_MAX) |
| 4140 | return -TARGET_EINVAL; |
| 4141 | seg_32bit = ldt_info.flags & 1; |
| 4142 | contents = (ldt_info.flags >> 1) & 3; |
| 4143 | read_exec_only = (ldt_info.flags >> 3) & 1; |
| 4144 | limit_in_pages = (ldt_info.flags >> 4) & 1; |
| 4145 | seg_not_present = (ldt_info.flags >> 5) & 1; |
| 4146 | useable = (ldt_info.flags >> 6) & 1; |
| 4147 | #ifdef TARGET_ABI32 |
| 4148 | lm = 0; |
| 4149 | #else |
| 4150 | lm = (ldt_info.flags >> 7) & 1; |
| 4151 | #endif |
| 4152 | |
| 4153 | if (contents == 3) { |
| 4154 | if (seg_not_present == 0) |
| 4155 | return -TARGET_EINVAL; |
| 4156 | } |
| 4157 | |
| 4158 | /* NOTE: same code as Linux kernel */ |
| 4159 | /* Allow LDTs to be cleared by the user. */ |
| 4160 | if (ldt_info.base_addr == 0 && ldt_info.limit == 0) { |
| 4161 | if ((contents == 0 && |
| 4162 | read_exec_only == 1 && |
| 4163 | seg_32bit == 0 && |
| 4164 | limit_in_pages == 0 && |
| 4165 | seg_not_present == 1 && |
| 4166 | useable == 0 )) { |
| 4167 | entry_1 = 0; |
| 4168 | entry_2 = 0; |
| 4169 | goto install; |
| 4170 | } |
| 4171 | } |
| 4172 | |
| 4173 | entry_1 = ((ldt_info.base_addr & 0x0000ffff) << 16) | |
| 4174 | (ldt_info.limit & 0x0ffff); |
| 4175 | entry_2 = (ldt_info.base_addr & 0xff000000) | |
| 4176 | ((ldt_info.base_addr & 0x00ff0000) >> 16) | |
| 4177 | (ldt_info.limit & 0xf0000) | |
| 4178 | ((read_exec_only ^ 1) << 9) | |
| 4179 | (contents << 10) | |
| 4180 | ((seg_not_present ^ 1) << 15) | |
| 4181 | (seg_32bit << 22) | |
| 4182 | (limit_in_pages << 23) | |
| 4183 | (useable << 20) | |
| 4184 | (lm << 21) | |
| 4185 | 0x7000; |
| 4186 | |
| 4187 | /* Install the new entry ... */ |
| 4188 | install: |
| 4189 | lp = (uint32_t *)(gdt_table + ldt_info.entry_number); |
| 4190 | lp[0] = tswap32(entry_1); |
| 4191 | lp[1] = tswap32(entry_2); |
| 4192 | return 0; |
| 4193 | } |
| 4194 | |
blueswir1 | 8fcd369 | 2008-08-17 20:26:25 +0000 | [diff] [blame] | 4195 | static abi_long do_get_thread_area(CPUX86State *env, abi_ulong ptr) |
bellard | 8d18e89 | 2007-11-14 15:18:40 +0000 | [diff] [blame] | 4196 | { |
| 4197 | struct target_modify_ldt_ldt_s *target_ldt_info; |
| 4198 | uint64_t *gdt_table = g2h(env->gdt.base); |
| 4199 | uint32_t base_addr, limit, flags; |
| 4200 | int seg_32bit, contents, read_exec_only, limit_in_pages, idx; |
| 4201 | int seg_not_present, useable, lm; |
| 4202 | uint32_t *lp, entry_1, entry_2; |
| 4203 | |
| 4204 | lock_user_struct(VERIFY_WRITE, target_ldt_info, ptr, 1); |
| 4205 | if (!target_ldt_info) |
| 4206 | return -TARGET_EFAULT; |
| 4207 | idx = tswap32(target_ldt_info->entry_number); |
| 4208 | if (idx < TARGET_GDT_ENTRY_TLS_MIN || |
| 4209 | idx > TARGET_GDT_ENTRY_TLS_MAX) { |
| 4210 | unlock_user_struct(target_ldt_info, ptr, 1); |
| 4211 | return -TARGET_EINVAL; |
| 4212 | } |
| 4213 | lp = (uint32_t *)(gdt_table + idx); |
| 4214 | entry_1 = tswap32(lp[0]); |
| 4215 | entry_2 = tswap32(lp[1]); |
| 4216 | |
| 4217 | read_exec_only = ((entry_2 >> 9) & 1) ^ 1; |
| 4218 | contents = (entry_2 >> 10) & 3; |
| 4219 | seg_not_present = ((entry_2 >> 15) & 1) ^ 1; |
| 4220 | seg_32bit = (entry_2 >> 22) & 1; |
| 4221 | limit_in_pages = (entry_2 >> 23) & 1; |
| 4222 | useable = (entry_2 >> 20) & 1; |
| 4223 | #ifdef TARGET_ABI32 |
| 4224 | lm = 0; |
| 4225 | #else |
| 4226 | lm = (entry_2 >> 21) & 1; |
| 4227 | #endif |
| 4228 | flags = (seg_32bit << 0) | (contents << 1) | |
| 4229 | (read_exec_only << 3) | (limit_in_pages << 4) | |
| 4230 | (seg_not_present << 5) | (useable << 6) | (lm << 7); |
| 4231 | limit = (entry_1 & 0xffff) | (entry_2 & 0xf0000); |
| 4232 | base_addr = (entry_1 >> 16) | |
| 4233 | (entry_2 & 0xff000000) | |
| 4234 | ((entry_2 & 0xff) << 16); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 4235 | target_ldt_info->base_addr = tswapal(base_addr); |
bellard | 8d18e89 | 2007-11-14 15:18:40 +0000 | [diff] [blame] | 4236 | target_ldt_info->limit = tswap32(limit); |
| 4237 | target_ldt_info->flags = tswap32(flags); |
| 4238 | unlock_user_struct(target_ldt_info, ptr, 1); |
| 4239 | return 0; |
| 4240 | } |
blueswir1 | 4583f58 | 2008-08-24 10:35:55 +0000 | [diff] [blame] | 4241 | #endif /* TARGET_I386 && TARGET_ABI32 */ |
bellard | 8d18e89 | 2007-11-14 15:18:40 +0000 | [diff] [blame] | 4242 | |
bellard | d2fd1af | 2007-11-14 18:08:56 +0000 | [diff] [blame] | 4243 | #ifndef TARGET_ABI32 |
blueswir1 | 8fcd369 | 2008-08-17 20:26:25 +0000 | [diff] [blame] | 4244 | static abi_long do_arch_prctl(CPUX86State *env, int code, abi_ulong addr) |
bellard | d2fd1af | 2007-11-14 18:08:56 +0000 | [diff] [blame] | 4245 | { |
Juan Quintela | 1add869 | 2011-06-16 17:37:09 +0100 | [diff] [blame] | 4246 | abi_long ret = 0; |
bellard | d2fd1af | 2007-11-14 18:08:56 +0000 | [diff] [blame] | 4247 | abi_ulong val; |
| 4248 | int idx; |
Juan Quintela | 1add869 | 2011-06-16 17:37:09 +0100 | [diff] [blame] | 4249 | |
bellard | d2fd1af | 2007-11-14 18:08:56 +0000 | [diff] [blame] | 4250 | switch(code) { |
| 4251 | case TARGET_ARCH_SET_GS: |
| 4252 | case TARGET_ARCH_SET_FS: |
| 4253 | if (code == TARGET_ARCH_SET_GS) |
| 4254 | idx = R_GS; |
| 4255 | else |
| 4256 | idx = R_FS; |
| 4257 | cpu_x86_load_seg(env, idx, 0); |
| 4258 | env->segs[idx].base = addr; |
| 4259 | break; |
| 4260 | case TARGET_ARCH_GET_GS: |
| 4261 | case TARGET_ARCH_GET_FS: |
| 4262 | if (code == TARGET_ARCH_GET_GS) |
| 4263 | idx = R_GS; |
| 4264 | else |
| 4265 | idx = R_FS; |
| 4266 | val = env->segs[idx].base; |
| 4267 | if (put_user(val, addr, abi_ulong)) |
Juan Quintela | 1add869 | 2011-06-16 17:37:09 +0100 | [diff] [blame] | 4268 | ret = -TARGET_EFAULT; |
bellard | d2fd1af | 2007-11-14 18:08:56 +0000 | [diff] [blame] | 4269 | break; |
| 4270 | default: |
| 4271 | ret = -TARGET_EINVAL; |
| 4272 | break; |
| 4273 | } |
Juan Quintela | 1add869 | 2011-06-16 17:37:09 +0100 | [diff] [blame] | 4274 | return ret; |
bellard | d2fd1af | 2007-11-14 18:08:56 +0000 | [diff] [blame] | 4275 | } |
| 4276 | #endif |
| 4277 | |
bellard | 2ab83ea | 2003-06-15 19:56:46 +0000 | [diff] [blame] | 4278 | #endif /* defined(TARGET_I386) */ |
| 4279 | |
Riku Voipio | 05098a9 | 2011-03-04 15:27:29 +0200 | [diff] [blame] | 4280 | #define NEW_STACK_SIZE 0x40000 |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4281 | |
Riku Voipio | 05098a9 | 2011-03-04 15:27:29 +0200 | [diff] [blame] | 4282 | #if defined(CONFIG_USE_NPTL) |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4283 | |
| 4284 | static pthread_mutex_t clone_lock = PTHREAD_MUTEX_INITIALIZER; |
| 4285 | typedef struct { |
Andreas Färber | 9349b4f | 2012-03-14 01:38:32 +0100 | [diff] [blame] | 4286 | CPUArchState *env; |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4287 | pthread_mutex_t mutex; |
| 4288 | pthread_cond_t cond; |
| 4289 | pthread_t thread; |
| 4290 | uint32_t tid; |
| 4291 | abi_ulong child_tidptr; |
| 4292 | abi_ulong parent_tidptr; |
| 4293 | sigset_t sigmask; |
| 4294 | } new_thread_info; |
| 4295 | |
| 4296 | static void *clone_func(void *arg) |
| 4297 | { |
| 4298 | new_thread_info *info = arg; |
Andreas Färber | 9349b4f | 2012-03-14 01:38:32 +0100 | [diff] [blame] | 4299 | CPUArchState *env; |
Mika Westerberg | edf8e2a | 2009-04-07 09:57:11 +0300 | [diff] [blame] | 4300 | TaskState *ts; |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4301 | |
| 4302 | env = info->env; |
| 4303 | thread_env = env; |
Mika Westerberg | edf8e2a | 2009-04-07 09:57:11 +0300 | [diff] [blame] | 4304 | ts = (TaskState *)thread_env->opaque; |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4305 | info->tid = gettid(); |
Nathan Froyd | 1e9fa73 | 2009-06-03 11:33:08 -0700 | [diff] [blame] | 4306 | env->host_tid = info->tid; |
Mika Westerberg | edf8e2a | 2009-04-07 09:57:11 +0300 | [diff] [blame] | 4307 | task_settid(ts); |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4308 | if (info->child_tidptr) |
| 4309 | put_user_u32(info->tid, info->child_tidptr); |
| 4310 | if (info->parent_tidptr) |
| 4311 | put_user_u32(info->tid, info->parent_tidptr); |
| 4312 | /* Enable signals. */ |
| 4313 | sigprocmask(SIG_SETMASK, &info->sigmask, NULL); |
| 4314 | /* Signal to the parent that we're ready. */ |
| 4315 | pthread_mutex_lock(&info->mutex); |
| 4316 | pthread_cond_broadcast(&info->cond); |
| 4317 | pthread_mutex_unlock(&info->mutex); |
| 4318 | /* Wait until the parent has finshed initializing the tls state. */ |
| 4319 | pthread_mutex_lock(&clone_lock); |
| 4320 | pthread_mutex_unlock(&clone_lock); |
| 4321 | cpu_loop(env); |
| 4322 | /* never exits */ |
| 4323 | return NULL; |
| 4324 | } |
| 4325 | #else |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 4326 | |
| 4327 | static int clone_func(void *arg) |
| 4328 | { |
Andreas Färber | 9349b4f | 2012-03-14 01:38:32 +0100 | [diff] [blame] | 4329 | CPUArchState *env = arg; |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 4330 | cpu_loop(env); |
| 4331 | /* never exits */ |
| 4332 | return 0; |
| 4333 | } |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4334 | #endif |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 4335 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 4336 | /* do_fork() Must return host values and target errnos (unlike most |
| 4337 | do_*() functions). */ |
Andreas Färber | 9349b4f | 2012-03-14 01:38:32 +0100 | [diff] [blame] | 4338 | static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp, |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4339 | abi_ulong parent_tidptr, target_ulong newtls, |
| 4340 | abi_ulong child_tidptr) |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 4341 | { |
| 4342 | int ret; |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 4343 | TaskState *ts; |
Andreas Färber | 9349b4f | 2012-03-14 01:38:32 +0100 | [diff] [blame] | 4344 | CPUArchState *new_env; |
Juan Quintela | 2f7bb87 | 2009-07-27 16:13:24 +0200 | [diff] [blame] | 4345 | #if defined(CONFIG_USE_NPTL) |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4346 | unsigned int nptl_flags; |
| 4347 | sigset_t sigmask; |
Riku Voipio | 9190749 | 2010-11-26 16:21:34 +0200 | [diff] [blame] | 4348 | #else |
| 4349 | uint8_t *new_stack; |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4350 | #endif |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 4351 | |
balrog | 436d124 | 2008-09-21 02:39:45 +0000 | [diff] [blame] | 4352 | /* Emulate vfork() with fork() */ |
| 4353 | if (flags & CLONE_VFORK) |
| 4354 | flags &= ~(CLONE_VFORK | CLONE_VM); |
| 4355 | |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 4356 | if (flags & CLONE_VM) { |
Mika Westerberg | edf8e2a | 2009-04-07 09:57:11 +0300 | [diff] [blame] | 4357 | TaskState *parent_ts = (TaskState *)env->opaque; |
Juan Quintela | 2f7bb87 | 2009-07-27 16:13:24 +0200 | [diff] [blame] | 4358 | #if defined(CONFIG_USE_NPTL) |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4359 | new_thread_info info; |
| 4360 | pthread_attr_t attr; |
pbrook | bd0c566 | 2008-05-29 14:34:11 +0000 | [diff] [blame] | 4361 | #endif |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 4362 | ts = g_malloc0(sizeof(TaskState)); |
pbrook | 624f797 | 2008-05-31 16:11:38 +0000 | [diff] [blame] | 4363 | init_task_state(ts); |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 4364 | /* we create a new CPU instance. */ |
ths | c5be9f0 | 2007-02-28 20:20:53 +0000 | [diff] [blame] | 4365 | new_env = cpu_copy(env); |
Blue Swirl | b4558d7 | 2009-11-07 16:34:12 +0000 | [diff] [blame] | 4366 | #if defined(TARGET_I386) || defined(TARGET_SPARC) || defined(TARGET_PPC) |
Andreas Färber | ff18b76 | 2012-05-05 14:47:34 +0200 | [diff] [blame] | 4367 | cpu_reset(ENV_GET_CPU(new_env)); |
Blue Swirl | b4558d7 | 2009-11-07 16:34:12 +0000 | [diff] [blame] | 4368 | #endif |
pbrook | 6e68e07 | 2008-05-30 17:22:15 +0000 | [diff] [blame] | 4369 | /* Init regs that differ from the parent. */ |
| 4370 | cpu_clone_regs(new_env, newsp); |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 4371 | new_env->opaque = ts; |
Mika Westerberg | edf8e2a | 2009-04-07 09:57:11 +0300 | [diff] [blame] | 4372 | ts->bprm = parent_ts->bprm; |
| 4373 | ts->info = parent_ts->info; |
Juan Quintela | 2f7bb87 | 2009-07-27 16:13:24 +0200 | [diff] [blame] | 4374 | #if defined(CONFIG_USE_NPTL) |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4375 | nptl_flags = flags; |
| 4376 | flags &= ~CLONE_NPTL_FLAGS2; |
| 4377 | |
pbrook | c276471 | 2009-03-07 15:24:59 +0000 | [diff] [blame] | 4378 | if (nptl_flags & CLONE_CHILD_CLEARTID) { |
| 4379 | ts->child_tidptr = child_tidptr; |
| 4380 | } |
| 4381 | |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4382 | if (nptl_flags & CLONE_SETTLS) |
| 4383 | cpu_set_tls (new_env, newtls); |
| 4384 | |
| 4385 | /* Grab a mutex so that thread setup appears atomic. */ |
| 4386 | pthread_mutex_lock(&clone_lock); |
| 4387 | |
| 4388 | memset(&info, 0, sizeof(info)); |
| 4389 | pthread_mutex_init(&info.mutex, NULL); |
| 4390 | pthread_mutex_lock(&info.mutex); |
| 4391 | pthread_cond_init(&info.cond, NULL); |
| 4392 | info.env = new_env; |
| 4393 | if (nptl_flags & CLONE_CHILD_SETTID) |
| 4394 | info.child_tidptr = child_tidptr; |
| 4395 | if (nptl_flags & CLONE_PARENT_SETTID) |
| 4396 | info.parent_tidptr = parent_tidptr; |
| 4397 | |
| 4398 | ret = pthread_attr_init(&attr); |
Nathan Froyd | 48e15fc | 2010-10-29 07:48:57 -0700 | [diff] [blame] | 4399 | ret = pthread_attr_setstacksize(&attr, NEW_STACK_SIZE); |
| 4400 | ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4401 | /* It is not safe to deliver signals until the child has finished |
| 4402 | initializing, so temporarily block all signals. */ |
| 4403 | sigfillset(&sigmask); |
| 4404 | sigprocmask(SIG_BLOCK, &sigmask, &info.sigmask); |
| 4405 | |
| 4406 | ret = pthread_create(&info.thread, &attr, clone_func, &info); |
pbrook | c276471 | 2009-03-07 15:24:59 +0000 | [diff] [blame] | 4407 | /* TODO: Free new CPU state if thread creation failed. */ |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4408 | |
| 4409 | sigprocmask(SIG_SETMASK, &info.sigmask, NULL); |
| 4410 | pthread_attr_destroy(&attr); |
| 4411 | if (ret == 0) { |
| 4412 | /* Wait for the child to initialize. */ |
| 4413 | pthread_cond_wait(&info.cond, &info.mutex); |
| 4414 | ret = info.tid; |
| 4415 | if (flags & CLONE_PARENT_SETTID) |
| 4416 | put_user_u32(ret, parent_tidptr); |
| 4417 | } else { |
| 4418 | ret = -1; |
| 4419 | } |
| 4420 | pthread_mutex_unlock(&info.mutex); |
| 4421 | pthread_cond_destroy(&info.cond); |
| 4422 | pthread_mutex_destroy(&info.mutex); |
| 4423 | pthread_mutex_unlock(&clone_lock); |
| 4424 | #else |
| 4425 | if (flags & CLONE_NPTL_FLAGS2) |
| 4426 | return -EINVAL; |
| 4427 | /* This is probably going to die very quickly, but do it anyway. */ |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 4428 | new_stack = g_malloc0 (NEW_STACK_SIZE); |
bellard | 27725c1 | 2003-04-29 21:08:18 +0000 | [diff] [blame] | 4429 | #ifdef __ia64__ |
Aurelien Jarno | 60e9924 | 2010-03-29 02:12:51 +0200 | [diff] [blame] | 4430 | ret = __clone2(clone_func, new_stack, NEW_STACK_SIZE, flags, new_env); |
bellard | 27725c1 | 2003-04-29 21:08:18 +0000 | [diff] [blame] | 4431 | #else |
| 4432 | ret = clone(clone_func, new_stack + NEW_STACK_SIZE, flags, new_env); |
| 4433 | #endif |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4434 | #endif |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 4435 | } else { |
| 4436 | /* if no CLONE_VM, we consider it is a fork */ |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4437 | if ((flags & ~(CSIGNAL | CLONE_NPTL_FLAGS2)) != 0) |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 4438 | return -EINVAL; |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4439 | fork_start(); |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 4440 | ret = fork(); |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4441 | if (ret == 0) { |
aurel32 | 2b1319c | 2008-12-18 22:44:04 +0000 | [diff] [blame] | 4442 | /* Child Process. */ |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4443 | cpu_clone_regs(env, newsp); |
| 4444 | fork_end(1); |
Juan Quintela | 2f7bb87 | 2009-07-27 16:13:24 +0200 | [diff] [blame] | 4445 | #if defined(CONFIG_USE_NPTL) |
aurel32 | 2b1319c | 2008-12-18 22:44:04 +0000 | [diff] [blame] | 4446 | /* There is a race condition here. The parent process could |
| 4447 | theoretically read the TID in the child process before the child |
| 4448 | tid is set. This would require using either ptrace |
| 4449 | (not implemented) or having *_tidptr to point at a shared memory |
| 4450 | mapping. We can't repeat the spinlock hack used above because |
| 4451 | the child process gets its own copy of the lock. */ |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4452 | if (flags & CLONE_CHILD_SETTID) |
| 4453 | put_user_u32(gettid(), child_tidptr); |
| 4454 | if (flags & CLONE_PARENT_SETTID) |
| 4455 | put_user_u32(gettid(), parent_tidptr); |
| 4456 | ts = (TaskState *)env->opaque; |
| 4457 | if (flags & CLONE_SETTLS) |
| 4458 | cpu_set_tls (env, newtls); |
pbrook | c276471 | 2009-03-07 15:24:59 +0000 | [diff] [blame] | 4459 | if (flags & CLONE_CHILD_CLEARTID) |
| 4460 | ts->child_tidptr = child_tidptr; |
aurel32 | 2b1319c | 2008-12-18 22:44:04 +0000 | [diff] [blame] | 4461 | #endif |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4462 | } else { |
| 4463 | fork_end(0); |
| 4464 | } |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 4465 | } |
| 4466 | return ret; |
| 4467 | } |
| 4468 | |
Arnaud Patard (Rtp) | 5f10681 | 2009-06-03 14:35:04 +0200 | [diff] [blame] | 4469 | /* warning : doesn't handle linux specific flags... */ |
| 4470 | static int target_to_host_fcntl_cmd(int cmd) |
| 4471 | { |
| 4472 | switch(cmd) { |
| 4473 | case TARGET_F_DUPFD: |
| 4474 | case TARGET_F_GETFD: |
| 4475 | case TARGET_F_SETFD: |
| 4476 | case TARGET_F_GETFL: |
| 4477 | case TARGET_F_SETFL: |
| 4478 | return cmd; |
| 4479 | case TARGET_F_GETLK: |
| 4480 | return F_GETLK; |
| 4481 | case TARGET_F_SETLK: |
| 4482 | return F_SETLK; |
| 4483 | case TARGET_F_SETLKW: |
| 4484 | return F_SETLKW; |
| 4485 | case TARGET_F_GETOWN: |
| 4486 | return F_GETOWN; |
| 4487 | case TARGET_F_SETOWN: |
| 4488 | return F_SETOWN; |
| 4489 | case TARGET_F_GETSIG: |
| 4490 | return F_GETSIG; |
| 4491 | case TARGET_F_SETSIG: |
| 4492 | return F_SETSIG; |
| 4493 | #if TARGET_ABI_BITS == 32 |
| 4494 | case TARGET_F_GETLK64: |
| 4495 | return F_GETLK64; |
| 4496 | case TARGET_F_SETLK64: |
| 4497 | return F_SETLK64; |
| 4498 | case TARGET_F_SETLKW64: |
| 4499 | return F_SETLKW64; |
| 4500 | #endif |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 4501 | case TARGET_F_SETLEASE: |
| 4502 | return F_SETLEASE; |
| 4503 | case TARGET_F_GETLEASE: |
| 4504 | return F_GETLEASE; |
malc | fbd5de9 | 2009-09-06 06:31:59 +0400 | [diff] [blame] | 4505 | #ifdef F_DUPFD_CLOEXEC |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 4506 | case TARGET_F_DUPFD_CLOEXEC: |
| 4507 | return F_DUPFD_CLOEXEC; |
malc | fbd5de9 | 2009-09-06 06:31:59 +0400 | [diff] [blame] | 4508 | #endif |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 4509 | case TARGET_F_NOTIFY: |
| 4510 | return F_NOTIFY; |
Arnaud Patard (Rtp) | 5f10681 | 2009-06-03 14:35:04 +0200 | [diff] [blame] | 4511 | default: |
| 4512 | return -TARGET_EINVAL; |
| 4513 | } |
| 4514 | return -TARGET_EINVAL; |
| 4515 | } |
| 4516 | |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 4517 | static abi_long do_fcntl(int fd, int cmd, abi_ulong arg) |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4518 | { |
| 4519 | struct flock fl; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 4520 | struct target_flock *target_fl; |
ths | 43f238d | 2007-01-05 20:55:49 +0000 | [diff] [blame] | 4521 | struct flock64 fl64; |
| 4522 | struct target_flock64 *target_fl64; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 4523 | abi_long ret; |
Arnaud Patard (Rtp) | 5f10681 | 2009-06-03 14:35:04 +0200 | [diff] [blame] | 4524 | int host_cmd = target_to_host_fcntl_cmd(cmd); |
| 4525 | |
| 4526 | if (host_cmd == -TARGET_EINVAL) |
| 4527 | return host_cmd; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 4528 | |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4529 | switch(cmd) { |
| 4530 | case TARGET_F_GETLK: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 4531 | if (!lock_user_struct(VERIFY_READ, target_fl, arg, 1)) |
| 4532 | return -TARGET_EFAULT; |
ths | 5813427 | 2007-03-31 18:59:32 +0000 | [diff] [blame] | 4533 | fl.l_type = tswap16(target_fl->l_type); |
| 4534 | fl.l_whence = tswap16(target_fl->l_whence); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 4535 | fl.l_start = tswapal(target_fl->l_start); |
| 4536 | fl.l_len = tswapal(target_fl->l_len); |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 4537 | fl.l_pid = tswap32(target_fl->l_pid); |
ths | 5813427 | 2007-03-31 18:59:32 +0000 | [diff] [blame] | 4538 | unlock_user_struct(target_fl, arg, 0); |
Arnaud Patard (Rtp) | 5f10681 | 2009-06-03 14:35:04 +0200 | [diff] [blame] | 4539 | ret = get_errno(fcntl(fd, host_cmd, &fl)); |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4540 | if (ret == 0) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 4541 | if (!lock_user_struct(VERIFY_WRITE, target_fl, arg, 0)) |
| 4542 | return -TARGET_EFAULT; |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4543 | target_fl->l_type = tswap16(fl.l_type); |
| 4544 | target_fl->l_whence = tswap16(fl.l_whence); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 4545 | target_fl->l_start = tswapal(fl.l_start); |
| 4546 | target_fl->l_len = tswapal(fl.l_len); |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 4547 | target_fl->l_pid = tswap32(fl.l_pid); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 4548 | unlock_user_struct(target_fl, arg, 1); |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4549 | } |
| 4550 | break; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 4551 | |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4552 | case TARGET_F_SETLK: |
| 4553 | case TARGET_F_SETLKW: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 4554 | if (!lock_user_struct(VERIFY_READ, target_fl, arg, 1)) |
| 4555 | return -TARGET_EFAULT; |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4556 | fl.l_type = tswap16(target_fl->l_type); |
| 4557 | fl.l_whence = tswap16(target_fl->l_whence); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 4558 | fl.l_start = tswapal(target_fl->l_start); |
| 4559 | fl.l_len = tswapal(target_fl->l_len); |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 4560 | fl.l_pid = tswap32(target_fl->l_pid); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 4561 | unlock_user_struct(target_fl, arg, 0); |
Arnaud Patard (Rtp) | 5f10681 | 2009-06-03 14:35:04 +0200 | [diff] [blame] | 4562 | ret = get_errno(fcntl(fd, host_cmd, &fl)); |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4563 | break; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 4564 | |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4565 | case TARGET_F_GETLK64: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 4566 | if (!lock_user_struct(VERIFY_READ, target_fl64, arg, 1)) |
| 4567 | return -TARGET_EFAULT; |
ths | 5813427 | 2007-03-31 18:59:32 +0000 | [diff] [blame] | 4568 | fl64.l_type = tswap16(target_fl64->l_type) >> 1; |
| 4569 | fl64.l_whence = tswap16(target_fl64->l_whence); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 4570 | fl64.l_start = tswap64(target_fl64->l_start); |
| 4571 | fl64.l_len = tswap64(target_fl64->l_len); |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 4572 | fl64.l_pid = tswap32(target_fl64->l_pid); |
ths | 5813427 | 2007-03-31 18:59:32 +0000 | [diff] [blame] | 4573 | unlock_user_struct(target_fl64, arg, 0); |
Arnaud Patard (Rtp) | 5f10681 | 2009-06-03 14:35:04 +0200 | [diff] [blame] | 4574 | ret = get_errno(fcntl(fd, host_cmd, &fl64)); |
ths | 43f238d | 2007-01-05 20:55:49 +0000 | [diff] [blame] | 4575 | if (ret == 0) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 4576 | if (!lock_user_struct(VERIFY_WRITE, target_fl64, arg, 0)) |
| 4577 | return -TARGET_EFAULT; |
ths | 43f238d | 2007-01-05 20:55:49 +0000 | [diff] [blame] | 4578 | target_fl64->l_type = tswap16(fl64.l_type) >> 1; |
| 4579 | target_fl64->l_whence = tswap16(fl64.l_whence); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 4580 | target_fl64->l_start = tswap64(fl64.l_start); |
| 4581 | target_fl64->l_len = tswap64(fl64.l_len); |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 4582 | target_fl64->l_pid = tswap32(fl64.l_pid); |
ths | 43f238d | 2007-01-05 20:55:49 +0000 | [diff] [blame] | 4583 | unlock_user_struct(target_fl64, arg, 1); |
| 4584 | } |
bellard | 9ee1fa2 | 2007-11-11 15:11:19 +0000 | [diff] [blame] | 4585 | break; |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4586 | case TARGET_F_SETLK64: |
| 4587 | case TARGET_F_SETLKW64: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 4588 | if (!lock_user_struct(VERIFY_READ, target_fl64, arg, 1)) |
| 4589 | return -TARGET_EFAULT; |
ths | 43f238d | 2007-01-05 20:55:49 +0000 | [diff] [blame] | 4590 | fl64.l_type = tswap16(target_fl64->l_type) >> 1; |
| 4591 | fl64.l_whence = tswap16(target_fl64->l_whence); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 4592 | fl64.l_start = tswap64(target_fl64->l_start); |
| 4593 | fl64.l_len = tswap64(target_fl64->l_len); |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 4594 | fl64.l_pid = tswap32(target_fl64->l_pid); |
ths | 43f238d | 2007-01-05 20:55:49 +0000 | [diff] [blame] | 4595 | unlock_user_struct(target_fl64, arg, 0); |
Arnaud Patard (Rtp) | 5f10681 | 2009-06-03 14:35:04 +0200 | [diff] [blame] | 4596 | ret = get_errno(fcntl(fd, host_cmd, &fl64)); |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4597 | break; |
| 4598 | |
Arnaud Patard (Rtp) | 5f10681 | 2009-06-03 14:35:04 +0200 | [diff] [blame] | 4599 | case TARGET_F_GETFL: |
| 4600 | ret = get_errno(fcntl(fd, host_cmd, arg)); |
bellard | 9ee1fa2 | 2007-11-11 15:11:19 +0000 | [diff] [blame] | 4601 | if (ret >= 0) { |
| 4602 | ret = host_to_target_bitmask(ret, fcntl_flags_tbl); |
| 4603 | } |
bellard | ffa65c3 | 2004-01-04 23:57:22 +0000 | [diff] [blame] | 4604 | break; |
| 4605 | |
Arnaud Patard (Rtp) | 5f10681 | 2009-06-03 14:35:04 +0200 | [diff] [blame] | 4606 | case TARGET_F_SETFL: |
| 4607 | ret = get_errno(fcntl(fd, host_cmd, target_to_host_bitmask(arg, fcntl_flags_tbl))); |
| 4608 | break; |
| 4609 | |
| 4610 | case TARGET_F_SETOWN: |
| 4611 | case TARGET_F_GETOWN: |
| 4612 | case TARGET_F_SETSIG: |
| 4613 | case TARGET_F_GETSIG: |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 4614 | case TARGET_F_SETLEASE: |
| 4615 | case TARGET_F_GETLEASE: |
Arnaud Patard (Rtp) | 5f10681 | 2009-06-03 14:35:04 +0200 | [diff] [blame] | 4616 | ret = get_errno(fcntl(fd, host_cmd, arg)); |
bellard | ffa65c3 | 2004-01-04 23:57:22 +0000 | [diff] [blame] | 4617 | break; |
| 4618 | |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4619 | default: |
bellard | 9ee1fa2 | 2007-11-11 15:11:19 +0000 | [diff] [blame] | 4620 | ret = get_errno(fcntl(fd, cmd, arg)); |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4621 | break; |
| 4622 | } |
| 4623 | return ret; |
| 4624 | } |
| 4625 | |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 4626 | #ifdef USE_UID16 |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4627 | |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 4628 | static inline int high2lowuid(int uid) |
| 4629 | { |
| 4630 | if (uid > 65535) |
| 4631 | return 65534; |
| 4632 | else |
| 4633 | return uid; |
| 4634 | } |
| 4635 | |
| 4636 | static inline int high2lowgid(int gid) |
| 4637 | { |
| 4638 | if (gid > 65535) |
| 4639 | return 65534; |
| 4640 | else |
| 4641 | return gid; |
| 4642 | } |
| 4643 | |
| 4644 | static inline int low2highuid(int uid) |
| 4645 | { |
| 4646 | if ((int16_t)uid == -1) |
| 4647 | return -1; |
| 4648 | else |
| 4649 | return uid; |
| 4650 | } |
| 4651 | |
| 4652 | static inline int low2highgid(int gid) |
| 4653 | { |
| 4654 | if ((int16_t)gid == -1) |
| 4655 | return -1; |
| 4656 | else |
| 4657 | return gid; |
| 4658 | } |
Riku Voipio | 0c866a7 | 2011-04-18 15:23:06 +0300 | [diff] [blame] | 4659 | static inline int tswapid(int id) |
| 4660 | { |
| 4661 | return tswap16(id); |
| 4662 | } |
| 4663 | #else /* !USE_UID16 */ |
| 4664 | static inline int high2lowuid(int uid) |
| 4665 | { |
| 4666 | return uid; |
| 4667 | } |
| 4668 | static inline int high2lowgid(int gid) |
| 4669 | { |
| 4670 | return gid; |
| 4671 | } |
| 4672 | static inline int low2highuid(int uid) |
| 4673 | { |
| 4674 | return uid; |
| 4675 | } |
| 4676 | static inline int low2highgid(int gid) |
| 4677 | { |
| 4678 | return gid; |
| 4679 | } |
| 4680 | static inline int tswapid(int id) |
| 4681 | { |
| 4682 | return tswap32(id); |
| 4683 | } |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 4684 | #endif /* USE_UID16 */ |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 4685 | |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 4686 | void syscall_init(void) |
| 4687 | { |
bellard | 2ab83ea | 2003-06-15 19:56:46 +0000 | [diff] [blame] | 4688 | IOCTLEntry *ie; |
| 4689 | const argtype *arg_type; |
| 4690 | int size; |
ths | b92c47c | 2007-11-01 00:07:38 +0000 | [diff] [blame] | 4691 | int i; |
bellard | 2ab83ea | 2003-06-15 19:56:46 +0000 | [diff] [blame] | 4692 | |
Blue Swirl | 001faf3 | 2009-05-13 17:53:17 +0000 | [diff] [blame] | 4693 | #define STRUCT(name, ...) thunk_register_struct(STRUCT_ ## name, #name, struct_ ## name ## _def); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 4694 | #define STRUCT_SPECIAL(name) thunk_register_struct_direct(STRUCT_ ## name, #name, &struct_ ## name ## _def); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 4695 | #include "syscall_types.h" |
| 4696 | #undef STRUCT |
| 4697 | #undef STRUCT_SPECIAL |
bellard | 2ab83ea | 2003-06-15 19:56:46 +0000 | [diff] [blame] | 4698 | |
Peter Maydell | dd6e957 | 2012-07-23 08:07:22 +0000 | [diff] [blame] | 4699 | /* Build target_to_host_errno_table[] table from |
| 4700 | * host_to_target_errno_table[]. */ |
| 4701 | for (i = 0; i < ERRNO_TABLE_SIZE; i++) { |
| 4702 | target_to_host_errno_table[host_to_target_errno_table[i]] = i; |
| 4703 | } |
| 4704 | |
bellard | 2ab83ea | 2003-06-15 19:56:46 +0000 | [diff] [blame] | 4705 | /* we patch the ioctl size if necessary. We rely on the fact that |
| 4706 | no ioctl has all the bits at '1' in the size field */ |
| 4707 | ie = ioctl_entries; |
| 4708 | while (ie->target_cmd != 0) { |
| 4709 | if (((ie->target_cmd >> TARGET_IOC_SIZESHIFT) & TARGET_IOC_SIZEMASK) == |
| 4710 | TARGET_IOC_SIZEMASK) { |
| 4711 | arg_type = ie->arg_type; |
| 4712 | if (arg_type[0] != TYPE_PTR) { |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 4713 | fprintf(stderr, "cannot patch size for ioctl 0x%x\n", |
bellard | 2ab83ea | 2003-06-15 19:56:46 +0000 | [diff] [blame] | 4714 | ie->target_cmd); |
| 4715 | exit(1); |
| 4716 | } |
| 4717 | arg_type++; |
| 4718 | size = thunk_type_size(arg_type, 0); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 4719 | ie->target_cmd = (ie->target_cmd & |
bellard | 2ab83ea | 2003-06-15 19:56:46 +0000 | [diff] [blame] | 4720 | ~(TARGET_IOC_SIZEMASK << TARGET_IOC_SIZESHIFT)) | |
| 4721 | (size << TARGET_IOC_SIZESHIFT); |
| 4722 | } |
ths | b92c47c | 2007-11-01 00:07:38 +0000 | [diff] [blame] | 4723 | |
bellard | 2ab83ea | 2003-06-15 19:56:46 +0000 | [diff] [blame] | 4724 | /* automatic consistency check if same arch */ |
balrog | 872ea0c | 2008-09-21 02:31:19 +0000 | [diff] [blame] | 4725 | #if (defined(__i386__) && defined(TARGET_I386) && defined(TARGET_ABI32)) || \ |
| 4726 | (defined(__x86_64__) && defined(TARGET_X86_64)) |
| 4727 | if (unlikely(ie->target_cmd != ie->host_cmd)) { |
| 4728 | fprintf(stderr, "ERROR: ioctl(%s): target=0x%x host=0x%x\n", |
| 4729 | ie->name, ie->target_cmd, ie->host_cmd); |
bellard | 2ab83ea | 2003-06-15 19:56:46 +0000 | [diff] [blame] | 4730 | } |
| 4731 | #endif |
| 4732 | ie++; |
| 4733 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 4734 | } |
bellard | c573ff6 | 2004-01-04 15:51:36 +0000 | [diff] [blame] | 4735 | |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 4736 | #if TARGET_ABI_BITS == 32 |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 4737 | static inline uint64_t target_offset64(uint32_t word0, uint32_t word1) |
| 4738 | { |
ths | af325d3 | 2008-06-10 15:29:15 +0000 | [diff] [blame] | 4739 | #ifdef TARGET_WORDS_BIGENDIAN |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 4740 | return ((uint64_t)word0 << 32) | word1; |
| 4741 | #else |
| 4742 | return ((uint64_t)word1 << 32) | word0; |
| 4743 | #endif |
| 4744 | } |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 4745 | #else /* TARGET_ABI_BITS == 32 */ |
j_mayer | 3240710 | 2007-09-26 23:01:49 +0000 | [diff] [blame] | 4746 | static inline uint64_t target_offset64(uint64_t word0, uint64_t word1) |
| 4747 | { |
| 4748 | return word0; |
| 4749 | } |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 4750 | #endif /* TARGET_ABI_BITS != 32 */ |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 4751 | |
| 4752 | #ifdef TARGET_NR_truncate64 |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 4753 | static inline abi_long target_truncate64(void *cpu_env, const char *arg1, |
| 4754 | abi_long arg2, |
| 4755 | abi_long arg3, |
| 4756 | abi_long arg4) |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 4757 | { |
Riku Voipio | 48e515d | 2011-07-12 15:40:51 +0300 | [diff] [blame] | 4758 | if (regpairs_aligned(cpu_env)) { |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 4759 | arg2 = arg3; |
| 4760 | arg3 = arg4; |
Riku Voipio | 48e515d | 2011-07-12 15:40:51 +0300 | [diff] [blame] | 4761 | } |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 4762 | return get_errno(truncate64(arg1, target_offset64(arg2, arg3))); |
| 4763 | } |
| 4764 | #endif |
| 4765 | |
| 4766 | #ifdef TARGET_NR_ftruncate64 |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 4767 | static inline abi_long target_ftruncate64(void *cpu_env, abi_long arg1, |
| 4768 | abi_long arg2, |
| 4769 | abi_long arg3, |
| 4770 | abi_long arg4) |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 4771 | { |
Riku Voipio | 48e515d | 2011-07-12 15:40:51 +0300 | [diff] [blame] | 4772 | if (regpairs_aligned(cpu_env)) { |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 4773 | arg2 = arg3; |
| 4774 | arg3 = arg4; |
Riku Voipio | 48e515d | 2011-07-12 15:40:51 +0300 | [diff] [blame] | 4775 | } |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 4776 | return get_errno(ftruncate64(arg1, target_offset64(arg2, arg3))); |
| 4777 | } |
| 4778 | #endif |
| 4779 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 4780 | static inline abi_long target_to_host_timespec(struct timespec *host_ts, |
| 4781 | abi_ulong target_addr) |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 4782 | { |
| 4783 | struct target_timespec *target_ts; |
| 4784 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 4785 | if (!lock_user_struct(VERIFY_READ, target_ts, target_addr, 1)) |
| 4786 | return -TARGET_EFAULT; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 4787 | host_ts->tv_sec = tswapal(target_ts->tv_sec); |
| 4788 | host_ts->tv_nsec = tswapal(target_ts->tv_nsec); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 4789 | unlock_user_struct(target_ts, target_addr, 0); |
bellard | b255bfa | 2008-05-10 21:51:02 +0000 | [diff] [blame] | 4790 | return 0; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 4791 | } |
| 4792 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 4793 | static inline abi_long host_to_target_timespec(abi_ulong target_addr, |
| 4794 | struct timespec *host_ts) |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 4795 | { |
| 4796 | struct target_timespec *target_ts; |
| 4797 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 4798 | if (!lock_user_struct(VERIFY_WRITE, target_ts, target_addr, 0)) |
| 4799 | return -TARGET_EFAULT; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 4800 | target_ts->tv_sec = tswapal(host_ts->tv_sec); |
| 4801 | target_ts->tv_nsec = tswapal(host_ts->tv_nsec); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 4802 | unlock_user_struct(target_ts, target_addr, 1); |
bellard | b255bfa | 2008-05-10 21:51:02 +0000 | [diff] [blame] | 4803 | return 0; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 4804 | } |
| 4805 | |
aurel32 | 9d33b76 | 2009-04-08 23:07:05 +0000 | [diff] [blame] | 4806 | #if defined(TARGET_NR_stat64) || defined(TARGET_NR_newfstatat) |
balrog | 6a24a77 | 2008-09-20 02:23:36 +0000 | [diff] [blame] | 4807 | static inline abi_long host_to_target_stat64(void *cpu_env, |
| 4808 | abi_ulong target_addr, |
| 4809 | struct stat *host_st) |
| 4810 | { |
| 4811 | #ifdef TARGET_ARM |
| 4812 | if (((CPUARMState *)cpu_env)->eabi) { |
| 4813 | struct target_eabi_stat64 *target_st; |
| 4814 | |
| 4815 | if (!lock_user_struct(VERIFY_WRITE, target_st, target_addr, 0)) |
| 4816 | return -TARGET_EFAULT; |
| 4817 | memset(target_st, 0, sizeof(struct target_eabi_stat64)); |
| 4818 | __put_user(host_st->st_dev, &target_st->st_dev); |
| 4819 | __put_user(host_st->st_ino, &target_st->st_ino); |
| 4820 | #ifdef TARGET_STAT64_HAS_BROKEN_ST_INO |
| 4821 | __put_user(host_st->st_ino, &target_st->__st_ino); |
| 4822 | #endif |
| 4823 | __put_user(host_st->st_mode, &target_st->st_mode); |
| 4824 | __put_user(host_st->st_nlink, &target_st->st_nlink); |
| 4825 | __put_user(host_st->st_uid, &target_st->st_uid); |
| 4826 | __put_user(host_st->st_gid, &target_st->st_gid); |
| 4827 | __put_user(host_st->st_rdev, &target_st->st_rdev); |
| 4828 | __put_user(host_st->st_size, &target_st->st_size); |
| 4829 | __put_user(host_st->st_blksize, &target_st->st_blksize); |
| 4830 | __put_user(host_st->st_blocks, &target_st->st_blocks); |
| 4831 | __put_user(host_st->st_atime, &target_st->target_st_atime); |
| 4832 | __put_user(host_st->st_mtime, &target_st->target_st_mtime); |
| 4833 | __put_user(host_st->st_ctime, &target_st->target_st_ctime); |
| 4834 | unlock_user_struct(target_st, target_addr, 1); |
| 4835 | } else |
| 4836 | #endif |
| 4837 | { |
Richard Henderson | ed18c5c | 2010-04-26 10:27:22 -0700 | [diff] [blame] | 4838 | #if TARGET_ABI_BITS == 64 && !defined(TARGET_ALPHA) |
aurel32 | 9d33b76 | 2009-04-08 23:07:05 +0000 | [diff] [blame] | 4839 | struct target_stat *target_st; |
| 4840 | #else |
balrog | 6a24a77 | 2008-09-20 02:23:36 +0000 | [diff] [blame] | 4841 | struct target_stat64 *target_st; |
aurel32 | 9d33b76 | 2009-04-08 23:07:05 +0000 | [diff] [blame] | 4842 | #endif |
balrog | 6a24a77 | 2008-09-20 02:23:36 +0000 | [diff] [blame] | 4843 | |
| 4844 | if (!lock_user_struct(VERIFY_WRITE, target_st, target_addr, 0)) |
| 4845 | return -TARGET_EFAULT; |
aurel32 | 9d33b76 | 2009-04-08 23:07:05 +0000 | [diff] [blame] | 4846 | memset(target_st, 0, sizeof(*target_st)); |
balrog | 6a24a77 | 2008-09-20 02:23:36 +0000 | [diff] [blame] | 4847 | __put_user(host_st->st_dev, &target_st->st_dev); |
| 4848 | __put_user(host_st->st_ino, &target_st->st_ino); |
| 4849 | #ifdef TARGET_STAT64_HAS_BROKEN_ST_INO |
| 4850 | __put_user(host_st->st_ino, &target_st->__st_ino); |
| 4851 | #endif |
| 4852 | __put_user(host_st->st_mode, &target_st->st_mode); |
| 4853 | __put_user(host_st->st_nlink, &target_st->st_nlink); |
| 4854 | __put_user(host_st->st_uid, &target_st->st_uid); |
| 4855 | __put_user(host_st->st_gid, &target_st->st_gid); |
| 4856 | __put_user(host_st->st_rdev, &target_st->st_rdev); |
| 4857 | /* XXX: better use of kernel struct */ |
| 4858 | __put_user(host_st->st_size, &target_st->st_size); |
| 4859 | __put_user(host_st->st_blksize, &target_st->st_blksize); |
| 4860 | __put_user(host_st->st_blocks, &target_st->st_blocks); |
| 4861 | __put_user(host_st->st_atime, &target_st->target_st_atime); |
| 4862 | __put_user(host_st->st_mtime, &target_st->target_st_mtime); |
| 4863 | __put_user(host_st->st_ctime, &target_st->target_st_ctime); |
| 4864 | unlock_user_struct(target_st, target_addr, 1); |
| 4865 | } |
| 4866 | |
| 4867 | return 0; |
| 4868 | } |
| 4869 | #endif |
| 4870 | |
Juan Quintela | 2f7bb87 | 2009-07-27 16:13:24 +0200 | [diff] [blame] | 4871 | #if defined(CONFIG_USE_NPTL) |
pbrook | bd0c566 | 2008-05-29 14:34:11 +0000 | [diff] [blame] | 4872 | /* ??? Using host futex calls even when target atomic operations |
| 4873 | are not really atomic probably breaks things. However implementing |
| 4874 | futexes locally would make futexes shared between multiple processes |
| 4875 | tricky. However they're probably useless because guest atomic |
| 4876 | operations won't work either. */ |
blueswir1 | 8fcd369 | 2008-08-17 20:26:25 +0000 | [diff] [blame] | 4877 | static int do_futex(target_ulong uaddr, int op, int val, target_ulong timeout, |
| 4878 | target_ulong uaddr2, int val3) |
pbrook | bd0c566 | 2008-05-29 14:34:11 +0000 | [diff] [blame] | 4879 | { |
| 4880 | struct timespec ts, *pts; |
Nathan Froyd | a16aae0 | 2009-08-03 08:43:29 -0700 | [diff] [blame] | 4881 | int base_op; |
pbrook | bd0c566 | 2008-05-29 14:34:11 +0000 | [diff] [blame] | 4882 | |
| 4883 | /* ??? We assume FUTEX_* constants are the same on both host |
| 4884 | and target. */ |
Martin Mohring | a29ccd6 | 2009-05-04 21:34:56 +0300 | [diff] [blame] | 4885 | #ifdef FUTEX_CMD_MASK |
Nathan Froyd | a16aae0 | 2009-08-03 08:43:29 -0700 | [diff] [blame] | 4886 | base_op = op & FUTEX_CMD_MASK; |
Martin Mohring | a29ccd6 | 2009-05-04 21:34:56 +0300 | [diff] [blame] | 4887 | #else |
Nathan Froyd | a16aae0 | 2009-08-03 08:43:29 -0700 | [diff] [blame] | 4888 | base_op = op; |
Martin Mohring | a29ccd6 | 2009-05-04 21:34:56 +0300 | [diff] [blame] | 4889 | #endif |
Nathan Froyd | a16aae0 | 2009-08-03 08:43:29 -0700 | [diff] [blame] | 4890 | switch (base_op) { |
pbrook | bd0c566 | 2008-05-29 14:34:11 +0000 | [diff] [blame] | 4891 | case FUTEX_WAIT: |
| 4892 | if (timeout) { |
| 4893 | pts = &ts; |
| 4894 | target_to_host_timespec(pts, timeout); |
| 4895 | } else { |
| 4896 | pts = NULL; |
| 4897 | } |
Martin Mohring | a29ccd6 | 2009-05-04 21:34:56 +0300 | [diff] [blame] | 4898 | return get_errno(sys_futex(g2h(uaddr), op, tswap32(val), |
pbrook | bd0c566 | 2008-05-29 14:34:11 +0000 | [diff] [blame] | 4899 | pts, NULL, 0)); |
| 4900 | case FUTEX_WAKE: |
Martin Mohring | a29ccd6 | 2009-05-04 21:34:56 +0300 | [diff] [blame] | 4901 | return get_errno(sys_futex(g2h(uaddr), op, val, NULL, NULL, 0)); |
pbrook | bd0c566 | 2008-05-29 14:34:11 +0000 | [diff] [blame] | 4902 | case FUTEX_FD: |
Martin Mohring | a29ccd6 | 2009-05-04 21:34:56 +0300 | [diff] [blame] | 4903 | return get_errno(sys_futex(g2h(uaddr), op, val, NULL, NULL, 0)); |
pbrook | bd0c566 | 2008-05-29 14:34:11 +0000 | [diff] [blame] | 4904 | case FUTEX_REQUEUE: |
pbrook | bd0c566 | 2008-05-29 14:34:11 +0000 | [diff] [blame] | 4905 | case FUTEX_CMP_REQUEUE: |
Nathan Froyd | a16aae0 | 2009-08-03 08:43:29 -0700 | [diff] [blame] | 4906 | case FUTEX_WAKE_OP: |
| 4907 | /* For FUTEX_REQUEUE, FUTEX_CMP_REQUEUE, and FUTEX_WAKE_OP, the |
| 4908 | TIMEOUT parameter is interpreted as a uint32_t by the kernel. |
| 4909 | But the prototype takes a `struct timespec *'; insert casts |
| 4910 | to satisfy the compiler. We do not need to tswap TIMEOUT |
| 4911 | since it's not compared to guest memory. */ |
| 4912 | pts = (struct timespec *)(uintptr_t) timeout; |
| 4913 | return get_errno(sys_futex(g2h(uaddr), op, val, pts, |
| 4914 | g2h(uaddr2), |
| 4915 | (base_op == FUTEX_CMP_REQUEUE |
| 4916 | ? tswap32(val3) |
| 4917 | : val3))); |
pbrook | bd0c566 | 2008-05-29 14:34:11 +0000 | [diff] [blame] | 4918 | default: |
| 4919 | return -TARGET_ENOSYS; |
| 4920 | } |
| 4921 | } |
| 4922 | #endif |
| 4923 | |
pbrook | 1d9d8b5 | 2009-04-16 15:17:02 +0000 | [diff] [blame] | 4924 | /* Map host to target signal numbers for the wait family of syscalls. |
| 4925 | Assume all other status bits are the same. */ |
Richard Henderson | a05c640 | 2012-09-15 11:34:20 -0700 | [diff] [blame] | 4926 | int host_to_target_waitstatus(int status) |
pbrook | 1d9d8b5 | 2009-04-16 15:17:02 +0000 | [diff] [blame] | 4927 | { |
| 4928 | if (WIFSIGNALED(status)) { |
| 4929 | return host_to_target_signal(WTERMSIG(status)) | (status & ~0x7f); |
| 4930 | } |
| 4931 | if (WIFSTOPPED(status)) { |
| 4932 | return (host_to_target_signal(WSTOPSIG(status)) << 8) |
| 4933 | | (status & 0xff); |
| 4934 | } |
| 4935 | return status; |
| 4936 | } |
| 4937 | |
pbrook | a745ec6 | 2008-05-06 15:36:17 +0000 | [diff] [blame] | 4938 | int get_osversion(void) |
| 4939 | { |
| 4940 | static int osversion; |
| 4941 | struct new_utsname buf; |
| 4942 | const char *s; |
| 4943 | int i, n, tmp; |
| 4944 | if (osversion) |
| 4945 | return osversion; |
| 4946 | if (qemu_uname_release && *qemu_uname_release) { |
| 4947 | s = qemu_uname_release; |
| 4948 | } else { |
| 4949 | if (sys_uname(&buf)) |
| 4950 | return 0; |
| 4951 | s = buf.release; |
| 4952 | } |
| 4953 | tmp = 0; |
| 4954 | for (i = 0; i < 3; i++) { |
| 4955 | n = 0; |
| 4956 | while (*s >= '0' && *s <= '9') { |
| 4957 | n *= 10; |
| 4958 | n += *s - '0'; |
| 4959 | s++; |
| 4960 | } |
| 4961 | tmp = (tmp << 8) + n; |
| 4962 | if (*s == '.') |
| 4963 | s++; |
| 4964 | } |
| 4965 | osversion = tmp; |
| 4966 | return osversion; |
| 4967 | } |
| 4968 | |
Alexander Graf | 36c08d4 | 2011-11-02 20:23:24 +0100 | [diff] [blame] | 4969 | |
| 4970 | static int open_self_maps(void *cpu_env, int fd) |
| 4971 | { |
Alexander Graf | 1a49ef2 | 2012-05-01 16:30:28 +0100 | [diff] [blame] | 4972 | #if defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_UNICORE32) |
Andreas Färber | 9349b4f | 2012-03-14 01:38:32 +0100 | [diff] [blame] | 4973 | TaskState *ts = ((CPUArchState *)cpu_env)->opaque; |
Alexander Graf | 1a49ef2 | 2012-05-01 16:30:28 +0100 | [diff] [blame] | 4974 | #endif |
| 4975 | FILE *fp; |
| 4976 | char *line = NULL; |
| 4977 | size_t len = 0; |
| 4978 | ssize_t read; |
Alexander Graf | 36c08d4 | 2011-11-02 20:23:24 +0100 | [diff] [blame] | 4979 | |
Alexander Graf | 1a49ef2 | 2012-05-01 16:30:28 +0100 | [diff] [blame] | 4980 | fp = fopen("/proc/self/maps", "r"); |
| 4981 | if (fp == NULL) { |
| 4982 | return -EACCES; |
| 4983 | } |
| 4984 | |
| 4985 | while ((read = getline(&line, &len, fp)) != -1) { |
| 4986 | int fields, dev_maj, dev_min, inode; |
| 4987 | uint64_t min, max, offset; |
| 4988 | char flag_r, flag_w, flag_x, flag_p; |
| 4989 | char path[512] = ""; |
| 4990 | fields = sscanf(line, "%"PRIx64"-%"PRIx64" %c%c%c%c %"PRIx64" %x:%x %d" |
| 4991 | " %512s", &min, &max, &flag_r, &flag_w, &flag_x, |
| 4992 | &flag_p, &offset, &dev_maj, &dev_min, &inode, path); |
| 4993 | |
| 4994 | if ((fields < 10) || (fields > 11)) { |
| 4995 | continue; |
| 4996 | } |
| 4997 | if (!strncmp(path, "[stack]", 7)) { |
| 4998 | continue; |
| 4999 | } |
| 5000 | if (h2g_valid(min) && h2g_valid(max)) { |
| 5001 | dprintf(fd, TARGET_ABI_FMT_lx "-" TARGET_ABI_FMT_lx |
| 5002 | " %c%c%c%c %08" PRIx64 " %02x:%02x %d%s%s\n", |
| 5003 | h2g(min), h2g(max), flag_r, flag_w, |
| 5004 | flag_x, flag_p, offset, dev_maj, dev_min, inode, |
| 5005 | path[0] ? " " : "", path); |
| 5006 | } |
| 5007 | } |
| 5008 | |
| 5009 | free(line); |
| 5010 | fclose(fp); |
| 5011 | |
| 5012 | #if defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_UNICORE32) |
Alexander Graf | 36c08d4 | 2011-11-02 20:23:24 +0100 | [diff] [blame] | 5013 | dprintf(fd, "%08llx-%08llx rw-p %08llx 00:00 0 [stack]\n", |
| 5014 | (unsigned long long)ts->info->stack_limit, |
Alexander Graf | 1bdd7c7 | 2012-05-30 14:45:21 +0200 | [diff] [blame] | 5015 | (unsigned long long)(ts->info->start_stack + |
| 5016 | (TARGET_PAGE_SIZE - 1)) & TARGET_PAGE_MASK, |
Alexander Graf | 1a49ef2 | 2012-05-01 16:30:28 +0100 | [diff] [blame] | 5017 | (unsigned long long)0); |
| 5018 | #endif |
Alexander Graf | 36c08d4 | 2011-11-02 20:23:24 +0100 | [diff] [blame] | 5019 | |
| 5020 | return 0; |
| 5021 | } |
| 5022 | |
Alexander Graf | 480b8e7 | 2011-11-02 20:23:25 +0100 | [diff] [blame] | 5023 | static int open_self_stat(void *cpu_env, int fd) |
| 5024 | { |
Andreas Färber | 9349b4f | 2012-03-14 01:38:32 +0100 | [diff] [blame] | 5025 | TaskState *ts = ((CPUArchState *)cpu_env)->opaque; |
Alexander Graf | 480b8e7 | 2011-11-02 20:23:25 +0100 | [diff] [blame] | 5026 | abi_ulong start_stack = ts->info->start_stack; |
| 5027 | int i; |
| 5028 | |
| 5029 | for (i = 0; i < 44; i++) { |
| 5030 | char buf[128]; |
| 5031 | int len; |
| 5032 | uint64_t val = 0; |
| 5033 | |
Fabio Erculiani | e0e65be | 2012-01-03 09:38:34 +0000 | [diff] [blame] | 5034 | if (i == 0) { |
| 5035 | /* pid */ |
| 5036 | val = getpid(); |
| 5037 | snprintf(buf, sizeof(buf), "%"PRId64 " ", val); |
| 5038 | } else if (i == 1) { |
| 5039 | /* app name */ |
| 5040 | snprintf(buf, sizeof(buf), "(%s) ", ts->bprm->argv[0]); |
| 5041 | } else if (i == 27) { |
| 5042 | /* stack bottom */ |
| 5043 | val = start_stack; |
| 5044 | snprintf(buf, sizeof(buf), "%"PRId64 " ", val); |
| 5045 | } else { |
| 5046 | /* for the rest, there is MasterCard */ |
| 5047 | snprintf(buf, sizeof(buf), "0%c", i == 43 ? '\n' : ' '); |
Alexander Graf | 480b8e7 | 2011-11-02 20:23:25 +0100 | [diff] [blame] | 5048 | } |
Fabio Erculiani | e0e65be | 2012-01-03 09:38:34 +0000 | [diff] [blame] | 5049 | |
Alexander Graf | 480b8e7 | 2011-11-02 20:23:25 +0100 | [diff] [blame] | 5050 | len = strlen(buf); |
| 5051 | if (write(fd, buf, len) != len) { |
| 5052 | return -1; |
| 5053 | } |
| 5054 | } |
| 5055 | |
| 5056 | return 0; |
| 5057 | } |
| 5058 | |
Alexander Graf | 257450e | 2011-11-02 20:23:26 +0100 | [diff] [blame] | 5059 | static int open_self_auxv(void *cpu_env, int fd) |
| 5060 | { |
Andreas Färber | 9349b4f | 2012-03-14 01:38:32 +0100 | [diff] [blame] | 5061 | TaskState *ts = ((CPUArchState *)cpu_env)->opaque; |
Alexander Graf | 257450e | 2011-11-02 20:23:26 +0100 | [diff] [blame] | 5062 | abi_ulong auxv = ts->info->saved_auxv; |
| 5063 | abi_ulong len = ts->info->auxv_len; |
| 5064 | char *ptr; |
| 5065 | |
| 5066 | /* |
| 5067 | * Auxiliary vector is stored in target process stack. |
| 5068 | * read in whole auxv vector and copy it to file |
| 5069 | */ |
| 5070 | ptr = lock_user(VERIFY_READ, auxv, len, 0); |
| 5071 | if (ptr != NULL) { |
| 5072 | while (len > 0) { |
| 5073 | ssize_t r; |
| 5074 | r = write(fd, ptr, len); |
| 5075 | if (r <= 0) { |
| 5076 | break; |
| 5077 | } |
| 5078 | len -= r; |
| 5079 | ptr += r; |
| 5080 | } |
| 5081 | lseek(fd, 0, SEEK_SET); |
| 5082 | unlock_user(ptr, auxv, len); |
| 5083 | } |
| 5084 | |
| 5085 | return 0; |
| 5086 | } |
| 5087 | |
Alexander Graf | 3be14d0 | 2011-11-02 20:23:23 +0100 | [diff] [blame] | 5088 | static int do_open(void *cpu_env, const char *pathname, int flags, mode_t mode) |
| 5089 | { |
| 5090 | struct fake_open { |
| 5091 | const char *filename; |
| 5092 | int (*fill)(void *cpu_env, int fd); |
| 5093 | }; |
| 5094 | const struct fake_open *fake_open; |
| 5095 | static const struct fake_open fakes[] = { |
Alexander Graf | 36c08d4 | 2011-11-02 20:23:24 +0100 | [diff] [blame] | 5096 | { "/proc/self/maps", open_self_maps }, |
Alexander Graf | 480b8e7 | 2011-11-02 20:23:25 +0100 | [diff] [blame] | 5097 | { "/proc/self/stat", open_self_stat }, |
Alexander Graf | 257450e | 2011-11-02 20:23:26 +0100 | [diff] [blame] | 5098 | { "/proc/self/auxv", open_self_auxv }, |
Alexander Graf | 3be14d0 | 2011-11-02 20:23:23 +0100 | [diff] [blame] | 5099 | { NULL, NULL } |
| 5100 | }; |
| 5101 | |
| 5102 | for (fake_open = fakes; fake_open->filename; fake_open++) { |
| 5103 | if (!strncmp(pathname, fake_open->filename, |
| 5104 | strlen(fake_open->filename))) { |
| 5105 | break; |
| 5106 | } |
| 5107 | } |
| 5108 | |
| 5109 | if (fake_open->filename) { |
| 5110 | const char *tmpdir; |
| 5111 | char filename[PATH_MAX]; |
| 5112 | int fd, r; |
| 5113 | |
| 5114 | /* create temporary file to map stat to */ |
| 5115 | tmpdir = getenv("TMPDIR"); |
| 5116 | if (!tmpdir) |
| 5117 | tmpdir = "/tmp"; |
| 5118 | snprintf(filename, sizeof(filename), "%s/qemu-open.XXXXXX", tmpdir); |
| 5119 | fd = mkstemp(filename); |
| 5120 | if (fd < 0) { |
| 5121 | return fd; |
| 5122 | } |
| 5123 | unlink(filename); |
| 5124 | |
| 5125 | if ((r = fake_open->fill(cpu_env, fd))) { |
| 5126 | close(fd); |
| 5127 | return r; |
| 5128 | } |
| 5129 | lseek(fd, 0, SEEK_SET); |
| 5130 | |
| 5131 | return fd; |
| 5132 | } |
| 5133 | |
| 5134 | return get_errno(open(path(pathname), flags, mode)); |
| 5135 | } |
| 5136 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 5137 | /* do_syscall() should always have a single exit point at the end so |
| 5138 | that actions, such as logging of syscall results, can be performed. |
| 5139 | All errnos that do_syscall() returns must be -TARGET_<errcode>. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 5140 | abi_long do_syscall(void *cpu_env, int num, abi_long arg1, |
| 5141 | abi_long arg2, abi_long arg3, abi_long arg4, |
Peter Maydell | 5945cfc | 2011-06-16 17:37:13 +0100 | [diff] [blame] | 5142 | abi_long arg5, abi_long arg6, abi_long arg7, |
| 5143 | abi_long arg8) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5144 | { |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 5145 | abi_long ret; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5146 | struct stat st; |
bellard | 56c8f68 | 2005-11-28 22:28:41 +0000 | [diff] [blame] | 5147 | struct statfs stfs; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5148 | void *p; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 5149 | |
bellard | 72f0390 | 2003-02-18 23:33:18 +0000 | [diff] [blame] | 5150 | #ifdef DEBUG |
bellard | c573ff6 | 2004-01-04 15:51:36 +0000 | [diff] [blame] | 5151 | gemu_log("syscall %d", num); |
bellard | 72f0390 | 2003-02-18 23:33:18 +0000 | [diff] [blame] | 5152 | #endif |
ths | b92c47c | 2007-11-01 00:07:38 +0000 | [diff] [blame] | 5153 | if(do_strace) |
| 5154 | print_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6); |
| 5155 | |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5156 | switch(num) { |
| 5157 | case TARGET_NR_exit: |
Juan Quintela | 2f7bb87 | 2009-07-27 16:13:24 +0200 | [diff] [blame] | 5158 | #ifdef CONFIG_USE_NPTL |
pbrook | c276471 | 2009-03-07 15:24:59 +0000 | [diff] [blame] | 5159 | /* In old applications this may be used to implement _exit(2). |
| 5160 | However in threaded applictions it is used for thread termination, |
| 5161 | and _exit_group is used for application termination. |
| 5162 | Do thread termination if we have more then one thread. */ |
| 5163 | /* FIXME: This probably breaks if a signal arrives. We should probably |
| 5164 | be disabling signals. */ |
| 5165 | if (first_cpu->next_cpu) { |
Nathan Froyd | 1e9fa73 | 2009-06-03 11:33:08 -0700 | [diff] [blame] | 5166 | TaskState *ts; |
Andreas Färber | 9349b4f | 2012-03-14 01:38:32 +0100 | [diff] [blame] | 5167 | CPUArchState **lastp; |
| 5168 | CPUArchState *p; |
pbrook | c276471 | 2009-03-07 15:24:59 +0000 | [diff] [blame] | 5169 | |
| 5170 | cpu_list_lock(); |
| 5171 | lastp = &first_cpu; |
| 5172 | p = first_cpu; |
Andreas Färber | 9349b4f | 2012-03-14 01:38:32 +0100 | [diff] [blame] | 5173 | while (p && p != (CPUArchState *)cpu_env) { |
pbrook | c276471 | 2009-03-07 15:24:59 +0000 | [diff] [blame] | 5174 | lastp = &p->next_cpu; |
| 5175 | p = p->next_cpu; |
| 5176 | } |
| 5177 | /* If we didn't find the CPU for this thread then something is |
| 5178 | horribly wrong. */ |
| 5179 | if (!p) |
| 5180 | abort(); |
| 5181 | /* Remove the CPU from the list. */ |
| 5182 | *lastp = p->next_cpu; |
| 5183 | cpu_list_unlock(); |
Andreas Färber | 9349b4f | 2012-03-14 01:38:32 +0100 | [diff] [blame] | 5184 | ts = ((CPUArchState *)cpu_env)->opaque; |
pbrook | c276471 | 2009-03-07 15:24:59 +0000 | [diff] [blame] | 5185 | if (ts->child_tidptr) { |
| 5186 | put_user_u32(0, ts->child_tidptr); |
| 5187 | sys_futex(g2h(ts->child_tidptr), FUTEX_WAKE, INT_MAX, |
| 5188 | NULL, NULL, 0); |
| 5189 | } |
Nathan Froyd | 48e15fc | 2010-10-29 07:48:57 -0700 | [diff] [blame] | 5190 | thread_env = NULL; |
Andreas Färber | 11ea409 | 2012-04-15 18:51:01 +0200 | [diff] [blame] | 5191 | object_delete(OBJECT(ENV_GET_CPU(cpu_env))); |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 5192 | g_free(ts); |
pbrook | c276471 | 2009-03-07 15:24:59 +0000 | [diff] [blame] | 5193 | pthread_exit(NULL); |
| 5194 | } |
| 5195 | #endif |
Juan Quintela | 9788c9c | 2009-07-27 16:13:02 +0200 | [diff] [blame] | 5196 | #ifdef TARGET_GPROF |
bellard | 7d13299 | 2003-03-06 23:23:54 +0000 | [diff] [blame] | 5197 | _mcleanup(); |
| 5198 | #endif |
bellard | e900967 | 2005-04-26 20:42:36 +0000 | [diff] [blame] | 5199 | gdb_exit(cpu_env, arg1); |
pbrook | c276471 | 2009-03-07 15:24:59 +0000 | [diff] [blame] | 5200 | _exit(arg1); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5201 | ret = 0; /* avoid warning */ |
| 5202 | break; |
| 5203 | case TARGET_NR_read: |
aurel32 | 38d840e | 2009-01-30 19:48:17 +0000 | [diff] [blame] | 5204 | if (arg3 == 0) |
| 5205 | ret = 0; |
| 5206 | else { |
| 5207 | if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0))) |
| 5208 | goto efault; |
| 5209 | ret = get_errno(read(arg1, p, arg3)); |
| 5210 | unlock_user(p, arg2, ret); |
| 5211 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5212 | break; |
| 5213 | case TARGET_NR_write: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5214 | if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1))) |
| 5215 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5216 | ret = get_errno(write(arg1, p, arg3)); |
| 5217 | unlock_user(p, arg2, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5218 | break; |
| 5219 | case TARGET_NR_open: |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 5220 | if (!(p = lock_user_string(arg1))) |
| 5221 | goto efault; |
Alexander Graf | 3be14d0 | 2011-11-02 20:23:23 +0100 | [diff] [blame] | 5222 | ret = get_errno(do_open(cpu_env, p, |
| 5223 | target_to_host_bitmask(arg2, fcntl_flags_tbl), |
| 5224 | arg3)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5225 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5226 | break; |
ths | 8242483 | 2007-09-24 09:21:55 +0000 | [diff] [blame] | 5227 | #if defined(TARGET_NR_openat) && defined(__NR_openat) |
| 5228 | case TARGET_NR_openat: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5229 | if (!(p = lock_user_string(arg2))) |
| 5230 | goto efault; |
| 5231 | ret = get_errno(sys_openat(arg1, |
| 5232 | path(p), |
| 5233 | target_to_host_bitmask(arg3, fcntl_flags_tbl), |
| 5234 | arg4)); |
| 5235 | unlock_user(p, arg2, 0); |
ths | 8242483 | 2007-09-24 09:21:55 +0000 | [diff] [blame] | 5236 | break; |
| 5237 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5238 | case TARGET_NR_close: |
| 5239 | ret = get_errno(close(arg1)); |
| 5240 | break; |
| 5241 | case TARGET_NR_brk: |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5242 | ret = do_brk(arg1); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5243 | break; |
| 5244 | case TARGET_NR_fork: |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 5245 | ret = get_errno(do_fork(cpu_env, SIGCHLD, 0, 0, 0, 0)); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5246 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 5247 | #ifdef TARGET_NR_waitpid |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5248 | case TARGET_NR_waitpid: |
| 5249 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5250 | int status; |
| 5251 | ret = get_errno(waitpid(arg1, &status, arg3)); |
Alexander Graf | 5379557 | 2011-11-24 00:44:43 +0100 | [diff] [blame] | 5252 | if (!is_error(ret) && arg2 && ret |
pbrook | 1d9d8b5 | 2009-04-16 15:17:02 +0000 | [diff] [blame] | 5253 | && put_user_s32(host_to_target_waitstatus(status), arg2)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 5254 | goto efault; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5255 | } |
| 5256 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 5257 | #endif |
pbrook | f0cbb61 | 2008-05-30 18:20:05 +0000 | [diff] [blame] | 5258 | #ifdef TARGET_NR_waitid |
| 5259 | case TARGET_NR_waitid: |
| 5260 | { |
| 5261 | siginfo_t info; |
| 5262 | info.si_pid = 0; |
| 5263 | ret = get_errno(waitid(arg1, arg2, &info, arg4)); |
| 5264 | if (!is_error(ret) && arg3 && info.si_pid != 0) { |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 5265 | if (!(p = lock_user(VERIFY_WRITE, arg3, sizeof(target_siginfo_t), 0))) |
pbrook | f0cbb61 | 2008-05-30 18:20:05 +0000 | [diff] [blame] | 5266 | goto efault; |
| 5267 | host_to_target_siginfo(p, &info); |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 5268 | unlock_user(p, arg3, sizeof(target_siginfo_t)); |
pbrook | f0cbb61 | 2008-05-30 18:20:05 +0000 | [diff] [blame] | 5269 | } |
| 5270 | } |
| 5271 | break; |
| 5272 | #endif |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 5273 | #ifdef TARGET_NR_creat /* not on alpha */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5274 | case TARGET_NR_creat: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5275 | if (!(p = lock_user_string(arg1))) |
| 5276 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5277 | ret = get_errno(creat(p, arg2)); |
| 5278 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5279 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 5280 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5281 | case TARGET_NR_link: |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5282 | { |
| 5283 | void * p2; |
| 5284 | p = lock_user_string(arg1); |
| 5285 | p2 = lock_user_string(arg2); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5286 | if (!p || !p2) |
| 5287 | ret = -TARGET_EFAULT; |
| 5288 | else |
| 5289 | ret = get_errno(link(p, p2)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5290 | unlock_user(p2, arg2, 0); |
| 5291 | unlock_user(p, arg1, 0); |
| 5292 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5293 | break; |
ths | 64f0ce4 | 2007-09-24 09:25:06 +0000 | [diff] [blame] | 5294 | #if defined(TARGET_NR_linkat) && defined(__NR_linkat) |
| 5295 | case TARGET_NR_linkat: |
ths | 64f0ce4 | 2007-09-24 09:25:06 +0000 | [diff] [blame] | 5296 | { |
| 5297 | void * p2 = NULL; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5298 | if (!arg2 || !arg4) |
| 5299 | goto efault; |
ths | 64f0ce4 | 2007-09-24 09:25:06 +0000 | [diff] [blame] | 5300 | p = lock_user_string(arg2); |
| 5301 | p2 = lock_user_string(arg4); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5302 | if (!p || !p2) |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 5303 | ret = -TARGET_EFAULT; |
ths | 64f0ce4 | 2007-09-24 09:25:06 +0000 | [diff] [blame] | 5304 | else |
| 5305 | ret = get_errno(sys_linkat(arg1, p, arg3, p2, arg5)); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5306 | unlock_user(p, arg2, 0); |
| 5307 | unlock_user(p2, arg4, 0); |
ths | 64f0ce4 | 2007-09-24 09:25:06 +0000 | [diff] [blame] | 5308 | } |
| 5309 | break; |
| 5310 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5311 | case TARGET_NR_unlink: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5312 | if (!(p = lock_user_string(arg1))) |
| 5313 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5314 | ret = get_errno(unlink(p)); |
| 5315 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5316 | break; |
ths | 8170f56 | 2007-09-24 09:24:11 +0000 | [diff] [blame] | 5317 | #if defined(TARGET_NR_unlinkat) && defined(__NR_unlinkat) |
| 5318 | case TARGET_NR_unlinkat: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5319 | if (!(p = lock_user_string(arg2))) |
| 5320 | goto efault; |
| 5321 | ret = get_errno(sys_unlinkat(arg1, p, arg3)); |
| 5322 | unlock_user(p, arg2, 0); |
balrog | ed494d8 | 2007-12-11 23:23:52 +0000 | [diff] [blame] | 5323 | break; |
balrog | b7d35e6 | 2007-12-12 00:40:24 +0000 | [diff] [blame] | 5324 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5325 | case TARGET_NR_execve: |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 5326 | { |
| 5327 | char **argp, **envp; |
bellard | f7341ff | 2003-03-30 21:00:25 +0000 | [diff] [blame] | 5328 | int argc, envc; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 5329 | abi_ulong gp; |
| 5330 | abi_ulong guest_argp; |
| 5331 | abi_ulong guest_envp; |
| 5332 | abi_ulong addr; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 5333 | char **q; |
Ulrich Hecht | a6f79cc | 2012-01-31 12:43:16 +0100 | [diff] [blame] | 5334 | int total_size = 0; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 5335 | |
bellard | f7341ff | 2003-03-30 21:00:25 +0000 | [diff] [blame] | 5336 | argc = 0; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5337 | guest_argp = arg2; |
pbrook | da94d26 | 2008-05-30 18:24:00 +0000 | [diff] [blame] | 5338 | for (gp = guest_argp; gp; gp += sizeof(abi_ulong)) { |
ths | 03aa197 | 2007-12-02 06:28:08 +0000 | [diff] [blame] | 5339 | if (get_user_ual(addr, gp)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 5340 | goto efault; |
ths | 03aa197 | 2007-12-02 06:28:08 +0000 | [diff] [blame] | 5341 | if (!addr) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 5342 | break; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 5343 | argc++; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 5344 | } |
bellard | f7341ff | 2003-03-30 21:00:25 +0000 | [diff] [blame] | 5345 | envc = 0; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5346 | guest_envp = arg3; |
pbrook | da94d26 | 2008-05-30 18:24:00 +0000 | [diff] [blame] | 5347 | for (gp = guest_envp; gp; gp += sizeof(abi_ulong)) { |
ths | 03aa197 | 2007-12-02 06:28:08 +0000 | [diff] [blame] | 5348 | if (get_user_ual(addr, gp)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 5349 | goto efault; |
ths | 03aa197 | 2007-12-02 06:28:08 +0000 | [diff] [blame] | 5350 | if (!addr) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 5351 | break; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 5352 | envc++; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 5353 | } |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 5354 | |
bellard | f7341ff | 2003-03-30 21:00:25 +0000 | [diff] [blame] | 5355 | argp = alloca((argc + 1) * sizeof(void *)); |
| 5356 | envp = alloca((envc + 1) * sizeof(void *)); |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 5357 | |
pbrook | da94d26 | 2008-05-30 18:24:00 +0000 | [diff] [blame] | 5358 | for (gp = guest_argp, q = argp; gp; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 5359 | gp += sizeof(abi_ulong), q++) { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 5360 | if (get_user_ual(addr, gp)) |
| 5361 | goto execve_efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5362 | if (!addr) |
| 5363 | break; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 5364 | if (!(*q = lock_user_string(addr))) |
| 5365 | goto execve_efault; |
Ulrich Hecht | a6f79cc | 2012-01-31 12:43:16 +0100 | [diff] [blame] | 5366 | total_size += strlen(*q) + 1; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5367 | } |
bellard | f7341ff | 2003-03-30 21:00:25 +0000 | [diff] [blame] | 5368 | *q = NULL; |
| 5369 | |
pbrook | da94d26 | 2008-05-30 18:24:00 +0000 | [diff] [blame] | 5370 | for (gp = guest_envp, q = envp; gp; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 5371 | gp += sizeof(abi_ulong), q++) { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 5372 | if (get_user_ual(addr, gp)) |
| 5373 | goto execve_efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5374 | if (!addr) |
| 5375 | break; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 5376 | if (!(*q = lock_user_string(addr))) |
| 5377 | goto execve_efault; |
Ulrich Hecht | a6f79cc | 2012-01-31 12:43:16 +0100 | [diff] [blame] | 5378 | total_size += strlen(*q) + 1; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5379 | } |
bellard | f7341ff | 2003-03-30 21:00:25 +0000 | [diff] [blame] | 5380 | *q = NULL; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 5381 | |
Ulrich Hecht | a6f79cc | 2012-01-31 12:43:16 +0100 | [diff] [blame] | 5382 | /* This case will not be caught by the host's execve() if its |
| 5383 | page size is bigger than the target's. */ |
| 5384 | if (total_size > MAX_ARG_PAGES * TARGET_PAGE_SIZE) { |
| 5385 | ret = -TARGET_E2BIG; |
| 5386 | goto execve_end; |
| 5387 | } |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 5388 | if (!(p = lock_user_string(arg1))) |
| 5389 | goto execve_efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5390 | ret = get_errno(execve(p, argp, envp)); |
| 5391 | unlock_user(p, arg1, 0); |
| 5392 | |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 5393 | goto execve_end; |
| 5394 | |
| 5395 | execve_efault: |
| 5396 | ret = -TARGET_EFAULT; |
| 5397 | |
| 5398 | execve_end: |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5399 | for (gp = guest_argp, q = argp; *q; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 5400 | gp += sizeof(abi_ulong), q++) { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 5401 | if (get_user_ual(addr, gp) |
| 5402 | || !addr) |
| 5403 | break; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5404 | unlock_user(*q, addr, 0); |
| 5405 | } |
| 5406 | for (gp = guest_envp, q = envp; *q; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 5407 | gp += sizeof(abi_ulong), q++) { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 5408 | if (get_user_ual(addr, gp) |
| 5409 | || !addr) |
| 5410 | break; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5411 | unlock_user(*q, addr, 0); |
| 5412 | } |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 5413 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5414 | break; |
| 5415 | case TARGET_NR_chdir: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5416 | if (!(p = lock_user_string(arg1))) |
| 5417 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5418 | ret = get_errno(chdir(p)); |
| 5419 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5420 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 5421 | #ifdef TARGET_NR_time |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5422 | case TARGET_NR_time: |
| 5423 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5424 | time_t host_time; |
| 5425 | ret = get_errno(time(&host_time)); |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 5426 | if (!is_error(ret) |
| 5427 | && arg1 |
| 5428 | && put_user_sal(host_time, arg1)) |
| 5429 | goto efault; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5430 | } |
| 5431 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 5432 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5433 | case TARGET_NR_mknod: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5434 | if (!(p = lock_user_string(arg1))) |
| 5435 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5436 | ret = get_errno(mknod(p, arg2, arg3)); |
| 5437 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5438 | break; |
ths | 75ac37a | 2007-09-24 09:23:05 +0000 | [diff] [blame] | 5439 | #if defined(TARGET_NR_mknodat) && defined(__NR_mknodat) |
| 5440 | case TARGET_NR_mknodat: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5441 | if (!(p = lock_user_string(arg2))) |
| 5442 | goto efault; |
| 5443 | ret = get_errno(sys_mknodat(arg1, p, arg3, arg4)); |
| 5444 | unlock_user(p, arg2, 0); |
ths | 75ac37a | 2007-09-24 09:23:05 +0000 | [diff] [blame] | 5445 | break; |
| 5446 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5447 | case TARGET_NR_chmod: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5448 | if (!(p = lock_user_string(arg1))) |
| 5449 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5450 | ret = get_errno(chmod(p, arg2)); |
| 5451 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5452 | break; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5453 | #ifdef TARGET_NR_break |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5454 | case TARGET_NR_break: |
| 5455 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5456 | #endif |
| 5457 | #ifdef TARGET_NR_oldstat |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5458 | case TARGET_NR_oldstat: |
| 5459 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5460 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5461 | case TARGET_NR_lseek: |
| 5462 | ret = get_errno(lseek(arg1, arg2, arg3)); |
| 5463 | break; |
Richard Henderson | 9231733 | 2010-05-03 10:07:53 -0700 | [diff] [blame] | 5464 | #if defined(TARGET_NR_getxpid) && defined(TARGET_ALPHA) |
| 5465 | /* Alpha specific */ |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 5466 | case TARGET_NR_getxpid: |
Richard Henderson | 9231733 | 2010-05-03 10:07:53 -0700 | [diff] [blame] | 5467 | ((CPUAlphaState *)cpu_env)->ir[IR_A4] = getppid(); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5468 | ret = get_errno(getpid()); |
| 5469 | break; |
Richard Henderson | 9231733 | 2010-05-03 10:07:53 -0700 | [diff] [blame] | 5470 | #endif |
| 5471 | #ifdef TARGET_NR_getpid |
| 5472 | case TARGET_NR_getpid: |
| 5473 | ret = get_errno(getpid()); |
| 5474 | break; |
| 5475 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5476 | case TARGET_NR_mount: |
ths | 8026591 | 2007-02-17 22:25:41 +0000 | [diff] [blame] | 5477 | { |
| 5478 | /* need to look at the data field */ |
| 5479 | void *p2, *p3; |
| 5480 | p = lock_user_string(arg1); |
| 5481 | p2 = lock_user_string(arg2); |
| 5482 | p3 = lock_user_string(arg3); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5483 | if (!p || !p2 || !p3) |
| 5484 | ret = -TARGET_EFAULT; |
Jan-Simon Möller | dab4640 | 2009-10-17 21:52:43 +0300 | [diff] [blame] | 5485 | else { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5486 | /* FIXME - arg5 should be locked, but it isn't clear how to |
| 5487 | * do that since it's not guaranteed to be a NULL-terminated |
| 5488 | * string. |
| 5489 | */ |
Jan-Simon Möller | dab4640 | 2009-10-17 21:52:43 +0300 | [diff] [blame] | 5490 | if ( ! arg5 ) |
| 5491 | ret = get_errno(mount(p, p2, p3, (unsigned long)arg4, NULL)); |
| 5492 | else |
| 5493 | ret = get_errno(mount(p, p2, p3, (unsigned long)arg4, g2h(arg5))); |
| 5494 | } |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5495 | unlock_user(p, arg1, 0); |
| 5496 | unlock_user(p2, arg2, 0); |
| 5497 | unlock_user(p3, arg3, 0); |
ths | 8026591 | 2007-02-17 22:25:41 +0000 | [diff] [blame] | 5498 | break; |
| 5499 | } |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 5500 | #ifdef TARGET_NR_umount |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5501 | case TARGET_NR_umount: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5502 | if (!(p = lock_user_string(arg1))) |
| 5503 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5504 | ret = get_errno(umount(p)); |
| 5505 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5506 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 5507 | #endif |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 5508 | #ifdef TARGET_NR_stime /* not on alpha */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5509 | case TARGET_NR_stime: |
| 5510 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5511 | time_t host_time; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 5512 | if (get_user_sal(host_time, arg1)) |
| 5513 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5514 | ret = get_errno(stime(&host_time)); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5515 | } |
| 5516 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 5517 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5518 | case TARGET_NR_ptrace: |
| 5519 | goto unimplemented; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 5520 | #ifdef TARGET_NR_alarm /* not on alpha */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5521 | case TARGET_NR_alarm: |
| 5522 | ret = alarm(arg1); |
| 5523 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 5524 | #endif |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5525 | #ifdef TARGET_NR_oldfstat |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5526 | case TARGET_NR_oldfstat: |
| 5527 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5528 | #endif |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 5529 | #ifdef TARGET_NR_pause /* not on alpha */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5530 | case TARGET_NR_pause: |
| 5531 | ret = get_errno(pause()); |
| 5532 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 5533 | #endif |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 5534 | #ifdef TARGET_NR_utime |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5535 | case TARGET_NR_utime: |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5536 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5537 | struct utimbuf tbuf, *host_tbuf; |
| 5538 | struct target_utimbuf *target_tbuf; |
| 5539 | if (arg2) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5540 | if (!lock_user_struct(VERIFY_READ, target_tbuf, arg2, 1)) |
| 5541 | goto efault; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 5542 | tbuf.actime = tswapal(target_tbuf->actime); |
| 5543 | tbuf.modtime = tswapal(target_tbuf->modtime); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5544 | unlock_user_struct(target_tbuf, arg2, 0); |
| 5545 | host_tbuf = &tbuf; |
bellard | f72e8ff | 2004-05-03 19:23:07 +0000 | [diff] [blame] | 5546 | } else { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5547 | host_tbuf = NULL; |
bellard | f72e8ff | 2004-05-03 19:23:07 +0000 | [diff] [blame] | 5548 | } |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5549 | if (!(p = lock_user_string(arg1))) |
| 5550 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5551 | ret = get_errno(utime(p, host_tbuf)); |
| 5552 | unlock_user(p, arg1, 0); |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5553 | } |
| 5554 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 5555 | #endif |
bellard | 978a66f | 2004-12-06 22:58:05 +0000 | [diff] [blame] | 5556 | case TARGET_NR_utimes: |
| 5557 | { |
bellard | 978a66f | 2004-12-06 22:58:05 +0000 | [diff] [blame] | 5558 | struct timeval *tvp, tv[2]; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5559 | if (arg2) { |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 5560 | if (copy_from_user_timeval(&tv[0], arg2) |
| 5561 | || copy_from_user_timeval(&tv[1], |
| 5562 | arg2 + sizeof(struct target_timeval))) |
| 5563 | goto efault; |
bellard | 978a66f | 2004-12-06 22:58:05 +0000 | [diff] [blame] | 5564 | tvp = tv; |
| 5565 | } else { |
| 5566 | tvp = NULL; |
| 5567 | } |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5568 | if (!(p = lock_user_string(arg1))) |
| 5569 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5570 | ret = get_errno(utimes(p, tvp)); |
| 5571 | unlock_user(p, arg1, 0); |
bellard | 978a66f | 2004-12-06 22:58:05 +0000 | [diff] [blame] | 5572 | } |
| 5573 | break; |
balrog | ac8a655 | 2008-09-20 02:25:39 +0000 | [diff] [blame] | 5574 | #if defined(TARGET_NR_futimesat) && defined(__NR_futimesat) |
| 5575 | case TARGET_NR_futimesat: |
| 5576 | { |
| 5577 | struct timeval *tvp, tv[2]; |
| 5578 | if (arg3) { |
| 5579 | if (copy_from_user_timeval(&tv[0], arg3) |
| 5580 | || copy_from_user_timeval(&tv[1], |
| 5581 | arg3 + sizeof(struct target_timeval))) |
| 5582 | goto efault; |
| 5583 | tvp = tv; |
| 5584 | } else { |
| 5585 | tvp = NULL; |
| 5586 | } |
| 5587 | if (!(p = lock_user_string(arg2))) |
| 5588 | goto efault; |
| 5589 | ret = get_errno(sys_futimesat(arg1, path(p), tvp)); |
| 5590 | unlock_user(p, arg2, 0); |
| 5591 | } |
| 5592 | break; |
| 5593 | #endif |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5594 | #ifdef TARGET_NR_stty |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5595 | case TARGET_NR_stty: |
| 5596 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5597 | #endif |
| 5598 | #ifdef TARGET_NR_gtty |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5599 | case TARGET_NR_gtty: |
| 5600 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5601 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5602 | case TARGET_NR_access: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5603 | if (!(p = lock_user_string(arg1))) |
| 5604 | goto efault; |
Ulrich Hecht | 719f908 | 2009-07-03 17:09:29 +0200 | [diff] [blame] | 5605 | ret = get_errno(access(path(p), arg2)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5606 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5607 | break; |
ths | 92a34c1 | 2007-09-24 09:27:49 +0000 | [diff] [blame] | 5608 | #if defined(TARGET_NR_faccessat) && defined(__NR_faccessat) |
| 5609 | case TARGET_NR_faccessat: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5610 | if (!(p = lock_user_string(arg2))) |
| 5611 | goto efault; |
aurel32 | 465c9f0 | 2009-04-19 08:52:17 +0000 | [diff] [blame] | 5612 | ret = get_errno(sys_faccessat(arg1, p, arg3)); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5613 | unlock_user(p, arg2, 0); |
ths | 92a34c1 | 2007-09-24 09:27:49 +0000 | [diff] [blame] | 5614 | break; |
| 5615 | #endif |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 5616 | #ifdef TARGET_NR_nice /* not on alpha */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5617 | case TARGET_NR_nice: |
| 5618 | ret = get_errno(nice(arg1)); |
| 5619 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 5620 | #endif |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5621 | #ifdef TARGET_NR_ftime |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5622 | case TARGET_NR_ftime: |
| 5623 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5624 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5625 | case TARGET_NR_sync: |
bellard | 04369ff | 2003-03-20 22:33:23 +0000 | [diff] [blame] | 5626 | sync(); |
| 5627 | ret = 0; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5628 | break; |
| 5629 | case TARGET_NR_kill: |
pbrook | 4cb0596 | 2008-05-30 18:05:19 +0000 | [diff] [blame] | 5630 | ret = get_errno(kill(arg1, target_to_host_signal(arg2))); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5631 | break; |
| 5632 | case TARGET_NR_rename: |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5633 | { |
| 5634 | void *p2; |
| 5635 | p = lock_user_string(arg1); |
| 5636 | p2 = lock_user_string(arg2); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5637 | if (!p || !p2) |
| 5638 | ret = -TARGET_EFAULT; |
| 5639 | else |
| 5640 | ret = get_errno(rename(p, p2)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5641 | unlock_user(p2, arg2, 0); |
| 5642 | unlock_user(p, arg1, 0); |
| 5643 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5644 | break; |
ths | 722183f | 2007-09-24 09:24:37 +0000 | [diff] [blame] | 5645 | #if defined(TARGET_NR_renameat) && defined(__NR_renameat) |
| 5646 | case TARGET_NR_renameat: |
ths | 722183f | 2007-09-24 09:24:37 +0000 | [diff] [blame] | 5647 | { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5648 | void *p2; |
ths | 722183f | 2007-09-24 09:24:37 +0000 | [diff] [blame] | 5649 | p = lock_user_string(arg2); |
| 5650 | p2 = lock_user_string(arg4); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5651 | if (!p || !p2) |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 5652 | ret = -TARGET_EFAULT; |
ths | 722183f | 2007-09-24 09:24:37 +0000 | [diff] [blame] | 5653 | else |
| 5654 | ret = get_errno(sys_renameat(arg1, p, arg3, p2)); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5655 | unlock_user(p2, arg4, 0); |
| 5656 | unlock_user(p, arg2, 0); |
ths | 722183f | 2007-09-24 09:24:37 +0000 | [diff] [blame] | 5657 | } |
| 5658 | break; |
| 5659 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5660 | case TARGET_NR_mkdir: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5661 | if (!(p = lock_user_string(arg1))) |
| 5662 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5663 | ret = get_errno(mkdir(p, arg2)); |
| 5664 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5665 | break; |
ths | 4472ad0 | 2007-09-24 09:22:32 +0000 | [diff] [blame] | 5666 | #if defined(TARGET_NR_mkdirat) && defined(__NR_mkdirat) |
| 5667 | case TARGET_NR_mkdirat: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5668 | if (!(p = lock_user_string(arg2))) |
| 5669 | goto efault; |
| 5670 | ret = get_errno(sys_mkdirat(arg1, p, arg3)); |
| 5671 | unlock_user(p, arg2, 0); |
ths | 4472ad0 | 2007-09-24 09:22:32 +0000 | [diff] [blame] | 5672 | break; |
| 5673 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5674 | case TARGET_NR_rmdir: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5675 | if (!(p = lock_user_string(arg1))) |
| 5676 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5677 | ret = get_errno(rmdir(p)); |
| 5678 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5679 | break; |
| 5680 | case TARGET_NR_dup: |
| 5681 | ret = get_errno(dup(arg1)); |
| 5682 | break; |
| 5683 | case TARGET_NR_pipe: |
Richard Henderson | fb41a66 | 2010-05-03 10:07:52 -0700 | [diff] [blame] | 5684 | ret = do_pipe(cpu_env, arg1, 0, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5685 | break; |
Riku Voipio | 099d6b0 | 2009-05-05 12:10:04 +0300 | [diff] [blame] | 5686 | #ifdef TARGET_NR_pipe2 |
| 5687 | case TARGET_NR_pipe2: |
Richard Henderson | e7ea6cb | 2012-06-01 18:48:39 -0700 | [diff] [blame] | 5688 | ret = do_pipe(cpu_env, arg1, |
| 5689 | target_to_host_bitmask(arg2, fcntl_flags_tbl), 1); |
Riku Voipio | 099d6b0 | 2009-05-05 12:10:04 +0300 | [diff] [blame] | 5690 | break; |
| 5691 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5692 | case TARGET_NR_times: |
bellard | 32f36bc | 2003-03-30 21:29:48 +0000 | [diff] [blame] | 5693 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5694 | struct target_tms *tmsp; |
bellard | 32f36bc | 2003-03-30 21:29:48 +0000 | [diff] [blame] | 5695 | struct tms tms; |
| 5696 | ret = get_errno(times(&tms)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5697 | if (arg1) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5698 | tmsp = lock_user(VERIFY_WRITE, arg1, sizeof(struct target_tms), 0); |
| 5699 | if (!tmsp) |
| 5700 | goto efault; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 5701 | tmsp->tms_utime = tswapal(host_to_target_clock_t(tms.tms_utime)); |
| 5702 | tmsp->tms_stime = tswapal(host_to_target_clock_t(tms.tms_stime)); |
| 5703 | tmsp->tms_cutime = tswapal(host_to_target_clock_t(tms.tms_cutime)); |
| 5704 | tmsp->tms_cstime = tswapal(host_to_target_clock_t(tms.tms_cstime)); |
bellard | 32f36bc | 2003-03-30 21:29:48 +0000 | [diff] [blame] | 5705 | } |
bellard | c596ed1 | 2003-07-13 17:32:31 +0000 | [diff] [blame] | 5706 | if (!is_error(ret)) |
| 5707 | ret = host_to_target_clock_t(ret); |
bellard | 32f36bc | 2003-03-30 21:29:48 +0000 | [diff] [blame] | 5708 | } |
| 5709 | break; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5710 | #ifdef TARGET_NR_prof |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5711 | case TARGET_NR_prof: |
| 5712 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5713 | #endif |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 5714 | #ifdef TARGET_NR_signal |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5715 | case TARGET_NR_signal: |
| 5716 | goto unimplemented; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 5717 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5718 | case TARGET_NR_acct: |
aurel32 | 38d840e | 2009-01-30 19:48:17 +0000 | [diff] [blame] | 5719 | if (arg1 == 0) { |
| 5720 | ret = get_errno(acct(NULL)); |
| 5721 | } else { |
| 5722 | if (!(p = lock_user_string(arg1))) |
| 5723 | goto efault; |
| 5724 | ret = get_errno(acct(path(p))); |
| 5725 | unlock_user(p, arg1, 0); |
| 5726 | } |
pbrook | 2483668 | 2006-04-16 14:14:53 +0000 | [diff] [blame] | 5727 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 5728 | #ifdef TARGET_NR_umount2 /* not on alpha */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5729 | case TARGET_NR_umount2: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5730 | if (!(p = lock_user_string(arg1))) |
| 5731 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5732 | ret = get_errno(umount2(p, arg2)); |
| 5733 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5734 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 5735 | #endif |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5736 | #ifdef TARGET_NR_lock |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5737 | case TARGET_NR_lock: |
| 5738 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5739 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5740 | case TARGET_NR_ioctl: |
| 5741 | ret = do_ioctl(arg1, arg2, arg3); |
| 5742 | break; |
| 5743 | case TARGET_NR_fcntl: |
bellard | 9ee1fa2 | 2007-11-11 15:11:19 +0000 | [diff] [blame] | 5744 | ret = do_fcntl(arg1, arg2, arg3); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5745 | break; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5746 | #ifdef TARGET_NR_mpx |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5747 | case TARGET_NR_mpx: |
| 5748 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5749 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5750 | case TARGET_NR_setpgid: |
| 5751 | ret = get_errno(setpgid(arg1, arg2)); |
| 5752 | break; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5753 | #ifdef TARGET_NR_ulimit |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5754 | case TARGET_NR_ulimit: |
| 5755 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5756 | #endif |
| 5757 | #ifdef TARGET_NR_oldolduname |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5758 | case TARGET_NR_oldolduname: |
| 5759 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5760 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5761 | case TARGET_NR_umask: |
| 5762 | ret = get_errno(umask(arg1)); |
| 5763 | break; |
| 5764 | case TARGET_NR_chroot: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5765 | if (!(p = lock_user_string(arg1))) |
| 5766 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5767 | ret = get_errno(chroot(p)); |
| 5768 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5769 | break; |
| 5770 | case TARGET_NR_ustat: |
| 5771 | goto unimplemented; |
| 5772 | case TARGET_NR_dup2: |
| 5773 | ret = get_errno(dup2(arg1, arg2)); |
| 5774 | break; |
Ulrich Hecht | d092793 | 2009-09-17 20:22:14 +0300 | [diff] [blame] | 5775 | #if defined(CONFIG_DUP3) && defined(TARGET_NR_dup3) |
| 5776 | case TARGET_NR_dup3: |
| 5777 | ret = get_errno(dup3(arg1, arg2, arg3)); |
| 5778 | break; |
| 5779 | #endif |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 5780 | #ifdef TARGET_NR_getppid /* not on alpha */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5781 | case TARGET_NR_getppid: |
| 5782 | ret = get_errno(getppid()); |
| 5783 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 5784 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5785 | case TARGET_NR_getpgrp: |
| 5786 | ret = get_errno(getpgrp()); |
| 5787 | break; |
| 5788 | case TARGET_NR_setsid: |
| 5789 | ret = get_errno(setsid()); |
| 5790 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 5791 | #ifdef TARGET_NR_sigaction |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5792 | case TARGET_NR_sigaction: |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5793 | { |
Richard Henderson | 6049f4f | 2009-12-27 18:30:03 -0800 | [diff] [blame] | 5794 | #if defined(TARGET_ALPHA) |
| 5795 | struct target_sigaction act, oact, *pact = 0; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5796 | struct target_old_sigaction *old_act; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5797 | if (arg2) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5798 | if (!lock_user_struct(VERIFY_READ, old_act, arg2, 1)) |
| 5799 | goto efault; |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 5800 | act._sa_handler = old_act->_sa_handler; |
| 5801 | target_siginitset(&act.sa_mask, old_act->sa_mask); |
| 5802 | act.sa_flags = old_act->sa_flags; |
Richard Henderson | 6049f4f | 2009-12-27 18:30:03 -0800 | [diff] [blame] | 5803 | act.sa_restorer = 0; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5804 | unlock_user_struct(old_act, arg2, 0); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 5805 | pact = &act; |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 5806 | } |
| 5807 | ret = get_errno(do_sigaction(arg1, pact, &oact)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5808 | if (!is_error(ret) && arg3) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5809 | if (!lock_user_struct(VERIFY_WRITE, old_act, arg3, 0)) |
| 5810 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5811 | old_act->_sa_handler = oact._sa_handler; |
| 5812 | old_act->sa_mask = oact.sa_mask.sig[0]; |
| 5813 | old_act->sa_flags = oact.sa_flags; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5814 | unlock_user_struct(old_act, arg3, 1); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 5815 | } |
Richard Henderson | 6049f4f | 2009-12-27 18:30:03 -0800 | [diff] [blame] | 5816 | #elif defined(TARGET_MIPS) |
bellard | 106ec87 | 2006-06-27 21:08:10 +0000 | [diff] [blame] | 5817 | struct target_sigaction act, oact, *pact, *old_act; |
| 5818 | |
| 5819 | if (arg2) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5820 | if (!lock_user_struct(VERIFY_READ, old_act, arg2, 1)) |
| 5821 | goto efault; |
bellard | 106ec87 | 2006-06-27 21:08:10 +0000 | [diff] [blame] | 5822 | act._sa_handler = old_act->_sa_handler; |
| 5823 | target_siginitset(&act.sa_mask, old_act->sa_mask.sig[0]); |
| 5824 | act.sa_flags = old_act->sa_flags; |
| 5825 | unlock_user_struct(old_act, arg2, 0); |
| 5826 | pact = &act; |
| 5827 | } else { |
| 5828 | pact = NULL; |
| 5829 | } |
| 5830 | |
| 5831 | ret = get_errno(do_sigaction(arg1, pact, &oact)); |
| 5832 | |
| 5833 | if (!is_error(ret) && arg3) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5834 | if (!lock_user_struct(VERIFY_WRITE, old_act, arg3, 0)) |
| 5835 | goto efault; |
bellard | 106ec87 | 2006-06-27 21:08:10 +0000 | [diff] [blame] | 5836 | old_act->_sa_handler = oact._sa_handler; |
| 5837 | old_act->sa_flags = oact.sa_flags; |
| 5838 | old_act->sa_mask.sig[0] = oact.sa_mask.sig[0]; |
| 5839 | old_act->sa_mask.sig[1] = 0; |
| 5840 | old_act->sa_mask.sig[2] = 0; |
| 5841 | old_act->sa_mask.sig[3] = 0; |
| 5842 | unlock_user_struct(old_act, arg3, 1); |
| 5843 | } |
Richard Henderson | 6049f4f | 2009-12-27 18:30:03 -0800 | [diff] [blame] | 5844 | #else |
| 5845 | struct target_old_sigaction *old_act; |
| 5846 | struct target_sigaction act, oact, *pact; |
| 5847 | if (arg2) { |
| 5848 | if (!lock_user_struct(VERIFY_READ, old_act, arg2, 1)) |
| 5849 | goto efault; |
| 5850 | act._sa_handler = old_act->_sa_handler; |
| 5851 | target_siginitset(&act.sa_mask, old_act->sa_mask); |
| 5852 | act.sa_flags = old_act->sa_flags; |
| 5853 | act.sa_restorer = old_act->sa_restorer; |
| 5854 | unlock_user_struct(old_act, arg2, 0); |
| 5855 | pact = &act; |
| 5856 | } else { |
| 5857 | pact = NULL; |
| 5858 | } |
| 5859 | ret = get_errno(do_sigaction(arg1, pact, &oact)); |
| 5860 | if (!is_error(ret) && arg3) { |
| 5861 | if (!lock_user_struct(VERIFY_WRITE, old_act, arg3, 0)) |
| 5862 | goto efault; |
| 5863 | old_act->_sa_handler = oact._sa_handler; |
| 5864 | old_act->sa_mask = oact.sa_mask.sig[0]; |
| 5865 | old_act->sa_flags = oact.sa_flags; |
| 5866 | old_act->sa_restorer = oact.sa_restorer; |
| 5867 | unlock_user_struct(old_act, arg3, 1); |
| 5868 | } |
ths | 388bb21 | 2007-05-13 13:58:00 +0000 | [diff] [blame] | 5869 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5870 | } |
| 5871 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 5872 | #endif |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 5873 | case TARGET_NR_rt_sigaction: |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5874 | { |
Richard Henderson | 6049f4f | 2009-12-27 18:30:03 -0800 | [diff] [blame] | 5875 | #if defined(TARGET_ALPHA) |
| 5876 | struct target_sigaction act, oact, *pact = 0; |
| 5877 | struct target_rt_sigaction *rt_act; |
| 5878 | /* ??? arg4 == sizeof(sigset_t). */ |
| 5879 | if (arg2) { |
| 5880 | if (!lock_user_struct(VERIFY_READ, rt_act, arg2, 1)) |
| 5881 | goto efault; |
| 5882 | act._sa_handler = rt_act->_sa_handler; |
| 5883 | act.sa_mask = rt_act->sa_mask; |
| 5884 | act.sa_flags = rt_act->sa_flags; |
| 5885 | act.sa_restorer = arg5; |
| 5886 | unlock_user_struct(rt_act, arg2, 0); |
| 5887 | pact = &act; |
| 5888 | } |
| 5889 | ret = get_errno(do_sigaction(arg1, pact, &oact)); |
| 5890 | if (!is_error(ret) && arg3) { |
| 5891 | if (!lock_user_struct(VERIFY_WRITE, rt_act, arg3, 0)) |
| 5892 | goto efault; |
| 5893 | rt_act->_sa_handler = oact._sa_handler; |
| 5894 | rt_act->sa_mask = oact.sa_mask; |
| 5895 | rt_act->sa_flags = oact.sa_flags; |
| 5896 | unlock_user_struct(rt_act, arg3, 1); |
| 5897 | } |
| 5898 | #else |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5899 | struct target_sigaction *act; |
| 5900 | struct target_sigaction *oact; |
| 5901 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5902 | if (arg2) { |
| 5903 | if (!lock_user_struct(VERIFY_READ, act, arg2, 1)) |
| 5904 | goto efault; |
| 5905 | } else |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5906 | act = NULL; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5907 | if (arg3) { |
| 5908 | if (!lock_user_struct(VERIFY_WRITE, oact, arg3, 0)) { |
| 5909 | ret = -TARGET_EFAULT; |
| 5910 | goto rt_sigaction_fail; |
| 5911 | } |
| 5912 | } else |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5913 | oact = NULL; |
| 5914 | ret = get_errno(do_sigaction(arg1, act, oact)); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5915 | rt_sigaction_fail: |
| 5916 | if (act) |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5917 | unlock_user_struct(act, arg2, 0); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5918 | if (oact) |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5919 | unlock_user_struct(oact, arg3, 1); |
Richard Henderson | 6049f4f | 2009-12-27 18:30:03 -0800 | [diff] [blame] | 5920 | #endif |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5921 | } |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 5922 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 5923 | #ifdef TARGET_NR_sgetmask /* not on alpha */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5924 | case TARGET_NR_sgetmask: |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 5925 | { |
| 5926 | sigset_t cur_set; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 5927 | abi_ulong target_set; |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 5928 | sigprocmask(0, NULL, &cur_set); |
| 5929 | host_to_target_old_sigset(&target_set, &cur_set); |
| 5930 | ret = target_set; |
| 5931 | } |
| 5932 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 5933 | #endif |
| 5934 | #ifdef TARGET_NR_ssetmask /* not on alpha */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5935 | case TARGET_NR_ssetmask: |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 5936 | { |
| 5937 | sigset_t set, oset, cur_set; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 5938 | abi_ulong target_set = arg1; |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 5939 | sigprocmask(0, NULL, &cur_set); |
| 5940 | target_to_host_old_sigset(&set, &target_set); |
| 5941 | sigorset(&set, &set, &cur_set); |
| 5942 | sigprocmask(SIG_SETMASK, &set, &oset); |
| 5943 | host_to_target_old_sigset(&target_set, &oset); |
| 5944 | ret = target_set; |
| 5945 | } |
| 5946 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 5947 | #endif |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 5948 | #ifdef TARGET_NR_sigprocmask |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 5949 | case TARGET_NR_sigprocmask: |
| 5950 | { |
Richard Henderson | a5b3b13 | 2010-05-03 10:07:55 -0700 | [diff] [blame] | 5951 | #if defined(TARGET_ALPHA) |
| 5952 | sigset_t set, oldset; |
| 5953 | abi_ulong mask; |
| 5954 | int how; |
| 5955 | |
| 5956 | switch (arg1) { |
| 5957 | case TARGET_SIG_BLOCK: |
| 5958 | how = SIG_BLOCK; |
| 5959 | break; |
| 5960 | case TARGET_SIG_UNBLOCK: |
| 5961 | how = SIG_UNBLOCK; |
| 5962 | break; |
| 5963 | case TARGET_SIG_SETMASK: |
| 5964 | how = SIG_SETMASK; |
| 5965 | break; |
| 5966 | default: |
| 5967 | ret = -TARGET_EINVAL; |
| 5968 | goto fail; |
| 5969 | } |
| 5970 | mask = arg2; |
| 5971 | target_to_host_old_sigset(&set, &mask); |
| 5972 | |
| 5973 | ret = get_errno(sigprocmask(how, &set, &oldset)); |
Richard Henderson | a5b3b13 | 2010-05-03 10:07:55 -0700 | [diff] [blame] | 5974 | if (!is_error(ret)) { |
| 5975 | host_to_target_old_sigset(&mask, &oldset); |
| 5976 | ret = mask; |
Richard Henderson | 0229f5a | 2012-06-07 15:02:49 -0700 | [diff] [blame] | 5977 | ((CPUAlphaState *)cpu_env)->ir[IR_V0] = 0; /* force no error */ |
Richard Henderson | a5b3b13 | 2010-05-03 10:07:55 -0700 | [diff] [blame] | 5978 | } |
| 5979 | #else |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 5980 | sigset_t set, oldset, *set_ptr; |
Richard Henderson | a5b3b13 | 2010-05-03 10:07:55 -0700 | [diff] [blame] | 5981 | int how; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 5982 | |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5983 | if (arg2) { |
Richard Henderson | a5b3b13 | 2010-05-03 10:07:55 -0700 | [diff] [blame] | 5984 | switch (arg1) { |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 5985 | case TARGET_SIG_BLOCK: |
| 5986 | how = SIG_BLOCK; |
| 5987 | break; |
| 5988 | case TARGET_SIG_UNBLOCK: |
| 5989 | how = SIG_UNBLOCK; |
| 5990 | break; |
| 5991 | case TARGET_SIG_SETMASK: |
| 5992 | how = SIG_SETMASK; |
| 5993 | break; |
| 5994 | default: |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 5995 | ret = -TARGET_EINVAL; |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 5996 | goto fail; |
| 5997 | } |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 5998 | if (!(p = lock_user(VERIFY_READ, arg2, sizeof(target_sigset_t), 1))) |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5999 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6000 | target_to_host_old_sigset(&set, p); |
| 6001 | unlock_user(p, arg2, 0); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6002 | set_ptr = &set; |
| 6003 | } else { |
| 6004 | how = 0; |
| 6005 | set_ptr = NULL; |
| 6006 | } |
Richard Henderson | a5b3b13 | 2010-05-03 10:07:55 -0700 | [diff] [blame] | 6007 | ret = get_errno(sigprocmask(how, set_ptr, &oldset)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6008 | if (!is_error(ret) && arg3) { |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6009 | if (!(p = lock_user(VERIFY_WRITE, arg3, sizeof(target_sigset_t), 0))) |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6010 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6011 | host_to_target_old_sigset(p, &oldset); |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6012 | unlock_user(p, arg3, sizeof(target_sigset_t)); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6013 | } |
Richard Henderson | a5b3b13 | 2010-05-03 10:07:55 -0700 | [diff] [blame] | 6014 | #endif |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6015 | } |
| 6016 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6017 | #endif |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6018 | case TARGET_NR_rt_sigprocmask: |
| 6019 | { |
| 6020 | int how = arg1; |
| 6021 | sigset_t set, oldset, *set_ptr; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 6022 | |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6023 | if (arg2) { |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6024 | switch(how) { |
| 6025 | case TARGET_SIG_BLOCK: |
| 6026 | how = SIG_BLOCK; |
| 6027 | break; |
| 6028 | case TARGET_SIG_UNBLOCK: |
| 6029 | how = SIG_UNBLOCK; |
| 6030 | break; |
| 6031 | case TARGET_SIG_SETMASK: |
| 6032 | how = SIG_SETMASK; |
| 6033 | break; |
| 6034 | default: |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 6035 | ret = -TARGET_EINVAL; |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6036 | goto fail; |
| 6037 | } |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6038 | if (!(p = lock_user(VERIFY_READ, arg2, sizeof(target_sigset_t), 1))) |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6039 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6040 | target_to_host_sigset(&set, p); |
| 6041 | unlock_user(p, arg2, 0); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6042 | set_ptr = &set; |
| 6043 | } else { |
| 6044 | how = 0; |
| 6045 | set_ptr = NULL; |
| 6046 | } |
| 6047 | ret = get_errno(sigprocmask(how, set_ptr, &oldset)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6048 | if (!is_error(ret) && arg3) { |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6049 | if (!(p = lock_user(VERIFY_WRITE, arg3, sizeof(target_sigset_t), 0))) |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6050 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6051 | host_to_target_sigset(p, &oldset); |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6052 | unlock_user(p, arg3, sizeof(target_sigset_t)); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6053 | } |
| 6054 | } |
| 6055 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6056 | #ifdef TARGET_NR_sigpending |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6057 | case TARGET_NR_sigpending: |
| 6058 | { |
| 6059 | sigset_t set; |
| 6060 | ret = get_errno(sigpending(&set)); |
| 6061 | if (!is_error(ret)) { |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6062 | if (!(p = lock_user(VERIFY_WRITE, arg1, sizeof(target_sigset_t), 0))) |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6063 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6064 | host_to_target_old_sigset(p, &set); |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6065 | unlock_user(p, arg1, sizeof(target_sigset_t)); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6066 | } |
| 6067 | } |
| 6068 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6069 | #endif |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6070 | case TARGET_NR_rt_sigpending: |
| 6071 | { |
| 6072 | sigset_t set; |
| 6073 | ret = get_errno(sigpending(&set)); |
| 6074 | if (!is_error(ret)) { |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6075 | if (!(p = lock_user(VERIFY_WRITE, arg1, sizeof(target_sigset_t), 0))) |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6076 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6077 | host_to_target_sigset(p, &set); |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6078 | unlock_user(p, arg1, sizeof(target_sigset_t)); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6079 | } |
| 6080 | } |
| 6081 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6082 | #ifdef TARGET_NR_sigsuspend |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6083 | case TARGET_NR_sigsuspend: |
| 6084 | { |
| 6085 | sigset_t set; |
Richard Henderson | f43ce12 | 2010-05-03 10:07:54 -0700 | [diff] [blame] | 6086 | #if defined(TARGET_ALPHA) |
| 6087 | abi_ulong mask = arg1; |
| 6088 | target_to_host_old_sigset(&set, &mask); |
| 6089 | #else |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6090 | if (!(p = lock_user(VERIFY_READ, arg1, sizeof(target_sigset_t), 1))) |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6091 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6092 | target_to_host_old_sigset(&set, p); |
| 6093 | unlock_user(p, arg1, 0); |
Richard Henderson | f43ce12 | 2010-05-03 10:07:54 -0700 | [diff] [blame] | 6094 | #endif |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6095 | ret = get_errno(sigsuspend(&set)); |
| 6096 | } |
| 6097 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6098 | #endif |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6099 | case TARGET_NR_rt_sigsuspend: |
| 6100 | { |
| 6101 | sigset_t set; |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6102 | if (!(p = lock_user(VERIFY_READ, arg1, sizeof(target_sigset_t), 1))) |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6103 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6104 | target_to_host_sigset(&set, p); |
| 6105 | unlock_user(p, arg1, 0); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6106 | ret = get_errno(sigsuspend(&set)); |
| 6107 | } |
| 6108 | break; |
| 6109 | case TARGET_NR_rt_sigtimedwait: |
| 6110 | { |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6111 | sigset_t set; |
| 6112 | struct timespec uts, *puts; |
| 6113 | siginfo_t uinfo; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 6114 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6115 | if (!(p = lock_user(VERIFY_READ, arg1, sizeof(target_sigset_t), 1))) |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6116 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6117 | target_to_host_sigset(&set, p); |
| 6118 | unlock_user(p, arg1, 0); |
| 6119 | if (arg3) { |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6120 | puts = &uts; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6121 | target_to_host_timespec(puts, arg3); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6122 | } else { |
| 6123 | puts = NULL; |
| 6124 | } |
| 6125 | ret = get_errno(sigtimedwait(&set, &uinfo, puts)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6126 | if (!is_error(ret) && arg2) { |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6127 | if (!(p = lock_user(VERIFY_WRITE, arg2, sizeof(target_siginfo_t), 0))) |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6128 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6129 | host_to_target_siginfo(p, &uinfo); |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6130 | unlock_user(p, arg2, sizeof(target_siginfo_t)); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6131 | } |
| 6132 | } |
| 6133 | break; |
| 6134 | case TARGET_NR_rt_sigqueueinfo: |
| 6135 | { |
| 6136 | siginfo_t uinfo; |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6137 | if (!(p = lock_user(VERIFY_READ, arg3, sizeof(target_sigset_t), 1))) |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6138 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6139 | target_to_host_siginfo(&uinfo, p); |
| 6140 | unlock_user(p, arg1, 0); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6141 | ret = get_errno(sys_rt_sigqueueinfo(arg1, arg2, &uinfo)); |
| 6142 | } |
| 6143 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6144 | #ifdef TARGET_NR_sigreturn |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6145 | case TARGET_NR_sigreturn: |
| 6146 | /* NOTE: ret is eax, so not transcoding must be done */ |
| 6147 | ret = do_sigreturn(cpu_env); |
| 6148 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6149 | #endif |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6150 | case TARGET_NR_rt_sigreturn: |
| 6151 | /* NOTE: ret is eax, so not transcoding must be done */ |
| 6152 | ret = do_rt_sigreturn(cpu_env); |
| 6153 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6154 | case TARGET_NR_sethostname: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6155 | if (!(p = lock_user_string(arg1))) |
| 6156 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6157 | ret = get_errno(sethostname(p, arg2)); |
| 6158 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6159 | break; |
| 6160 | case TARGET_NR_setrlimit: |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6161 | { |
Wesley W. Terpstra | e22b701 | 2011-07-12 14:42:00 +0300 | [diff] [blame] | 6162 | int resource = target_to_host_resource(arg1); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6163 | struct target_rlimit *target_rlim; |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6164 | struct rlimit rlim; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6165 | if (!lock_user_struct(VERIFY_READ, target_rlim, arg2, 1)) |
| 6166 | goto efault; |
takasi-y@ops.dti.ne.jp | 81bbe90 | 2010-04-12 04:07:35 +0900 | [diff] [blame] | 6167 | rlim.rlim_cur = target_to_host_rlim(target_rlim->rlim_cur); |
| 6168 | rlim.rlim_max = target_to_host_rlim(target_rlim->rlim_max); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6169 | unlock_user_struct(target_rlim, arg2, 0); |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6170 | ret = get_errno(setrlimit(resource, &rlim)); |
| 6171 | } |
| 6172 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6173 | case TARGET_NR_getrlimit: |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6174 | { |
Wesley W. Terpstra | e22b701 | 2011-07-12 14:42:00 +0300 | [diff] [blame] | 6175 | int resource = target_to_host_resource(arg1); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6176 | struct target_rlimit *target_rlim; |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6177 | struct rlimit rlim; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 6178 | |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6179 | ret = get_errno(getrlimit(resource, &rlim)); |
| 6180 | if (!is_error(ret)) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6181 | if (!lock_user_struct(VERIFY_WRITE, target_rlim, arg2, 0)) |
| 6182 | goto efault; |
takasi-y@ops.dti.ne.jp | 81bbe90 | 2010-04-12 04:07:35 +0900 | [diff] [blame] | 6183 | target_rlim->rlim_cur = host_to_target_rlim(rlim.rlim_cur); |
| 6184 | target_rlim->rlim_max = host_to_target_rlim(rlim.rlim_max); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6185 | unlock_user_struct(target_rlim, arg2, 1); |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6186 | } |
| 6187 | } |
| 6188 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6189 | case TARGET_NR_getrusage: |
bellard | b409186 | 2003-05-16 15:39:34 +0000 | [diff] [blame] | 6190 | { |
| 6191 | struct rusage rusage; |
bellard | b409186 | 2003-05-16 15:39:34 +0000 | [diff] [blame] | 6192 | ret = get_errno(getrusage(arg1, &rusage)); |
| 6193 | if (!is_error(ret)) { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6194 | host_to_target_rusage(arg2, &rusage); |
bellard | b409186 | 2003-05-16 15:39:34 +0000 | [diff] [blame] | 6195 | } |
| 6196 | } |
| 6197 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6198 | case TARGET_NR_gettimeofday: |
| 6199 | { |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6200 | struct timeval tv; |
| 6201 | ret = get_errno(gettimeofday(&tv, NULL)); |
| 6202 | if (!is_error(ret)) { |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 6203 | if (copy_to_user_timeval(arg1, &tv)) |
| 6204 | goto efault; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6205 | } |
| 6206 | } |
| 6207 | break; |
| 6208 | case TARGET_NR_settimeofday: |
| 6209 | { |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6210 | struct timeval tv; |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 6211 | if (copy_from_user_timeval(&tv, arg1)) |
| 6212 | goto efault; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6213 | ret = get_errno(settimeofday(&tv, NULL)); |
| 6214 | } |
| 6215 | break; |
Ulrich Hecht | a4c075f | 2009-07-24 16:57:31 +0200 | [diff] [blame] | 6216 | #if defined(TARGET_NR_select) && !defined(TARGET_S390X) && !defined(TARGET_S390) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6217 | case TARGET_NR_select: |
bellard | f2674e3 | 2003-07-09 12:26:09 +0000 | [diff] [blame] | 6218 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6219 | struct target_sel_arg_struct *sel; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 6220 | abi_ulong inp, outp, exp, tvp; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6221 | long nsel; |
| 6222 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6223 | if (!lock_user_struct(VERIFY_READ, sel, arg1, 1)) |
| 6224 | goto efault; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 6225 | nsel = tswapal(sel->n); |
| 6226 | inp = tswapal(sel->inp); |
| 6227 | outp = tswapal(sel->outp); |
| 6228 | exp = tswapal(sel->exp); |
| 6229 | tvp = tswapal(sel->tvp); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6230 | unlock_user_struct(sel, arg1, 0); |
| 6231 | ret = do_select(nsel, inp, outp, exp, tvp); |
bellard | f2674e3 | 2003-07-09 12:26:09 +0000 | [diff] [blame] | 6232 | } |
| 6233 | break; |
bellard | 048f6b4 | 2005-11-26 18:47:20 +0000 | [diff] [blame] | 6234 | #endif |
Riku Voipio | 9e42382 | 2010-05-07 12:28:05 +0000 | [diff] [blame] | 6235 | #ifdef TARGET_NR_pselect6 |
| 6236 | case TARGET_NR_pselect6: |
Mike Frysinger | 055e090 | 2011-06-03 17:01:49 -0400 | [diff] [blame] | 6237 | { |
| 6238 | abi_long rfd_addr, wfd_addr, efd_addr, n, ts_addr; |
| 6239 | fd_set rfds, wfds, efds; |
| 6240 | fd_set *rfds_ptr, *wfds_ptr, *efds_ptr; |
| 6241 | struct timespec ts, *ts_ptr; |
| 6242 | |
| 6243 | /* |
| 6244 | * The 6th arg is actually two args smashed together, |
| 6245 | * so we cannot use the C library. |
| 6246 | */ |
| 6247 | sigset_t set; |
| 6248 | struct { |
| 6249 | sigset_t *set; |
| 6250 | size_t size; |
| 6251 | } sig, *sig_ptr; |
| 6252 | |
| 6253 | abi_ulong arg_sigset, arg_sigsize, *arg7; |
| 6254 | target_sigset_t *target_sigset; |
| 6255 | |
| 6256 | n = arg1; |
| 6257 | rfd_addr = arg2; |
| 6258 | wfd_addr = arg3; |
| 6259 | efd_addr = arg4; |
| 6260 | ts_addr = arg5; |
| 6261 | |
| 6262 | ret = copy_from_user_fdset_ptr(&rfds, &rfds_ptr, rfd_addr, n); |
| 6263 | if (ret) { |
| 6264 | goto fail; |
| 6265 | } |
| 6266 | ret = copy_from_user_fdset_ptr(&wfds, &wfds_ptr, wfd_addr, n); |
| 6267 | if (ret) { |
| 6268 | goto fail; |
| 6269 | } |
| 6270 | ret = copy_from_user_fdset_ptr(&efds, &efds_ptr, efd_addr, n); |
| 6271 | if (ret) { |
| 6272 | goto fail; |
| 6273 | } |
| 6274 | |
| 6275 | /* |
| 6276 | * This takes a timespec, and not a timeval, so we cannot |
| 6277 | * use the do_select() helper ... |
| 6278 | */ |
| 6279 | if (ts_addr) { |
| 6280 | if (target_to_host_timespec(&ts, ts_addr)) { |
| 6281 | goto efault; |
| 6282 | } |
| 6283 | ts_ptr = &ts; |
| 6284 | } else { |
| 6285 | ts_ptr = NULL; |
| 6286 | } |
| 6287 | |
| 6288 | /* Extract the two packed args for the sigset */ |
| 6289 | if (arg6) { |
| 6290 | sig_ptr = &sig; |
| 6291 | sig.size = _NSIG / 8; |
| 6292 | |
| 6293 | arg7 = lock_user(VERIFY_READ, arg6, sizeof(*arg7) * 2, 1); |
| 6294 | if (!arg7) { |
| 6295 | goto efault; |
| 6296 | } |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 6297 | arg_sigset = tswapal(arg7[0]); |
| 6298 | arg_sigsize = tswapal(arg7[1]); |
Mike Frysinger | 055e090 | 2011-06-03 17:01:49 -0400 | [diff] [blame] | 6299 | unlock_user(arg7, arg6, 0); |
| 6300 | |
| 6301 | if (arg_sigset) { |
| 6302 | sig.set = &set; |
Peter Maydell | 8f04eeb | 2011-06-28 12:21:57 +0100 | [diff] [blame] | 6303 | if (arg_sigsize != sizeof(*target_sigset)) { |
| 6304 | /* Like the kernel, we enforce correct size sigsets */ |
| 6305 | ret = -TARGET_EINVAL; |
| 6306 | goto fail; |
| 6307 | } |
Mike Frysinger | 055e090 | 2011-06-03 17:01:49 -0400 | [diff] [blame] | 6308 | target_sigset = lock_user(VERIFY_READ, arg_sigset, |
| 6309 | sizeof(*target_sigset), 1); |
| 6310 | if (!target_sigset) { |
| 6311 | goto efault; |
| 6312 | } |
| 6313 | target_to_host_sigset(&set, target_sigset); |
| 6314 | unlock_user(target_sigset, arg_sigset, 0); |
| 6315 | } else { |
| 6316 | sig.set = NULL; |
| 6317 | } |
| 6318 | } else { |
| 6319 | sig_ptr = NULL; |
| 6320 | } |
| 6321 | |
| 6322 | ret = get_errno(sys_pselect6(n, rfds_ptr, wfds_ptr, efds_ptr, |
| 6323 | ts_ptr, sig_ptr)); |
| 6324 | |
| 6325 | if (!is_error(ret)) { |
| 6326 | if (rfd_addr && copy_to_user_fdset(rfd_addr, &rfds, n)) |
| 6327 | goto efault; |
| 6328 | if (wfd_addr && copy_to_user_fdset(wfd_addr, &wfds, n)) |
| 6329 | goto efault; |
| 6330 | if (efd_addr && copy_to_user_fdset(efd_addr, &efds, n)) |
| 6331 | goto efault; |
| 6332 | |
| 6333 | if (ts_addr && host_to_target_timespec(ts_addr, &ts)) |
| 6334 | goto efault; |
| 6335 | } |
| 6336 | } |
| 6337 | break; |
Riku Voipio | 9e42382 | 2010-05-07 12:28:05 +0000 | [diff] [blame] | 6338 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6339 | case TARGET_NR_symlink: |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6340 | { |
| 6341 | void *p2; |
| 6342 | p = lock_user_string(arg1); |
| 6343 | p2 = lock_user_string(arg2); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6344 | if (!p || !p2) |
| 6345 | ret = -TARGET_EFAULT; |
| 6346 | else |
| 6347 | ret = get_errno(symlink(p, p2)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6348 | unlock_user(p2, arg2, 0); |
| 6349 | unlock_user(p, arg1, 0); |
| 6350 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6351 | break; |
ths | f0b6243 | 2007-09-24 09:25:40 +0000 | [diff] [blame] | 6352 | #if defined(TARGET_NR_symlinkat) && defined(__NR_symlinkat) |
| 6353 | case TARGET_NR_symlinkat: |
ths | f0b6243 | 2007-09-24 09:25:40 +0000 | [diff] [blame] | 6354 | { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6355 | void *p2; |
ths | f0b6243 | 2007-09-24 09:25:40 +0000 | [diff] [blame] | 6356 | p = lock_user_string(arg1); |
| 6357 | p2 = lock_user_string(arg3); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6358 | if (!p || !p2) |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 6359 | ret = -TARGET_EFAULT; |
ths | f0b6243 | 2007-09-24 09:25:40 +0000 | [diff] [blame] | 6360 | else |
| 6361 | ret = get_errno(sys_symlinkat(p, arg2, p2)); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6362 | unlock_user(p2, arg3, 0); |
| 6363 | unlock_user(p, arg1, 0); |
ths | f0b6243 | 2007-09-24 09:25:40 +0000 | [diff] [blame] | 6364 | } |
| 6365 | break; |
| 6366 | #endif |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6367 | #ifdef TARGET_NR_oldlstat |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6368 | case TARGET_NR_oldlstat: |
| 6369 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6370 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6371 | case TARGET_NR_readlink: |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6372 | { |
aurel32 | d088d66 | 2009-01-30 20:09:01 +0000 | [diff] [blame] | 6373 | void *p2, *temp; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6374 | p = lock_user_string(arg1); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6375 | p2 = lock_user(VERIFY_WRITE, arg2, arg3, 0); |
| 6376 | if (!p || !p2) |
| 6377 | ret = -TARGET_EFAULT; |
aurel32 | d088d66 | 2009-01-30 20:09:01 +0000 | [diff] [blame] | 6378 | else { |
| 6379 | if (strncmp((const char *)p, "/proc/self/exe", 14) == 0) { |
| 6380 | char real[PATH_MAX]; |
| 6381 | temp = realpath(exec_path,real); |
| 6382 | ret = (temp==NULL) ? get_errno(-1) : strlen(real) ; |
| 6383 | snprintf((char *)p2, arg3, "%s", real); |
| 6384 | } |
| 6385 | else |
| 6386 | ret = get_errno(readlink(path(p), p2, arg3)); |
aurel32 | d088d66 | 2009-01-30 20:09:01 +0000 | [diff] [blame] | 6387 | } |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6388 | unlock_user(p2, arg2, ret); |
| 6389 | unlock_user(p, arg1, 0); |
| 6390 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6391 | break; |
ths | 5e0ccb1 | 2007-09-24 09:26:10 +0000 | [diff] [blame] | 6392 | #if defined(TARGET_NR_readlinkat) && defined(__NR_readlinkat) |
| 6393 | case TARGET_NR_readlinkat: |
ths | 5e0ccb1 | 2007-09-24 09:26:10 +0000 | [diff] [blame] | 6394 | { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6395 | void *p2; |
ths | 5e0ccb1 | 2007-09-24 09:26:10 +0000 | [diff] [blame] | 6396 | p = lock_user_string(arg2); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6397 | p2 = lock_user(VERIFY_WRITE, arg3, arg4, 0); |
| 6398 | if (!p || !p2) |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 6399 | ret = -TARGET_EFAULT; |
ths | 5e0ccb1 | 2007-09-24 09:26:10 +0000 | [diff] [blame] | 6400 | else |
| 6401 | ret = get_errno(sys_readlinkat(arg1, path(p), p2, arg4)); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6402 | unlock_user(p2, arg3, ret); |
| 6403 | unlock_user(p, arg2, 0); |
ths | 5e0ccb1 | 2007-09-24 09:26:10 +0000 | [diff] [blame] | 6404 | } |
| 6405 | break; |
| 6406 | #endif |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6407 | #ifdef TARGET_NR_uselib |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6408 | case TARGET_NR_uselib: |
| 6409 | goto unimplemented; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6410 | #endif |
| 6411 | #ifdef TARGET_NR_swapon |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6412 | case TARGET_NR_swapon: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6413 | if (!(p = lock_user_string(arg1))) |
| 6414 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6415 | ret = get_errno(swapon(p, arg2)); |
| 6416 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6417 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6418 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6419 | case TARGET_NR_reboot: |
Alexander Graf | 0f6b4d2 | 2011-09-27 14:39:42 +0200 | [diff] [blame] | 6420 | if (!(p = lock_user_string(arg4))) |
| 6421 | goto efault; |
| 6422 | ret = reboot(arg1, arg2, arg3, p); |
| 6423 | unlock_user(p, arg4, 0); |
| 6424 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6425 | #ifdef TARGET_NR_readdir |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6426 | case TARGET_NR_readdir: |
| 6427 | goto unimplemented; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6428 | #endif |
| 6429 | #ifdef TARGET_NR_mmap |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6430 | case TARGET_NR_mmap: |
Ulrich Hecht | a4c075f | 2009-07-24 16:57:31 +0200 | [diff] [blame] | 6431 | #if (defined(TARGET_I386) && defined(TARGET_ABI32)) || defined(TARGET_ARM) || \ |
| 6432 | defined(TARGET_M68K) || defined(TARGET_CRIS) || defined(TARGET_MICROBLAZE) \ |
| 6433 | || defined(TARGET_S390X) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6434 | { |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 6435 | abi_ulong *v; |
| 6436 | abi_ulong v1, v2, v3, v4, v5, v6; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6437 | if (!(v = lock_user(VERIFY_READ, arg1, 6 * sizeof(abi_ulong), 1))) |
| 6438 | goto efault; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 6439 | v1 = tswapal(v[0]); |
| 6440 | v2 = tswapal(v[1]); |
| 6441 | v3 = tswapal(v[2]); |
| 6442 | v4 = tswapal(v[3]); |
| 6443 | v5 = tswapal(v[4]); |
| 6444 | v6 = tswapal(v[5]); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6445 | unlock_user(v, arg1, 0); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 6446 | ret = get_errno(target_mmap(v1, v2, v3, |
bellard | 5286db7 | 2003-06-05 00:57:30 +0000 | [diff] [blame] | 6447 | target_to_host_bitmask(v4, mmap_flags_tbl), |
| 6448 | v5, v6)); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6449 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6450 | #else |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 6451 | ret = get_errno(target_mmap(arg1, arg2, arg3, |
| 6452 | target_to_host_bitmask(arg4, mmap_flags_tbl), |
bellard | 6fb883e | 2003-07-09 17:12:39 +0000 | [diff] [blame] | 6453 | arg5, |
| 6454 | arg6)); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6455 | #endif |
bellard | 6fb883e | 2003-07-09 17:12:39 +0000 | [diff] [blame] | 6456 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6457 | #endif |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 6458 | #ifdef TARGET_NR_mmap2 |
bellard | 6fb883e | 2003-07-09 17:12:39 +0000 | [diff] [blame] | 6459 | case TARGET_NR_mmap2: |
pbrook | bb7ec04 | 2008-03-25 22:28:25 +0000 | [diff] [blame] | 6460 | #ifndef MMAP_SHIFT |
bellard | c573ff6 | 2004-01-04 15:51:36 +0000 | [diff] [blame] | 6461 | #define MMAP_SHIFT 12 |
bellard | c573ff6 | 2004-01-04 15:51:36 +0000 | [diff] [blame] | 6462 | #endif |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 6463 | ret = get_errno(target_mmap(arg1, arg2, arg3, |
| 6464 | target_to_host_bitmask(arg4, mmap_flags_tbl), |
bellard | 5286db7 | 2003-06-05 00:57:30 +0000 | [diff] [blame] | 6465 | arg5, |
bellard | c573ff6 | 2004-01-04 15:51:36 +0000 | [diff] [blame] | 6466 | arg6 << MMAP_SHIFT)); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6467 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 6468 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6469 | case TARGET_NR_munmap: |
bellard | 5493600 | 2003-05-13 00:25:15 +0000 | [diff] [blame] | 6470 | ret = get_errno(target_munmap(arg1, arg2)); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6471 | break; |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6472 | case TARGET_NR_mprotect: |
Paul Brook | 97374d3 | 2010-06-16 13:03:51 +0100 | [diff] [blame] | 6473 | { |
Andreas Färber | 9349b4f | 2012-03-14 01:38:32 +0100 | [diff] [blame] | 6474 | TaskState *ts = ((CPUArchState *)cpu_env)->opaque; |
Paul Brook | 97374d3 | 2010-06-16 13:03:51 +0100 | [diff] [blame] | 6475 | /* Special hack to detect libc making the stack executable. */ |
| 6476 | if ((arg3 & PROT_GROWSDOWN) |
| 6477 | && arg1 >= ts->info->stack_limit |
| 6478 | && arg1 <= ts->info->start_stack) { |
| 6479 | arg3 &= ~PROT_GROWSDOWN; |
| 6480 | arg2 = arg2 + arg1 - ts->info->stack_limit; |
| 6481 | arg1 = ts->info->stack_limit; |
| 6482 | } |
| 6483 | } |
bellard | 5493600 | 2003-05-13 00:25:15 +0000 | [diff] [blame] | 6484 | ret = get_errno(target_mprotect(arg1, arg2, arg3)); |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6485 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6486 | #ifdef TARGET_NR_mremap |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6487 | case TARGET_NR_mremap: |
bellard | 5493600 | 2003-05-13 00:25:15 +0000 | [diff] [blame] | 6488 | ret = get_errno(target_mremap(arg1, arg2, arg3, arg4, arg5)); |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6489 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6490 | #endif |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6491 | /* ??? msync/mlock/munlock are broken for softmmu. */ |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6492 | #ifdef TARGET_NR_msync |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6493 | case TARGET_NR_msync: |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6494 | ret = get_errno(msync(g2h(arg1), arg2, arg3)); |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6495 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6496 | #endif |
| 6497 | #ifdef TARGET_NR_mlock |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6498 | case TARGET_NR_mlock: |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6499 | ret = get_errno(mlock(g2h(arg1), arg2)); |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6500 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6501 | #endif |
| 6502 | #ifdef TARGET_NR_munlock |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6503 | case TARGET_NR_munlock: |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6504 | ret = get_errno(munlock(g2h(arg1), arg2)); |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6505 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6506 | #endif |
| 6507 | #ifdef TARGET_NR_mlockall |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6508 | case TARGET_NR_mlockall: |
| 6509 | ret = get_errno(mlockall(arg1)); |
| 6510 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6511 | #endif |
| 6512 | #ifdef TARGET_NR_munlockall |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6513 | case TARGET_NR_munlockall: |
| 6514 | ret = get_errno(munlockall()); |
| 6515 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6516 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6517 | case TARGET_NR_truncate: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6518 | if (!(p = lock_user_string(arg1))) |
| 6519 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6520 | ret = get_errno(truncate(p, arg2)); |
| 6521 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6522 | break; |
| 6523 | case TARGET_NR_ftruncate: |
| 6524 | ret = get_errno(ftruncate(arg1, arg2)); |
| 6525 | break; |
| 6526 | case TARGET_NR_fchmod: |
| 6527 | ret = get_errno(fchmod(arg1, arg2)); |
| 6528 | break; |
ths | 814d797 | 2007-09-24 09:26:51 +0000 | [diff] [blame] | 6529 | #if defined(TARGET_NR_fchmodat) && defined(__NR_fchmodat) |
| 6530 | case TARGET_NR_fchmodat: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6531 | if (!(p = lock_user_string(arg2))) |
| 6532 | goto efault; |
aurel32 | 465c9f0 | 2009-04-19 08:52:17 +0000 | [diff] [blame] | 6533 | ret = get_errno(sys_fchmodat(arg1, p, arg3)); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6534 | unlock_user(p, arg2, 0); |
ths | 814d797 | 2007-09-24 09:26:51 +0000 | [diff] [blame] | 6535 | break; |
| 6536 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6537 | case TARGET_NR_getpriority: |
Richard Henderson | 95c0982 | 2012-06-07 15:14:50 -0700 | [diff] [blame] | 6538 | /* Note that negative values are valid for getpriority, so we must |
| 6539 | differentiate based on errno settings. */ |
| 6540 | errno = 0; |
| 6541 | ret = getpriority(arg1, arg2); |
| 6542 | if (ret == -1 && errno != 0) { |
| 6543 | ret = -host_to_target_errno(errno); |
| 6544 | break; |
| 6545 | } |
| 6546 | #ifdef TARGET_ALPHA |
| 6547 | /* Return value is the unbiased priority. Signal no error. */ |
| 6548 | ((CPUAlphaState *)cpu_env)->ir[IR_V0] = 0; |
| 6549 | #else |
| 6550 | /* Return value is a biased priority to avoid negative numbers. */ |
| 6551 | ret = 20 - ret; |
| 6552 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6553 | break; |
| 6554 | case TARGET_NR_setpriority: |
| 6555 | ret = get_errno(setpriority(arg1, arg2, arg3)); |
| 6556 | break; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6557 | #ifdef TARGET_NR_profil |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6558 | case TARGET_NR_profil: |
| 6559 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6560 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6561 | case TARGET_NR_statfs: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6562 | if (!(p = lock_user_string(arg1))) |
| 6563 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6564 | ret = get_errno(statfs(path(p), &stfs)); |
| 6565 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6566 | convert_statfs: |
| 6567 | if (!is_error(ret)) { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6568 | struct target_statfs *target_stfs; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 6569 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6570 | if (!lock_user_struct(VERIFY_WRITE, target_stfs, arg2, 0)) |
| 6571 | goto efault; |
| 6572 | __put_user(stfs.f_type, &target_stfs->f_type); |
| 6573 | __put_user(stfs.f_bsize, &target_stfs->f_bsize); |
| 6574 | __put_user(stfs.f_blocks, &target_stfs->f_blocks); |
| 6575 | __put_user(stfs.f_bfree, &target_stfs->f_bfree); |
| 6576 | __put_user(stfs.f_bavail, &target_stfs->f_bavail); |
| 6577 | __put_user(stfs.f_files, &target_stfs->f_files); |
| 6578 | __put_user(stfs.f_ffree, &target_stfs->f_ffree); |
| 6579 | __put_user(stfs.f_fsid.__val[0], &target_stfs->f_fsid.val[0]); |
| 6580 | __put_user(stfs.f_fsid.__val[1], &target_stfs->f_fsid.val[1]); |
| 6581 | __put_user(stfs.f_namelen, &target_stfs->f_namelen); |
Alexander Graf | 229d337 | 2012-09-19 04:39:53 +0200 | [diff] [blame] | 6582 | __put_user(stfs.f_frsize, &target_stfs->f_frsize); |
| 6583 | memset(target_stfs->f_spare, 0, sizeof(target_stfs->f_spare)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6584 | unlock_user_struct(target_stfs, arg2, 1); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6585 | } |
| 6586 | break; |
| 6587 | case TARGET_NR_fstatfs: |
bellard | 56c8f68 | 2005-11-28 22:28:41 +0000 | [diff] [blame] | 6588 | ret = get_errno(fstatfs(arg1, &stfs)); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6589 | goto convert_statfs; |
bellard | 56c8f68 | 2005-11-28 22:28:41 +0000 | [diff] [blame] | 6590 | #ifdef TARGET_NR_statfs64 |
| 6591 | case TARGET_NR_statfs64: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6592 | if (!(p = lock_user_string(arg1))) |
| 6593 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6594 | ret = get_errno(statfs(path(p), &stfs)); |
| 6595 | unlock_user(p, arg1, 0); |
bellard | 56c8f68 | 2005-11-28 22:28:41 +0000 | [diff] [blame] | 6596 | convert_statfs64: |
| 6597 | if (!is_error(ret)) { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6598 | struct target_statfs64 *target_stfs; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 6599 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6600 | if (!lock_user_struct(VERIFY_WRITE, target_stfs, arg3, 0)) |
| 6601 | goto efault; |
| 6602 | __put_user(stfs.f_type, &target_stfs->f_type); |
| 6603 | __put_user(stfs.f_bsize, &target_stfs->f_bsize); |
| 6604 | __put_user(stfs.f_blocks, &target_stfs->f_blocks); |
| 6605 | __put_user(stfs.f_bfree, &target_stfs->f_bfree); |
| 6606 | __put_user(stfs.f_bavail, &target_stfs->f_bavail); |
| 6607 | __put_user(stfs.f_files, &target_stfs->f_files); |
| 6608 | __put_user(stfs.f_ffree, &target_stfs->f_ffree); |
| 6609 | __put_user(stfs.f_fsid.__val[0], &target_stfs->f_fsid.val[0]); |
| 6610 | __put_user(stfs.f_fsid.__val[1], &target_stfs->f_fsid.val[1]); |
| 6611 | __put_user(stfs.f_namelen, &target_stfs->f_namelen); |
Alexander Graf | 229d337 | 2012-09-19 04:39:53 +0200 | [diff] [blame] | 6612 | __put_user(stfs.f_frsize, &target_stfs->f_frsize); |
| 6613 | memset(target_stfs->f_spare, 0, sizeof(target_stfs->f_spare)); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6614 | unlock_user_struct(target_stfs, arg3, 1); |
bellard | 56c8f68 | 2005-11-28 22:28:41 +0000 | [diff] [blame] | 6615 | } |
| 6616 | break; |
| 6617 | case TARGET_NR_fstatfs64: |
| 6618 | ret = get_errno(fstatfs(arg1, &stfs)); |
| 6619 | goto convert_statfs64; |
| 6620 | #endif |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6621 | #ifdef TARGET_NR_ioperm |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6622 | case TARGET_NR_ioperm: |
| 6623 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6624 | #endif |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6625 | #ifdef TARGET_NR_socketcall |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6626 | case TARGET_NR_socketcall: |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6627 | ret = do_socketcall(arg1, arg2); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6628 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6629 | #endif |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 6630 | #ifdef TARGET_NR_accept |
| 6631 | case TARGET_NR_accept: |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 6632 | ret = do_accept(arg1, arg2, arg3); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 6633 | break; |
| 6634 | #endif |
| 6635 | #ifdef TARGET_NR_bind |
| 6636 | case TARGET_NR_bind: |
| 6637 | ret = do_bind(arg1, arg2, arg3); |
| 6638 | break; |
| 6639 | #endif |
| 6640 | #ifdef TARGET_NR_connect |
| 6641 | case TARGET_NR_connect: |
| 6642 | ret = do_connect(arg1, arg2, arg3); |
| 6643 | break; |
| 6644 | #endif |
| 6645 | #ifdef TARGET_NR_getpeername |
| 6646 | case TARGET_NR_getpeername: |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 6647 | ret = do_getpeername(arg1, arg2, arg3); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 6648 | break; |
| 6649 | #endif |
| 6650 | #ifdef TARGET_NR_getsockname |
| 6651 | case TARGET_NR_getsockname: |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 6652 | ret = do_getsockname(arg1, arg2, arg3); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 6653 | break; |
| 6654 | #endif |
| 6655 | #ifdef TARGET_NR_getsockopt |
| 6656 | case TARGET_NR_getsockopt: |
| 6657 | ret = do_getsockopt(arg1, arg2, arg3, arg4, arg5); |
| 6658 | break; |
| 6659 | #endif |
| 6660 | #ifdef TARGET_NR_listen |
| 6661 | case TARGET_NR_listen: |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 6662 | ret = get_errno(listen(arg1, arg2)); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 6663 | break; |
| 6664 | #endif |
| 6665 | #ifdef TARGET_NR_recv |
| 6666 | case TARGET_NR_recv: |
pbrook | 214201b | 2007-03-17 01:27:24 +0000 | [diff] [blame] | 6667 | ret = do_recvfrom(arg1, arg2, arg3, arg4, 0, 0); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 6668 | break; |
| 6669 | #endif |
| 6670 | #ifdef TARGET_NR_recvfrom |
| 6671 | case TARGET_NR_recvfrom: |
pbrook | 214201b | 2007-03-17 01:27:24 +0000 | [diff] [blame] | 6672 | ret = do_recvfrom(arg1, arg2, arg3, arg4, arg5, arg6); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 6673 | break; |
| 6674 | #endif |
| 6675 | #ifdef TARGET_NR_recvmsg |
| 6676 | case TARGET_NR_recvmsg: |
| 6677 | ret = do_sendrecvmsg(arg1, arg2, arg3, 0); |
| 6678 | break; |
| 6679 | #endif |
| 6680 | #ifdef TARGET_NR_send |
| 6681 | case TARGET_NR_send: |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 6682 | ret = do_sendto(arg1, arg2, arg3, arg4, 0, 0); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 6683 | break; |
| 6684 | #endif |
| 6685 | #ifdef TARGET_NR_sendmsg |
| 6686 | case TARGET_NR_sendmsg: |
| 6687 | ret = do_sendrecvmsg(arg1, arg2, arg3, 1); |
| 6688 | break; |
| 6689 | #endif |
| 6690 | #ifdef TARGET_NR_sendto |
| 6691 | case TARGET_NR_sendto: |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 6692 | ret = do_sendto(arg1, arg2, arg3, arg4, arg5, arg6); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 6693 | break; |
| 6694 | #endif |
| 6695 | #ifdef TARGET_NR_shutdown |
| 6696 | case TARGET_NR_shutdown: |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 6697 | ret = get_errno(shutdown(arg1, arg2)); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 6698 | break; |
| 6699 | #endif |
| 6700 | #ifdef TARGET_NR_socket |
| 6701 | case TARGET_NR_socket: |
| 6702 | ret = do_socket(arg1, arg2, arg3); |
| 6703 | break; |
| 6704 | #endif |
| 6705 | #ifdef TARGET_NR_socketpair |
| 6706 | case TARGET_NR_socketpair: |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 6707 | ret = do_socketpair(arg1, arg2, arg3, arg4); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 6708 | break; |
| 6709 | #endif |
| 6710 | #ifdef TARGET_NR_setsockopt |
| 6711 | case TARGET_NR_setsockopt: |
| 6712 | ret = do_setsockopt(arg1, arg2, arg3, arg4, (socklen_t) arg5); |
| 6713 | break; |
| 6714 | #endif |
ths | 7494b0f | 2007-02-11 18:26:53 +0000 | [diff] [blame] | 6715 | |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6716 | case TARGET_NR_syslog: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6717 | if (!(p = lock_user_string(arg2))) |
| 6718 | goto efault; |
ths | e557448 | 2007-02-11 20:03:13 +0000 | [diff] [blame] | 6719 | ret = get_errno(sys_syslog((int)arg1, p, (int)arg3)); |
| 6720 | unlock_user(p, arg2, 0); |
ths | 7494b0f | 2007-02-11 18:26:53 +0000 | [diff] [blame] | 6721 | break; |
| 6722 | |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6723 | case TARGET_NR_setitimer: |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6724 | { |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6725 | struct itimerval value, ovalue, *pvalue; |
| 6726 | |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6727 | if (arg2) { |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6728 | pvalue = &value; |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 6729 | if (copy_from_user_timeval(&pvalue->it_interval, arg2) |
| 6730 | || copy_from_user_timeval(&pvalue->it_value, |
| 6731 | arg2 + sizeof(struct target_timeval))) |
| 6732 | goto efault; |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6733 | } else { |
| 6734 | pvalue = NULL; |
| 6735 | } |
| 6736 | ret = get_errno(setitimer(arg1, pvalue, &ovalue)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6737 | if (!is_error(ret) && arg3) { |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 6738 | if (copy_to_user_timeval(arg3, |
| 6739 | &ovalue.it_interval) |
| 6740 | || copy_to_user_timeval(arg3 + sizeof(struct target_timeval), |
| 6741 | &ovalue.it_value)) |
| 6742 | goto efault; |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6743 | } |
| 6744 | } |
| 6745 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6746 | case TARGET_NR_getitimer: |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6747 | { |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6748 | struct itimerval value; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 6749 | |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6750 | ret = get_errno(getitimer(arg1, &value)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6751 | if (!is_error(ret) && arg2) { |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 6752 | if (copy_to_user_timeval(arg2, |
| 6753 | &value.it_interval) |
| 6754 | || copy_to_user_timeval(arg2 + sizeof(struct target_timeval), |
| 6755 | &value.it_value)) |
| 6756 | goto efault; |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6757 | } |
| 6758 | } |
| 6759 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6760 | case TARGET_NR_stat: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6761 | if (!(p = lock_user_string(arg1))) |
| 6762 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6763 | ret = get_errno(stat(path(p), &st)); |
| 6764 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6765 | goto do_stat; |
| 6766 | case TARGET_NR_lstat: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6767 | if (!(p = lock_user_string(arg1))) |
| 6768 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6769 | ret = get_errno(lstat(path(p), &st)); |
| 6770 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6771 | goto do_stat; |
| 6772 | case TARGET_NR_fstat: |
| 6773 | { |
| 6774 | ret = get_errno(fstat(arg1, &st)); |
| 6775 | do_stat: |
| 6776 | if (!is_error(ret)) { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6777 | struct target_stat *target_st; |
ths | e358465 | 2007-06-01 11:49:38 +0000 | [diff] [blame] | 6778 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6779 | if (!lock_user_struct(VERIFY_WRITE, target_st, arg2, 0)) |
| 6780 | goto efault; |
Ulrich Hecht | 1272791 | 2009-07-24 19:10:32 +0200 | [diff] [blame] | 6781 | memset(target_st, 0, sizeof(*target_st)); |
bellard | d2fd1af | 2007-11-14 18:08:56 +0000 | [diff] [blame] | 6782 | __put_user(st.st_dev, &target_st->st_dev); |
| 6783 | __put_user(st.st_ino, &target_st->st_ino); |
| 6784 | __put_user(st.st_mode, &target_st->st_mode); |
| 6785 | __put_user(st.st_uid, &target_st->st_uid); |
| 6786 | __put_user(st.st_gid, &target_st->st_gid); |
| 6787 | __put_user(st.st_nlink, &target_st->st_nlink); |
| 6788 | __put_user(st.st_rdev, &target_st->st_rdev); |
| 6789 | __put_user(st.st_size, &target_st->st_size); |
| 6790 | __put_user(st.st_blksize, &target_st->st_blksize); |
| 6791 | __put_user(st.st_blocks, &target_st->st_blocks); |
| 6792 | __put_user(st.st_atime, &target_st->target_st_atime); |
| 6793 | __put_user(st.st_mtime, &target_st->target_st_mtime); |
| 6794 | __put_user(st.st_ctime, &target_st->target_st_ctime); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6795 | unlock_user_struct(target_st, arg2, 1); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6796 | } |
| 6797 | } |
| 6798 | break; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6799 | #ifdef TARGET_NR_olduname |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6800 | case TARGET_NR_olduname: |
| 6801 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6802 | #endif |
| 6803 | #ifdef TARGET_NR_iopl |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6804 | case TARGET_NR_iopl: |
| 6805 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6806 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6807 | case TARGET_NR_vhangup: |
| 6808 | ret = get_errno(vhangup()); |
| 6809 | break; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6810 | #ifdef TARGET_NR_idle |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6811 | case TARGET_NR_idle: |
| 6812 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6813 | #endif |
bellard | 42ad6ae | 2005-01-03 22:48:11 +0000 | [diff] [blame] | 6814 | #ifdef TARGET_NR_syscall |
| 6815 | case TARGET_NR_syscall: |
Peter Maydell | 5945cfc | 2011-06-16 17:37:13 +0100 | [diff] [blame] | 6816 | ret = do_syscall(cpu_env, arg1 & 0xffff, arg2, arg3, arg4, arg5, |
| 6817 | arg6, arg7, arg8, 0); |
| 6818 | break; |
bellard | 42ad6ae | 2005-01-03 22:48:11 +0000 | [diff] [blame] | 6819 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6820 | case TARGET_NR_wait4: |
| 6821 | { |
| 6822 | int status; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 6823 | abi_long status_ptr = arg2; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6824 | struct rusage rusage, *rusage_ptr; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 6825 | abi_ulong target_rusage = arg4; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6826 | if (target_rusage) |
| 6827 | rusage_ptr = &rusage; |
| 6828 | else |
| 6829 | rusage_ptr = NULL; |
| 6830 | ret = get_errno(wait4(arg1, &status, arg3, rusage_ptr)); |
| 6831 | if (!is_error(ret)) { |
Alexander Graf | 5379557 | 2011-11-24 00:44:43 +0100 | [diff] [blame] | 6832 | if (status_ptr && ret) { |
pbrook | 1d9d8b5 | 2009-04-16 15:17:02 +0000 | [diff] [blame] | 6833 | status = host_to_target_waitstatus(status); |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 6834 | if (put_user_s32(status, status_ptr)) |
| 6835 | goto efault; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6836 | } |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 6837 | if (target_rusage) |
| 6838 | host_to_target_rusage(target_rusage, &rusage); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6839 | } |
| 6840 | } |
| 6841 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6842 | #ifdef TARGET_NR_swapoff |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6843 | case TARGET_NR_swapoff: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6844 | if (!(p = lock_user_string(arg1))) |
| 6845 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6846 | ret = get_errno(swapoff(p)); |
| 6847 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6848 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6849 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6850 | case TARGET_NR_sysinfo: |
bellard | a5448a7 | 2004-06-19 16:59:03 +0000 | [diff] [blame] | 6851 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6852 | struct target_sysinfo *target_value; |
bellard | a5448a7 | 2004-06-19 16:59:03 +0000 | [diff] [blame] | 6853 | struct sysinfo value; |
| 6854 | ret = get_errno(sysinfo(&value)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6855 | if (!is_error(ret) && arg1) |
bellard | a5448a7 | 2004-06-19 16:59:03 +0000 | [diff] [blame] | 6856 | { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6857 | if (!lock_user_struct(VERIFY_WRITE, target_value, arg1, 0)) |
| 6858 | goto efault; |
bellard | a5448a7 | 2004-06-19 16:59:03 +0000 | [diff] [blame] | 6859 | __put_user(value.uptime, &target_value->uptime); |
| 6860 | __put_user(value.loads[0], &target_value->loads[0]); |
| 6861 | __put_user(value.loads[1], &target_value->loads[1]); |
| 6862 | __put_user(value.loads[2], &target_value->loads[2]); |
| 6863 | __put_user(value.totalram, &target_value->totalram); |
| 6864 | __put_user(value.freeram, &target_value->freeram); |
| 6865 | __put_user(value.sharedram, &target_value->sharedram); |
| 6866 | __put_user(value.bufferram, &target_value->bufferram); |
| 6867 | __put_user(value.totalswap, &target_value->totalswap); |
| 6868 | __put_user(value.freeswap, &target_value->freeswap); |
| 6869 | __put_user(value.procs, &target_value->procs); |
| 6870 | __put_user(value.totalhigh, &target_value->totalhigh); |
| 6871 | __put_user(value.freehigh, &target_value->freehigh); |
| 6872 | __put_user(value.mem_unit, &target_value->mem_unit); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6873 | unlock_user_struct(target_value, arg1, 1); |
bellard | a5448a7 | 2004-06-19 16:59:03 +0000 | [diff] [blame] | 6874 | } |
| 6875 | } |
| 6876 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6877 | #ifdef TARGET_NR_ipc |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6878 | case TARGET_NR_ipc: |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 6879 | ret = do_ipc(arg1, arg2, arg3, arg4, arg5, arg6); |
| 6880 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6881 | #endif |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 6882 | #ifdef TARGET_NR_semget |
| 6883 | case TARGET_NR_semget: |
| 6884 | ret = get_errno(semget(arg1, arg2, arg3)); |
| 6885 | break; |
| 6886 | #endif |
| 6887 | #ifdef TARGET_NR_semop |
| 6888 | case TARGET_NR_semop: |
| 6889 | ret = get_errno(do_semop(arg1, arg2, arg3)); |
| 6890 | break; |
| 6891 | #endif |
| 6892 | #ifdef TARGET_NR_semctl |
| 6893 | case TARGET_NR_semctl: |
| 6894 | ret = do_semctl(arg1, arg2, arg3, (union target_semun)(abi_ulong)arg4); |
| 6895 | break; |
| 6896 | #endif |
aurel32 | eeb438c | 2008-10-13 21:08:55 +0000 | [diff] [blame] | 6897 | #ifdef TARGET_NR_msgctl |
| 6898 | case TARGET_NR_msgctl: |
| 6899 | ret = do_msgctl(arg1, arg2, arg3); |
| 6900 | break; |
| 6901 | #endif |
| 6902 | #ifdef TARGET_NR_msgget |
| 6903 | case TARGET_NR_msgget: |
| 6904 | ret = get_errno(msgget(arg1, arg2)); |
| 6905 | break; |
| 6906 | #endif |
| 6907 | #ifdef TARGET_NR_msgrcv |
| 6908 | case TARGET_NR_msgrcv: |
| 6909 | ret = do_msgrcv(arg1, arg2, arg3, arg4, arg5); |
| 6910 | break; |
| 6911 | #endif |
| 6912 | #ifdef TARGET_NR_msgsnd |
| 6913 | case TARGET_NR_msgsnd: |
| 6914 | ret = do_msgsnd(arg1, arg2, arg3, arg4); |
| 6915 | break; |
| 6916 | #endif |
Riku Voipio | 88a8c98 | 2009-04-03 10:42:00 +0300 | [diff] [blame] | 6917 | #ifdef TARGET_NR_shmget |
| 6918 | case TARGET_NR_shmget: |
| 6919 | ret = get_errno(shmget(arg1, arg2, arg3)); |
| 6920 | break; |
| 6921 | #endif |
| 6922 | #ifdef TARGET_NR_shmctl |
| 6923 | case TARGET_NR_shmctl: |
| 6924 | ret = do_shmctl(arg1, arg2, arg3); |
| 6925 | break; |
| 6926 | #endif |
| 6927 | #ifdef TARGET_NR_shmat |
| 6928 | case TARGET_NR_shmat: |
| 6929 | ret = do_shmat(arg1, arg2, arg3); |
| 6930 | break; |
| 6931 | #endif |
| 6932 | #ifdef TARGET_NR_shmdt |
| 6933 | case TARGET_NR_shmdt: |
| 6934 | ret = do_shmdt(arg1); |
| 6935 | break; |
| 6936 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6937 | case TARGET_NR_fsync: |
| 6938 | ret = get_errno(fsync(arg1)); |
| 6939 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6940 | case TARGET_NR_clone: |
Richard Henderson | a4b388f | 2010-04-12 16:17:22 -0700 | [diff] [blame] | 6941 | #if defined(TARGET_SH4) || defined(TARGET_ALPHA) |
aurel32 | 0b6d3ae | 2008-09-15 07:43:43 +0000 | [diff] [blame] | 6942 | ret = get_errno(do_fork(cpu_env, arg1, arg2, arg3, arg5, arg4)); |
edgar_igl | b15ad61 | 2009-01-07 19:43:47 +0000 | [diff] [blame] | 6943 | #elif defined(TARGET_CRIS) |
| 6944 | ret = get_errno(do_fork(cpu_env, arg2, arg1, arg3, arg4, arg5)); |
Ulrich Hecht | a4c075f | 2009-07-24 16:57:31 +0200 | [diff] [blame] | 6945 | #elif defined(TARGET_S390X) |
| 6946 | ret = get_errno(do_fork(cpu_env, arg2, arg1, arg3, arg5, arg4)); |
aurel32 | 0b6d3ae | 2008-09-15 07:43:43 +0000 | [diff] [blame] | 6947 | #else |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 6948 | ret = get_errno(do_fork(cpu_env, arg1, arg2, arg3, arg4, arg5)); |
aurel32 | 0b6d3ae | 2008-09-15 07:43:43 +0000 | [diff] [blame] | 6949 | #endif |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 6950 | break; |
bellard | ec86b0f | 2003-04-11 00:15:04 +0000 | [diff] [blame] | 6951 | #ifdef __NR_exit_group |
| 6952 | /* new thread calls */ |
| 6953 | case TARGET_NR_exit_group: |
Juan Quintela | 9788c9c | 2009-07-27 16:13:02 +0200 | [diff] [blame] | 6954 | #ifdef TARGET_GPROF |
aurel32 | 6d946cd | 2008-11-06 16:15:18 +0000 | [diff] [blame] | 6955 | _mcleanup(); |
| 6956 | #endif |
bellard | e900967 | 2005-04-26 20:42:36 +0000 | [diff] [blame] | 6957 | gdb_exit(cpu_env, arg1); |
bellard | ec86b0f | 2003-04-11 00:15:04 +0000 | [diff] [blame] | 6958 | ret = get_errno(exit_group(arg1)); |
| 6959 | break; |
| 6960 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6961 | case TARGET_NR_setdomainname: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6962 | if (!(p = lock_user_string(arg1))) |
| 6963 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6964 | ret = get_errno(setdomainname(p, arg2)); |
| 6965 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6966 | break; |
| 6967 | case TARGET_NR_uname: |
| 6968 | /* no need to transcode because we use the linux syscall */ |
bellard | 29e619b | 2004-09-13 21:41:04 +0000 | [diff] [blame] | 6969 | { |
| 6970 | struct new_utsname * buf; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 6971 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6972 | if (!lock_user_struct(VERIFY_WRITE, buf, arg1, 0)) |
| 6973 | goto efault; |
bellard | 29e619b | 2004-09-13 21:41:04 +0000 | [diff] [blame] | 6974 | ret = get_errno(sys_uname(buf)); |
| 6975 | if (!is_error(ret)) { |
| 6976 | /* Overrite the native machine name with whatever is being |
| 6977 | emulated. */ |
Loïc Minier | da79030 | 2009-12-29 22:06:13 +0100 | [diff] [blame] | 6978 | strcpy (buf->machine, cpu_to_uname_machine(cpu_env)); |
pbrook | c593722 | 2006-05-14 11:30:38 +0000 | [diff] [blame] | 6979 | /* Allow the user to override the reported release. */ |
| 6980 | if (qemu_uname_release && *qemu_uname_release) |
| 6981 | strcpy (buf->release, qemu_uname_release); |
bellard | 29e619b | 2004-09-13 21:41:04 +0000 | [diff] [blame] | 6982 | } |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6983 | unlock_user_struct(buf, arg1, 1); |
bellard | 29e619b | 2004-09-13 21:41:04 +0000 | [diff] [blame] | 6984 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6985 | break; |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 6986 | #ifdef TARGET_I386 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6987 | case TARGET_NR_modify_ldt: |
bellard | 03acab6 | 2007-11-11 14:57:14 +0000 | [diff] [blame] | 6988 | ret = do_modify_ldt(cpu_env, arg1, arg2, arg3); |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 6989 | break; |
j_mayer | 84409dd | 2007-04-06 08:56:50 +0000 | [diff] [blame] | 6990 | #if !defined(TARGET_X86_64) |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 6991 | case TARGET_NR_vm86old: |
| 6992 | goto unimplemented; |
| 6993 | case TARGET_NR_vm86: |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6994 | ret = do_vm86(cpu_env, arg1, arg2); |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 6995 | break; |
| 6996 | #endif |
j_mayer | 84409dd | 2007-04-06 08:56:50 +0000 | [diff] [blame] | 6997 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6998 | case TARGET_NR_adjtimex: |
| 6999 | goto unimplemented; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7000 | #ifdef TARGET_NR_create_module |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7001 | case TARGET_NR_create_module: |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7002 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7003 | case TARGET_NR_init_module: |
| 7004 | case TARGET_NR_delete_module: |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7005 | #ifdef TARGET_NR_get_kernel_syms |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7006 | case TARGET_NR_get_kernel_syms: |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7007 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7008 | goto unimplemented; |
| 7009 | case TARGET_NR_quotactl: |
| 7010 | goto unimplemented; |
| 7011 | case TARGET_NR_getpgid: |
| 7012 | ret = get_errno(getpgid(arg1)); |
| 7013 | break; |
| 7014 | case TARGET_NR_fchdir: |
| 7015 | ret = get_errno(fchdir(arg1)); |
| 7016 | break; |
j_mayer | 84409dd | 2007-04-06 08:56:50 +0000 | [diff] [blame] | 7017 | #ifdef TARGET_NR_bdflush /* not on x86_64 */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7018 | case TARGET_NR_bdflush: |
| 7019 | goto unimplemented; |
j_mayer | 84409dd | 2007-04-06 08:56:50 +0000 | [diff] [blame] | 7020 | #endif |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7021 | #ifdef TARGET_NR_sysfs |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7022 | case TARGET_NR_sysfs: |
| 7023 | goto unimplemented; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7024 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7025 | case TARGET_NR_personality: |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 7026 | ret = get_errno(personality(arg1)); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7027 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7028 | #ifdef TARGET_NR_afs_syscall |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7029 | case TARGET_NR_afs_syscall: |
| 7030 | goto unimplemented; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7031 | #endif |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 7032 | #ifdef TARGET_NR__llseek /* Not on alpha */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7033 | case TARGET_NR__llseek: |
| 7034 | { |
| 7035 | int64_t res; |
Peter Maydell | 0c1592d | 2011-02-22 13:02:26 +0000 | [diff] [blame] | 7036 | #if !defined(__NR_llseek) |
| 7037 | res = lseek(arg1, ((uint64_t)arg2 << 32) | arg3, arg5); |
| 7038 | if (res == -1) { |
| 7039 | ret = get_errno(res); |
| 7040 | } else { |
| 7041 | ret = 0; |
| 7042 | } |
| 7043 | #else |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7044 | ret = get_errno(_llseek(arg1, arg2, arg3, &res, arg5)); |
bellard | 4f2ac23 | 2004-04-26 19:44:02 +0000 | [diff] [blame] | 7045 | #endif |
Peter Maydell | 0c1592d | 2011-02-22 13:02:26 +0000 | [diff] [blame] | 7046 | if ((ret == 0) && put_user_s64(res, arg4)) { |
| 7047 | goto efault; |
| 7048 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7049 | } |
| 7050 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 7051 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7052 | case TARGET_NR_getdents: |
Ulrich Hecht | d83c873 | 2009-07-24 19:10:28 +0200 | [diff] [blame] | 7053 | #if TARGET_ABI_BITS == 32 && HOST_LONG_BITS == 64 |
bellard | 4add45b | 2003-06-05 01:52:59 +0000 | [diff] [blame] | 7054 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7055 | struct target_dirent *target_dirp; |
aurel32 | 6556a83 | 2008-10-13 21:08:17 +0000 | [diff] [blame] | 7056 | struct linux_dirent *dirp; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 7057 | abi_long count = arg3; |
bellard | 4add45b | 2003-06-05 01:52:59 +0000 | [diff] [blame] | 7058 | |
| 7059 | dirp = malloc(count); |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 7060 | if (!dirp) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7061 | ret = -TARGET_ENOMEM; |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 7062 | goto fail; |
| 7063 | } |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 7064 | |
bellard | 4add45b | 2003-06-05 01:52:59 +0000 | [diff] [blame] | 7065 | ret = get_errno(sys_getdents(arg1, dirp, count)); |
| 7066 | if (!is_error(ret)) { |
aurel32 | 6556a83 | 2008-10-13 21:08:17 +0000 | [diff] [blame] | 7067 | struct linux_dirent *de; |
bellard | 4add45b | 2003-06-05 01:52:59 +0000 | [diff] [blame] | 7068 | struct target_dirent *tde; |
| 7069 | int len = ret; |
| 7070 | int reclen, treclen; |
| 7071 | int count1, tnamelen; |
| 7072 | |
| 7073 | count1 = 0; |
| 7074 | de = dirp; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7075 | if (!(target_dirp = lock_user(VERIFY_WRITE, arg2, count, 0))) |
| 7076 | goto efault; |
bellard | 4add45b | 2003-06-05 01:52:59 +0000 | [diff] [blame] | 7077 | tde = target_dirp; |
| 7078 | while (len > 0) { |
| 7079 | reclen = de->d_reclen; |
Dmitry V. Levin | 333858b | 2012-08-21 02:13:12 +0400 | [diff] [blame] | 7080 | tnamelen = reclen - offsetof(struct linux_dirent, d_name); |
| 7081 | assert(tnamelen >= 0); |
| 7082 | treclen = tnamelen + offsetof(struct target_dirent, d_name); |
| 7083 | assert(count1 + treclen <= count); |
bellard | 4add45b | 2003-06-05 01:52:59 +0000 | [diff] [blame] | 7084 | tde->d_reclen = tswap16(treclen); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 7085 | tde->d_ino = tswapal(de->d_ino); |
| 7086 | tde->d_off = tswapal(de->d_off); |
Dmitry V. Levin | 333858b | 2012-08-21 02:13:12 +0400 | [diff] [blame] | 7087 | memcpy(tde->d_name, de->d_name, tnamelen); |
aurel32 | 6556a83 | 2008-10-13 21:08:17 +0000 | [diff] [blame] | 7088 | de = (struct linux_dirent *)((char *)de + reclen); |
bellard | 4add45b | 2003-06-05 01:52:59 +0000 | [diff] [blame] | 7089 | len -= reclen; |
j_mayer | 1c5bf3b | 2007-04-14 12:17:59 +0000 | [diff] [blame] | 7090 | tde = (struct target_dirent *)((char *)tde + treclen); |
bellard | 4add45b | 2003-06-05 01:52:59 +0000 | [diff] [blame] | 7091 | count1 += treclen; |
| 7092 | } |
| 7093 | ret = count1; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7094 | unlock_user(target_dirp, arg2, ret); |
bellard | 4add45b | 2003-06-05 01:52:59 +0000 | [diff] [blame] | 7095 | } |
| 7096 | free(dirp); |
| 7097 | } |
| 7098 | #else |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7099 | { |
aurel32 | 6556a83 | 2008-10-13 21:08:17 +0000 | [diff] [blame] | 7100 | struct linux_dirent *dirp; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 7101 | abi_long count = arg3; |
bellard | dab2ed9 | 2003-03-22 15:23:14 +0000 | [diff] [blame] | 7102 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7103 | if (!(dirp = lock_user(VERIFY_WRITE, arg2, count, 0))) |
| 7104 | goto efault; |
bellard | 72f0390 | 2003-02-18 23:33:18 +0000 | [diff] [blame] | 7105 | ret = get_errno(sys_getdents(arg1, dirp, count)); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7106 | if (!is_error(ret)) { |
aurel32 | 6556a83 | 2008-10-13 21:08:17 +0000 | [diff] [blame] | 7107 | struct linux_dirent *de; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7108 | int len = ret; |
| 7109 | int reclen; |
| 7110 | de = dirp; |
| 7111 | while (len > 0) { |
bellard | 8083a3e | 2003-03-24 23:12:16 +0000 | [diff] [blame] | 7112 | reclen = de->d_reclen; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7113 | if (reclen > len) |
| 7114 | break; |
bellard | 8083a3e | 2003-03-24 23:12:16 +0000 | [diff] [blame] | 7115 | de->d_reclen = tswap16(reclen); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7116 | tswapls(&de->d_ino); |
| 7117 | tswapls(&de->d_off); |
aurel32 | 6556a83 | 2008-10-13 21:08:17 +0000 | [diff] [blame] | 7118 | de = (struct linux_dirent *)((char *)de + reclen); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7119 | len -= reclen; |
| 7120 | } |
| 7121 | } |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7122 | unlock_user(dirp, arg2, ret); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7123 | } |
bellard | 4add45b | 2003-06-05 01:52:59 +0000 | [diff] [blame] | 7124 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7125 | break; |
ths | 3ae4320 | 2007-09-16 21:39:48 +0000 | [diff] [blame] | 7126 | #if defined(TARGET_NR_getdents64) && defined(__NR_getdents64) |
bellard | dab2ed9 | 2003-03-22 15:23:14 +0000 | [diff] [blame] | 7127 | case TARGET_NR_getdents64: |
| 7128 | { |
aurel32 | 6556a83 | 2008-10-13 21:08:17 +0000 | [diff] [blame] | 7129 | struct linux_dirent64 *dirp; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 7130 | abi_long count = arg3; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7131 | if (!(dirp = lock_user(VERIFY_WRITE, arg2, count, 0))) |
| 7132 | goto efault; |
bellard | dab2ed9 | 2003-03-22 15:23:14 +0000 | [diff] [blame] | 7133 | ret = get_errno(sys_getdents64(arg1, dirp, count)); |
| 7134 | if (!is_error(ret)) { |
aurel32 | 6556a83 | 2008-10-13 21:08:17 +0000 | [diff] [blame] | 7135 | struct linux_dirent64 *de; |
bellard | dab2ed9 | 2003-03-22 15:23:14 +0000 | [diff] [blame] | 7136 | int len = ret; |
| 7137 | int reclen; |
| 7138 | de = dirp; |
| 7139 | while (len > 0) { |
bellard | 8083a3e | 2003-03-24 23:12:16 +0000 | [diff] [blame] | 7140 | reclen = de->d_reclen; |
bellard | dab2ed9 | 2003-03-22 15:23:14 +0000 | [diff] [blame] | 7141 | if (reclen > len) |
| 7142 | break; |
bellard | 8083a3e | 2003-03-24 23:12:16 +0000 | [diff] [blame] | 7143 | de->d_reclen = tswap16(reclen); |
bellard | 8582a53 | 2007-11-11 23:11:36 +0000 | [diff] [blame] | 7144 | tswap64s((uint64_t *)&de->d_ino); |
| 7145 | tswap64s((uint64_t *)&de->d_off); |
aurel32 | 6556a83 | 2008-10-13 21:08:17 +0000 | [diff] [blame] | 7146 | de = (struct linux_dirent64 *)((char *)de + reclen); |
bellard | dab2ed9 | 2003-03-22 15:23:14 +0000 | [diff] [blame] | 7147 | len -= reclen; |
| 7148 | } |
| 7149 | } |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7150 | unlock_user(dirp, arg2, ret); |
bellard | dab2ed9 | 2003-03-22 15:23:14 +0000 | [diff] [blame] | 7151 | } |
| 7152 | break; |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 7153 | #endif /* TARGET_NR_getdents64 */ |
Ulrich Hecht | a4c075f | 2009-07-24 16:57:31 +0200 | [diff] [blame] | 7154 | #if defined(TARGET_NR__newselect) || defined(TARGET_S390X) |
| 7155 | #ifdef TARGET_S390X |
| 7156 | case TARGET_NR_select: |
| 7157 | #else |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7158 | case TARGET_NR__newselect: |
Ulrich Hecht | a4c075f | 2009-07-24 16:57:31 +0200 | [diff] [blame] | 7159 | #endif |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7160 | ret = do_select(arg1, arg2, arg3, arg4, arg5); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7161 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7162 | #endif |
Mike Frysinger | d8035d4 | 2011-02-07 01:05:51 -0500 | [diff] [blame] | 7163 | #if defined(TARGET_NR_poll) || defined(TARGET_NR_ppoll) |
| 7164 | # ifdef TARGET_NR_poll |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 7165 | case TARGET_NR_poll: |
Mike Frysinger | d8035d4 | 2011-02-07 01:05:51 -0500 | [diff] [blame] | 7166 | # endif |
| 7167 | # ifdef TARGET_NR_ppoll |
| 7168 | case TARGET_NR_ppoll: |
| 7169 | # endif |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 7170 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7171 | struct target_pollfd *target_pfd; |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 7172 | unsigned int nfds = arg2; |
| 7173 | int timeout = arg3; |
| 7174 | struct pollfd *pfd; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 7175 | unsigned int i; |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 7176 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7177 | target_pfd = lock_user(VERIFY_WRITE, arg1, sizeof(struct target_pollfd) * nfds, 1); |
| 7178 | if (!target_pfd) |
| 7179 | goto efault; |
Mike Frysinger | d8035d4 | 2011-02-07 01:05:51 -0500 | [diff] [blame] | 7180 | |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 7181 | pfd = alloca(sizeof(struct pollfd) * nfds); |
| 7182 | for(i = 0; i < nfds; i++) { |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7183 | pfd[i].fd = tswap32(target_pfd[i].fd); |
| 7184 | pfd[i].events = tswap16(target_pfd[i].events); |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 7185 | } |
Mike Frysinger | d8035d4 | 2011-02-07 01:05:51 -0500 | [diff] [blame] | 7186 | |
| 7187 | # ifdef TARGET_NR_ppoll |
| 7188 | if (num == TARGET_NR_ppoll) { |
| 7189 | struct timespec _timeout_ts, *timeout_ts = &_timeout_ts; |
| 7190 | target_sigset_t *target_set; |
| 7191 | sigset_t _set, *set = &_set; |
| 7192 | |
| 7193 | if (arg3) { |
| 7194 | if (target_to_host_timespec(timeout_ts, arg3)) { |
| 7195 | unlock_user(target_pfd, arg1, 0); |
| 7196 | goto efault; |
| 7197 | } |
| 7198 | } else { |
| 7199 | timeout_ts = NULL; |
| 7200 | } |
| 7201 | |
| 7202 | if (arg4) { |
| 7203 | target_set = lock_user(VERIFY_READ, arg4, sizeof(target_sigset_t), 1); |
| 7204 | if (!target_set) { |
| 7205 | unlock_user(target_pfd, arg1, 0); |
| 7206 | goto efault; |
| 7207 | } |
| 7208 | target_to_host_sigset(set, target_set); |
| 7209 | } else { |
| 7210 | set = NULL; |
| 7211 | } |
| 7212 | |
| 7213 | ret = get_errno(sys_ppoll(pfd, nfds, timeout_ts, set, _NSIG/8)); |
| 7214 | |
| 7215 | if (!is_error(ret) && arg3) { |
| 7216 | host_to_target_timespec(arg3, timeout_ts); |
| 7217 | } |
| 7218 | if (arg4) { |
| 7219 | unlock_user(target_set, arg4, 0); |
| 7220 | } |
| 7221 | } else |
| 7222 | # endif |
| 7223 | ret = get_errno(poll(pfd, nfds, timeout)); |
| 7224 | |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 7225 | if (!is_error(ret)) { |
| 7226 | for(i = 0; i < nfds; i++) { |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7227 | target_pfd[i].revents = tswap16(pfd[i].revents); |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 7228 | } |
| 7229 | } |
Peter Maydell | 30cb4cd | 2011-02-25 10:27:40 +0000 | [diff] [blame] | 7230 | unlock_user(target_pfd, arg1, sizeof(struct target_pollfd) * nfds); |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 7231 | } |
| 7232 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7233 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7234 | case TARGET_NR_flock: |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 7235 | /* NOTE: the flock constant seems to be the same for every |
| 7236 | Linux platform */ |
| 7237 | ret = get_errno(flock(arg1, arg2)); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7238 | break; |
| 7239 | case TARGET_NR_readv: |
| 7240 | { |
Richard Henderson | f287b2c | 2012-09-15 13:20:25 -0700 | [diff] [blame] | 7241 | struct iovec *vec = lock_iovec(VERIFY_WRITE, arg2, arg3, 0); |
| 7242 | if (vec != NULL) { |
| 7243 | ret = get_errno(readv(arg1, vec, arg3)); |
| 7244 | unlock_iovec(vec, arg2, arg3, 1); |
| 7245 | } else { |
| 7246 | ret = -host_to_target_errno(errno); |
| 7247 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7248 | } |
| 7249 | break; |
| 7250 | case TARGET_NR_writev: |
| 7251 | { |
Richard Henderson | f287b2c | 2012-09-15 13:20:25 -0700 | [diff] [blame] | 7252 | struct iovec *vec = lock_iovec(VERIFY_READ, arg2, arg3, 1); |
| 7253 | if (vec != NULL) { |
| 7254 | ret = get_errno(writev(arg1, vec, arg3)); |
| 7255 | unlock_iovec(vec, arg2, arg3, 0); |
| 7256 | } else { |
| 7257 | ret = -host_to_target_errno(errno); |
| 7258 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7259 | } |
| 7260 | break; |
| 7261 | case TARGET_NR_getsid: |
| 7262 | ret = get_errno(getsid(arg1)); |
| 7263 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 7264 | #if defined(TARGET_NR_fdatasync) /* Not on alpha (osf_datasync ?) */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7265 | case TARGET_NR_fdatasync: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7266 | ret = get_errno(fdatasync(arg1)); |
| 7267 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 7268 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7269 | case TARGET_NR__sysctl: |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 7270 | /* We don't implement this, but ENOTDIR is always a safe |
bellard | 29e619b | 2004-09-13 21:41:04 +0000 | [diff] [blame] | 7271 | return value. */ |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 7272 | ret = -TARGET_ENOTDIR; |
| 7273 | break; |
Mike Frysinger | 737de1d | 2011-02-07 01:05:55 -0500 | [diff] [blame] | 7274 | case TARGET_NR_sched_getaffinity: |
| 7275 | { |
| 7276 | unsigned int mask_size; |
| 7277 | unsigned long *mask; |
| 7278 | |
| 7279 | /* |
| 7280 | * sched_getaffinity needs multiples of ulong, so need to take |
| 7281 | * care of mismatches between target ulong and host ulong sizes. |
| 7282 | */ |
| 7283 | if (arg2 & (sizeof(abi_ulong) - 1)) { |
| 7284 | ret = -TARGET_EINVAL; |
| 7285 | break; |
| 7286 | } |
| 7287 | mask_size = (arg2 + (sizeof(*mask) - 1)) & ~(sizeof(*mask) - 1); |
| 7288 | |
| 7289 | mask = alloca(mask_size); |
| 7290 | ret = get_errno(sys_sched_getaffinity(arg1, mask_size, mask)); |
| 7291 | |
| 7292 | if (!is_error(ret)) { |
Mike McCormack | cd18f05 | 2011-04-18 14:43:36 +0900 | [diff] [blame] | 7293 | if (copy_to_user(arg3, mask, ret)) { |
Mike Frysinger | 737de1d | 2011-02-07 01:05:55 -0500 | [diff] [blame] | 7294 | goto efault; |
| 7295 | } |
Mike Frysinger | 737de1d | 2011-02-07 01:05:55 -0500 | [diff] [blame] | 7296 | } |
| 7297 | } |
| 7298 | break; |
| 7299 | case TARGET_NR_sched_setaffinity: |
| 7300 | { |
| 7301 | unsigned int mask_size; |
| 7302 | unsigned long *mask; |
| 7303 | |
| 7304 | /* |
| 7305 | * sched_setaffinity needs multiples of ulong, so need to take |
| 7306 | * care of mismatches between target ulong and host ulong sizes. |
| 7307 | */ |
| 7308 | if (arg2 & (sizeof(abi_ulong) - 1)) { |
| 7309 | ret = -TARGET_EINVAL; |
| 7310 | break; |
| 7311 | } |
| 7312 | mask_size = (arg2 + (sizeof(*mask) - 1)) & ~(sizeof(*mask) - 1); |
| 7313 | |
| 7314 | mask = alloca(mask_size); |
| 7315 | if (!lock_user_struct(VERIFY_READ, p, arg3, 1)) { |
| 7316 | goto efault; |
| 7317 | } |
| 7318 | memcpy(mask, p, arg2); |
| 7319 | unlock_user_struct(p, arg2, 0); |
| 7320 | |
| 7321 | ret = get_errno(sys_sched_setaffinity(arg1, mask_size, mask)); |
| 7322 | } |
| 7323 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7324 | case TARGET_NR_sched_setparam: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7325 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7326 | struct sched_param *target_schp; |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7327 | struct sched_param schp; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7328 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7329 | if (!lock_user_struct(VERIFY_READ, target_schp, arg2, 1)) |
| 7330 | goto efault; |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7331 | schp.sched_priority = tswap32(target_schp->sched_priority); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7332 | unlock_user_struct(target_schp, arg2, 0); |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7333 | ret = get_errno(sched_setparam(arg1, &schp)); |
| 7334 | } |
| 7335 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7336 | case TARGET_NR_sched_getparam: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7337 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7338 | struct sched_param *target_schp; |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7339 | struct sched_param schp; |
| 7340 | ret = get_errno(sched_getparam(arg1, &schp)); |
| 7341 | if (!is_error(ret)) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7342 | if (!lock_user_struct(VERIFY_WRITE, target_schp, arg2, 0)) |
| 7343 | goto efault; |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7344 | target_schp->sched_priority = tswap32(schp.sched_priority); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7345 | unlock_user_struct(target_schp, arg2, 1); |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7346 | } |
| 7347 | } |
| 7348 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7349 | case TARGET_NR_sched_setscheduler: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7350 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7351 | struct sched_param *target_schp; |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7352 | struct sched_param schp; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7353 | if (!lock_user_struct(VERIFY_READ, target_schp, arg3, 1)) |
| 7354 | goto efault; |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7355 | schp.sched_priority = tswap32(target_schp->sched_priority); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7356 | unlock_user_struct(target_schp, arg3, 0); |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7357 | ret = get_errno(sched_setscheduler(arg1, arg2, &schp)); |
| 7358 | } |
| 7359 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7360 | case TARGET_NR_sched_getscheduler: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7361 | ret = get_errno(sched_getscheduler(arg1)); |
| 7362 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7363 | case TARGET_NR_sched_yield: |
| 7364 | ret = get_errno(sched_yield()); |
| 7365 | break; |
| 7366 | case TARGET_NR_sched_get_priority_max: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7367 | ret = get_errno(sched_get_priority_max(arg1)); |
| 7368 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7369 | case TARGET_NR_sched_get_priority_min: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7370 | ret = get_errno(sched_get_priority_min(arg1)); |
| 7371 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7372 | case TARGET_NR_sched_rr_get_interval: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7373 | { |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7374 | struct timespec ts; |
| 7375 | ret = get_errno(sched_rr_get_interval(arg1, &ts)); |
| 7376 | if (!is_error(ret)) { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7377 | host_to_target_timespec(arg2, &ts); |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7378 | } |
| 7379 | } |
| 7380 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7381 | case TARGET_NR_nanosleep: |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 7382 | { |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 7383 | struct timespec req, rem; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7384 | target_to_host_timespec(&req, arg1); |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 7385 | ret = get_errno(nanosleep(&req, &rem)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7386 | if (is_error(ret) && arg2) { |
| 7387 | host_to_target_timespec(arg2, &rem); |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 7388 | } |
| 7389 | } |
| 7390 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7391 | #ifdef TARGET_NR_query_module |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7392 | case TARGET_NR_query_module: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7393 | goto unimplemented; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7394 | #endif |
| 7395 | #ifdef TARGET_NR_nfsservctl |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7396 | case TARGET_NR_nfsservctl: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7397 | goto unimplemented; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7398 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7399 | case TARGET_NR_prctl: |
Peter Maydell | 1e6722f | 2012-02-03 14:48:03 +0000 | [diff] [blame] | 7400 | switch (arg1) { |
| 7401 | case PR_GET_PDEATHSIG: |
| 7402 | { |
| 7403 | int deathsig; |
| 7404 | ret = get_errno(prctl(arg1, &deathsig, arg3, arg4, arg5)); |
| 7405 | if (!is_error(ret) && arg2 |
| 7406 | && put_user_ual(deathsig, arg2)) { |
| 7407 | goto efault; |
ths | e557448 | 2007-02-11 20:03:13 +0000 | [diff] [blame] | 7408 | } |
Peter Maydell | 1e6722f | 2012-02-03 14:48:03 +0000 | [diff] [blame] | 7409 | break; |
| 7410 | } |
Peter Maydell | db9526b | 2012-02-03 14:48:03 +0000 | [diff] [blame] | 7411 | #ifdef PR_GET_NAME |
| 7412 | case PR_GET_NAME: |
| 7413 | { |
| 7414 | void *name = lock_user(VERIFY_WRITE, arg2, 16, 1); |
| 7415 | if (!name) { |
| 7416 | goto efault; |
| 7417 | } |
| 7418 | ret = get_errno(prctl(arg1, (unsigned long)name, |
| 7419 | arg3, arg4, arg5)); |
| 7420 | unlock_user(name, arg2, 16); |
| 7421 | break; |
| 7422 | } |
| 7423 | case PR_SET_NAME: |
| 7424 | { |
| 7425 | void *name = lock_user(VERIFY_READ, arg2, 16, 1); |
| 7426 | if (!name) { |
| 7427 | goto efault; |
| 7428 | } |
| 7429 | ret = get_errno(prctl(arg1, (unsigned long)name, |
| 7430 | arg3, arg4, arg5)); |
| 7431 | unlock_user(name, arg2, 0); |
| 7432 | break; |
| 7433 | } |
| 7434 | #endif |
Peter Maydell | 1e6722f | 2012-02-03 14:48:03 +0000 | [diff] [blame] | 7435 | default: |
| 7436 | /* Most prctl options have no pointer arguments */ |
| 7437 | ret = get_errno(prctl(arg1, arg2, arg3, arg4, arg5)); |
| 7438 | break; |
| 7439 | } |
ths | 39b9aae | 2007-02-11 18:36:44 +0000 | [diff] [blame] | 7440 | break; |
bellard | d2fd1af | 2007-11-14 18:08:56 +0000 | [diff] [blame] | 7441 | #ifdef TARGET_NR_arch_prctl |
| 7442 | case TARGET_NR_arch_prctl: |
| 7443 | #if defined(TARGET_I386) && !defined(TARGET_ABI32) |
| 7444 | ret = do_arch_prctl(cpu_env, arg1, arg2); |
| 7445 | break; |
| 7446 | #else |
| 7447 | goto unimplemented; |
| 7448 | #endif |
| 7449 | #endif |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7450 | #ifdef TARGET_NR_pread |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7451 | case TARGET_NR_pread: |
Riku Voipio | 48e515d | 2011-07-12 15:40:51 +0300 | [diff] [blame] | 7452 | if (regpairs_aligned(cpu_env)) |
balrog | a4ae00b | 2008-09-20 03:14:14 +0000 | [diff] [blame] | 7453 | arg4 = arg5; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7454 | if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0))) |
| 7455 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7456 | ret = get_errno(pread(arg1, p, arg3, arg4)); |
| 7457 | unlock_user(p, arg2, ret); |
bellard | 206f0fa | 2003-05-14 19:01:56 +0000 | [diff] [blame] | 7458 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7459 | case TARGET_NR_pwrite: |
Riku Voipio | 48e515d | 2011-07-12 15:40:51 +0300 | [diff] [blame] | 7460 | if (regpairs_aligned(cpu_env)) |
balrog | a4ae00b | 2008-09-20 03:14:14 +0000 | [diff] [blame] | 7461 | arg4 = arg5; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7462 | if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1))) |
| 7463 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7464 | ret = get_errno(pwrite(arg1, p, arg3, arg4)); |
| 7465 | unlock_user(p, arg2, 0); |
bellard | 206f0fa | 2003-05-14 19:01:56 +0000 | [diff] [blame] | 7466 | break; |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7467 | #endif |
aurel32 | f2c7ba1 | 2008-03-28 22:32:06 +0000 | [diff] [blame] | 7468 | #ifdef TARGET_NR_pread64 |
| 7469 | case TARGET_NR_pread64: |
Alexander Graf | ae017a5 | 2012-09-29 15:32:39 +0000 | [diff] [blame^] | 7470 | if (regpairs_aligned(cpu_env)) { |
| 7471 | arg4 = arg5; |
| 7472 | arg5 = arg6; |
| 7473 | } |
aurel32 | f2c7ba1 | 2008-03-28 22:32:06 +0000 | [diff] [blame] | 7474 | if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0))) |
| 7475 | goto efault; |
| 7476 | ret = get_errno(pread64(arg1, p, arg3, target_offset64(arg4, arg5))); |
| 7477 | unlock_user(p, arg2, ret); |
| 7478 | break; |
| 7479 | case TARGET_NR_pwrite64: |
Alexander Graf | ae017a5 | 2012-09-29 15:32:39 +0000 | [diff] [blame^] | 7480 | if (regpairs_aligned(cpu_env)) { |
| 7481 | arg4 = arg5; |
| 7482 | arg5 = arg6; |
| 7483 | } |
aurel32 | f2c7ba1 | 2008-03-28 22:32:06 +0000 | [diff] [blame] | 7484 | if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1))) |
| 7485 | goto efault; |
| 7486 | ret = get_errno(pwrite64(arg1, p, arg3, target_offset64(arg4, arg5))); |
| 7487 | unlock_user(p, arg2, 0); |
| 7488 | break; |
| 7489 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7490 | case TARGET_NR_getcwd: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7491 | if (!(p = lock_user(VERIFY_WRITE, arg1, arg2, 0))) |
| 7492 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7493 | ret = get_errno(sys_getcwd1(p, arg2)); |
| 7494 | unlock_user(p, arg1, ret); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7495 | break; |
| 7496 | case TARGET_NR_capget: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7497 | goto unimplemented; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7498 | case TARGET_NR_capset: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7499 | goto unimplemented; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7500 | case TARGET_NR_sigaltstack: |
ths | 198a74d | 2007-09-27 16:44:32 +0000 | [diff] [blame] | 7501 | #if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_MIPS) || \ |
Laurent Vivier | c761c15 | 2009-08-03 16:12:19 +0200 | [diff] [blame] | 7502 | defined(TARGET_SPARC) || defined(TARGET_PPC) || defined(TARGET_ALPHA) || \ |
Jia Liu | d962783 | 2012-07-20 15:50:52 +0800 | [diff] [blame] | 7503 | defined(TARGET_M68K) || defined(TARGET_S390X) || defined(TARGET_OPENRISC) |
Andreas Färber | 9349b4f | 2012-03-14 01:38:32 +0100 | [diff] [blame] | 7504 | ret = do_sigaltstack(arg1, arg2, get_sp_from_cpustate((CPUArchState *)cpu_env)); |
ths | a04e134 | 2007-09-27 13:57:58 +0000 | [diff] [blame] | 7505 | break; |
| 7506 | #else |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7507 | goto unimplemented; |
ths | a04e134 | 2007-09-27 13:57:58 +0000 | [diff] [blame] | 7508 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7509 | case TARGET_NR_sendfile: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7510 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 7511 | #ifdef TARGET_NR_getpmsg |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7512 | case TARGET_NR_getpmsg: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7513 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 7514 | #endif |
| 7515 | #ifdef TARGET_NR_putpmsg |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7516 | case TARGET_NR_putpmsg: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7517 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 7518 | #endif |
bellard | 048f6b4 | 2005-11-26 18:47:20 +0000 | [diff] [blame] | 7519 | #ifdef TARGET_NR_vfork |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7520 | case TARGET_NR_vfork: |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 7521 | ret = get_errno(do_fork(cpu_env, CLONE_VFORK | CLONE_VM | SIGCHLD, |
| 7522 | 0, 0, 0, 0)); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7523 | break; |
bellard | 048f6b4 | 2005-11-26 18:47:20 +0000 | [diff] [blame] | 7524 | #endif |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 7525 | #ifdef TARGET_NR_ugetrlimit |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7526 | case TARGET_NR_ugetrlimit: |
bellard | 728584b | 2003-04-29 20:43:36 +0000 | [diff] [blame] | 7527 | { |
| 7528 | struct rlimit rlim; |
Wesley W. Terpstra | e22b701 | 2011-07-12 14:42:00 +0300 | [diff] [blame] | 7529 | int resource = target_to_host_resource(arg1); |
| 7530 | ret = get_errno(getrlimit(resource, &rlim)); |
bellard | 728584b | 2003-04-29 20:43:36 +0000 | [diff] [blame] | 7531 | if (!is_error(ret)) { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7532 | struct target_rlimit *target_rlim; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7533 | if (!lock_user_struct(VERIFY_WRITE, target_rlim, arg2, 0)) |
| 7534 | goto efault; |
takasi-y@ops.dti.ne.jp | 81bbe90 | 2010-04-12 04:07:35 +0900 | [diff] [blame] | 7535 | target_rlim->rlim_cur = host_to_target_rlim(rlim.rlim_cur); |
| 7536 | target_rlim->rlim_max = host_to_target_rlim(rlim.rlim_max); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7537 | unlock_user_struct(target_rlim, arg2, 1); |
bellard | 728584b | 2003-04-29 20:43:36 +0000 | [diff] [blame] | 7538 | } |
| 7539 | break; |
| 7540 | } |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 7541 | #endif |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7542 | #ifdef TARGET_NR_truncate64 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7543 | case TARGET_NR_truncate64: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7544 | if (!(p = lock_user_string(arg1))) |
| 7545 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7546 | ret = target_truncate64(cpu_env, p, arg2, arg3, arg4); |
| 7547 | unlock_user(p, arg1, 0); |
bellard | 667f38b | 2005-07-23 14:46:27 +0000 | [diff] [blame] | 7548 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7549 | #endif |
| 7550 | #ifdef TARGET_NR_ftruncate64 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7551 | case TARGET_NR_ftruncate64: |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 7552 | ret = target_ftruncate64(cpu_env, arg1, arg2, arg3, arg4); |
bellard | 667f38b | 2005-07-23 14:46:27 +0000 | [diff] [blame] | 7553 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7554 | #endif |
| 7555 | #ifdef TARGET_NR_stat64 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7556 | case TARGET_NR_stat64: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7557 | if (!(p = lock_user_string(arg1))) |
| 7558 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7559 | ret = get_errno(stat(path(p), &st)); |
| 7560 | unlock_user(p, arg1, 0); |
balrog | 6a24a77 | 2008-09-20 02:23:36 +0000 | [diff] [blame] | 7561 | if (!is_error(ret)) |
| 7562 | ret = host_to_target_stat64(cpu_env, arg2, &st); |
| 7563 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7564 | #endif |
| 7565 | #ifdef TARGET_NR_lstat64 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7566 | case TARGET_NR_lstat64: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7567 | if (!(p = lock_user_string(arg1))) |
| 7568 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7569 | ret = get_errno(lstat(path(p), &st)); |
| 7570 | unlock_user(p, arg1, 0); |
balrog | 6a24a77 | 2008-09-20 02:23:36 +0000 | [diff] [blame] | 7571 | if (!is_error(ret)) |
| 7572 | ret = host_to_target_stat64(cpu_env, arg2, &st); |
| 7573 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7574 | #endif |
| 7575 | #ifdef TARGET_NR_fstat64 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7576 | case TARGET_NR_fstat64: |
balrog | 6a24a77 | 2008-09-20 02:23:36 +0000 | [diff] [blame] | 7577 | ret = get_errno(fstat(arg1, &st)); |
| 7578 | if (!is_error(ret)) |
| 7579 | ret = host_to_target_stat64(cpu_env, arg2, &st); |
| 7580 | break; |
bellard | ec86b0f | 2003-04-11 00:15:04 +0000 | [diff] [blame] | 7581 | #endif |
aurel32 | 9d33b76 | 2009-04-08 23:07:05 +0000 | [diff] [blame] | 7582 | #if (defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)) && \ |
| 7583 | (defined(__NR_fstatat64) || defined(__NR_newfstatat)) |
| 7584 | #ifdef TARGET_NR_fstatat64 |
balrog | 6a24a77 | 2008-09-20 02:23:36 +0000 | [diff] [blame] | 7585 | case TARGET_NR_fstatat64: |
aurel32 | 9d33b76 | 2009-04-08 23:07:05 +0000 | [diff] [blame] | 7586 | #endif |
| 7587 | #ifdef TARGET_NR_newfstatat |
| 7588 | case TARGET_NR_newfstatat: |
| 7589 | #endif |
balrog | 6a24a77 | 2008-09-20 02:23:36 +0000 | [diff] [blame] | 7590 | if (!(p = lock_user_string(arg2))) |
| 7591 | goto efault; |
aurel32 | 9d33b76 | 2009-04-08 23:07:05 +0000 | [diff] [blame] | 7592 | #ifdef __NR_fstatat64 |
balrog | 6a24a77 | 2008-09-20 02:23:36 +0000 | [diff] [blame] | 7593 | ret = get_errno(sys_fstatat64(arg1, path(p), &st, arg4)); |
aurel32 | 9d33b76 | 2009-04-08 23:07:05 +0000 | [diff] [blame] | 7594 | #else |
| 7595 | ret = get_errno(sys_newfstatat(arg1, path(p), &st, arg4)); |
| 7596 | #endif |
balrog | 6a24a77 | 2008-09-20 02:23:36 +0000 | [diff] [blame] | 7597 | if (!is_error(ret)) |
| 7598 | ret = host_to_target_stat64(cpu_env, arg3, &st); |
bellard | 60cd49d | 2003-03-16 22:53:56 +0000 | [diff] [blame] | 7599 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7600 | #endif |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7601 | case TARGET_NR_lchown: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7602 | if (!(p = lock_user_string(arg1))) |
| 7603 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7604 | ret = get_errno(lchown(p, low2highuid(arg2), low2highgid(arg3))); |
| 7605 | unlock_user(p, arg1, 0); |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7606 | break; |
Riku Voipio | 0c866a7 | 2011-04-18 15:23:06 +0300 | [diff] [blame] | 7607 | #ifdef TARGET_NR_getuid |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7608 | case TARGET_NR_getuid: |
| 7609 | ret = get_errno(high2lowuid(getuid())); |
| 7610 | break; |
Riku Voipio | 0c866a7 | 2011-04-18 15:23:06 +0300 | [diff] [blame] | 7611 | #endif |
| 7612 | #ifdef TARGET_NR_getgid |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7613 | case TARGET_NR_getgid: |
| 7614 | ret = get_errno(high2lowgid(getgid())); |
| 7615 | break; |
Riku Voipio | 0c866a7 | 2011-04-18 15:23:06 +0300 | [diff] [blame] | 7616 | #endif |
| 7617 | #ifdef TARGET_NR_geteuid |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7618 | case TARGET_NR_geteuid: |
| 7619 | ret = get_errno(high2lowuid(geteuid())); |
| 7620 | break; |
Riku Voipio | 0c866a7 | 2011-04-18 15:23:06 +0300 | [diff] [blame] | 7621 | #endif |
| 7622 | #ifdef TARGET_NR_getegid |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7623 | case TARGET_NR_getegid: |
| 7624 | ret = get_errno(high2lowgid(getegid())); |
| 7625 | break; |
Riku Voipio | 0c866a7 | 2011-04-18 15:23:06 +0300 | [diff] [blame] | 7626 | #endif |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7627 | case TARGET_NR_setreuid: |
| 7628 | ret = get_errno(setreuid(low2highuid(arg1), low2highuid(arg2))); |
| 7629 | break; |
| 7630 | case TARGET_NR_setregid: |
| 7631 | ret = get_errno(setregid(low2highgid(arg1), low2highgid(arg2))); |
| 7632 | break; |
| 7633 | case TARGET_NR_getgroups: |
| 7634 | { |
| 7635 | int gidsetsize = arg1; |
Riku Voipio | 0c866a7 | 2011-04-18 15:23:06 +0300 | [diff] [blame] | 7636 | target_id *target_grouplist; |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7637 | gid_t *grouplist; |
| 7638 | int i; |
| 7639 | |
| 7640 | grouplist = alloca(gidsetsize * sizeof(gid_t)); |
| 7641 | ret = get_errno(getgroups(gidsetsize, grouplist)); |
balrog | cb3bc23 | 2008-09-20 02:08:13 +0000 | [diff] [blame] | 7642 | if (gidsetsize == 0) |
| 7643 | break; |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7644 | if (!is_error(ret)) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7645 | target_grouplist = lock_user(VERIFY_WRITE, arg2, gidsetsize * 2, 0); |
| 7646 | if (!target_grouplist) |
| 7647 | goto efault; |
balrog | a2155fc | 2008-09-20 02:12:08 +0000 | [diff] [blame] | 7648 | for(i = 0;i < ret; i++) |
Riku Voipio | 0c866a7 | 2011-04-18 15:23:06 +0300 | [diff] [blame] | 7649 | target_grouplist[i] = tswapid(high2lowgid(grouplist[i])); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7650 | unlock_user(target_grouplist, arg2, gidsetsize * 2); |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7651 | } |
| 7652 | } |
| 7653 | break; |
| 7654 | case TARGET_NR_setgroups: |
| 7655 | { |
| 7656 | int gidsetsize = arg1; |
Riku Voipio | 0c866a7 | 2011-04-18 15:23:06 +0300 | [diff] [blame] | 7657 | target_id *target_grouplist; |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7658 | gid_t *grouplist; |
| 7659 | int i; |
| 7660 | |
| 7661 | grouplist = alloca(gidsetsize * sizeof(gid_t)); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7662 | target_grouplist = lock_user(VERIFY_READ, arg2, gidsetsize * 2, 1); |
| 7663 | if (!target_grouplist) { |
| 7664 | ret = -TARGET_EFAULT; |
| 7665 | goto fail; |
| 7666 | } |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7667 | for(i = 0;i < gidsetsize; i++) |
Riku Voipio | 0c866a7 | 2011-04-18 15:23:06 +0300 | [diff] [blame] | 7668 | grouplist[i] = low2highgid(tswapid(target_grouplist[i])); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7669 | unlock_user(target_grouplist, arg2, 0); |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7670 | ret = get_errno(setgroups(gidsetsize, grouplist)); |
| 7671 | } |
| 7672 | break; |
| 7673 | case TARGET_NR_fchown: |
| 7674 | ret = get_errno(fchown(arg1, low2highuid(arg2), low2highgid(arg3))); |
| 7675 | break; |
ths | ccfa72b | 2007-09-24 09:23:34 +0000 | [diff] [blame] | 7676 | #if defined(TARGET_NR_fchownat) && defined(__NR_fchownat) |
| 7677 | case TARGET_NR_fchownat: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7678 | if (!(p = lock_user_string(arg2))) |
| 7679 | goto efault; |
| 7680 | ret = get_errno(sys_fchownat(arg1, p, low2highuid(arg3), low2highgid(arg4), arg5)); |
| 7681 | unlock_user(p, arg2, 0); |
ths | ccfa72b | 2007-09-24 09:23:34 +0000 | [diff] [blame] | 7682 | break; |
| 7683 | #endif |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7684 | #ifdef TARGET_NR_setresuid |
| 7685 | case TARGET_NR_setresuid: |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 7686 | ret = get_errno(setresuid(low2highuid(arg1), |
| 7687 | low2highuid(arg2), |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7688 | low2highuid(arg3))); |
| 7689 | break; |
| 7690 | #endif |
| 7691 | #ifdef TARGET_NR_getresuid |
| 7692 | case TARGET_NR_getresuid: |
| 7693 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7694 | uid_t ruid, euid, suid; |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7695 | ret = get_errno(getresuid(&ruid, &euid, &suid)); |
| 7696 | if (!is_error(ret)) { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 7697 | if (put_user_u16(high2lowuid(ruid), arg1) |
| 7698 | || put_user_u16(high2lowuid(euid), arg2) |
| 7699 | || put_user_u16(high2lowuid(suid), arg3)) |
| 7700 | goto efault; |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7701 | } |
| 7702 | } |
| 7703 | break; |
| 7704 | #endif |
| 7705 | #ifdef TARGET_NR_getresgid |
| 7706 | case TARGET_NR_setresgid: |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 7707 | ret = get_errno(setresgid(low2highgid(arg1), |
| 7708 | low2highgid(arg2), |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7709 | low2highgid(arg3))); |
| 7710 | break; |
| 7711 | #endif |
| 7712 | #ifdef TARGET_NR_getresgid |
| 7713 | case TARGET_NR_getresgid: |
| 7714 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7715 | gid_t rgid, egid, sgid; |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7716 | ret = get_errno(getresgid(&rgid, &egid, &sgid)); |
| 7717 | if (!is_error(ret)) { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 7718 | if (put_user_u16(high2lowgid(rgid), arg1) |
| 7719 | || put_user_u16(high2lowgid(egid), arg2) |
| 7720 | || put_user_u16(high2lowgid(sgid), arg3)) |
| 7721 | goto efault; |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7722 | } |
| 7723 | } |
| 7724 | break; |
| 7725 | #endif |
| 7726 | case TARGET_NR_chown: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7727 | if (!(p = lock_user_string(arg1))) |
| 7728 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7729 | ret = get_errno(chown(p, low2highuid(arg2), low2highgid(arg3))); |
| 7730 | unlock_user(p, arg1, 0); |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7731 | break; |
| 7732 | case TARGET_NR_setuid: |
| 7733 | ret = get_errno(setuid(low2highuid(arg1))); |
| 7734 | break; |
| 7735 | case TARGET_NR_setgid: |
| 7736 | ret = get_errno(setgid(low2highgid(arg1))); |
| 7737 | break; |
| 7738 | case TARGET_NR_setfsuid: |
| 7739 | ret = get_errno(setfsuid(arg1)); |
| 7740 | break; |
| 7741 | case TARGET_NR_setfsgid: |
| 7742 | ret = get_errno(setfsgid(arg1)); |
| 7743 | break; |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7744 | |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7745 | #ifdef TARGET_NR_lchown32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7746 | case TARGET_NR_lchown32: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7747 | if (!(p = lock_user_string(arg1))) |
| 7748 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7749 | ret = get_errno(lchown(p, arg2, arg3)); |
| 7750 | unlock_user(p, arg1, 0); |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 7751 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7752 | #endif |
| 7753 | #ifdef TARGET_NR_getuid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7754 | case TARGET_NR_getuid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 7755 | ret = get_errno(getuid()); |
| 7756 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7757 | #endif |
aurel32 | 64b4d28 | 2008-11-14 17:20:15 +0000 | [diff] [blame] | 7758 | |
| 7759 | #if defined(TARGET_NR_getxuid) && defined(TARGET_ALPHA) |
| 7760 | /* Alpha specific */ |
| 7761 | case TARGET_NR_getxuid: |
Richard Henderson | ba0e276 | 2009-12-09 15:56:29 -0800 | [diff] [blame] | 7762 | { |
| 7763 | uid_t euid; |
| 7764 | euid=geteuid(); |
| 7765 | ((CPUAlphaState *)cpu_env)->ir[IR_A4]=euid; |
| 7766 | } |
aurel32 | 64b4d28 | 2008-11-14 17:20:15 +0000 | [diff] [blame] | 7767 | ret = get_errno(getuid()); |
| 7768 | break; |
| 7769 | #endif |
| 7770 | #if defined(TARGET_NR_getxgid) && defined(TARGET_ALPHA) |
| 7771 | /* Alpha specific */ |
| 7772 | case TARGET_NR_getxgid: |
Richard Henderson | ba0e276 | 2009-12-09 15:56:29 -0800 | [diff] [blame] | 7773 | { |
| 7774 | uid_t egid; |
| 7775 | egid=getegid(); |
| 7776 | ((CPUAlphaState *)cpu_env)->ir[IR_A4]=egid; |
| 7777 | } |
aurel32 | 64b4d28 | 2008-11-14 17:20:15 +0000 | [diff] [blame] | 7778 | ret = get_errno(getgid()); |
| 7779 | break; |
| 7780 | #endif |
Richard Henderson | ba0e276 | 2009-12-09 15:56:29 -0800 | [diff] [blame] | 7781 | #if defined(TARGET_NR_osf_getsysinfo) && defined(TARGET_ALPHA) |
| 7782 | /* Alpha specific */ |
| 7783 | case TARGET_NR_osf_getsysinfo: |
| 7784 | ret = -TARGET_EOPNOTSUPP; |
| 7785 | switch (arg1) { |
| 7786 | case TARGET_GSI_IEEE_FP_CONTROL: |
| 7787 | { |
| 7788 | uint64_t swcr, fpcr = cpu_alpha_load_fpcr (cpu_env); |
| 7789 | |
| 7790 | /* Copied from linux ieee_fpcr_to_swcr. */ |
| 7791 | swcr = (fpcr >> 35) & SWCR_STATUS_MASK; |
| 7792 | swcr |= (fpcr >> 36) & SWCR_MAP_DMZ; |
| 7793 | swcr |= (~fpcr >> 48) & (SWCR_TRAP_ENABLE_INV |
| 7794 | | SWCR_TRAP_ENABLE_DZE |
| 7795 | | SWCR_TRAP_ENABLE_OVF); |
| 7796 | swcr |= (~fpcr >> 57) & (SWCR_TRAP_ENABLE_UNF |
| 7797 | | SWCR_TRAP_ENABLE_INE); |
| 7798 | swcr |= (fpcr >> 47) & SWCR_MAP_UMZ; |
| 7799 | swcr |= (~fpcr >> 41) & SWCR_TRAP_ENABLE_DNO; |
| 7800 | |
| 7801 | if (put_user_u64 (swcr, arg2)) |
| 7802 | goto efault; |
| 7803 | ret = 0; |
| 7804 | } |
| 7805 | break; |
| 7806 | |
| 7807 | /* case GSI_IEEE_STATE_AT_SIGNAL: |
| 7808 | -- Not implemented in linux kernel. |
| 7809 | case GSI_UACPROC: |
| 7810 | -- Retrieves current unaligned access state; not much used. |
| 7811 | case GSI_PROC_TYPE: |
| 7812 | -- Retrieves implver information; surely not used. |
| 7813 | case GSI_GET_HWRPB: |
| 7814 | -- Grabs a copy of the HWRPB; surely not used. |
| 7815 | */ |
| 7816 | } |
| 7817 | break; |
| 7818 | #endif |
| 7819 | #if defined(TARGET_NR_osf_setsysinfo) && defined(TARGET_ALPHA) |
| 7820 | /* Alpha specific */ |
| 7821 | case TARGET_NR_osf_setsysinfo: |
| 7822 | ret = -TARGET_EOPNOTSUPP; |
| 7823 | switch (arg1) { |
| 7824 | case TARGET_SSI_IEEE_FP_CONTROL: |
Richard Henderson | ba0e276 | 2009-12-09 15:56:29 -0800 | [diff] [blame] | 7825 | { |
| 7826 | uint64_t swcr, fpcr, orig_fpcr; |
| 7827 | |
Richard Henderson | 6e06d51 | 2012-06-01 09:08:21 -0700 | [diff] [blame] | 7828 | if (get_user_u64 (swcr, arg2)) { |
Richard Henderson | ba0e276 | 2009-12-09 15:56:29 -0800 | [diff] [blame] | 7829 | goto efault; |
Richard Henderson | 6e06d51 | 2012-06-01 09:08:21 -0700 | [diff] [blame] | 7830 | } |
| 7831 | orig_fpcr = cpu_alpha_load_fpcr(cpu_env); |
Richard Henderson | ba0e276 | 2009-12-09 15:56:29 -0800 | [diff] [blame] | 7832 | fpcr = orig_fpcr & FPCR_DYN_MASK; |
| 7833 | |
| 7834 | /* Copied from linux ieee_swcr_to_fpcr. */ |
| 7835 | fpcr |= (swcr & SWCR_STATUS_MASK) << 35; |
| 7836 | fpcr |= (swcr & SWCR_MAP_DMZ) << 36; |
| 7837 | fpcr |= (~swcr & (SWCR_TRAP_ENABLE_INV |
| 7838 | | SWCR_TRAP_ENABLE_DZE |
| 7839 | | SWCR_TRAP_ENABLE_OVF)) << 48; |
| 7840 | fpcr |= (~swcr & (SWCR_TRAP_ENABLE_UNF |
| 7841 | | SWCR_TRAP_ENABLE_INE)) << 57; |
| 7842 | fpcr |= (swcr & SWCR_MAP_UMZ ? FPCR_UNDZ | FPCR_UNFD : 0); |
| 7843 | fpcr |= (~swcr & SWCR_TRAP_ENABLE_DNO) << 41; |
| 7844 | |
Richard Henderson | 6e06d51 | 2012-06-01 09:08:21 -0700 | [diff] [blame] | 7845 | cpu_alpha_store_fpcr(cpu_env, fpcr); |
| 7846 | ret = 0; |
| 7847 | } |
| 7848 | break; |
| 7849 | |
| 7850 | case TARGET_SSI_IEEE_RAISE_EXCEPTION: |
| 7851 | { |
| 7852 | uint64_t exc, fpcr, orig_fpcr; |
| 7853 | int si_code; |
| 7854 | |
| 7855 | if (get_user_u64(exc, arg2)) { |
| 7856 | goto efault; |
| 7857 | } |
| 7858 | |
| 7859 | orig_fpcr = cpu_alpha_load_fpcr(cpu_env); |
| 7860 | |
| 7861 | /* We only add to the exception status here. */ |
| 7862 | fpcr = orig_fpcr | ((exc & SWCR_STATUS_MASK) << 35); |
| 7863 | |
| 7864 | cpu_alpha_store_fpcr(cpu_env, fpcr); |
Richard Henderson | ba0e276 | 2009-12-09 15:56:29 -0800 | [diff] [blame] | 7865 | ret = 0; |
| 7866 | |
Richard Henderson | 6e06d51 | 2012-06-01 09:08:21 -0700 | [diff] [blame] | 7867 | /* Old exceptions are not signaled. */ |
| 7868 | fpcr &= ~(orig_fpcr & FPCR_STATUS_MASK); |
Richard Henderson | ba0e276 | 2009-12-09 15:56:29 -0800 | [diff] [blame] | 7869 | |
Richard Henderson | 6e06d51 | 2012-06-01 09:08:21 -0700 | [diff] [blame] | 7870 | /* If any exceptions set by this call, |
| 7871 | and are unmasked, send a signal. */ |
| 7872 | si_code = 0; |
| 7873 | if ((fpcr & (FPCR_INE | FPCR_INED)) == FPCR_INE) { |
| 7874 | si_code = TARGET_FPE_FLTRES; |
| 7875 | } |
| 7876 | if ((fpcr & (FPCR_UNF | FPCR_UNFD)) == FPCR_UNF) { |
| 7877 | si_code = TARGET_FPE_FLTUND; |
| 7878 | } |
| 7879 | if ((fpcr & (FPCR_OVF | FPCR_OVFD)) == FPCR_OVF) { |
| 7880 | si_code = TARGET_FPE_FLTOVF; |
| 7881 | } |
| 7882 | if ((fpcr & (FPCR_DZE | FPCR_DZED)) == FPCR_DZE) { |
| 7883 | si_code = TARGET_FPE_FLTDIV; |
| 7884 | } |
| 7885 | if ((fpcr & (FPCR_INV | FPCR_INVD)) == FPCR_INV) { |
| 7886 | si_code = TARGET_FPE_FLTINV; |
| 7887 | } |
| 7888 | if (si_code != 0) { |
| 7889 | target_siginfo_t info; |
| 7890 | info.si_signo = SIGFPE; |
| 7891 | info.si_errno = 0; |
| 7892 | info.si_code = si_code; |
| 7893 | info._sifields._sigfault._addr |
| 7894 | = ((CPUArchState *)cpu_env)->pc; |
| 7895 | queue_signal((CPUArchState *)cpu_env, info.si_signo, &info); |
Richard Henderson | ba0e276 | 2009-12-09 15:56:29 -0800 | [diff] [blame] | 7896 | } |
| 7897 | } |
| 7898 | break; |
| 7899 | |
| 7900 | /* case SSI_NVPAIRS: |
| 7901 | -- Used with SSIN_UACPROC to enable unaligned accesses. |
| 7902 | case SSI_IEEE_STATE_AT_SIGNAL: |
| 7903 | case SSI_IEEE_IGNORE_STATE_AT_SIGNAL: |
| 7904 | -- Not implemented in linux kernel |
| 7905 | */ |
| 7906 | } |
| 7907 | break; |
| 7908 | #endif |
| 7909 | #ifdef TARGET_NR_osf_sigprocmask |
| 7910 | /* Alpha specific. */ |
| 7911 | case TARGET_NR_osf_sigprocmask: |
| 7912 | { |
| 7913 | abi_ulong mask; |
Juan Quintela | bc088ba | 2011-06-16 17:37:10 +0100 | [diff] [blame] | 7914 | int how; |
Richard Henderson | ba0e276 | 2009-12-09 15:56:29 -0800 | [diff] [blame] | 7915 | sigset_t set, oldset; |
| 7916 | |
| 7917 | switch(arg1) { |
| 7918 | case TARGET_SIG_BLOCK: |
| 7919 | how = SIG_BLOCK; |
| 7920 | break; |
| 7921 | case TARGET_SIG_UNBLOCK: |
| 7922 | how = SIG_UNBLOCK; |
| 7923 | break; |
| 7924 | case TARGET_SIG_SETMASK: |
| 7925 | how = SIG_SETMASK; |
| 7926 | break; |
| 7927 | default: |
| 7928 | ret = -TARGET_EINVAL; |
| 7929 | goto fail; |
| 7930 | } |
| 7931 | mask = arg2; |
| 7932 | target_to_host_old_sigset(&set, &mask); |
Juan Quintela | bc088ba | 2011-06-16 17:37:10 +0100 | [diff] [blame] | 7933 | sigprocmask(how, &set, &oldset); |
Richard Henderson | ba0e276 | 2009-12-09 15:56:29 -0800 | [diff] [blame] | 7934 | host_to_target_old_sigset(&mask, &oldset); |
| 7935 | ret = mask; |
| 7936 | } |
| 7937 | break; |
| 7938 | #endif |
aurel32 | 64b4d28 | 2008-11-14 17:20:15 +0000 | [diff] [blame] | 7939 | |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7940 | #ifdef TARGET_NR_getgid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7941 | case TARGET_NR_getgid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 7942 | ret = get_errno(getgid()); |
| 7943 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7944 | #endif |
| 7945 | #ifdef TARGET_NR_geteuid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7946 | case TARGET_NR_geteuid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 7947 | ret = get_errno(geteuid()); |
| 7948 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7949 | #endif |
| 7950 | #ifdef TARGET_NR_getegid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7951 | case TARGET_NR_getegid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 7952 | ret = get_errno(getegid()); |
| 7953 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7954 | #endif |
| 7955 | #ifdef TARGET_NR_setreuid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7956 | case TARGET_NR_setreuid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 7957 | ret = get_errno(setreuid(arg1, arg2)); |
| 7958 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7959 | #endif |
| 7960 | #ifdef TARGET_NR_setregid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7961 | case TARGET_NR_setregid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 7962 | ret = get_errno(setregid(arg1, arg2)); |
| 7963 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7964 | #endif |
| 7965 | #ifdef TARGET_NR_getgroups32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7966 | case TARGET_NR_getgroups32: |
bellard | 99c475a | 2005-01-31 20:45:13 +0000 | [diff] [blame] | 7967 | { |
| 7968 | int gidsetsize = arg1; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7969 | uint32_t *target_grouplist; |
bellard | 99c475a | 2005-01-31 20:45:13 +0000 | [diff] [blame] | 7970 | gid_t *grouplist; |
| 7971 | int i; |
| 7972 | |
| 7973 | grouplist = alloca(gidsetsize * sizeof(gid_t)); |
| 7974 | ret = get_errno(getgroups(gidsetsize, grouplist)); |
balrog | cb3bc23 | 2008-09-20 02:08:13 +0000 | [diff] [blame] | 7975 | if (gidsetsize == 0) |
| 7976 | break; |
bellard | 99c475a | 2005-01-31 20:45:13 +0000 | [diff] [blame] | 7977 | if (!is_error(ret)) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7978 | target_grouplist = lock_user(VERIFY_WRITE, arg2, gidsetsize * 4, 0); |
| 7979 | if (!target_grouplist) { |
| 7980 | ret = -TARGET_EFAULT; |
| 7981 | goto fail; |
| 7982 | } |
balrog | a2155fc | 2008-09-20 02:12:08 +0000 | [diff] [blame] | 7983 | for(i = 0;i < ret; i++) |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7984 | target_grouplist[i] = tswap32(grouplist[i]); |
| 7985 | unlock_user(target_grouplist, arg2, gidsetsize * 4); |
bellard | 99c475a | 2005-01-31 20:45:13 +0000 | [diff] [blame] | 7986 | } |
| 7987 | } |
| 7988 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7989 | #endif |
| 7990 | #ifdef TARGET_NR_setgroups32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7991 | case TARGET_NR_setgroups32: |
bellard | 99c475a | 2005-01-31 20:45:13 +0000 | [diff] [blame] | 7992 | { |
| 7993 | int gidsetsize = arg1; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7994 | uint32_t *target_grouplist; |
bellard | 99c475a | 2005-01-31 20:45:13 +0000 | [diff] [blame] | 7995 | gid_t *grouplist; |
| 7996 | int i; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 7997 | |
bellard | 99c475a | 2005-01-31 20:45:13 +0000 | [diff] [blame] | 7998 | grouplist = alloca(gidsetsize * sizeof(gid_t)); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7999 | target_grouplist = lock_user(VERIFY_READ, arg2, gidsetsize * 4, 1); |
| 8000 | if (!target_grouplist) { |
| 8001 | ret = -TARGET_EFAULT; |
| 8002 | goto fail; |
| 8003 | } |
bellard | 99c475a | 2005-01-31 20:45:13 +0000 | [diff] [blame] | 8004 | for(i = 0;i < gidsetsize; i++) |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8005 | grouplist[i] = tswap32(target_grouplist[i]); |
| 8006 | unlock_user(target_grouplist, arg2, 0); |
bellard | 99c475a | 2005-01-31 20:45:13 +0000 | [diff] [blame] | 8007 | ret = get_errno(setgroups(gidsetsize, grouplist)); |
| 8008 | } |
| 8009 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 8010 | #endif |
| 8011 | #ifdef TARGET_NR_fchown32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8012 | case TARGET_NR_fchown32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 8013 | ret = get_errno(fchown(arg1, arg2, arg3)); |
| 8014 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 8015 | #endif |
| 8016 | #ifdef TARGET_NR_setresuid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8017 | case TARGET_NR_setresuid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 8018 | ret = get_errno(setresuid(arg1, arg2, arg3)); |
| 8019 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 8020 | #endif |
| 8021 | #ifdef TARGET_NR_getresuid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8022 | case TARGET_NR_getresuid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 8023 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8024 | uid_t ruid, euid, suid; |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 8025 | ret = get_errno(getresuid(&ruid, &euid, &suid)); |
| 8026 | if (!is_error(ret)) { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 8027 | if (put_user_u32(ruid, arg1) |
| 8028 | || put_user_u32(euid, arg2) |
| 8029 | || put_user_u32(suid, arg3)) |
| 8030 | goto efault; |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 8031 | } |
| 8032 | } |
| 8033 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 8034 | #endif |
| 8035 | #ifdef TARGET_NR_setresgid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8036 | case TARGET_NR_setresgid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 8037 | ret = get_errno(setresgid(arg1, arg2, arg3)); |
| 8038 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 8039 | #endif |
| 8040 | #ifdef TARGET_NR_getresgid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8041 | case TARGET_NR_getresgid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 8042 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8043 | gid_t rgid, egid, sgid; |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 8044 | ret = get_errno(getresgid(&rgid, &egid, &sgid)); |
| 8045 | if (!is_error(ret)) { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 8046 | if (put_user_u32(rgid, arg1) |
| 8047 | || put_user_u32(egid, arg2) |
| 8048 | || put_user_u32(sgid, arg3)) |
| 8049 | goto efault; |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 8050 | } |
| 8051 | } |
| 8052 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 8053 | #endif |
| 8054 | #ifdef TARGET_NR_chown32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8055 | case TARGET_NR_chown32: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 8056 | if (!(p = lock_user_string(arg1))) |
| 8057 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8058 | ret = get_errno(chown(p, arg2, arg3)); |
| 8059 | unlock_user(p, arg1, 0); |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 8060 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 8061 | #endif |
| 8062 | #ifdef TARGET_NR_setuid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8063 | case TARGET_NR_setuid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 8064 | ret = get_errno(setuid(arg1)); |
| 8065 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 8066 | #endif |
| 8067 | #ifdef TARGET_NR_setgid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8068 | case TARGET_NR_setgid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 8069 | ret = get_errno(setgid(arg1)); |
| 8070 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 8071 | #endif |
| 8072 | #ifdef TARGET_NR_setfsuid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8073 | case TARGET_NR_setfsuid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 8074 | ret = get_errno(setfsuid(arg1)); |
| 8075 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 8076 | #endif |
| 8077 | #ifdef TARGET_NR_setfsgid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8078 | case TARGET_NR_setfsgid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 8079 | ret = get_errno(setfsgid(arg1)); |
| 8080 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 8081 | #endif |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 8082 | |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8083 | case TARGET_NR_pivot_root: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 8084 | goto unimplemented; |
bellard | ffa65c3 | 2004-01-04 23:57:22 +0000 | [diff] [blame] | 8085 | #ifdef TARGET_NR_mincore |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8086 | case TARGET_NR_mincore: |
aurel32 | 04bb9ac | 2008-10-01 21:46:41 +0000 | [diff] [blame] | 8087 | { |
| 8088 | void *a; |
| 8089 | ret = -TARGET_EFAULT; |
| 8090 | if (!(a = lock_user(VERIFY_READ, arg1,arg2, 0))) |
| 8091 | goto efault; |
| 8092 | if (!(p = lock_user_string(arg3))) |
| 8093 | goto mincore_fail; |
| 8094 | ret = get_errno(mincore(a, arg2, p)); |
| 8095 | unlock_user(p, arg3, ret); |
| 8096 | mincore_fail: |
| 8097 | unlock_user(a, arg1, 0); |
| 8098 | } |
| 8099 | break; |
bellard | ffa65c3 | 2004-01-04 23:57:22 +0000 | [diff] [blame] | 8100 | #endif |
aurel32 | 408321b | 2008-10-01 21:46:32 +0000 | [diff] [blame] | 8101 | #ifdef TARGET_NR_arm_fadvise64_64 |
| 8102 | case TARGET_NR_arm_fadvise64_64: |
| 8103 | { |
| 8104 | /* |
| 8105 | * arm_fadvise64_64 looks like fadvise64_64 but |
| 8106 | * with different argument order |
| 8107 | */ |
| 8108 | abi_long temp; |
| 8109 | temp = arg3; |
| 8110 | arg3 = arg4; |
| 8111 | arg4 = temp; |
| 8112 | } |
| 8113 | #endif |
Ulrich Hecht | e72d2cc | 2009-07-24 19:10:31 +0200 | [diff] [blame] | 8114 | #if defined(TARGET_NR_fadvise64_64) || defined(TARGET_NR_arm_fadvise64_64) || defined(TARGET_NR_fadvise64) |
aurel32 | 408321b | 2008-10-01 21:46:32 +0000 | [diff] [blame] | 8115 | #ifdef TARGET_NR_fadvise64_64 |
| 8116 | case TARGET_NR_fadvise64_64: |
| 8117 | #endif |
Ulrich Hecht | e72d2cc | 2009-07-24 19:10:31 +0200 | [diff] [blame] | 8118 | #ifdef TARGET_NR_fadvise64 |
| 8119 | case TARGET_NR_fadvise64: |
| 8120 | #endif |
| 8121 | #ifdef TARGET_S390X |
| 8122 | switch (arg4) { |
| 8123 | case 4: arg4 = POSIX_FADV_NOREUSE + 1; break; /* make sure it's an invalid value */ |
| 8124 | case 5: arg4 = POSIX_FADV_NOREUSE + 2; break; /* ditto */ |
| 8125 | case 6: arg4 = POSIX_FADV_DONTNEED; break; |
| 8126 | case 7: arg4 = POSIX_FADV_NOREUSE; break; |
| 8127 | default: break; |
| 8128 | } |
| 8129 | #endif |
| 8130 | ret = -posix_fadvise(arg1, arg2, arg3, arg4); |
aurel32 | 408321b | 2008-10-01 21:46:32 +0000 | [diff] [blame] | 8131 | break; |
| 8132 | #endif |
bellard | ffa65c3 | 2004-01-04 23:57:22 +0000 | [diff] [blame] | 8133 | #ifdef TARGET_NR_madvise |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8134 | case TARGET_NR_madvise: |
pbrook | 2483668 | 2006-04-16 14:14:53 +0000 | [diff] [blame] | 8135 | /* A straight passthrough may not be safe because qemu sometimes |
| 8136 | turns private flie-backed mappings into anonymous mappings. |
| 8137 | This will break MADV_DONTNEED. |
| 8138 | This is a hint, so ignoring and returning success is ok. */ |
| 8139 | ret = get_errno(0); |
| 8140 | break; |
bellard | ffa65c3 | 2004-01-04 23:57:22 +0000 | [diff] [blame] | 8141 | #endif |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 8142 | #if TARGET_ABI_BITS == 32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8143 | case TARGET_NR_fcntl64: |
bellard | 77e4672 | 2003-04-29 20:39:06 +0000 | [diff] [blame] | 8144 | { |
ths | b1e341e | 2007-03-20 21:50:52 +0000 | [diff] [blame] | 8145 | int cmd; |
bellard | 77e4672 | 2003-04-29 20:39:06 +0000 | [diff] [blame] | 8146 | struct flock64 fl; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8147 | struct target_flock64 *target_fl; |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 8148 | #ifdef TARGET_ARM |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8149 | struct target_eabi_flock64 *target_efl; |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 8150 | #endif |
bellard | 77e4672 | 2003-04-29 20:39:06 +0000 | [diff] [blame] | 8151 | |
Arnaud Patard (Rtp) | 5f10681 | 2009-06-03 14:35:04 +0200 | [diff] [blame] | 8152 | cmd = target_to_host_fcntl_cmd(arg2); |
Peter Maydell | 31b6319 | 2011-12-05 23:11:50 +0000 | [diff] [blame] | 8153 | if (cmd == -TARGET_EINVAL) { |
| 8154 | ret = cmd; |
| 8155 | break; |
| 8156 | } |
ths | b1e341e | 2007-03-20 21:50:52 +0000 | [diff] [blame] | 8157 | |
bellard | 60cd49d | 2003-03-16 22:53:56 +0000 | [diff] [blame] | 8158 | switch(arg2) { |
ths | b1e341e | 2007-03-20 21:50:52 +0000 | [diff] [blame] | 8159 | case TARGET_F_GETLK64: |
ths | 5813427 | 2007-03-31 18:59:32 +0000 | [diff] [blame] | 8160 | #ifdef TARGET_ARM |
| 8161 | if (((CPUARMState *)cpu_env)->eabi) { |
bellard | 9ee1fa2 | 2007-11-11 15:11:19 +0000 | [diff] [blame] | 8162 | if (!lock_user_struct(VERIFY_READ, target_efl, arg3, 1)) |
| 8163 | goto efault; |
ths | 5813427 | 2007-03-31 18:59:32 +0000 | [diff] [blame] | 8164 | fl.l_type = tswap16(target_efl->l_type); |
| 8165 | fl.l_whence = tswap16(target_efl->l_whence); |
| 8166 | fl.l_start = tswap64(target_efl->l_start); |
| 8167 | fl.l_len = tswap64(target_efl->l_len); |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 8168 | fl.l_pid = tswap32(target_efl->l_pid); |
ths | 5813427 | 2007-03-31 18:59:32 +0000 | [diff] [blame] | 8169 | unlock_user_struct(target_efl, arg3, 0); |
| 8170 | } else |
| 8171 | #endif |
| 8172 | { |
bellard | 9ee1fa2 | 2007-11-11 15:11:19 +0000 | [diff] [blame] | 8173 | if (!lock_user_struct(VERIFY_READ, target_fl, arg3, 1)) |
| 8174 | goto efault; |
ths | 5813427 | 2007-03-31 18:59:32 +0000 | [diff] [blame] | 8175 | fl.l_type = tswap16(target_fl->l_type); |
| 8176 | fl.l_whence = tswap16(target_fl->l_whence); |
| 8177 | fl.l_start = tswap64(target_fl->l_start); |
| 8178 | fl.l_len = tswap64(target_fl->l_len); |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 8179 | fl.l_pid = tswap32(target_fl->l_pid); |
ths | 5813427 | 2007-03-31 18:59:32 +0000 | [diff] [blame] | 8180 | unlock_user_struct(target_fl, arg3, 0); |
| 8181 | } |
ths | b1e341e | 2007-03-20 21:50:52 +0000 | [diff] [blame] | 8182 | ret = get_errno(fcntl(arg1, cmd, &fl)); |
bellard | 77e4672 | 2003-04-29 20:39:06 +0000 | [diff] [blame] | 8183 | if (ret == 0) { |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 8184 | #ifdef TARGET_ARM |
| 8185 | if (((CPUARMState *)cpu_env)->eabi) { |
bellard | 9ee1fa2 | 2007-11-11 15:11:19 +0000 | [diff] [blame] | 8186 | if (!lock_user_struct(VERIFY_WRITE, target_efl, arg3, 0)) |
| 8187 | goto efault; |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 8188 | target_efl->l_type = tswap16(fl.l_type); |
| 8189 | target_efl->l_whence = tswap16(fl.l_whence); |
| 8190 | target_efl->l_start = tswap64(fl.l_start); |
| 8191 | target_efl->l_len = tswap64(fl.l_len); |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 8192 | target_efl->l_pid = tswap32(fl.l_pid); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8193 | unlock_user_struct(target_efl, arg3, 1); |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 8194 | } else |
| 8195 | #endif |
| 8196 | { |
bellard | 9ee1fa2 | 2007-11-11 15:11:19 +0000 | [diff] [blame] | 8197 | if (!lock_user_struct(VERIFY_WRITE, target_fl, arg3, 0)) |
| 8198 | goto efault; |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 8199 | target_fl->l_type = tswap16(fl.l_type); |
| 8200 | target_fl->l_whence = tswap16(fl.l_whence); |
| 8201 | target_fl->l_start = tswap64(fl.l_start); |
| 8202 | target_fl->l_len = tswap64(fl.l_len); |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 8203 | target_fl->l_pid = tswap32(fl.l_pid); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8204 | unlock_user_struct(target_fl, arg3, 1); |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 8205 | } |
bellard | 77e4672 | 2003-04-29 20:39:06 +0000 | [diff] [blame] | 8206 | } |
| 8207 | break; |
| 8208 | |
ths | b1e341e | 2007-03-20 21:50:52 +0000 | [diff] [blame] | 8209 | case TARGET_F_SETLK64: |
| 8210 | case TARGET_F_SETLKW64: |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 8211 | #ifdef TARGET_ARM |
| 8212 | if (((CPUARMState *)cpu_env)->eabi) { |
bellard | 9ee1fa2 | 2007-11-11 15:11:19 +0000 | [diff] [blame] | 8213 | if (!lock_user_struct(VERIFY_READ, target_efl, arg3, 1)) |
| 8214 | goto efault; |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 8215 | fl.l_type = tswap16(target_efl->l_type); |
| 8216 | fl.l_whence = tswap16(target_efl->l_whence); |
| 8217 | fl.l_start = tswap64(target_efl->l_start); |
| 8218 | fl.l_len = tswap64(target_efl->l_len); |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 8219 | fl.l_pid = tswap32(target_efl->l_pid); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8220 | unlock_user_struct(target_efl, arg3, 0); |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 8221 | } else |
| 8222 | #endif |
| 8223 | { |
bellard | 9ee1fa2 | 2007-11-11 15:11:19 +0000 | [diff] [blame] | 8224 | if (!lock_user_struct(VERIFY_READ, target_fl, arg3, 1)) |
| 8225 | goto efault; |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 8226 | fl.l_type = tswap16(target_fl->l_type); |
| 8227 | fl.l_whence = tswap16(target_fl->l_whence); |
| 8228 | fl.l_start = tswap64(target_fl->l_start); |
| 8229 | fl.l_len = tswap64(target_fl->l_len); |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 8230 | fl.l_pid = tswap32(target_fl->l_pid); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8231 | unlock_user_struct(target_fl, arg3, 0); |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 8232 | } |
ths | b1e341e | 2007-03-20 21:50:52 +0000 | [diff] [blame] | 8233 | ret = get_errno(fcntl(arg1, cmd, &fl)); |
bellard | 77e4672 | 2003-04-29 20:39:06 +0000 | [diff] [blame] | 8234 | break; |
bellard | 60cd49d | 2003-03-16 22:53:56 +0000 | [diff] [blame] | 8235 | default: |
Arnaud Patard (Rtp) | 5f10681 | 2009-06-03 14:35:04 +0200 | [diff] [blame] | 8236 | ret = do_fcntl(arg1, arg2, arg3); |
bellard | 60cd49d | 2003-03-16 22:53:56 +0000 | [diff] [blame] | 8237 | break; |
| 8238 | } |
bellard | 77e4672 | 2003-04-29 20:39:06 +0000 | [diff] [blame] | 8239 | break; |
| 8240 | } |
bellard | 60cd49d | 2003-03-16 22:53:56 +0000 | [diff] [blame] | 8241 | #endif |
ths | 7d600c8 | 2006-12-08 01:32:58 +0000 | [diff] [blame] | 8242 | #ifdef TARGET_NR_cacheflush |
| 8243 | case TARGET_NR_cacheflush: |
| 8244 | /* self-modifying code is handled automatically, so nothing needed */ |
| 8245 | ret = 0; |
| 8246 | break; |
| 8247 | #endif |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 8248 | #ifdef TARGET_NR_security |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8249 | case TARGET_NR_security: |
| 8250 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 8251 | #endif |
bellard | c573ff6 | 2004-01-04 15:51:36 +0000 | [diff] [blame] | 8252 | #ifdef TARGET_NR_getpagesize |
| 8253 | case TARGET_NR_getpagesize: |
| 8254 | ret = TARGET_PAGE_SIZE; |
| 8255 | break; |
| 8256 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8257 | case TARGET_NR_gettid: |
| 8258 | ret = get_errno(gettid()); |
| 8259 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 8260 | #ifdef TARGET_NR_readahead |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8261 | case TARGET_NR_readahead: |
aurel32 | 2054ac9 | 2008-10-13 21:08:07 +0000 | [diff] [blame] | 8262 | #if TARGET_ABI_BITS == 32 |
Riku Voipio | 48e515d | 2011-07-12 15:40:51 +0300 | [diff] [blame] | 8263 | if (regpairs_aligned(cpu_env)) { |
aurel32 | 2054ac9 | 2008-10-13 21:08:07 +0000 | [diff] [blame] | 8264 | arg2 = arg3; |
| 8265 | arg3 = arg4; |
| 8266 | arg4 = arg5; |
| 8267 | } |
aurel32 | 2054ac9 | 2008-10-13 21:08:07 +0000 | [diff] [blame] | 8268 | ret = get_errno(readahead(arg1, ((off64_t)arg3 << 32) | arg2, arg4)); |
| 8269 | #else |
| 8270 | ret = get_errno(readahead(arg1, arg2, arg3)); |
| 8271 | #endif |
| 8272 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 8273 | #endif |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 8274 | #ifdef CONFIG_ATTR |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 8275 | #ifdef TARGET_NR_setxattr |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8276 | case TARGET_NR_listxattr: |
| 8277 | case TARGET_NR_llistxattr: |
Peter Maydell | fb5590f | 2011-12-14 15:37:19 +0000 | [diff] [blame] | 8278 | { |
| 8279 | void *p, *b = 0; |
| 8280 | if (arg2) { |
| 8281 | b = lock_user(VERIFY_WRITE, arg2, arg3, 0); |
| 8282 | if (!b) { |
| 8283 | ret = -TARGET_EFAULT; |
| 8284 | break; |
| 8285 | } |
| 8286 | } |
| 8287 | p = lock_user_string(arg1); |
| 8288 | if (p) { |
| 8289 | if (num == TARGET_NR_listxattr) { |
| 8290 | ret = get_errno(listxattr(p, b, arg3)); |
| 8291 | } else { |
| 8292 | ret = get_errno(llistxattr(p, b, arg3)); |
| 8293 | } |
| 8294 | } else { |
| 8295 | ret = -TARGET_EFAULT; |
| 8296 | } |
| 8297 | unlock_user(p, arg1, 0); |
| 8298 | unlock_user(b, arg2, arg3); |
Arnaud Patard | 6f932f9 | 2009-04-21 21:04:18 +0300 | [diff] [blame] | 8299 | break; |
Peter Maydell | fb5590f | 2011-12-14 15:37:19 +0000 | [diff] [blame] | 8300 | } |
| 8301 | case TARGET_NR_flistxattr: |
| 8302 | { |
| 8303 | void *b = 0; |
| 8304 | if (arg2) { |
| 8305 | b = lock_user(VERIFY_WRITE, arg2, arg3, 0); |
| 8306 | if (!b) { |
| 8307 | ret = -TARGET_EFAULT; |
| 8308 | break; |
| 8309 | } |
| 8310 | } |
| 8311 | ret = get_errno(flistxattr(arg1, b, arg3)); |
| 8312 | unlock_user(b, arg2, arg3); |
| 8313 | break; |
| 8314 | } |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 8315 | case TARGET_NR_setxattr: |
Peter Maydell | 30297b5 | 2011-12-14 15:37:18 +0000 | [diff] [blame] | 8316 | case TARGET_NR_lsetxattr: |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 8317 | { |
Peter Maydell | e3c33ec | 2011-12-14 15:37:17 +0000 | [diff] [blame] | 8318 | void *p, *n, *v = 0; |
| 8319 | if (arg3) { |
| 8320 | v = lock_user(VERIFY_READ, arg3, arg4, 1); |
| 8321 | if (!v) { |
| 8322 | ret = -TARGET_EFAULT; |
| 8323 | break; |
| 8324 | } |
| 8325 | } |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 8326 | p = lock_user_string(arg1); |
| 8327 | n = lock_user_string(arg2); |
Peter Maydell | e3c33ec | 2011-12-14 15:37:17 +0000 | [diff] [blame] | 8328 | if (p && n) { |
Peter Maydell | 30297b5 | 2011-12-14 15:37:18 +0000 | [diff] [blame] | 8329 | if (num == TARGET_NR_setxattr) { |
| 8330 | ret = get_errno(setxattr(p, n, v, arg4, arg5)); |
| 8331 | } else { |
| 8332 | ret = get_errno(lsetxattr(p, n, v, arg4, arg5)); |
| 8333 | } |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 8334 | } else { |
| 8335 | ret = -TARGET_EFAULT; |
| 8336 | } |
| 8337 | unlock_user(p, arg1, 0); |
| 8338 | unlock_user(n, arg2, 0); |
| 8339 | unlock_user(v, arg3, 0); |
| 8340 | } |
| 8341 | break; |
Peter Maydell | 30297b5 | 2011-12-14 15:37:18 +0000 | [diff] [blame] | 8342 | case TARGET_NR_fsetxattr: |
| 8343 | { |
| 8344 | void *n, *v = 0; |
| 8345 | if (arg3) { |
| 8346 | v = lock_user(VERIFY_READ, arg3, arg4, 1); |
| 8347 | if (!v) { |
| 8348 | ret = -TARGET_EFAULT; |
| 8349 | break; |
| 8350 | } |
| 8351 | } |
| 8352 | n = lock_user_string(arg2); |
| 8353 | if (n) { |
| 8354 | ret = get_errno(fsetxattr(arg1, n, v, arg4, arg5)); |
| 8355 | } else { |
| 8356 | ret = -TARGET_EFAULT; |
| 8357 | } |
| 8358 | unlock_user(n, arg2, 0); |
| 8359 | unlock_user(v, arg3, 0); |
| 8360 | } |
| 8361 | break; |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 8362 | case TARGET_NR_getxattr: |
Peter Maydell | 30297b5 | 2011-12-14 15:37:18 +0000 | [diff] [blame] | 8363 | case TARGET_NR_lgetxattr: |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 8364 | { |
Peter Maydell | e3c33ec | 2011-12-14 15:37:17 +0000 | [diff] [blame] | 8365 | void *p, *n, *v = 0; |
| 8366 | if (arg3) { |
| 8367 | v = lock_user(VERIFY_WRITE, arg3, arg4, 0); |
| 8368 | if (!v) { |
| 8369 | ret = -TARGET_EFAULT; |
| 8370 | break; |
| 8371 | } |
| 8372 | } |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 8373 | p = lock_user_string(arg1); |
| 8374 | n = lock_user_string(arg2); |
Peter Maydell | e3c33ec | 2011-12-14 15:37:17 +0000 | [diff] [blame] | 8375 | if (p && n) { |
Peter Maydell | 30297b5 | 2011-12-14 15:37:18 +0000 | [diff] [blame] | 8376 | if (num == TARGET_NR_getxattr) { |
| 8377 | ret = get_errno(getxattr(p, n, v, arg4)); |
| 8378 | } else { |
| 8379 | ret = get_errno(lgetxattr(p, n, v, arg4)); |
| 8380 | } |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 8381 | } else { |
| 8382 | ret = -TARGET_EFAULT; |
| 8383 | } |
| 8384 | unlock_user(p, arg1, 0); |
| 8385 | unlock_user(n, arg2, 0); |
| 8386 | unlock_user(v, arg3, arg4); |
| 8387 | } |
| 8388 | break; |
Peter Maydell | 30297b5 | 2011-12-14 15:37:18 +0000 | [diff] [blame] | 8389 | case TARGET_NR_fgetxattr: |
| 8390 | { |
| 8391 | void *n, *v = 0; |
| 8392 | if (arg3) { |
| 8393 | v = lock_user(VERIFY_WRITE, arg3, arg4, 0); |
| 8394 | if (!v) { |
| 8395 | ret = -TARGET_EFAULT; |
| 8396 | break; |
| 8397 | } |
| 8398 | } |
| 8399 | n = lock_user_string(arg2); |
| 8400 | if (n) { |
| 8401 | ret = get_errno(fgetxattr(arg1, n, v, arg4)); |
| 8402 | } else { |
| 8403 | ret = -TARGET_EFAULT; |
| 8404 | } |
| 8405 | unlock_user(n, arg2, 0); |
| 8406 | unlock_user(v, arg3, arg4); |
| 8407 | } |
| 8408 | break; |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 8409 | case TARGET_NR_removexattr: |
Peter Maydell | 30297b5 | 2011-12-14 15:37:18 +0000 | [diff] [blame] | 8410 | case TARGET_NR_lremovexattr: |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 8411 | { |
| 8412 | void *p, *n; |
| 8413 | p = lock_user_string(arg1); |
| 8414 | n = lock_user_string(arg2); |
| 8415 | if (p && n) { |
Peter Maydell | 30297b5 | 2011-12-14 15:37:18 +0000 | [diff] [blame] | 8416 | if (num == TARGET_NR_removexattr) { |
| 8417 | ret = get_errno(removexattr(p, n)); |
| 8418 | } else { |
| 8419 | ret = get_errno(lremovexattr(p, n)); |
| 8420 | } |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 8421 | } else { |
| 8422 | ret = -TARGET_EFAULT; |
| 8423 | } |
| 8424 | unlock_user(p, arg1, 0); |
| 8425 | unlock_user(n, arg2, 0); |
| 8426 | } |
| 8427 | break; |
Peter Maydell | 30297b5 | 2011-12-14 15:37:18 +0000 | [diff] [blame] | 8428 | case TARGET_NR_fremovexattr: |
| 8429 | { |
| 8430 | void *n; |
| 8431 | n = lock_user_string(arg2); |
| 8432 | if (n) { |
| 8433 | ret = get_errno(fremovexattr(arg1, n)); |
| 8434 | } else { |
| 8435 | ret = -TARGET_EFAULT; |
| 8436 | } |
| 8437 | unlock_user(n, arg2, 0); |
| 8438 | } |
| 8439 | break; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 8440 | #endif |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 8441 | #endif /* CONFIG_ATTR */ |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 8442 | #ifdef TARGET_NR_set_thread_area |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 8443 | case TARGET_NR_set_thread_area: |
bellard | 8d18e89 | 2007-11-14 15:18:40 +0000 | [diff] [blame] | 8444 | #if defined(TARGET_MIPS) |
ths | 6f5b89a | 2007-03-02 20:48:00 +0000 | [diff] [blame] | 8445 | ((CPUMIPSState *) cpu_env)->tls_value = arg1; |
| 8446 | ret = 0; |
| 8447 | break; |
edgar_igl | ef96779 | 2009-01-07 14:19:38 +0000 | [diff] [blame] | 8448 | #elif defined(TARGET_CRIS) |
| 8449 | if (arg1 & 0xff) |
| 8450 | ret = -TARGET_EINVAL; |
| 8451 | else { |
| 8452 | ((CPUCRISState *) cpu_env)->pregs[PR_PID] = arg1; |
| 8453 | ret = 0; |
| 8454 | } |
| 8455 | break; |
bellard | 8d18e89 | 2007-11-14 15:18:40 +0000 | [diff] [blame] | 8456 | #elif defined(TARGET_I386) && defined(TARGET_ABI32) |
| 8457 | ret = do_set_thread_area(cpu_env, arg1); |
| 8458 | break; |
ths | 6f5b89a | 2007-03-02 20:48:00 +0000 | [diff] [blame] | 8459 | #else |
| 8460 | goto unimplemented_nowarn; |
| 8461 | #endif |
| 8462 | #endif |
| 8463 | #ifdef TARGET_NR_get_thread_area |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 8464 | case TARGET_NR_get_thread_area: |
bellard | 8d18e89 | 2007-11-14 15:18:40 +0000 | [diff] [blame] | 8465 | #if defined(TARGET_I386) && defined(TARGET_ABI32) |
| 8466 | ret = do_get_thread_area(cpu_env, arg1); |
| 8467 | #else |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 8468 | goto unimplemented_nowarn; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 8469 | #endif |
bellard | 8d18e89 | 2007-11-14 15:18:40 +0000 | [diff] [blame] | 8470 | #endif |
bellard | 48dc41e | 2006-06-21 18:15:50 +0000 | [diff] [blame] | 8471 | #ifdef TARGET_NR_getdomainname |
| 8472 | case TARGET_NR_getdomainname: |
| 8473 | goto unimplemented_nowarn; |
| 8474 | #endif |
ths | 6f5b89a | 2007-03-02 20:48:00 +0000 | [diff] [blame] | 8475 | |
ths | b5906f9 | 2007-03-19 13:32:45 +0000 | [diff] [blame] | 8476 | #ifdef TARGET_NR_clock_gettime |
| 8477 | case TARGET_NR_clock_gettime: |
| 8478 | { |
| 8479 | struct timespec ts; |
| 8480 | ret = get_errno(clock_gettime(arg1, &ts)); |
| 8481 | if (!is_error(ret)) { |
| 8482 | host_to_target_timespec(arg2, &ts); |
| 8483 | } |
| 8484 | break; |
| 8485 | } |
| 8486 | #endif |
| 8487 | #ifdef TARGET_NR_clock_getres |
| 8488 | case TARGET_NR_clock_getres: |
| 8489 | { |
| 8490 | struct timespec ts; |
| 8491 | ret = get_errno(clock_getres(arg1, &ts)); |
| 8492 | if (!is_error(ret)) { |
| 8493 | host_to_target_timespec(arg2, &ts); |
| 8494 | } |
| 8495 | break; |
| 8496 | } |
| 8497 | #endif |
pbrook | 63d7651 | 2008-05-29 13:43:29 +0000 | [diff] [blame] | 8498 | #ifdef TARGET_NR_clock_nanosleep |
| 8499 | case TARGET_NR_clock_nanosleep: |
| 8500 | { |
| 8501 | struct timespec ts; |
| 8502 | target_to_host_timespec(&ts, arg3); |
| 8503 | ret = get_errno(clock_nanosleep(arg1, arg2, &ts, arg4 ? &ts : NULL)); |
| 8504 | if (arg4) |
| 8505 | host_to_target_timespec(arg4, &ts); |
| 8506 | break; |
| 8507 | } |
| 8508 | #endif |
ths | b5906f9 | 2007-03-19 13:32:45 +0000 | [diff] [blame] | 8509 | |
ths | 6f5b89a | 2007-03-02 20:48:00 +0000 | [diff] [blame] | 8510 | #if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address) |
| 8511 | case TARGET_NR_set_tid_address: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 8512 | ret = get_errno(set_tid_address((int *)g2h(arg1))); |
| 8513 | break; |
ths | 6f5b89a | 2007-03-02 20:48:00 +0000 | [diff] [blame] | 8514 | #endif |
| 8515 | |
ths | 3ae4320 | 2007-09-16 21:39:48 +0000 | [diff] [blame] | 8516 | #if defined(TARGET_NR_tkill) && defined(__NR_tkill) |
ths | 4cae1d1 | 2007-07-12 11:06:53 +0000 | [diff] [blame] | 8517 | case TARGET_NR_tkill: |
pbrook | 4cb0596 | 2008-05-30 18:05:19 +0000 | [diff] [blame] | 8518 | ret = get_errno(sys_tkill((int)arg1, target_to_host_signal(arg2))); |
ths | 4cae1d1 | 2007-07-12 11:06:53 +0000 | [diff] [blame] | 8519 | break; |
| 8520 | #endif |
| 8521 | |
ths | 3ae4320 | 2007-09-16 21:39:48 +0000 | [diff] [blame] | 8522 | #if defined(TARGET_NR_tgkill) && defined(__NR_tgkill) |
ths | 7145557 | 2007-06-21 21:45:30 +0000 | [diff] [blame] | 8523 | case TARGET_NR_tgkill: |
pbrook | 4cb0596 | 2008-05-30 18:05:19 +0000 | [diff] [blame] | 8524 | ret = get_errno(sys_tgkill((int)arg1, (int)arg2, |
| 8525 | target_to_host_signal(arg3))); |
ths | 7145557 | 2007-06-21 21:45:30 +0000 | [diff] [blame] | 8526 | break; |
| 8527 | #endif |
| 8528 | |
ths | 4f2b1fe | 2007-06-21 21:57:12 +0000 | [diff] [blame] | 8529 | #ifdef TARGET_NR_set_robust_list |
| 8530 | case TARGET_NR_set_robust_list: |
| 8531 | goto unimplemented_nowarn; |
| 8532 | #endif |
| 8533 | |
ths | 9007f0e | 2007-09-25 17:50:37 +0000 | [diff] [blame] | 8534 | #if defined(TARGET_NR_utimensat) && defined(__NR_utimensat) |
| 8535 | case TARGET_NR_utimensat: |
| 8536 | { |
Riku Voipio | ebc996f | 2009-04-21 15:01:51 +0300 | [diff] [blame] | 8537 | struct timespec *tsp, ts[2]; |
| 8538 | if (!arg3) { |
| 8539 | tsp = NULL; |
| 8540 | } else { |
| 8541 | target_to_host_timespec(ts, arg3); |
| 8542 | target_to_host_timespec(ts+1, arg3+sizeof(struct target_timespec)); |
| 8543 | tsp = ts; |
| 8544 | } |
ths | 9007f0e | 2007-09-25 17:50:37 +0000 | [diff] [blame] | 8545 | if (!arg2) |
Riku Voipio | ebc996f | 2009-04-21 15:01:51 +0300 | [diff] [blame] | 8546 | ret = get_errno(sys_utimensat(arg1, NULL, tsp, arg4)); |
ths | 9007f0e | 2007-09-25 17:50:37 +0000 | [diff] [blame] | 8547 | else { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 8548 | if (!(p = lock_user_string(arg2))) { |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 8549 | ret = -TARGET_EFAULT; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 8550 | goto fail; |
| 8551 | } |
Riku Voipio | ebc996f | 2009-04-21 15:01:51 +0300 | [diff] [blame] | 8552 | ret = get_errno(sys_utimensat(arg1, path(p), tsp, arg4)); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 8553 | unlock_user(p, arg2, 0); |
ths | 9007f0e | 2007-09-25 17:50:37 +0000 | [diff] [blame] | 8554 | } |
| 8555 | } |
| 8556 | break; |
| 8557 | #endif |
Juan Quintela | 2f7bb87 | 2009-07-27 16:13:24 +0200 | [diff] [blame] | 8558 | #if defined(CONFIG_USE_NPTL) |
pbrook | bd0c566 | 2008-05-29 14:34:11 +0000 | [diff] [blame] | 8559 | case TARGET_NR_futex: |
| 8560 | ret = do_futex(arg1, arg2, arg3, arg4, arg5, arg6); |
| 8561 | break; |
| 8562 | #endif |
aurel32 | dbfe4c3 | 2009-04-08 21:29:30 +0000 | [diff] [blame] | 8563 | #if defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init) |
aurel32 | 39b5976 | 2008-10-01 21:46:50 +0000 | [diff] [blame] | 8564 | case TARGET_NR_inotify_init: |
| 8565 | ret = get_errno(sys_inotify_init()); |
| 8566 | break; |
| 8567 | #endif |
Stefan Weil | a1606b0 | 2010-03-28 11:44:41 +0200 | [diff] [blame] | 8568 | #ifdef CONFIG_INOTIFY1 |
Riku Voipio | c05c7a7 | 2010-03-26 15:25:11 +0000 | [diff] [blame] | 8569 | #if defined(TARGET_NR_inotify_init1) && defined(__NR_inotify_init1) |
| 8570 | case TARGET_NR_inotify_init1: |
| 8571 | ret = get_errno(sys_inotify_init1(arg1)); |
| 8572 | break; |
| 8573 | #endif |
Stefan Weil | a1606b0 | 2010-03-28 11:44:41 +0200 | [diff] [blame] | 8574 | #endif |
aurel32 | dbfe4c3 | 2009-04-08 21:29:30 +0000 | [diff] [blame] | 8575 | #if defined(TARGET_NR_inotify_add_watch) && defined(__NR_inotify_add_watch) |
aurel32 | 39b5976 | 2008-10-01 21:46:50 +0000 | [diff] [blame] | 8576 | case TARGET_NR_inotify_add_watch: |
| 8577 | p = lock_user_string(arg2); |
| 8578 | ret = get_errno(sys_inotify_add_watch(arg1, path(p), arg3)); |
| 8579 | unlock_user(p, arg2, 0); |
| 8580 | break; |
| 8581 | #endif |
aurel32 | dbfe4c3 | 2009-04-08 21:29:30 +0000 | [diff] [blame] | 8582 | #if defined(TARGET_NR_inotify_rm_watch) && defined(__NR_inotify_rm_watch) |
aurel32 | 39b5976 | 2008-10-01 21:46:50 +0000 | [diff] [blame] | 8583 | case TARGET_NR_inotify_rm_watch: |
| 8584 | ret = get_errno(sys_inotify_rm_watch(arg1, arg2)); |
| 8585 | break; |
| 8586 | #endif |
ths | 9007f0e | 2007-09-25 17:50:37 +0000 | [diff] [blame] | 8587 | |
Nathan Froyd | 8ec9cf8 | 2009-07-22 09:14:36 -0700 | [diff] [blame] | 8588 | #if defined(TARGET_NR_mq_open) && defined(__NR_mq_open) |
aurel32 | 24e1003 | 2009-04-15 16:11:43 +0000 | [diff] [blame] | 8589 | case TARGET_NR_mq_open: |
| 8590 | { |
| 8591 | struct mq_attr posix_mq_attr; |
| 8592 | |
| 8593 | p = lock_user_string(arg1 - 1); |
| 8594 | if (arg4 != 0) |
| 8595 | copy_from_user_mq_attr (&posix_mq_attr, arg4); |
| 8596 | ret = get_errno(mq_open(p, arg2, arg3, &posix_mq_attr)); |
| 8597 | unlock_user (p, arg1, 0); |
| 8598 | } |
| 8599 | break; |
| 8600 | |
| 8601 | case TARGET_NR_mq_unlink: |
| 8602 | p = lock_user_string(arg1 - 1); |
| 8603 | ret = get_errno(mq_unlink(p)); |
| 8604 | unlock_user (p, arg1, 0); |
| 8605 | break; |
| 8606 | |
| 8607 | case TARGET_NR_mq_timedsend: |
| 8608 | { |
| 8609 | struct timespec ts; |
| 8610 | |
| 8611 | p = lock_user (VERIFY_READ, arg2, arg3, 1); |
| 8612 | if (arg5 != 0) { |
| 8613 | target_to_host_timespec(&ts, arg5); |
| 8614 | ret = get_errno(mq_timedsend(arg1, p, arg3, arg4, &ts)); |
| 8615 | host_to_target_timespec(arg5, &ts); |
| 8616 | } |
| 8617 | else |
| 8618 | ret = get_errno(mq_send(arg1, p, arg3, arg4)); |
| 8619 | unlock_user (p, arg2, arg3); |
| 8620 | } |
| 8621 | break; |
| 8622 | |
| 8623 | case TARGET_NR_mq_timedreceive: |
| 8624 | { |
| 8625 | struct timespec ts; |
| 8626 | unsigned int prio; |
| 8627 | |
| 8628 | p = lock_user (VERIFY_READ, arg2, arg3, 1); |
| 8629 | if (arg5 != 0) { |
| 8630 | target_to_host_timespec(&ts, arg5); |
| 8631 | ret = get_errno(mq_timedreceive(arg1, p, arg3, &prio, &ts)); |
| 8632 | host_to_target_timespec(arg5, &ts); |
| 8633 | } |
| 8634 | else |
| 8635 | ret = get_errno(mq_receive(arg1, p, arg3, &prio)); |
| 8636 | unlock_user (p, arg2, arg3); |
| 8637 | if (arg4 != 0) |
| 8638 | put_user_u32(prio, arg4); |
| 8639 | } |
| 8640 | break; |
| 8641 | |
| 8642 | /* Not implemented for now... */ |
| 8643 | /* case TARGET_NR_mq_notify: */ |
| 8644 | /* break; */ |
| 8645 | |
| 8646 | case TARGET_NR_mq_getsetattr: |
| 8647 | { |
| 8648 | struct mq_attr posix_mq_attr_in, posix_mq_attr_out; |
| 8649 | ret = 0; |
| 8650 | if (arg3 != 0) { |
| 8651 | ret = mq_getattr(arg1, &posix_mq_attr_out); |
| 8652 | copy_to_user_mq_attr(arg3, &posix_mq_attr_out); |
| 8653 | } |
| 8654 | if (arg2 != 0) { |
| 8655 | copy_from_user_mq_attr(&posix_mq_attr_in, arg2); |
| 8656 | ret |= mq_setattr(arg1, &posix_mq_attr_in, &posix_mq_attr_out); |
| 8657 | } |
| 8658 | |
| 8659 | } |
| 8660 | break; |
| 8661 | #endif |
| 8662 | |
vibisreenivasan | 3ce34df | 2009-05-16 18:32:41 +0530 | [diff] [blame] | 8663 | #ifdef CONFIG_SPLICE |
| 8664 | #ifdef TARGET_NR_tee |
| 8665 | case TARGET_NR_tee: |
| 8666 | { |
| 8667 | ret = get_errno(tee(arg1,arg2,arg3,arg4)); |
| 8668 | } |
| 8669 | break; |
| 8670 | #endif |
| 8671 | #ifdef TARGET_NR_splice |
| 8672 | case TARGET_NR_splice: |
| 8673 | { |
| 8674 | loff_t loff_in, loff_out; |
| 8675 | loff_t *ploff_in = NULL, *ploff_out = NULL; |
| 8676 | if(arg2) { |
| 8677 | get_user_u64(loff_in, arg2); |
| 8678 | ploff_in = &loff_in; |
| 8679 | } |
| 8680 | if(arg4) { |
| 8681 | get_user_u64(loff_out, arg2); |
| 8682 | ploff_out = &loff_out; |
| 8683 | } |
| 8684 | ret = get_errno(splice(arg1, ploff_in, arg3, ploff_out, arg5, arg6)); |
| 8685 | } |
| 8686 | break; |
| 8687 | #endif |
| 8688 | #ifdef TARGET_NR_vmsplice |
| 8689 | case TARGET_NR_vmsplice: |
| 8690 | { |
Richard Henderson | f287b2c | 2012-09-15 13:20:25 -0700 | [diff] [blame] | 8691 | struct iovec *vec = lock_iovec(VERIFY_READ, arg2, arg3, 1); |
| 8692 | if (vec != NULL) { |
| 8693 | ret = get_errno(vmsplice(arg1, vec, arg3, arg4)); |
| 8694 | unlock_iovec(vec, arg2, arg3, 0); |
| 8695 | } else { |
| 8696 | ret = -host_to_target_errno(errno); |
| 8697 | } |
vibisreenivasan | 3ce34df | 2009-05-16 18:32:41 +0530 | [diff] [blame] | 8698 | } |
| 8699 | break; |
| 8700 | #endif |
| 8701 | #endif /* CONFIG_SPLICE */ |
Riku Voipio | c2882b9 | 2009-08-12 15:08:24 +0300 | [diff] [blame] | 8702 | #ifdef CONFIG_EVENTFD |
| 8703 | #if defined(TARGET_NR_eventfd) |
| 8704 | case TARGET_NR_eventfd: |
| 8705 | ret = get_errno(eventfd(arg1, 0)); |
| 8706 | break; |
| 8707 | #endif |
| 8708 | #if defined(TARGET_NR_eventfd2) |
| 8709 | case TARGET_NR_eventfd2: |
| 8710 | ret = get_errno(eventfd(arg1, arg2)); |
| 8711 | break; |
| 8712 | #endif |
| 8713 | #endif /* CONFIG_EVENTFD */ |
Ulrich Hecht | d092793 | 2009-09-17 20:22:14 +0300 | [diff] [blame] | 8714 | #if defined(CONFIG_FALLOCATE) && defined(TARGET_NR_fallocate) |
| 8715 | case TARGET_NR_fallocate: |
Alexander Graf | 20249ae | 2012-02-06 21:37:07 +0100 | [diff] [blame] | 8716 | #if TARGET_ABI_BITS == 32 |
| 8717 | ret = get_errno(fallocate(arg1, arg2, target_offset64(arg3, arg4), |
| 8718 | target_offset64(arg5, arg6))); |
| 8719 | #else |
Ulrich Hecht | d092793 | 2009-09-17 20:22:14 +0300 | [diff] [blame] | 8720 | ret = get_errno(fallocate(arg1, arg2, arg3, arg4)); |
Alexander Graf | 20249ae | 2012-02-06 21:37:07 +0100 | [diff] [blame] | 8721 | #endif |
Ulrich Hecht | d092793 | 2009-09-17 20:22:14 +0300 | [diff] [blame] | 8722 | break; |
| 8723 | #endif |
Peter Maydell | c727f47 | 2011-01-06 11:05:10 +0000 | [diff] [blame] | 8724 | #if defined(CONFIG_SYNC_FILE_RANGE) |
| 8725 | #if defined(TARGET_NR_sync_file_range) |
| 8726 | case TARGET_NR_sync_file_range: |
| 8727 | #if TARGET_ABI_BITS == 32 |
Riku Voipio | bfcedc5 | 2011-06-20 16:24:39 +0300 | [diff] [blame] | 8728 | #if defined(TARGET_MIPS) |
| 8729 | ret = get_errno(sync_file_range(arg1, target_offset64(arg3, arg4), |
| 8730 | target_offset64(arg5, arg6), arg7)); |
| 8731 | #else |
Peter Maydell | c727f47 | 2011-01-06 11:05:10 +0000 | [diff] [blame] | 8732 | ret = get_errno(sync_file_range(arg1, target_offset64(arg2, arg3), |
| 8733 | target_offset64(arg4, arg5), arg6)); |
Riku Voipio | bfcedc5 | 2011-06-20 16:24:39 +0300 | [diff] [blame] | 8734 | #endif /* !TARGET_MIPS */ |
Peter Maydell | c727f47 | 2011-01-06 11:05:10 +0000 | [diff] [blame] | 8735 | #else |
| 8736 | ret = get_errno(sync_file_range(arg1, arg2, arg3, arg4)); |
| 8737 | #endif |
| 8738 | break; |
| 8739 | #endif |
| 8740 | #if defined(TARGET_NR_sync_file_range2) |
| 8741 | case TARGET_NR_sync_file_range2: |
| 8742 | /* This is like sync_file_range but the arguments are reordered */ |
| 8743 | #if TARGET_ABI_BITS == 32 |
| 8744 | ret = get_errno(sync_file_range(arg1, target_offset64(arg3, arg4), |
| 8745 | target_offset64(arg5, arg6), arg2)); |
| 8746 | #else |
| 8747 | ret = get_errno(sync_file_range(arg1, arg3, arg4, arg2)); |
| 8748 | #endif |
| 8749 | break; |
| 8750 | #endif |
| 8751 | #endif |
Peter Maydell | 3b6edd1 | 2011-02-15 18:35:05 +0000 | [diff] [blame] | 8752 | #if defined(CONFIG_EPOLL) |
| 8753 | #if defined(TARGET_NR_epoll_create) |
| 8754 | case TARGET_NR_epoll_create: |
| 8755 | ret = get_errno(epoll_create(arg1)); |
| 8756 | break; |
| 8757 | #endif |
| 8758 | #if defined(TARGET_NR_epoll_create1) && defined(CONFIG_EPOLL_CREATE1) |
| 8759 | case TARGET_NR_epoll_create1: |
| 8760 | ret = get_errno(epoll_create1(arg1)); |
| 8761 | break; |
| 8762 | #endif |
| 8763 | #if defined(TARGET_NR_epoll_ctl) |
| 8764 | case TARGET_NR_epoll_ctl: |
| 8765 | { |
| 8766 | struct epoll_event ep; |
| 8767 | struct epoll_event *epp = 0; |
| 8768 | if (arg4) { |
| 8769 | struct target_epoll_event *target_ep; |
| 8770 | if (!lock_user_struct(VERIFY_READ, target_ep, arg4, 1)) { |
| 8771 | goto efault; |
| 8772 | } |
| 8773 | ep.events = tswap32(target_ep->events); |
| 8774 | /* The epoll_data_t union is just opaque data to the kernel, |
| 8775 | * so we transfer all 64 bits across and need not worry what |
| 8776 | * actual data type it is. |
| 8777 | */ |
| 8778 | ep.data.u64 = tswap64(target_ep->data.u64); |
| 8779 | unlock_user_struct(target_ep, arg4, 0); |
| 8780 | epp = &ep; |
| 8781 | } |
| 8782 | ret = get_errno(epoll_ctl(arg1, arg2, arg3, epp)); |
| 8783 | break; |
| 8784 | } |
| 8785 | #endif |
| 8786 | |
| 8787 | #if defined(TARGET_NR_epoll_pwait) && defined(CONFIG_EPOLL_PWAIT) |
| 8788 | #define IMPLEMENT_EPOLL_PWAIT |
| 8789 | #endif |
| 8790 | #if defined(TARGET_NR_epoll_wait) || defined(IMPLEMENT_EPOLL_PWAIT) |
| 8791 | #if defined(TARGET_NR_epoll_wait) |
| 8792 | case TARGET_NR_epoll_wait: |
| 8793 | #endif |
| 8794 | #if defined(IMPLEMENT_EPOLL_PWAIT) |
| 8795 | case TARGET_NR_epoll_pwait: |
| 8796 | #endif |
| 8797 | { |
| 8798 | struct target_epoll_event *target_ep; |
| 8799 | struct epoll_event *ep; |
| 8800 | int epfd = arg1; |
| 8801 | int maxevents = arg3; |
| 8802 | int timeout = arg4; |
| 8803 | |
| 8804 | target_ep = lock_user(VERIFY_WRITE, arg2, |
| 8805 | maxevents * sizeof(struct target_epoll_event), 1); |
| 8806 | if (!target_ep) { |
| 8807 | goto efault; |
| 8808 | } |
| 8809 | |
| 8810 | ep = alloca(maxevents * sizeof(struct epoll_event)); |
| 8811 | |
| 8812 | switch (num) { |
| 8813 | #if defined(IMPLEMENT_EPOLL_PWAIT) |
| 8814 | case TARGET_NR_epoll_pwait: |
| 8815 | { |
| 8816 | target_sigset_t *target_set; |
| 8817 | sigset_t _set, *set = &_set; |
| 8818 | |
| 8819 | if (arg5) { |
| 8820 | target_set = lock_user(VERIFY_READ, arg5, |
| 8821 | sizeof(target_sigset_t), 1); |
| 8822 | if (!target_set) { |
| 8823 | unlock_user(target_ep, arg2, 0); |
| 8824 | goto efault; |
| 8825 | } |
| 8826 | target_to_host_sigset(set, target_set); |
| 8827 | unlock_user(target_set, arg5, 0); |
| 8828 | } else { |
| 8829 | set = NULL; |
| 8830 | } |
| 8831 | |
| 8832 | ret = get_errno(epoll_pwait(epfd, ep, maxevents, timeout, set)); |
| 8833 | break; |
| 8834 | } |
| 8835 | #endif |
| 8836 | #if defined(TARGET_NR_epoll_wait) |
| 8837 | case TARGET_NR_epoll_wait: |
| 8838 | ret = get_errno(epoll_wait(epfd, ep, maxevents, timeout)); |
| 8839 | break; |
| 8840 | #endif |
| 8841 | default: |
| 8842 | ret = -TARGET_ENOSYS; |
| 8843 | } |
| 8844 | if (!is_error(ret)) { |
| 8845 | int i; |
| 8846 | for (i = 0; i < ret; i++) { |
| 8847 | target_ep[i].events = tswap32(ep[i].events); |
| 8848 | target_ep[i].data.u64 = tswap64(ep[i].data.u64); |
| 8849 | } |
| 8850 | } |
| 8851 | unlock_user(target_ep, arg2, ret * sizeof(struct target_epoll_event)); |
| 8852 | break; |
| 8853 | } |
| 8854 | #endif |
| 8855 | #endif |
Peter Maydell | 163a05a | 2011-06-27 17:44:52 +0100 | [diff] [blame] | 8856 | #ifdef TARGET_NR_prlimit64 |
| 8857 | case TARGET_NR_prlimit64: |
| 8858 | { |
| 8859 | /* args: pid, resource number, ptr to new rlimit, ptr to old rlimit */ |
| 8860 | struct target_rlimit64 *target_rnew, *target_rold; |
| 8861 | struct host_rlimit64 rnew, rold, *rnewp = 0; |
| 8862 | if (arg3) { |
| 8863 | if (!lock_user_struct(VERIFY_READ, target_rnew, arg3, 1)) { |
| 8864 | goto efault; |
| 8865 | } |
| 8866 | rnew.rlim_cur = tswap64(target_rnew->rlim_cur); |
| 8867 | rnew.rlim_max = tswap64(target_rnew->rlim_max); |
| 8868 | unlock_user_struct(target_rnew, arg3, 0); |
| 8869 | rnewp = &rnew; |
| 8870 | } |
| 8871 | |
| 8872 | ret = get_errno(sys_prlimit64(arg1, arg2, rnewp, arg4 ? &rold : 0)); |
| 8873 | if (!is_error(ret) && arg4) { |
| 8874 | if (!lock_user_struct(VERIFY_WRITE, target_rold, arg4, 1)) { |
| 8875 | goto efault; |
| 8876 | } |
| 8877 | target_rold->rlim_cur = tswap64(rold.rlim_cur); |
| 8878 | target_rold->rlim_max = tswap64(rold.rlim_max); |
| 8879 | unlock_user_struct(target_rold, arg4, 1); |
| 8880 | } |
| 8881 | break; |
| 8882 | } |
| 8883 | #endif |
Richard Henderson | 3d21d29 | 2012-09-15 13:20:46 -0700 | [diff] [blame] | 8884 | #ifdef TARGET_NR_gethostname |
| 8885 | case TARGET_NR_gethostname: |
| 8886 | { |
| 8887 | char *name = lock_user(VERIFY_WRITE, arg1, arg2, 0); |
| 8888 | if (name) { |
| 8889 | ret = get_errno(gethostname(name, arg2)); |
| 8890 | unlock_user(name, arg1, arg2); |
| 8891 | } else { |
| 8892 | ret = -TARGET_EFAULT; |
| 8893 | } |
| 8894 | break; |
| 8895 | } |
| 8896 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8897 | default: |
| 8898 | unimplemented: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 8899 | gemu_log("qemu: Unsupported syscall: %d\n", num); |
ths | 4f2b1fe | 2007-06-21 21:57:12 +0000 | [diff] [blame] | 8900 | #if defined(TARGET_NR_setxattr) || defined(TARGET_NR_get_thread_area) || defined(TARGET_NR_getdomainname) || defined(TARGET_NR_set_robust_list) |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 8901 | unimplemented_nowarn: |
bellard | 80a9d03 | 2005-01-03 23:31:27 +0000 | [diff] [blame] | 8902 | #endif |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 8903 | ret = -TARGET_ENOSYS; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8904 | break; |
| 8905 | } |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 8906 | fail: |
bellard | c573ff6 | 2004-01-04 15:51:36 +0000 | [diff] [blame] | 8907 | #ifdef DEBUG |
Blue Swirl | 0bf9e31 | 2009-07-20 17:19:25 +0000 | [diff] [blame] | 8908 | gemu_log(" = " TARGET_ABI_FMT_ld "\n", ret); |
bellard | c573ff6 | 2004-01-04 15:51:36 +0000 | [diff] [blame] | 8909 | #endif |
ths | b92c47c | 2007-11-01 00:07:38 +0000 | [diff] [blame] | 8910 | if(do_strace) |
| 8911 | print_syscall_ret(num, ret); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8912 | return ret; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 8913 | efault: |
| 8914 | ret = -TARGET_EFAULT; |
| 8915 | goto fail; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8916 | } |