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 | 79bbbaa | 2012-07-23 13:50:58 +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 |
| 222 | _syscall2(int, sys_getpriority, int, which, int, who); |
Richard Henderson | d35b261 | 2010-06-04 12:14:10 -0700 | [diff] [blame] | 223 | #if defined(TARGET_NR__llseek) && defined(__NR_llseek) |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 224 | _syscall5(int, _llseek, uint, fd, ulong, hi, ulong, lo, |
| 225 | loff_t *, res, uint, wh); |
| 226 | #endif |
| 227 | _syscall3(int,sys_rt_sigqueueinfo,int,pid,int,sig,siginfo_t *,uinfo) |
| 228 | _syscall3(int,sys_syslog,int,type,char*,bufp,int,len) |
| 229 | #if defined(TARGET_NR_tgkill) && defined(__NR_tgkill) |
| 230 | _syscall3(int,sys_tgkill,int,tgid,int,pid,int,sig) |
| 231 | #endif |
| 232 | #if defined(TARGET_NR_tkill) && defined(__NR_tkill) |
| 233 | _syscall2(int,sys_tkill,int,tid,int,sig) |
| 234 | #endif |
| 235 | #ifdef __NR_exit_group |
| 236 | _syscall1(int,exit_group,int,error_code) |
| 237 | #endif |
| 238 | #if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address) |
| 239 | _syscall1(int,set_tid_address,int *,tidptr) |
| 240 | #endif |
Juan Quintela | 2f7bb87 | 2009-07-27 16:13:24 +0200 | [diff] [blame] | 241 | #if defined(CONFIG_USE_NPTL) |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 242 | #if defined(TARGET_NR_futex) && defined(__NR_futex) |
| 243 | _syscall6(int,sys_futex,int *,uaddr,int,op,int,val, |
| 244 | const struct timespec *,timeout,int *,uaddr2,int,val3) |
| 245 | #endif |
| 246 | #endif |
Mike Frysinger | 737de1d | 2011-02-07 01:05:55 -0500 | [diff] [blame] | 247 | #define __NR_sys_sched_getaffinity __NR_sched_getaffinity |
| 248 | _syscall3(int, sys_sched_getaffinity, pid_t, pid, unsigned int, len, |
| 249 | unsigned long *, user_mask_ptr); |
| 250 | #define __NR_sys_sched_setaffinity __NR_sched_setaffinity |
| 251 | _syscall3(int, sys_sched_setaffinity, pid_t, pid, unsigned int, len, |
| 252 | unsigned long *, user_mask_ptr); |
Alexander Graf | 0f6b4d2 | 2011-09-27 14:39:42 +0200 | [diff] [blame] | 253 | _syscall4(int, reboot, int, magic1, int, magic2, unsigned int, cmd, |
| 254 | void *, arg); |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 255 | |
| 256 | static bitmask_transtbl fcntl_flags_tbl[] = { |
| 257 | { TARGET_O_ACCMODE, TARGET_O_WRONLY, O_ACCMODE, O_WRONLY, }, |
| 258 | { TARGET_O_ACCMODE, TARGET_O_RDWR, O_ACCMODE, O_RDWR, }, |
| 259 | { TARGET_O_CREAT, TARGET_O_CREAT, O_CREAT, O_CREAT, }, |
| 260 | { TARGET_O_EXCL, TARGET_O_EXCL, O_EXCL, O_EXCL, }, |
| 261 | { TARGET_O_NOCTTY, TARGET_O_NOCTTY, O_NOCTTY, O_NOCTTY, }, |
| 262 | { TARGET_O_TRUNC, TARGET_O_TRUNC, O_TRUNC, O_TRUNC, }, |
| 263 | { TARGET_O_APPEND, TARGET_O_APPEND, O_APPEND, O_APPEND, }, |
| 264 | { TARGET_O_NONBLOCK, TARGET_O_NONBLOCK, O_NONBLOCK, O_NONBLOCK, }, |
| 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, }, |
| 269 | { TARGET_O_LARGEFILE, TARGET_O_LARGEFILE, O_LARGEFILE, O_LARGEFILE, }, |
| 270 | #if defined(O_DIRECT) |
| 271 | { TARGET_O_DIRECT, TARGET_O_DIRECT, O_DIRECT, O_DIRECT, }, |
| 272 | #endif |
| 273 | { 0, 0, 0, 0 } |
| 274 | }; |
| 275 | |
| 276 | #define COPY_UTSNAME_FIELD(dest, src) \ |
| 277 | do { \ |
| 278 | /* __NEW_UTS_LEN doesn't include terminating null */ \ |
| 279 | (void) strncpy((dest), (src), __NEW_UTS_LEN); \ |
| 280 | (dest)[__NEW_UTS_LEN] = '\0'; \ |
| 281 | } while (0) |
| 282 | |
| 283 | static int sys_uname(struct new_utsname *buf) |
| 284 | { |
| 285 | struct utsname uts_buf; |
| 286 | |
| 287 | if (uname(&uts_buf) < 0) |
| 288 | return (-1); |
| 289 | |
| 290 | /* |
| 291 | * Just in case these have some differences, we |
| 292 | * translate utsname to new_utsname (which is the |
| 293 | * struct linux kernel uses). |
| 294 | */ |
| 295 | |
Stefan Weil | 67bd9ed | 2011-05-07 22:32:25 +0200 | [diff] [blame] | 296 | memset(buf, 0, sizeof(*buf)); |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 297 | COPY_UTSNAME_FIELD(buf->sysname, uts_buf.sysname); |
| 298 | COPY_UTSNAME_FIELD(buf->nodename, uts_buf.nodename); |
| 299 | COPY_UTSNAME_FIELD(buf->release, uts_buf.release); |
| 300 | COPY_UTSNAME_FIELD(buf->version, uts_buf.version); |
| 301 | COPY_UTSNAME_FIELD(buf->machine, uts_buf.machine); |
| 302 | #ifdef _GNU_SOURCE |
| 303 | COPY_UTSNAME_FIELD(buf->domainname, uts_buf.domainname); |
| 304 | #endif |
| 305 | return (0); |
| 306 | |
| 307 | #undef COPY_UTSNAME_FIELD |
| 308 | } |
| 309 | |
| 310 | static int sys_getcwd1(char *buf, size_t size) |
| 311 | { |
| 312 | if (getcwd(buf, size) == NULL) { |
| 313 | /* getcwd() sets errno */ |
| 314 | return (-1); |
| 315 | } |
aurel32 | aaf4ad3 | 2009-04-16 14:17:14 +0000 | [diff] [blame] | 316 | return strlen(buf)+1; |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | #ifdef CONFIG_ATFILE |
| 320 | /* |
| 321 | * Host system seems to have atfile syscall stubs available. We |
| 322 | * now enable them one by one as specified by target syscall_nr.h. |
| 323 | */ |
| 324 | |
| 325 | #ifdef TARGET_NR_faccessat |
aurel32 | 465c9f0 | 2009-04-19 08:52:17 +0000 | [diff] [blame] | 326 | static int sys_faccessat(int dirfd, const char *pathname, int mode) |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 327 | { |
aurel32 | 465c9f0 | 2009-04-19 08:52:17 +0000 | [diff] [blame] | 328 | return (faccessat(dirfd, pathname, mode, 0)); |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 329 | } |
| 330 | #endif |
| 331 | #ifdef TARGET_NR_fchmodat |
aurel32 | 465c9f0 | 2009-04-19 08:52:17 +0000 | [diff] [blame] | 332 | static int sys_fchmodat(int dirfd, const char *pathname, mode_t mode) |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 333 | { |
aurel32 | 465c9f0 | 2009-04-19 08:52:17 +0000 | [diff] [blame] | 334 | return (fchmodat(dirfd, pathname, mode, 0)); |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 335 | } |
| 336 | #endif |
Riku Voipio | 0c866a7 | 2011-04-18 15:23:06 +0300 | [diff] [blame] | 337 | #if defined(TARGET_NR_fchownat) |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 338 | static int sys_fchownat(int dirfd, const char *pathname, uid_t owner, |
| 339 | gid_t group, int flags) |
| 340 | { |
| 341 | return (fchownat(dirfd, pathname, owner, group, flags)); |
| 342 | } |
| 343 | #endif |
| 344 | #ifdef __NR_fstatat64 |
| 345 | static int sys_fstatat64(int dirfd, const char *pathname, struct stat *buf, |
| 346 | int flags) |
| 347 | { |
| 348 | return (fstatat(dirfd, pathname, buf, flags)); |
| 349 | } |
| 350 | #endif |
| 351 | #ifdef __NR_newfstatat |
| 352 | static int sys_newfstatat(int dirfd, const char *pathname, struct stat *buf, |
| 353 | int flags) |
| 354 | { |
| 355 | return (fstatat(dirfd, pathname, buf, flags)); |
| 356 | } |
| 357 | #endif |
| 358 | #ifdef TARGET_NR_futimesat |
| 359 | static int sys_futimesat(int dirfd, const char *pathname, |
| 360 | const struct timeval times[2]) |
| 361 | { |
| 362 | return (futimesat(dirfd, pathname, times)); |
| 363 | } |
| 364 | #endif |
| 365 | #ifdef TARGET_NR_linkat |
| 366 | static int sys_linkat(int olddirfd, const char *oldpath, |
| 367 | int newdirfd, const char *newpath, int flags) |
| 368 | { |
| 369 | return (linkat(olddirfd, oldpath, newdirfd, newpath, flags)); |
| 370 | } |
| 371 | #endif |
| 372 | #ifdef TARGET_NR_mkdirat |
| 373 | static int sys_mkdirat(int dirfd, const char *pathname, mode_t mode) |
| 374 | { |
| 375 | return (mkdirat(dirfd, pathname, mode)); |
| 376 | } |
| 377 | #endif |
| 378 | #ifdef TARGET_NR_mknodat |
| 379 | static int sys_mknodat(int dirfd, const char *pathname, mode_t mode, |
| 380 | dev_t dev) |
| 381 | { |
| 382 | return (mknodat(dirfd, pathname, mode, dev)); |
| 383 | } |
| 384 | #endif |
| 385 | #ifdef TARGET_NR_openat |
Alexander Graf | f4c6901 | 2011-09-25 06:25:35 +0200 | [diff] [blame] | 386 | 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] | 387 | { |
| 388 | /* |
| 389 | * open(2) has extra parameter 'mode' when called with |
| 390 | * flag O_CREAT. |
| 391 | */ |
| 392 | if ((flags & O_CREAT) != 0) { |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 393 | return (openat(dirfd, pathname, flags, mode)); |
| 394 | } |
| 395 | return (openat(dirfd, pathname, flags)); |
| 396 | } |
| 397 | #endif |
| 398 | #ifdef TARGET_NR_readlinkat |
| 399 | static int sys_readlinkat(int dirfd, const char *pathname, char *buf, size_t bufsiz) |
| 400 | { |
| 401 | return (readlinkat(dirfd, pathname, buf, bufsiz)); |
| 402 | } |
| 403 | #endif |
| 404 | #ifdef TARGET_NR_renameat |
| 405 | static int sys_renameat(int olddirfd, const char *oldpath, |
| 406 | int newdirfd, const char *newpath) |
| 407 | { |
| 408 | return (renameat(olddirfd, oldpath, newdirfd, newpath)); |
| 409 | } |
| 410 | #endif |
| 411 | #ifdef TARGET_NR_symlinkat |
| 412 | static int sys_symlinkat(const char *oldpath, int newdirfd, const char *newpath) |
| 413 | { |
| 414 | return (symlinkat(oldpath, newdirfd, newpath)); |
| 415 | } |
| 416 | #endif |
| 417 | #ifdef TARGET_NR_unlinkat |
| 418 | static int sys_unlinkat(int dirfd, const char *pathname, int flags) |
| 419 | { |
| 420 | return (unlinkat(dirfd, pathname, flags)); |
| 421 | } |
| 422 | #endif |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 423 | #else /* !CONFIG_ATFILE */ |
| 424 | |
| 425 | /* |
| 426 | * Try direct syscalls instead |
| 427 | */ |
ths | 92a34c1 | 2007-09-24 09:27:49 +0000 | [diff] [blame] | 428 | #if defined(TARGET_NR_faccessat) && defined(__NR_faccessat) |
aurel32 | 465c9f0 | 2009-04-19 08:52:17 +0000 | [diff] [blame] | 429 | _syscall3(int,sys_faccessat,int,dirfd,const char *,pathname,int,mode) |
ths | 92a34c1 | 2007-09-24 09:27:49 +0000 | [diff] [blame] | 430 | #endif |
ths | 814d797 | 2007-09-24 09:26:51 +0000 | [diff] [blame] | 431 | #if defined(TARGET_NR_fchmodat) && defined(__NR_fchmodat) |
aurel32 | 465c9f0 | 2009-04-19 08:52:17 +0000 | [diff] [blame] | 432 | _syscall3(int,sys_fchmodat,int,dirfd,const char *,pathname, mode_t,mode) |
ths | 814d797 | 2007-09-24 09:26:51 +0000 | [diff] [blame] | 433 | #endif |
Riku Voipio | 0c866a7 | 2011-04-18 15:23:06 +0300 | [diff] [blame] | 434 | #if defined(TARGET_NR_fchownat) && defined(__NR_fchownat) |
ths | ccfa72b | 2007-09-24 09:23:34 +0000 | [diff] [blame] | 435 | _syscall5(int,sys_fchownat,int,dirfd,const char *,pathname, |
| 436 | uid_t,owner,gid_t,group,int,flags) |
| 437 | #endif |
aurel32 | 9d33b76 | 2009-04-08 23:07:05 +0000 | [diff] [blame] | 438 | #if (defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)) && \ |
| 439 | defined(__NR_fstatat64) |
balrog | 6a24a77 | 2008-09-20 02:23:36 +0000 | [diff] [blame] | 440 | _syscall4(int,sys_fstatat64,int,dirfd,const char *,pathname, |
| 441 | struct stat *,buf,int,flags) |
| 442 | #endif |
balrog | ac8a655 | 2008-09-20 02:25:39 +0000 | [diff] [blame] | 443 | #if defined(TARGET_NR_futimesat) && defined(__NR_futimesat) |
| 444 | _syscall3(int,sys_futimesat,int,dirfd,const char *,pathname, |
| 445 | const struct timeval *,times) |
| 446 | #endif |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 447 | #if (defined(TARGET_NR_newfstatat) || defined(TARGET_NR_fstatat64) ) && \ |
| 448 | defined(__NR_newfstatat) |
| 449 | _syscall4(int,sys_newfstatat,int,dirfd,const char *,pathname, |
| 450 | struct stat *,buf,int,flags) |
blueswir1 | 8fcd369 | 2008-08-17 20:26:25 +0000 | [diff] [blame] | 451 | #endif |
ths | 64f0ce4 | 2007-09-24 09:25:06 +0000 | [diff] [blame] | 452 | #if defined(TARGET_NR_linkat) && defined(__NR_linkat) |
| 453 | _syscall5(int,sys_linkat,int,olddirfd,const char *,oldpath, |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 454 | int,newdirfd,const char *,newpath,int,flags) |
ths | 64f0ce4 | 2007-09-24 09:25:06 +0000 | [diff] [blame] | 455 | #endif |
ths | 4472ad0 | 2007-09-24 09:22:32 +0000 | [diff] [blame] | 456 | #if defined(TARGET_NR_mkdirat) && defined(__NR_mkdirat) |
| 457 | _syscall3(int,sys_mkdirat,int,dirfd,const char *,pathname,mode_t,mode) |
| 458 | #endif |
ths | 75ac37a | 2007-09-24 09:23:05 +0000 | [diff] [blame] | 459 | #if defined(TARGET_NR_mknodat) && defined(__NR_mknodat) |
| 460 | _syscall4(int,sys_mknodat,int,dirfd,const char *,pathname, |
| 461 | mode_t,mode,dev_t,dev) |
| 462 | #endif |
ths | 8242483 | 2007-09-24 09:21:55 +0000 | [diff] [blame] | 463 | #if defined(TARGET_NR_openat) && defined(__NR_openat) |
| 464 | _syscall4(int,sys_openat,int,dirfd,const char *,pathname,int,flags,mode_t,mode) |
| 465 | #endif |
ths | 5e0ccb1 | 2007-09-24 09:26:10 +0000 | [diff] [blame] | 466 | #if defined(TARGET_NR_readlinkat) && defined(__NR_readlinkat) |
| 467 | _syscall4(int,sys_readlinkat,int,dirfd,const char *,pathname, |
| 468 | char *,buf,size_t,bufsize) |
| 469 | #endif |
ths | 722183f | 2007-09-24 09:24:37 +0000 | [diff] [blame] | 470 | #if defined(TARGET_NR_renameat) && defined(__NR_renameat) |
| 471 | _syscall4(int,sys_renameat,int,olddirfd,const char *,oldpath, |
| 472 | int,newdirfd,const char *,newpath) |
| 473 | #endif |
ths | b51eaa8 | 2007-09-25 16:09:22 +0000 | [diff] [blame] | 474 | #if defined(TARGET_NR_symlinkat) && defined(__NR_symlinkat) |
ths | f0b6243 | 2007-09-24 09:25:40 +0000 | [diff] [blame] | 475 | _syscall3(int,sys_symlinkat,const char *,oldpath, |
| 476 | int,newdirfd,const char *,newpath) |
| 477 | #endif |
ths | 8170f56 | 2007-09-24 09:24:11 +0000 | [diff] [blame] | 478 | #if defined(TARGET_NR_unlinkat) && defined(__NR_unlinkat) |
| 479 | _syscall3(int,sys_unlinkat,int,dirfd,const char *,pathname,int,flags) |
| 480 | #endif |
Riku Voipio | ebc996f | 2009-04-21 15:01:51 +0300 | [diff] [blame] | 481 | |
| 482 | #endif /* CONFIG_ATFILE */ |
| 483 | |
| 484 | #ifdef CONFIG_UTIMENSAT |
| 485 | static int sys_utimensat(int dirfd, const char *pathname, |
| 486 | const struct timespec times[2], int flags) |
| 487 | { |
| 488 | if (pathname == NULL) |
| 489 | return futimens(dirfd, times); |
| 490 | else |
| 491 | return utimensat(dirfd, pathname, times, flags); |
| 492 | } |
| 493 | #else |
ths | 9007f0e | 2007-09-25 17:50:37 +0000 | [diff] [blame] | 494 | #if defined(TARGET_NR_utimensat) && defined(__NR_utimensat) |
| 495 | _syscall4(int,sys_utimensat,int,dirfd,const char *,pathname, |
| 496 | const struct timespec *,tsp,int,flags) |
| 497 | #endif |
Riku Voipio | ebc996f | 2009-04-21 15:01:51 +0300 | [diff] [blame] | 498 | #endif /* CONFIG_UTIMENSAT */ |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 499 | |
| 500 | #ifdef CONFIG_INOTIFY |
aurel32 | 8690e42 | 2009-04-17 13:50:32 +0000 | [diff] [blame] | 501 | #include <sys/inotify.h> |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 502 | |
aurel32 | 39b5976 | 2008-10-01 21:46:50 +0000 | [diff] [blame] | 503 | #if defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init) |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 504 | static int sys_inotify_init(void) |
| 505 | { |
| 506 | return (inotify_init()); |
| 507 | } |
aurel32 | 39b5976 | 2008-10-01 21:46:50 +0000 | [diff] [blame] | 508 | #endif |
| 509 | #if defined(TARGET_NR_inotify_add_watch) && defined(__NR_inotify_add_watch) |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 510 | static int sys_inotify_add_watch(int fd,const char *pathname, int32_t mask) |
| 511 | { |
| 512 | return (inotify_add_watch(fd, pathname, mask)); |
| 513 | } |
aurel32 | 39b5976 | 2008-10-01 21:46:50 +0000 | [diff] [blame] | 514 | #endif |
| 515 | #if defined(TARGET_NR_inotify_rm_watch) && defined(__NR_inotify_rm_watch) |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 516 | static int sys_inotify_rm_watch(int fd, int32_t wd) |
| 517 | { |
aurel32 | 8690e42 | 2009-04-17 13:50:32 +0000 | [diff] [blame] | 518 | return (inotify_rm_watch(fd, wd)); |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 519 | } |
aurel32 | 39b5976 | 2008-10-01 21:46:50 +0000 | [diff] [blame] | 520 | #endif |
Riku Voipio | c05c7a7 | 2010-03-26 15:25:11 +0000 | [diff] [blame] | 521 | #ifdef CONFIG_INOTIFY1 |
| 522 | #if defined(TARGET_NR_inotify_init1) && defined(__NR_inotify_init1) |
| 523 | static int sys_inotify_init1(int flags) |
| 524 | { |
| 525 | return (inotify_init1(flags)); |
| 526 | } |
| 527 | #endif |
| 528 | #endif |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 529 | #else |
| 530 | /* Userspace can usually survive runtime without inotify */ |
| 531 | #undef TARGET_NR_inotify_init |
Riku Voipio | c05c7a7 | 2010-03-26 15:25:11 +0000 | [diff] [blame] | 532 | #undef TARGET_NR_inotify_init1 |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 533 | #undef TARGET_NR_inotify_add_watch |
| 534 | #undef TARGET_NR_inotify_rm_watch |
| 535 | #endif /* CONFIG_INOTIFY */ |
| 536 | |
Mike Frysinger | d8035d4 | 2011-02-07 01:05:51 -0500 | [diff] [blame] | 537 | #if defined(TARGET_NR_ppoll) |
| 538 | #ifndef __NR_ppoll |
| 539 | # define __NR_ppoll -1 |
| 540 | #endif |
| 541 | #define __NR_sys_ppoll __NR_ppoll |
| 542 | _syscall5(int, sys_ppoll, struct pollfd *, fds, nfds_t, nfds, |
| 543 | struct timespec *, timeout, const __sigset_t *, sigmask, |
| 544 | size_t, sigsetsize) |
| 545 | #endif |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 546 | |
Mike Frysinger | 055e090 | 2011-06-03 17:01:49 -0400 | [diff] [blame] | 547 | #if defined(TARGET_NR_pselect6) |
| 548 | #ifndef __NR_pselect6 |
| 549 | # define __NR_pselect6 -1 |
| 550 | #endif |
| 551 | #define __NR_sys_pselect6 __NR_pselect6 |
| 552 | _syscall6(int, sys_pselect6, int, nfds, fd_set *, readfds, fd_set *, writefds, |
| 553 | fd_set *, exceptfds, struct timespec *, timeout, void *, sig); |
| 554 | #endif |
| 555 | |
Peter Maydell | 163a05a | 2011-06-27 17:44:52 +0100 | [diff] [blame] | 556 | #if defined(TARGET_NR_prlimit64) |
| 557 | #ifndef __NR_prlimit64 |
| 558 | # define __NR_prlimit64 -1 |
| 559 | #endif |
| 560 | #define __NR_sys_prlimit64 __NR_prlimit64 |
| 561 | /* The glibc rlimit structure may not be that used by the underlying syscall */ |
| 562 | struct host_rlimit64 { |
| 563 | uint64_t rlim_cur; |
| 564 | uint64_t rlim_max; |
| 565 | }; |
| 566 | _syscall4(int, sys_prlimit64, pid_t, pid, int, resource, |
| 567 | const struct host_rlimit64 *, new_limit, |
| 568 | struct host_rlimit64 *, old_limit) |
| 569 | #endif |
| 570 | |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 571 | extern int personality(int); |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 572 | extern int flock(int, int); |
| 573 | extern int setfsuid(int); |
| 574 | extern int setfsgid(int); |
bellard | 19b84f3 | 2003-05-08 15:41:49 +0000 | [diff] [blame] | 575 | extern int setgroups(int, gid_t *); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 576 | |
Riku Voipio | 48e515d | 2011-07-12 15:40:51 +0300 | [diff] [blame] | 577 | /* ARM EABI and MIPS expect 64bit types aligned even on pairs or registers */ |
| 578 | #ifdef TARGET_ARM |
| 579 | static inline int regpairs_aligned(void *cpu_env) { |
| 580 | return ((((CPUARMState *)cpu_env)->eabi) == 1) ; |
| 581 | } |
| 582 | #elif defined(TARGET_MIPS) |
| 583 | static inline int regpairs_aligned(void *cpu_env) { return 1; } |
| 584 | #else |
| 585 | static inline int regpairs_aligned(void *cpu_env) { return 0; } |
| 586 | #endif |
| 587 | |
ths | b92c47c | 2007-11-01 00:07:38 +0000 | [diff] [blame] | 588 | #define ERRNO_TABLE_SIZE 1200 |
| 589 | |
| 590 | /* target_to_host_errno_table[] is initialized from |
| 591 | * host_to_target_errno_table[] in syscall_init(). */ |
| 592 | static uint16_t target_to_host_errno_table[ERRNO_TABLE_SIZE] = { |
| 593 | }; |
| 594 | |
ths | 637947f | 2007-06-01 12:09:19 +0000 | [diff] [blame] | 595 | /* |
ths | fe8f096 | 2007-07-12 10:59:21 +0000 | [diff] [blame] | 596 | * 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] | 597 | * minus the errnos that are not actually generic to all archs. |
| 598 | */ |
ths | b92c47c | 2007-11-01 00:07:38 +0000 | [diff] [blame] | 599 | static uint16_t host_to_target_errno_table[ERRNO_TABLE_SIZE] = { |
ths | 637947f | 2007-06-01 12:09:19 +0000 | [diff] [blame] | 600 | [EIDRM] = TARGET_EIDRM, |
| 601 | [ECHRNG] = TARGET_ECHRNG, |
| 602 | [EL2NSYNC] = TARGET_EL2NSYNC, |
| 603 | [EL3HLT] = TARGET_EL3HLT, |
| 604 | [EL3RST] = TARGET_EL3RST, |
| 605 | [ELNRNG] = TARGET_ELNRNG, |
| 606 | [EUNATCH] = TARGET_EUNATCH, |
| 607 | [ENOCSI] = TARGET_ENOCSI, |
| 608 | [EL2HLT] = TARGET_EL2HLT, |
| 609 | [EDEADLK] = TARGET_EDEADLK, |
| 610 | [ENOLCK] = TARGET_ENOLCK, |
| 611 | [EBADE] = TARGET_EBADE, |
| 612 | [EBADR] = TARGET_EBADR, |
| 613 | [EXFULL] = TARGET_EXFULL, |
| 614 | [ENOANO] = TARGET_ENOANO, |
| 615 | [EBADRQC] = TARGET_EBADRQC, |
| 616 | [EBADSLT] = TARGET_EBADSLT, |
| 617 | [EBFONT] = TARGET_EBFONT, |
| 618 | [ENOSTR] = TARGET_ENOSTR, |
| 619 | [ENODATA] = TARGET_ENODATA, |
| 620 | [ETIME] = TARGET_ETIME, |
| 621 | [ENOSR] = TARGET_ENOSR, |
| 622 | [ENONET] = TARGET_ENONET, |
| 623 | [ENOPKG] = TARGET_ENOPKG, |
| 624 | [EREMOTE] = TARGET_EREMOTE, |
| 625 | [ENOLINK] = TARGET_ENOLINK, |
| 626 | [EADV] = TARGET_EADV, |
| 627 | [ESRMNT] = TARGET_ESRMNT, |
| 628 | [ECOMM] = TARGET_ECOMM, |
| 629 | [EPROTO] = TARGET_EPROTO, |
| 630 | [EDOTDOT] = TARGET_EDOTDOT, |
| 631 | [EMULTIHOP] = TARGET_EMULTIHOP, |
| 632 | [EBADMSG] = TARGET_EBADMSG, |
| 633 | [ENAMETOOLONG] = TARGET_ENAMETOOLONG, |
| 634 | [EOVERFLOW] = TARGET_EOVERFLOW, |
| 635 | [ENOTUNIQ] = TARGET_ENOTUNIQ, |
| 636 | [EBADFD] = TARGET_EBADFD, |
| 637 | [EREMCHG] = TARGET_EREMCHG, |
| 638 | [ELIBACC] = TARGET_ELIBACC, |
| 639 | [ELIBBAD] = TARGET_ELIBBAD, |
| 640 | [ELIBSCN] = TARGET_ELIBSCN, |
| 641 | [ELIBMAX] = TARGET_ELIBMAX, |
| 642 | [ELIBEXEC] = TARGET_ELIBEXEC, |
| 643 | [EILSEQ] = TARGET_EILSEQ, |
| 644 | [ENOSYS] = TARGET_ENOSYS, |
| 645 | [ELOOP] = TARGET_ELOOP, |
| 646 | [ERESTART] = TARGET_ERESTART, |
| 647 | [ESTRPIPE] = TARGET_ESTRPIPE, |
| 648 | [ENOTEMPTY] = TARGET_ENOTEMPTY, |
| 649 | [EUSERS] = TARGET_EUSERS, |
| 650 | [ENOTSOCK] = TARGET_ENOTSOCK, |
| 651 | [EDESTADDRREQ] = TARGET_EDESTADDRREQ, |
| 652 | [EMSGSIZE] = TARGET_EMSGSIZE, |
| 653 | [EPROTOTYPE] = TARGET_EPROTOTYPE, |
| 654 | [ENOPROTOOPT] = TARGET_ENOPROTOOPT, |
| 655 | [EPROTONOSUPPORT] = TARGET_EPROTONOSUPPORT, |
| 656 | [ESOCKTNOSUPPORT] = TARGET_ESOCKTNOSUPPORT, |
| 657 | [EOPNOTSUPP] = TARGET_EOPNOTSUPP, |
| 658 | [EPFNOSUPPORT] = TARGET_EPFNOSUPPORT, |
| 659 | [EAFNOSUPPORT] = TARGET_EAFNOSUPPORT, |
| 660 | [EADDRINUSE] = TARGET_EADDRINUSE, |
| 661 | [EADDRNOTAVAIL] = TARGET_EADDRNOTAVAIL, |
| 662 | [ENETDOWN] = TARGET_ENETDOWN, |
| 663 | [ENETUNREACH] = TARGET_ENETUNREACH, |
| 664 | [ENETRESET] = TARGET_ENETRESET, |
| 665 | [ECONNABORTED] = TARGET_ECONNABORTED, |
| 666 | [ECONNRESET] = TARGET_ECONNRESET, |
| 667 | [ENOBUFS] = TARGET_ENOBUFS, |
| 668 | [EISCONN] = TARGET_EISCONN, |
| 669 | [ENOTCONN] = TARGET_ENOTCONN, |
| 670 | [EUCLEAN] = TARGET_EUCLEAN, |
| 671 | [ENOTNAM] = TARGET_ENOTNAM, |
| 672 | [ENAVAIL] = TARGET_ENAVAIL, |
| 673 | [EISNAM] = TARGET_EISNAM, |
| 674 | [EREMOTEIO] = TARGET_EREMOTEIO, |
| 675 | [ESHUTDOWN] = TARGET_ESHUTDOWN, |
| 676 | [ETOOMANYREFS] = TARGET_ETOOMANYREFS, |
| 677 | [ETIMEDOUT] = TARGET_ETIMEDOUT, |
| 678 | [ECONNREFUSED] = TARGET_ECONNREFUSED, |
| 679 | [EHOSTDOWN] = TARGET_EHOSTDOWN, |
| 680 | [EHOSTUNREACH] = TARGET_EHOSTUNREACH, |
| 681 | [EALREADY] = TARGET_EALREADY, |
| 682 | [EINPROGRESS] = TARGET_EINPROGRESS, |
| 683 | [ESTALE] = TARGET_ESTALE, |
| 684 | [ECANCELED] = TARGET_ECANCELED, |
| 685 | [ENOMEDIUM] = TARGET_ENOMEDIUM, |
| 686 | [EMEDIUMTYPE] = TARGET_EMEDIUMTYPE, |
ths | b7fe5db | 2007-07-23 15:37:46 +0000 | [diff] [blame] | 687 | #ifdef ENOKEY |
ths | 637947f | 2007-06-01 12:09:19 +0000 | [diff] [blame] | 688 | [ENOKEY] = TARGET_ENOKEY, |
ths | b7fe5db | 2007-07-23 15:37:46 +0000 | [diff] [blame] | 689 | #endif |
| 690 | #ifdef EKEYEXPIRED |
ths | 637947f | 2007-06-01 12:09:19 +0000 | [diff] [blame] | 691 | [EKEYEXPIRED] = TARGET_EKEYEXPIRED, |
ths | b7fe5db | 2007-07-23 15:37:46 +0000 | [diff] [blame] | 692 | #endif |
| 693 | #ifdef EKEYREVOKED |
ths | 637947f | 2007-06-01 12:09:19 +0000 | [diff] [blame] | 694 | [EKEYREVOKED] = TARGET_EKEYREVOKED, |
ths | b7fe5db | 2007-07-23 15:37:46 +0000 | [diff] [blame] | 695 | #endif |
| 696 | #ifdef EKEYREJECTED |
ths | 637947f | 2007-06-01 12:09:19 +0000 | [diff] [blame] | 697 | [EKEYREJECTED] = TARGET_EKEYREJECTED, |
ths | b7fe5db | 2007-07-23 15:37:46 +0000 | [diff] [blame] | 698 | #endif |
| 699 | #ifdef EOWNERDEAD |
ths | 637947f | 2007-06-01 12:09:19 +0000 | [diff] [blame] | 700 | [EOWNERDEAD] = TARGET_EOWNERDEAD, |
ths | b7fe5db | 2007-07-23 15:37:46 +0000 | [diff] [blame] | 701 | #endif |
| 702 | #ifdef ENOTRECOVERABLE |
ths | 637947f | 2007-06-01 12:09:19 +0000 | [diff] [blame] | 703 | [ENOTRECOVERABLE] = TARGET_ENOTRECOVERABLE, |
ths | b7fe5db | 2007-07-23 15:37:46 +0000 | [diff] [blame] | 704 | #endif |
ths | b92c47c | 2007-11-01 00:07:38 +0000 | [diff] [blame] | 705 | }; |
ths | 637947f | 2007-06-01 12:09:19 +0000 | [diff] [blame] | 706 | |
| 707 | static inline int host_to_target_errno(int err) |
| 708 | { |
| 709 | if(host_to_target_errno_table[err]) |
| 710 | return host_to_target_errno_table[err]; |
| 711 | return err; |
| 712 | } |
| 713 | |
ths | b92c47c | 2007-11-01 00:07:38 +0000 | [diff] [blame] | 714 | static inline int target_to_host_errno(int err) |
| 715 | { |
| 716 | if (target_to_host_errno_table[err]) |
| 717 | return target_to_host_errno_table[err]; |
| 718 | return err; |
| 719 | } |
| 720 | |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 721 | static inline abi_long get_errno(abi_long ret) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 722 | { |
| 723 | if (ret == -1) |
ths | 637947f | 2007-06-01 12:09:19 +0000 | [diff] [blame] | 724 | return -host_to_target_errno(errno); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 725 | else |
| 726 | return ret; |
| 727 | } |
| 728 | |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 729 | static inline int is_error(abi_long ret) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 730 | { |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 731 | return (abi_ulong)ret >= (abi_ulong)(-4096); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 732 | } |
| 733 | |
ths | b92c47c | 2007-11-01 00:07:38 +0000 | [diff] [blame] | 734 | char *target_strerror(int err) |
| 735 | { |
Alexander Graf | 962b289 | 2011-11-21 12:04:07 +0100 | [diff] [blame] | 736 | if ((err >= ERRNO_TABLE_SIZE) || (err < 0)) { |
| 737 | return NULL; |
| 738 | } |
ths | b92c47c | 2007-11-01 00:07:38 +0000 | [diff] [blame] | 739 | return strerror(target_to_host_errno(err)); |
| 740 | } |
| 741 | |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 742 | static abi_ulong target_brk; |
| 743 | static abi_ulong target_original_brk; |
vincent | 4d1de87 | 2011-06-14 21:56:33 +0000 | [diff] [blame] | 744 | static abi_ulong brk_page; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 745 | |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 746 | void target_set_brk(abi_ulong new_brk) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 747 | { |
blueswir1 | 4c1de73 | 2007-07-07 20:45:44 +0000 | [diff] [blame] | 748 | target_original_brk = target_brk = HOST_PAGE_ALIGN(new_brk); |
vincent | 4d1de87 | 2011-06-14 21:56:33 +0000 | [diff] [blame] | 749 | brk_page = HOST_PAGE_ALIGN(target_brk); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 750 | } |
| 751 | |
vincent | 4d1de87 | 2011-06-14 21:56:33 +0000 | [diff] [blame] | 752 | //#define DEBUGF_BRK(message, args...) do { fprintf(stderr, (message), ## args); } while (0) |
| 753 | #define DEBUGF_BRK(message, args...) |
| 754 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 755 | /* do_brk() must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 756 | abi_long do_brk(abi_ulong new_brk) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 757 | { |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 758 | abi_long mapped_addr; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 759 | int new_alloc_size; |
| 760 | |
Paul Brook | 3a0c6c4 | 2012-02-09 19:04:27 +0000 | [diff] [blame] | 761 | DEBUGF_BRK("do_brk(" TARGET_ABI_FMT_lx ") -> ", new_brk); |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 762 | |
vincent | 4d1de87 | 2011-06-14 21:56:33 +0000 | [diff] [blame] | 763 | if (!new_brk) { |
Paul Brook | 3a0c6c4 | 2012-02-09 19:04:27 +0000 | [diff] [blame] | 764 | DEBUGF_BRK(TARGET_ABI_FMT_lx " (!new_brk)\n", target_brk); |
vincent | 4d1de87 | 2011-06-14 21:56:33 +0000 | [diff] [blame] | 765 | return target_brk; |
| 766 | } |
| 767 | if (new_brk < target_original_brk) { |
Paul Brook | 3a0c6c4 | 2012-02-09 19:04:27 +0000 | [diff] [blame] | 768 | DEBUGF_BRK(TARGET_ABI_FMT_lx " (new_brk < target_original_brk)\n", |
| 769 | target_brk); |
vincent | 4d1de87 | 2011-06-14 21:56:33 +0000 | [diff] [blame] | 770 | return target_brk; |
| 771 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 772 | |
vincent | 4d1de87 | 2011-06-14 21:56:33 +0000 | [diff] [blame] | 773 | /* If the new brk is less than the highest page reserved to the |
| 774 | * target heap allocation, set it and we're almost done... */ |
| 775 | if (new_brk <= brk_page) { |
| 776 | /* Heap contents are initialized to zero, as for anonymous |
| 777 | * mapped pages. */ |
| 778 | if (new_brk > target_brk) { |
| 779 | memset(g2h(target_brk), 0, new_brk - target_brk); |
| 780 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 781 | target_brk = new_brk; |
Paul Brook | 3a0c6c4 | 2012-02-09 19:04:27 +0000 | [diff] [blame] | 782 | DEBUGF_BRK(TARGET_ABI_FMT_lx " (new_brk <= brk_page)\n", target_brk); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 783 | return target_brk; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 784 | } |
| 785 | |
Peter Maydell | 00faf08 | 2011-04-18 16:34:24 +0100 | [diff] [blame] | 786 | /* We need to allocate more memory after the brk... Note that |
| 787 | * we don't use MAP_FIXED because that will map over the top of |
| 788 | * any existing mapping (like the one with the host libc or qemu |
| 789 | * itself); instead we treat "mapped but at wrong address" as |
| 790 | * a failure and unmap again. |
| 791 | */ |
vincent | 4d1de87 | 2011-06-14 21:56:33 +0000 | [diff] [blame] | 792 | new_alloc_size = HOST_PAGE_ALIGN(new_brk - brk_page); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 793 | mapped_addr = get_errno(target_mmap(brk_page, new_alloc_size, |
bellard | 5493600 | 2003-05-13 00:25:15 +0000 | [diff] [blame] | 794 | PROT_READ|PROT_WRITE, |
Peter Maydell | 00faf08 | 2011-04-18 16:34:24 +0100 | [diff] [blame] | 795 | MAP_ANON|MAP_PRIVATE, 0, 0)); |
| 796 | |
| 797 | if (mapped_addr == brk_page) { |
Cédric VINCENT | 70afc34 | 2011-08-26 10:56:50 +0200 | [diff] [blame] | 798 | /* Heap contents are initialized to zero, as for anonymous |
| 799 | * mapped pages. Technically the new pages are already |
| 800 | * initialized to zero since they *are* anonymous mapped |
| 801 | * pages, however we have to take care with the contents that |
| 802 | * come from the remaining part of the previous page: it may |
| 803 | * contains garbage data due to a previous heap usage (grown |
| 804 | * then shrunken). */ |
| 805 | memset(g2h(target_brk), 0, brk_page - target_brk); |
| 806 | |
Peter Maydell | 00faf08 | 2011-04-18 16:34:24 +0100 | [diff] [blame] | 807 | target_brk = new_brk; |
vincent | 4d1de87 | 2011-06-14 21:56:33 +0000 | [diff] [blame] | 808 | brk_page = HOST_PAGE_ALIGN(target_brk); |
Paul Brook | 3a0c6c4 | 2012-02-09 19:04:27 +0000 | [diff] [blame] | 809 | DEBUGF_BRK(TARGET_ABI_FMT_lx " (mapped_addr == brk_page)\n", |
| 810 | target_brk); |
Peter Maydell | 00faf08 | 2011-04-18 16:34:24 +0100 | [diff] [blame] | 811 | return target_brk; |
| 812 | } else if (mapped_addr != -1) { |
| 813 | /* Mapped but at wrong address, meaning there wasn't actually |
| 814 | * enough space for this brk. |
| 815 | */ |
| 816 | target_munmap(mapped_addr, new_alloc_size); |
| 817 | mapped_addr = -1; |
Paul Brook | 3a0c6c4 | 2012-02-09 19:04:27 +0000 | [diff] [blame] | 818 | DEBUGF_BRK(TARGET_ABI_FMT_lx " (mapped_addr != -1)\n", target_brk); |
vincent | 4d1de87 | 2011-06-14 21:56:33 +0000 | [diff] [blame] | 819 | } |
| 820 | else { |
Paul Brook | 3a0c6c4 | 2012-02-09 19:04:27 +0000 | [diff] [blame] | 821 | DEBUGF_BRK(TARGET_ABI_FMT_lx " (otherwise)\n", target_brk); |
Peter Maydell | 00faf08 | 2011-04-18 16:34:24 +0100 | [diff] [blame] | 822 | } |
balrog | 7ab240a | 2008-04-26 12:17:34 +0000 | [diff] [blame] | 823 | |
Richard Henderson | 7dd46c0 | 2010-05-03 10:07:49 -0700 | [diff] [blame] | 824 | #if defined(TARGET_ALPHA) |
| 825 | /* We (partially) emulate OSF/1 on Alpha, which requires we |
| 826 | return a proper errno, not an unchanged brk value. */ |
Peter Maydell | 00faf08 | 2011-04-18 16:34:24 +0100 | [diff] [blame] | 827 | return -TARGET_ENOMEM; |
Richard Henderson | 7dd46c0 | 2010-05-03 10:07:49 -0700 | [diff] [blame] | 828 | #endif |
Peter Maydell | 00faf08 | 2011-04-18 16:34:24 +0100 | [diff] [blame] | 829 | /* For everything else, return the previous break. */ |
balrog | 7ab240a | 2008-04-26 12:17:34 +0000 | [diff] [blame] | 830 | return target_brk; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 831 | } |
| 832 | |
ths | 26edcf4 | 2007-12-09 02:25:24 +0000 | [diff] [blame] | 833 | static inline abi_long copy_from_user_fdset(fd_set *fds, |
| 834 | abi_ulong target_fds_addr, |
| 835 | int n) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 836 | { |
ths | 26edcf4 | 2007-12-09 02:25:24 +0000 | [diff] [blame] | 837 | int i, nw, j, k; |
| 838 | abi_ulong b, *target_fds; |
| 839 | |
| 840 | nw = (n + TARGET_ABI_BITS - 1) / TARGET_ABI_BITS; |
| 841 | if (!(target_fds = lock_user(VERIFY_READ, |
| 842 | target_fds_addr, |
| 843 | sizeof(abi_ulong) * nw, |
| 844 | 1))) |
| 845 | return -TARGET_EFAULT; |
| 846 | |
| 847 | FD_ZERO(fds); |
| 848 | k = 0; |
| 849 | for (i = 0; i < nw; i++) { |
| 850 | /* grab the abi_ulong */ |
| 851 | __get_user(b, &target_fds[i]); |
| 852 | for (j = 0; j < TARGET_ABI_BITS; j++) { |
| 853 | /* check the bit inside the abi_ulong */ |
| 854 | if ((b >> j) & 1) |
| 855 | FD_SET(k, fds); |
| 856 | k++; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 857 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 858 | } |
ths | 26edcf4 | 2007-12-09 02:25:24 +0000 | [diff] [blame] | 859 | |
| 860 | unlock_user(target_fds, target_fds_addr, 0); |
| 861 | |
| 862 | return 0; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 863 | } |
| 864 | |
Mike Frysinger | 055e090 | 2011-06-03 17:01:49 -0400 | [diff] [blame] | 865 | static inline abi_ulong copy_from_user_fdset_ptr(fd_set *fds, fd_set **fds_ptr, |
| 866 | abi_ulong target_fds_addr, |
| 867 | int n) |
| 868 | { |
| 869 | if (target_fds_addr) { |
| 870 | if (copy_from_user_fdset(fds, target_fds_addr, n)) |
| 871 | return -TARGET_EFAULT; |
| 872 | *fds_ptr = fds; |
| 873 | } else { |
| 874 | *fds_ptr = NULL; |
| 875 | } |
| 876 | return 0; |
| 877 | } |
| 878 | |
ths | 26edcf4 | 2007-12-09 02:25:24 +0000 | [diff] [blame] | 879 | static inline abi_long copy_to_user_fdset(abi_ulong target_fds_addr, |
| 880 | const fd_set *fds, |
| 881 | int n) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 882 | { |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 883 | int i, nw, j, k; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 884 | abi_long v; |
ths | 26edcf4 | 2007-12-09 02:25:24 +0000 | [diff] [blame] | 885 | abi_ulong *target_fds; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 886 | |
ths | 26edcf4 | 2007-12-09 02:25:24 +0000 | [diff] [blame] | 887 | nw = (n + TARGET_ABI_BITS - 1) / TARGET_ABI_BITS; |
| 888 | if (!(target_fds = lock_user(VERIFY_WRITE, |
| 889 | target_fds_addr, |
| 890 | sizeof(abi_ulong) * nw, |
| 891 | 0))) |
| 892 | return -TARGET_EFAULT; |
| 893 | |
| 894 | k = 0; |
| 895 | for (i = 0; i < nw; i++) { |
| 896 | v = 0; |
| 897 | for (j = 0; j < TARGET_ABI_BITS; j++) { |
| 898 | v |= ((FD_ISSET(k, fds) != 0) << j); |
| 899 | k++; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 900 | } |
ths | 26edcf4 | 2007-12-09 02:25:24 +0000 | [diff] [blame] | 901 | __put_user(v, &target_fds[i]); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 902 | } |
ths | 26edcf4 | 2007-12-09 02:25:24 +0000 | [diff] [blame] | 903 | |
| 904 | unlock_user(target_fds, target_fds_addr, sizeof(abi_ulong) * nw); |
| 905 | |
| 906 | return 0; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 907 | } |
| 908 | |
bellard | c596ed1 | 2003-07-13 17:32:31 +0000 | [diff] [blame] | 909 | #if defined(__alpha__) |
| 910 | #define HOST_HZ 1024 |
| 911 | #else |
| 912 | #define HOST_HZ 100 |
| 913 | #endif |
| 914 | |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 915 | static inline abi_long host_to_target_clock_t(long ticks) |
bellard | c596ed1 | 2003-07-13 17:32:31 +0000 | [diff] [blame] | 916 | { |
| 917 | #if HOST_HZ == TARGET_HZ |
| 918 | return ticks; |
| 919 | #else |
| 920 | return ((int64_t)ticks * TARGET_HZ) / HOST_HZ; |
| 921 | #endif |
| 922 | } |
| 923 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 924 | static inline abi_long host_to_target_rusage(abi_ulong target_addr, |
| 925 | const struct rusage *rusage) |
bellard | b409186 | 2003-05-16 15:39:34 +0000 | [diff] [blame] | 926 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 927 | struct target_rusage *target_rusage; |
| 928 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 929 | if (!lock_user_struct(VERIFY_WRITE, target_rusage, target_addr, 0)) |
| 930 | return -TARGET_EFAULT; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 931 | target_rusage->ru_utime.tv_sec = tswapal(rusage->ru_utime.tv_sec); |
| 932 | target_rusage->ru_utime.tv_usec = tswapal(rusage->ru_utime.tv_usec); |
| 933 | target_rusage->ru_stime.tv_sec = tswapal(rusage->ru_stime.tv_sec); |
| 934 | target_rusage->ru_stime.tv_usec = tswapal(rusage->ru_stime.tv_usec); |
| 935 | target_rusage->ru_maxrss = tswapal(rusage->ru_maxrss); |
| 936 | target_rusage->ru_ixrss = tswapal(rusage->ru_ixrss); |
| 937 | target_rusage->ru_idrss = tswapal(rusage->ru_idrss); |
| 938 | target_rusage->ru_isrss = tswapal(rusage->ru_isrss); |
| 939 | target_rusage->ru_minflt = tswapal(rusage->ru_minflt); |
| 940 | target_rusage->ru_majflt = tswapal(rusage->ru_majflt); |
| 941 | target_rusage->ru_nswap = tswapal(rusage->ru_nswap); |
| 942 | target_rusage->ru_inblock = tswapal(rusage->ru_inblock); |
| 943 | target_rusage->ru_oublock = tswapal(rusage->ru_oublock); |
| 944 | target_rusage->ru_msgsnd = tswapal(rusage->ru_msgsnd); |
| 945 | target_rusage->ru_msgrcv = tswapal(rusage->ru_msgrcv); |
| 946 | target_rusage->ru_nsignals = tswapal(rusage->ru_nsignals); |
| 947 | target_rusage->ru_nvcsw = tswapal(rusage->ru_nvcsw); |
| 948 | target_rusage->ru_nivcsw = tswapal(rusage->ru_nivcsw); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 949 | unlock_user_struct(target_rusage, target_addr, 1); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 950 | |
| 951 | return 0; |
bellard | b409186 | 2003-05-16 15:39:34 +0000 | [diff] [blame] | 952 | } |
| 953 | |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 954 | 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] | 955 | { |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 956 | abi_ulong target_rlim_swap; |
Wesley W. Terpstra | 95b33b2 | 2011-07-12 14:38:22 +0300 | [diff] [blame] | 957 | rlim_t result; |
| 958 | |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 959 | target_rlim_swap = tswapal(target_rlim); |
| 960 | if (target_rlim_swap == TARGET_RLIM_INFINITY) |
| 961 | return RLIM_INFINITY; |
| 962 | |
| 963 | result = target_rlim_swap; |
| 964 | if (target_rlim_swap != (rlim_t)result) |
| 965 | return RLIM_INFINITY; |
Wesley W. Terpstra | 95b33b2 | 2011-07-12 14:38:22 +0300 | [diff] [blame] | 966 | |
| 967 | return result; |
takasi-y@ops.dti.ne.jp | 81bbe90 | 2010-04-12 04:07:35 +0900 | [diff] [blame] | 968 | } |
| 969 | |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 970 | 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] | 971 | { |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 972 | abi_ulong target_rlim_swap; |
| 973 | abi_ulong result; |
Wesley W. Terpstra | 95b33b2 | 2011-07-12 14:38:22 +0300 | [diff] [blame] | 974 | |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 975 | if (rlim == RLIM_INFINITY || rlim != (abi_long)rlim) |
Wesley W. Terpstra | 95b33b2 | 2011-07-12 14:38:22 +0300 | [diff] [blame] | 976 | target_rlim_swap = TARGET_RLIM_INFINITY; |
takasi-y@ops.dti.ne.jp | 81bbe90 | 2010-04-12 04:07:35 +0900 | [diff] [blame] | 977 | else |
Wesley W. Terpstra | 95b33b2 | 2011-07-12 14:38:22 +0300 | [diff] [blame] | 978 | target_rlim_swap = rlim; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 979 | result = tswapal(target_rlim_swap); |
Wesley W. Terpstra | 95b33b2 | 2011-07-12 14:38:22 +0300 | [diff] [blame] | 980 | |
| 981 | return result; |
takasi-y@ops.dti.ne.jp | 81bbe90 | 2010-04-12 04:07:35 +0900 | [diff] [blame] | 982 | } |
| 983 | |
Wesley W. Terpstra | e22b701 | 2011-07-12 14:42:00 +0300 | [diff] [blame] | 984 | static inline int target_to_host_resource(int code) |
| 985 | { |
| 986 | switch (code) { |
| 987 | case TARGET_RLIMIT_AS: |
| 988 | return RLIMIT_AS; |
| 989 | case TARGET_RLIMIT_CORE: |
| 990 | return RLIMIT_CORE; |
| 991 | case TARGET_RLIMIT_CPU: |
| 992 | return RLIMIT_CPU; |
| 993 | case TARGET_RLIMIT_DATA: |
| 994 | return RLIMIT_DATA; |
| 995 | case TARGET_RLIMIT_FSIZE: |
| 996 | return RLIMIT_FSIZE; |
| 997 | case TARGET_RLIMIT_LOCKS: |
| 998 | return RLIMIT_LOCKS; |
| 999 | case TARGET_RLIMIT_MEMLOCK: |
| 1000 | return RLIMIT_MEMLOCK; |
| 1001 | case TARGET_RLIMIT_MSGQUEUE: |
| 1002 | return RLIMIT_MSGQUEUE; |
| 1003 | case TARGET_RLIMIT_NICE: |
| 1004 | return RLIMIT_NICE; |
| 1005 | case TARGET_RLIMIT_NOFILE: |
| 1006 | return RLIMIT_NOFILE; |
| 1007 | case TARGET_RLIMIT_NPROC: |
| 1008 | return RLIMIT_NPROC; |
| 1009 | case TARGET_RLIMIT_RSS: |
| 1010 | return RLIMIT_RSS; |
| 1011 | case TARGET_RLIMIT_RTPRIO: |
| 1012 | return RLIMIT_RTPRIO; |
| 1013 | case TARGET_RLIMIT_SIGPENDING: |
| 1014 | return RLIMIT_SIGPENDING; |
| 1015 | case TARGET_RLIMIT_STACK: |
| 1016 | return RLIMIT_STACK; |
| 1017 | default: |
| 1018 | return code; |
| 1019 | } |
| 1020 | } |
| 1021 | |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 1022 | static inline abi_long copy_from_user_timeval(struct timeval *tv, |
| 1023 | abi_ulong target_tv_addr) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 1024 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1025 | struct target_timeval *target_tv; |
| 1026 | |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 1027 | if (!lock_user_struct(VERIFY_READ, target_tv, target_tv_addr, 1)) |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1028 | return -TARGET_EFAULT; |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 1029 | |
| 1030 | __get_user(tv->tv_sec, &target_tv->tv_sec); |
| 1031 | __get_user(tv->tv_usec, &target_tv->tv_usec); |
| 1032 | |
| 1033 | unlock_user_struct(target_tv, target_tv_addr, 0); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1034 | |
| 1035 | return 0; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 1036 | } |
| 1037 | |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 1038 | static inline abi_long copy_to_user_timeval(abi_ulong target_tv_addr, |
| 1039 | const struct timeval *tv) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 1040 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1041 | struct target_timeval *target_tv; |
| 1042 | |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 1043 | if (!lock_user_struct(VERIFY_WRITE, target_tv, target_tv_addr, 0)) |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1044 | return -TARGET_EFAULT; |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 1045 | |
| 1046 | __put_user(tv->tv_sec, &target_tv->tv_sec); |
| 1047 | __put_user(tv->tv_usec, &target_tv->tv_usec); |
| 1048 | |
| 1049 | unlock_user_struct(target_tv, target_tv_addr, 1); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1050 | |
| 1051 | return 0; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 1052 | } |
| 1053 | |
Nathan Froyd | 8ec9cf8 | 2009-07-22 09:14:36 -0700 | [diff] [blame] | 1054 | #if defined(TARGET_NR_mq_open) && defined(__NR_mq_open) |
| 1055 | #include <mqueue.h> |
| 1056 | |
aurel32 | 24e1003 | 2009-04-15 16:11:43 +0000 | [diff] [blame] | 1057 | static inline abi_long copy_from_user_mq_attr(struct mq_attr *attr, |
| 1058 | abi_ulong target_mq_attr_addr) |
| 1059 | { |
| 1060 | struct target_mq_attr *target_mq_attr; |
| 1061 | |
| 1062 | if (!lock_user_struct(VERIFY_READ, target_mq_attr, |
| 1063 | target_mq_attr_addr, 1)) |
| 1064 | return -TARGET_EFAULT; |
| 1065 | |
| 1066 | __get_user(attr->mq_flags, &target_mq_attr->mq_flags); |
| 1067 | __get_user(attr->mq_maxmsg, &target_mq_attr->mq_maxmsg); |
| 1068 | __get_user(attr->mq_msgsize, &target_mq_attr->mq_msgsize); |
| 1069 | __get_user(attr->mq_curmsgs, &target_mq_attr->mq_curmsgs); |
| 1070 | |
| 1071 | unlock_user_struct(target_mq_attr, target_mq_attr_addr, 0); |
| 1072 | |
| 1073 | return 0; |
| 1074 | } |
| 1075 | |
| 1076 | static inline abi_long copy_to_user_mq_attr(abi_ulong target_mq_attr_addr, |
| 1077 | const struct mq_attr *attr) |
| 1078 | { |
| 1079 | struct target_mq_attr *target_mq_attr; |
| 1080 | |
| 1081 | if (!lock_user_struct(VERIFY_WRITE, target_mq_attr, |
| 1082 | target_mq_attr_addr, 0)) |
| 1083 | return -TARGET_EFAULT; |
| 1084 | |
| 1085 | __put_user(attr->mq_flags, &target_mq_attr->mq_flags); |
| 1086 | __put_user(attr->mq_maxmsg, &target_mq_attr->mq_maxmsg); |
| 1087 | __put_user(attr->mq_msgsize, &target_mq_attr->mq_msgsize); |
| 1088 | __put_user(attr->mq_curmsgs, &target_mq_attr->mq_curmsgs); |
| 1089 | |
| 1090 | unlock_user_struct(target_mq_attr, target_mq_attr_addr, 1); |
| 1091 | |
| 1092 | return 0; |
| 1093 | } |
Nathan Froyd | 8ec9cf8 | 2009-07-22 09:14:36 -0700 | [diff] [blame] | 1094 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 1095 | |
Mike Frysinger | 055e090 | 2011-06-03 17:01:49 -0400 | [diff] [blame] | 1096 | #if defined(TARGET_NR_select) || defined(TARGET_NR__newselect) |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 1097 | /* do_select() must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 1098 | static abi_long do_select(int n, |
ths | 26edcf4 | 2007-12-09 02:25:24 +0000 | [diff] [blame] | 1099 | abi_ulong rfd_addr, abi_ulong wfd_addr, |
| 1100 | abi_ulong efd_addr, abi_ulong target_tv_addr) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 1101 | { |
| 1102 | fd_set rfds, wfds, efds; |
| 1103 | fd_set *rfds_ptr, *wfds_ptr, *efds_ptr; |
| 1104 | struct timeval tv, *tv_ptr; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 1105 | abi_long ret; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 1106 | |
Mike Frysinger | 055e090 | 2011-06-03 17:01:49 -0400 | [diff] [blame] | 1107 | ret = copy_from_user_fdset_ptr(&rfds, &rfds_ptr, rfd_addr, n); |
| 1108 | if (ret) { |
| 1109 | return ret; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1110 | } |
Mike Frysinger | 055e090 | 2011-06-03 17:01:49 -0400 | [diff] [blame] | 1111 | ret = copy_from_user_fdset_ptr(&wfds, &wfds_ptr, wfd_addr, n); |
| 1112 | if (ret) { |
| 1113 | return ret; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1114 | } |
Mike Frysinger | 055e090 | 2011-06-03 17:01:49 -0400 | [diff] [blame] | 1115 | ret = copy_from_user_fdset_ptr(&efds, &efds_ptr, efd_addr, n); |
| 1116 | if (ret) { |
| 1117 | return ret; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1118 | } |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1119 | |
ths | 26edcf4 | 2007-12-09 02:25:24 +0000 | [diff] [blame] | 1120 | if (target_tv_addr) { |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 1121 | if (copy_from_user_timeval(&tv, target_tv_addr)) |
| 1122 | return -TARGET_EFAULT; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 1123 | tv_ptr = &tv; |
| 1124 | } else { |
| 1125 | tv_ptr = NULL; |
| 1126 | } |
ths | 26edcf4 | 2007-12-09 02:25:24 +0000 | [diff] [blame] | 1127 | |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 1128 | ret = get_errno(select(n, rfds_ptr, wfds_ptr, efds_ptr, tv_ptr)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1129 | |
ths | 26edcf4 | 2007-12-09 02:25:24 +0000 | [diff] [blame] | 1130 | if (!is_error(ret)) { |
| 1131 | if (rfd_addr && copy_to_user_fdset(rfd_addr, &rfds, n)) |
| 1132 | return -TARGET_EFAULT; |
| 1133 | if (wfd_addr && copy_to_user_fdset(wfd_addr, &wfds, n)) |
| 1134 | return -TARGET_EFAULT; |
| 1135 | if (efd_addr && copy_to_user_fdset(efd_addr, &efds, n)) |
| 1136 | return -TARGET_EFAULT; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 1137 | |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 1138 | if (target_tv_addr && copy_to_user_timeval(target_tv_addr, &tv)) |
| 1139 | return -TARGET_EFAULT; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 1140 | } |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1141 | |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 1142 | return ret; |
| 1143 | } |
Mike Frysinger | 055e090 | 2011-06-03 17:01:49 -0400 | [diff] [blame] | 1144 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 1145 | |
Riku Voipio | 099d6b0 | 2009-05-05 12:10:04 +0300 | [diff] [blame] | 1146 | static abi_long do_pipe2(int host_pipe[], int flags) |
| 1147 | { |
| 1148 | #ifdef CONFIG_PIPE2 |
| 1149 | return pipe2(host_pipe, flags); |
| 1150 | #else |
| 1151 | return -ENOSYS; |
| 1152 | #endif |
| 1153 | } |
| 1154 | |
Richard Henderson | fb41a66 | 2010-05-03 10:07:52 -0700 | [diff] [blame] | 1155 | static abi_long do_pipe(void *cpu_env, abi_ulong pipedes, |
| 1156 | int flags, int is_pipe2) |
Riku Voipio | 099d6b0 | 2009-05-05 12:10:04 +0300 | [diff] [blame] | 1157 | { |
| 1158 | int host_pipe[2]; |
| 1159 | abi_long ret; |
| 1160 | ret = flags ? do_pipe2(host_pipe, flags) : pipe(host_pipe); |
| 1161 | |
| 1162 | if (is_error(ret)) |
| 1163 | return get_errno(ret); |
Richard Henderson | fb41a66 | 2010-05-03 10:07:52 -0700 | [diff] [blame] | 1164 | |
| 1165 | /* Several targets have special calling conventions for the original |
| 1166 | pipe syscall, but didn't replicate this into the pipe2 syscall. */ |
| 1167 | if (!is_pipe2) { |
| 1168 | #if defined(TARGET_ALPHA) |
| 1169 | ((CPUAlphaState *)cpu_env)->ir[IR_A4] = host_pipe[1]; |
| 1170 | return host_pipe[0]; |
| 1171 | #elif defined(TARGET_MIPS) |
| 1172 | ((CPUMIPSState*)cpu_env)->active_tc.gpr[3] = host_pipe[1]; |
| 1173 | return host_pipe[0]; |
| 1174 | #elif defined(TARGET_SH4) |
takasi-y@ops.dti.ne.jp | 597c021 | 2010-02-18 00:35:03 +0900 | [diff] [blame] | 1175 | ((CPUSH4State*)cpu_env)->gregs[1] = host_pipe[1]; |
Richard Henderson | fb41a66 | 2010-05-03 10:07:52 -0700 | [diff] [blame] | 1176 | return host_pipe[0]; |
takasi-y@ops.dti.ne.jp | 597c021 | 2010-02-18 00:35:03 +0900 | [diff] [blame] | 1177 | #endif |
Richard Henderson | fb41a66 | 2010-05-03 10:07:52 -0700 | [diff] [blame] | 1178 | } |
| 1179 | |
Riku Voipio | 099d6b0 | 2009-05-05 12:10:04 +0300 | [diff] [blame] | 1180 | if (put_user_s32(host_pipe[0], pipedes) |
| 1181 | || put_user_s32(host_pipe[1], pipedes + sizeof(host_pipe[0]))) |
| 1182 | return -TARGET_EFAULT; |
Riku Voipio | 099d6b0 | 2009-05-05 12:10:04 +0300 | [diff] [blame] | 1183 | return get_errno(ret); |
| 1184 | } |
| 1185 | |
Lionel Landwerlin | b975b83 | 2009-04-25 23:30:19 +0200 | [diff] [blame] | 1186 | static inline abi_long target_to_host_ip_mreq(struct ip_mreqn *mreqn, |
| 1187 | abi_ulong target_addr, |
| 1188 | socklen_t len) |
| 1189 | { |
| 1190 | struct target_ip_mreqn *target_smreqn; |
| 1191 | |
| 1192 | target_smreqn = lock_user(VERIFY_READ, target_addr, len, 1); |
| 1193 | if (!target_smreqn) |
| 1194 | return -TARGET_EFAULT; |
| 1195 | mreqn->imr_multiaddr.s_addr = target_smreqn->imr_multiaddr.s_addr; |
| 1196 | mreqn->imr_address.s_addr = target_smreqn->imr_address.s_addr; |
| 1197 | if (len == sizeof(struct target_ip_mreqn)) |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 1198 | mreqn->imr_ifindex = tswapal(target_smreqn->imr_ifindex); |
Lionel Landwerlin | b975b83 | 2009-04-25 23:30:19 +0200 | [diff] [blame] | 1199 | unlock_user(target_smreqn, target_addr, 0); |
| 1200 | |
| 1201 | return 0; |
| 1202 | } |
| 1203 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1204 | static inline abi_long target_to_host_sockaddr(struct sockaddr *addr, |
| 1205 | abi_ulong target_addr, |
| 1206 | socklen_t len) |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1207 | { |
aurel32 | 607175e | 2009-04-15 16:11:59 +0000 | [diff] [blame] | 1208 | const socklen_t unix_maxlen = sizeof (struct sockaddr_un); |
| 1209 | sa_family_t sa_family; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1210 | struct target_sockaddr *target_saddr; |
| 1211 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1212 | target_saddr = lock_user(VERIFY_READ, target_addr, len, 1); |
| 1213 | if (!target_saddr) |
| 1214 | return -TARGET_EFAULT; |
aurel32 | 607175e | 2009-04-15 16:11:59 +0000 | [diff] [blame] | 1215 | |
| 1216 | sa_family = tswap16(target_saddr->sa_family); |
| 1217 | |
| 1218 | /* Oops. The caller might send a incomplete sun_path; sun_path |
| 1219 | * must be terminated by \0 (see the manual page), but |
| 1220 | * unfortunately it is quite common to specify sockaddr_un |
| 1221 | * length as "strlen(x->sun_path)" while it should be |
| 1222 | * "strlen(...) + 1". We'll fix that here if needed. |
| 1223 | * Linux kernel has a similar feature. |
| 1224 | */ |
| 1225 | |
| 1226 | if (sa_family == AF_UNIX) { |
| 1227 | if (len < unix_maxlen && len > 0) { |
| 1228 | char *cp = (char*)target_saddr; |
| 1229 | |
| 1230 | if ( cp[len-1] && !cp[len] ) |
| 1231 | len++; |
| 1232 | } |
| 1233 | if (len > unix_maxlen) |
| 1234 | len = unix_maxlen; |
| 1235 | } |
| 1236 | |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1237 | memcpy(addr, target_saddr, len); |
aurel32 | 607175e | 2009-04-15 16:11:59 +0000 | [diff] [blame] | 1238 | addr->sa_family = sa_family; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1239 | unlock_user(target_saddr, target_addr, 0); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1240 | |
| 1241 | return 0; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1242 | } |
| 1243 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1244 | static inline abi_long host_to_target_sockaddr(abi_ulong target_addr, |
| 1245 | struct sockaddr *addr, |
| 1246 | socklen_t len) |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1247 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1248 | struct target_sockaddr *target_saddr; |
| 1249 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1250 | target_saddr = lock_user(VERIFY_WRITE, target_addr, len, 0); |
| 1251 | if (!target_saddr) |
| 1252 | return -TARGET_EFAULT; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1253 | memcpy(target_saddr, addr, len); |
| 1254 | target_saddr->sa_family = tswap16(addr->sa_family); |
| 1255 | unlock_user(target_saddr, target_addr, len); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1256 | |
| 1257 | return 0; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1258 | } |
| 1259 | |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1260 | static inline abi_long target_to_host_cmsg(struct msghdr *msgh, |
| 1261 | struct target_msghdr *target_msgh) |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1262 | { |
| 1263 | struct cmsghdr *cmsg = CMSG_FIRSTHDR(msgh); |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1264 | abi_long msg_controllen; |
| 1265 | abi_ulong target_cmsg_addr; |
| 1266 | struct target_cmsghdr *target_cmsg; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1267 | socklen_t space = 0; |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1268 | |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 1269 | msg_controllen = tswapal(target_msgh->msg_controllen); |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1270 | if (msg_controllen < sizeof (struct target_cmsghdr)) |
| 1271 | goto the_end; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 1272 | target_cmsg_addr = tswapal(target_msgh->msg_control); |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1273 | target_cmsg = lock_user(VERIFY_READ, target_cmsg_addr, msg_controllen, 1); |
| 1274 | if (!target_cmsg) |
| 1275 | return -TARGET_EFAULT; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1276 | |
| 1277 | while (cmsg && target_cmsg) { |
| 1278 | void *data = CMSG_DATA(cmsg); |
| 1279 | void *target_data = TARGET_CMSG_DATA(target_cmsg); |
| 1280 | |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 1281 | int len = tswapal(target_cmsg->cmsg_len) |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1282 | - TARGET_CMSG_ALIGN(sizeof (struct target_cmsghdr)); |
| 1283 | |
| 1284 | space += CMSG_SPACE(len); |
| 1285 | if (space > msgh->msg_controllen) { |
| 1286 | space -= CMSG_SPACE(len); |
bellard | 31febb7 | 2005-12-18 20:03:27 +0000 | [diff] [blame] | 1287 | gemu_log("Host cmsg overflow\n"); |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1288 | break; |
| 1289 | } |
| 1290 | |
| 1291 | cmsg->cmsg_level = tswap32(target_cmsg->cmsg_level); |
| 1292 | cmsg->cmsg_type = tswap32(target_cmsg->cmsg_type); |
| 1293 | cmsg->cmsg_len = CMSG_LEN(len); |
| 1294 | |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1295 | if (cmsg->cmsg_level != TARGET_SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) { |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1296 | gemu_log("Unsupported ancillary data: %d/%d\n", cmsg->cmsg_level, cmsg->cmsg_type); |
| 1297 | memcpy(data, target_data, len); |
| 1298 | } else { |
| 1299 | int *fd = (int *)data; |
| 1300 | int *target_fd = (int *)target_data; |
| 1301 | int i, numfds = len / sizeof(int); |
| 1302 | |
| 1303 | for (i = 0; i < numfds; i++) |
| 1304 | fd[i] = tswap32(target_fd[i]); |
| 1305 | } |
| 1306 | |
| 1307 | cmsg = CMSG_NXTHDR(msgh, cmsg); |
| 1308 | target_cmsg = TARGET_CMSG_NXTHDR(target_msgh, target_cmsg); |
| 1309 | } |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1310 | unlock_user(target_cmsg, target_cmsg_addr, 0); |
| 1311 | the_end: |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1312 | msgh->msg_controllen = space; |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1313 | return 0; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1314 | } |
| 1315 | |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1316 | /* ??? Should this also swap msgh->name? */ |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1317 | static inline abi_long host_to_target_cmsg(struct target_msghdr *target_msgh, |
| 1318 | struct msghdr *msgh) |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1319 | { |
| 1320 | struct cmsghdr *cmsg = CMSG_FIRSTHDR(msgh); |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1321 | abi_long msg_controllen; |
| 1322 | abi_ulong target_cmsg_addr; |
| 1323 | struct target_cmsghdr *target_cmsg; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1324 | socklen_t space = 0; |
| 1325 | |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 1326 | msg_controllen = tswapal(target_msgh->msg_controllen); |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1327 | if (msg_controllen < sizeof (struct target_cmsghdr)) |
| 1328 | goto the_end; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 1329 | target_cmsg_addr = tswapal(target_msgh->msg_control); |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1330 | target_cmsg = lock_user(VERIFY_WRITE, target_cmsg_addr, msg_controllen, 0); |
| 1331 | if (!target_cmsg) |
| 1332 | return -TARGET_EFAULT; |
| 1333 | |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1334 | while (cmsg && target_cmsg) { |
| 1335 | void *data = CMSG_DATA(cmsg); |
| 1336 | void *target_data = TARGET_CMSG_DATA(target_cmsg); |
| 1337 | |
| 1338 | int len = cmsg->cmsg_len - CMSG_ALIGN(sizeof (struct cmsghdr)); |
| 1339 | |
| 1340 | space += TARGET_CMSG_SPACE(len); |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1341 | if (space > msg_controllen) { |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1342 | space -= TARGET_CMSG_SPACE(len); |
bellard | 31febb7 | 2005-12-18 20:03:27 +0000 | [diff] [blame] | 1343 | gemu_log("Target cmsg overflow\n"); |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1344 | break; |
| 1345 | } |
| 1346 | |
| 1347 | target_cmsg->cmsg_level = tswap32(cmsg->cmsg_level); |
| 1348 | target_cmsg->cmsg_type = tswap32(cmsg->cmsg_type); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 1349 | target_cmsg->cmsg_len = tswapal(TARGET_CMSG_LEN(len)); |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1350 | |
Jing Huang | 03e1ad9 | 2012-07-23 13:52:07 +0000 | [diff] [blame] | 1351 | if ((cmsg->cmsg_level == TARGET_SOL_SOCKET) && |
| 1352 | (cmsg->cmsg_type == SCM_RIGHTS)) { |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1353 | int *fd = (int *)data; |
| 1354 | int *target_fd = (int *)target_data; |
| 1355 | int i, numfds = len / sizeof(int); |
| 1356 | |
| 1357 | for (i = 0; i < numfds; i++) |
| 1358 | target_fd[i] = tswap32(fd[i]); |
Jing Huang | 03e1ad9 | 2012-07-23 13:52:07 +0000 | [diff] [blame] | 1359 | } else if ((cmsg->cmsg_level == TARGET_SOL_SOCKET) && |
| 1360 | (cmsg->cmsg_type == SO_TIMESTAMP) && |
| 1361 | (len == sizeof(struct timeval))) { |
| 1362 | /* copy struct timeval to target */ |
| 1363 | struct timeval *tv = (struct timeval *)data; |
| 1364 | struct target_timeval *target_tv = |
| 1365 | (struct target_timeval *)target_data; |
Peter Maydell | 120b438 | 2012-07-23 18:16:23 +0100 | [diff] [blame] | 1366 | printf("qemu: copying host to target timeval: %lx %lx\n", |
| 1367 | tv->tv_sec, tv->tv_usec); |
Jing Huang | 03e1ad9 | 2012-07-23 13:52:07 +0000 | [diff] [blame] | 1368 | |
Peter Maydell | 120b438 | 2012-07-23 18:16:23 +0100 | [diff] [blame] | 1369 | target_tv->tv_sec = tswapal(tv->tv_sec); |
| 1370 | target_tv->tv_usec = tswapal(tv->tv_usec); |
Jing Huang | 03e1ad9 | 2012-07-23 13:52:07 +0000 | [diff] [blame] | 1371 | } else { |
| 1372 | gemu_log("Unsupported ancillary data: %d/%d\n", |
| 1373 | cmsg->cmsg_level, cmsg->cmsg_type); |
| 1374 | memcpy(target_data, data, len); |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1375 | } |
| 1376 | |
| 1377 | cmsg = CMSG_NXTHDR(msgh, cmsg); |
| 1378 | target_cmsg = TARGET_CMSG_NXTHDR(target_msgh, target_cmsg); |
| 1379 | } |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1380 | unlock_user(target_cmsg, target_cmsg_addr, space); |
| 1381 | the_end: |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 1382 | target_msgh->msg_controllen = tswapal(space); |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1383 | return 0; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1384 | } |
| 1385 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 1386 | /* do_setsockopt() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 1387 | static abi_long do_setsockopt(int sockfd, int level, int optname, |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1388 | abi_ulong optval_addr, socklen_t optlen) |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1389 | { |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 1390 | abi_long ret; |
j_mayer | 3240710 | 2007-09-26 23:01:49 +0000 | [diff] [blame] | 1391 | int val; |
Lionel Landwerlin | b975b83 | 2009-04-25 23:30:19 +0200 | [diff] [blame] | 1392 | struct ip_mreqn *ip_mreq; |
Lionel Landwerlin | 6e3cb58 | 2009-04-25 23:31:18 +0200 | [diff] [blame] | 1393 | struct ip_mreq_source *ip_mreq_source; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1394 | |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1395 | switch(level) { |
| 1396 | case SOL_TCP: |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1397 | /* TCP options all take an 'int' value. */ |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1398 | if (optlen < sizeof(uint32_t)) |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 1399 | return -TARGET_EINVAL; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1400 | |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1401 | if (get_user_u32(val, optval_addr)) |
| 1402 | return -TARGET_EFAULT; |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1403 | ret = get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val))); |
| 1404 | break; |
| 1405 | case SOL_IP: |
| 1406 | switch(optname) { |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1407 | case IP_TOS: |
| 1408 | case IP_TTL: |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1409 | case IP_HDRINCL: |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1410 | case IP_ROUTER_ALERT: |
| 1411 | case IP_RECVOPTS: |
| 1412 | case IP_RETOPTS: |
| 1413 | case IP_PKTINFO: |
| 1414 | case IP_MTU_DISCOVER: |
| 1415 | case IP_RECVERR: |
| 1416 | case IP_RECVTOS: |
| 1417 | #ifdef IP_FREEBIND |
| 1418 | case IP_FREEBIND: |
| 1419 | #endif |
| 1420 | case IP_MULTICAST_TTL: |
| 1421 | case IP_MULTICAST_LOOP: |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1422 | val = 0; |
| 1423 | if (optlen >= sizeof(uint32_t)) { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1424 | if (get_user_u32(val, optval_addr)) |
| 1425 | return -TARGET_EFAULT; |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1426 | } else if (optlen >= 1) { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1427 | if (get_user_u8(val, optval_addr)) |
| 1428 | return -TARGET_EFAULT; |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1429 | } |
| 1430 | ret = get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val))); |
| 1431 | break; |
Lionel Landwerlin | b975b83 | 2009-04-25 23:30:19 +0200 | [diff] [blame] | 1432 | case IP_ADD_MEMBERSHIP: |
| 1433 | case IP_DROP_MEMBERSHIP: |
| 1434 | if (optlen < sizeof (struct target_ip_mreq) || |
| 1435 | optlen > sizeof (struct target_ip_mreqn)) |
| 1436 | return -TARGET_EINVAL; |
| 1437 | |
| 1438 | ip_mreq = (struct ip_mreqn *) alloca(optlen); |
| 1439 | target_to_host_ip_mreq(ip_mreq, optval_addr, optlen); |
| 1440 | ret = get_errno(setsockopt(sockfd, level, optname, ip_mreq, optlen)); |
| 1441 | break; |
| 1442 | |
Lionel Landwerlin | 6e3cb58 | 2009-04-25 23:31:18 +0200 | [diff] [blame] | 1443 | case IP_BLOCK_SOURCE: |
| 1444 | case IP_UNBLOCK_SOURCE: |
| 1445 | case IP_ADD_SOURCE_MEMBERSHIP: |
| 1446 | case IP_DROP_SOURCE_MEMBERSHIP: |
| 1447 | if (optlen != sizeof (struct target_ip_mreq_source)) |
| 1448 | return -TARGET_EINVAL; |
| 1449 | |
| 1450 | ip_mreq_source = lock_user(VERIFY_READ, optval_addr, optlen, 1); |
| 1451 | ret = get_errno(setsockopt(sockfd, level, optname, ip_mreq_source, optlen)); |
| 1452 | unlock_user (ip_mreq_source, optval_addr, 0); |
| 1453 | break; |
| 1454 | |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1455 | default: |
| 1456 | goto unimplemented; |
| 1457 | } |
| 1458 | break; |
Jing Huang | 79bbbaa | 2012-07-23 13:50:58 +0000 | [diff] [blame] | 1459 | case SOL_RAW: |
| 1460 | switch (optname) { |
| 1461 | case ICMP_FILTER: |
| 1462 | /* struct icmp_filter takes an u32 value */ |
| 1463 | if (optlen < sizeof(uint32_t)) { |
| 1464 | return -TARGET_EINVAL; |
| 1465 | } |
| 1466 | |
| 1467 | if (get_user_u32(val, optval_addr)) { |
| 1468 | return -TARGET_EFAULT; |
| 1469 | } |
| 1470 | ret = get_errno(setsockopt(sockfd, level, optname, |
| 1471 | &val, sizeof(val))); |
| 1472 | break; |
| 1473 | |
| 1474 | default: |
| 1475 | goto unimplemented; |
| 1476 | } |
| 1477 | break; |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1478 | case TARGET_SOL_SOCKET: |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1479 | switch (optname) { |
| 1480 | /* Options with 'int' argument. */ |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1481 | case TARGET_SO_DEBUG: |
| 1482 | optname = SO_DEBUG; |
| 1483 | break; |
| 1484 | case TARGET_SO_REUSEADDR: |
| 1485 | optname = SO_REUSEADDR; |
| 1486 | break; |
| 1487 | case TARGET_SO_TYPE: |
| 1488 | optname = SO_TYPE; |
| 1489 | break; |
| 1490 | case TARGET_SO_ERROR: |
| 1491 | optname = SO_ERROR; |
| 1492 | break; |
| 1493 | case TARGET_SO_DONTROUTE: |
| 1494 | optname = SO_DONTROUTE; |
| 1495 | break; |
| 1496 | case TARGET_SO_BROADCAST: |
| 1497 | optname = SO_BROADCAST; |
| 1498 | break; |
| 1499 | case TARGET_SO_SNDBUF: |
| 1500 | optname = SO_SNDBUF; |
| 1501 | break; |
| 1502 | case TARGET_SO_RCVBUF: |
| 1503 | optname = SO_RCVBUF; |
| 1504 | break; |
| 1505 | case TARGET_SO_KEEPALIVE: |
| 1506 | optname = SO_KEEPALIVE; |
| 1507 | break; |
| 1508 | case TARGET_SO_OOBINLINE: |
| 1509 | optname = SO_OOBINLINE; |
| 1510 | break; |
| 1511 | case TARGET_SO_NO_CHECK: |
| 1512 | optname = SO_NO_CHECK; |
| 1513 | break; |
| 1514 | case TARGET_SO_PRIORITY: |
| 1515 | optname = SO_PRIORITY; |
| 1516 | break; |
bellard | 5e83e8e | 2005-03-01 22:32:06 +0000 | [diff] [blame] | 1517 | #ifdef SO_BSDCOMPAT |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1518 | case TARGET_SO_BSDCOMPAT: |
| 1519 | optname = SO_BSDCOMPAT; |
| 1520 | break; |
bellard | 5e83e8e | 2005-03-01 22:32:06 +0000 | [diff] [blame] | 1521 | #endif |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1522 | case TARGET_SO_PASSCRED: |
| 1523 | optname = SO_PASSCRED; |
| 1524 | break; |
| 1525 | case TARGET_SO_TIMESTAMP: |
| 1526 | optname = SO_TIMESTAMP; |
| 1527 | break; |
| 1528 | case TARGET_SO_RCVLOWAT: |
| 1529 | optname = SO_RCVLOWAT; |
| 1530 | break; |
| 1531 | case TARGET_SO_RCVTIMEO: |
| 1532 | optname = SO_RCVTIMEO; |
| 1533 | break; |
| 1534 | case TARGET_SO_SNDTIMEO: |
| 1535 | optname = SO_SNDTIMEO; |
| 1536 | break; |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1537 | break; |
| 1538 | default: |
| 1539 | goto unimplemented; |
| 1540 | } |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1541 | if (optlen < sizeof(uint32_t)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1542 | return -TARGET_EINVAL; |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1543 | |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1544 | if (get_user_u32(val, optval_addr)) |
| 1545 | return -TARGET_EFAULT; |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1546 | ret = get_errno(setsockopt(sockfd, SOL_SOCKET, optname, &val, sizeof(val))); |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1547 | break; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1548 | default: |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1549 | unimplemented: |
Stefan Weil | b2bedb2 | 2011-09-12 22:33:01 +0200 | [diff] [blame] | 1550 | gemu_log("Unsupported setsockopt level=%d optname=%d\n", level, optname); |
ths | 6fa13c1 | 2007-12-18 02:41:04 +0000 | [diff] [blame] | 1551 | ret = -TARGET_ENOPROTOOPT; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1552 | } |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1553 | return ret; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1554 | } |
| 1555 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 1556 | /* do_getsockopt() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 1557 | static abi_long do_getsockopt(int sockfd, int level, int optname, |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1558 | abi_ulong optval_addr, abi_ulong optlen) |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1559 | { |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 1560 | abi_long ret; |
blueswir1 | b55266b | 2008-09-20 08:07:15 +0000 | [diff] [blame] | 1561 | int len, val; |
| 1562 | socklen_t lv; |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1563 | |
| 1564 | switch(level) { |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1565 | case TARGET_SOL_SOCKET: |
Jamie Lentin | f3b974c | 2010-11-26 15:04:08 +0200 | [diff] [blame] | 1566 | level = SOL_SOCKET; |
| 1567 | switch (optname) { |
| 1568 | /* These don't just return a single integer */ |
| 1569 | case TARGET_SO_LINGER: |
| 1570 | case TARGET_SO_RCVTIMEO: |
| 1571 | case TARGET_SO_SNDTIMEO: |
Jamie Lentin | f3b974c | 2010-11-26 15:04:08 +0200 | [diff] [blame] | 1572 | case TARGET_SO_PEERNAME: |
| 1573 | goto unimplemented; |
Akos PASZTORY | 583359a | 2011-11-14 15:09:49 +0200 | [diff] [blame] | 1574 | case TARGET_SO_PEERCRED: { |
| 1575 | struct ucred cr; |
| 1576 | socklen_t crlen; |
| 1577 | struct target_ucred *tcr; |
| 1578 | |
| 1579 | if (get_user_u32(len, optlen)) { |
| 1580 | return -TARGET_EFAULT; |
| 1581 | } |
| 1582 | if (len < 0) { |
| 1583 | return -TARGET_EINVAL; |
| 1584 | } |
| 1585 | |
| 1586 | crlen = sizeof(cr); |
| 1587 | ret = get_errno(getsockopt(sockfd, level, SO_PEERCRED, |
| 1588 | &cr, &crlen)); |
| 1589 | if (ret < 0) { |
| 1590 | return ret; |
| 1591 | } |
| 1592 | if (len > crlen) { |
| 1593 | len = crlen; |
| 1594 | } |
| 1595 | if (!lock_user_struct(VERIFY_WRITE, tcr, optval_addr, 0)) { |
| 1596 | return -TARGET_EFAULT; |
| 1597 | } |
| 1598 | __put_user(cr.pid, &tcr->pid); |
| 1599 | __put_user(cr.uid, &tcr->uid); |
| 1600 | __put_user(cr.gid, &tcr->gid); |
| 1601 | unlock_user_struct(tcr, optval_addr, 1); |
| 1602 | if (put_user_u32(len, optlen)) { |
| 1603 | return -TARGET_EFAULT; |
| 1604 | } |
| 1605 | break; |
| 1606 | } |
Jamie Lentin | f3b974c | 2010-11-26 15:04:08 +0200 | [diff] [blame] | 1607 | /* Options with 'int' argument. */ |
| 1608 | case TARGET_SO_DEBUG: |
| 1609 | optname = SO_DEBUG; |
| 1610 | goto int_case; |
| 1611 | case TARGET_SO_REUSEADDR: |
| 1612 | optname = SO_REUSEADDR; |
| 1613 | goto int_case; |
| 1614 | case TARGET_SO_TYPE: |
| 1615 | optname = SO_TYPE; |
| 1616 | goto int_case; |
| 1617 | case TARGET_SO_ERROR: |
| 1618 | optname = SO_ERROR; |
| 1619 | goto int_case; |
| 1620 | case TARGET_SO_DONTROUTE: |
| 1621 | optname = SO_DONTROUTE; |
| 1622 | goto int_case; |
| 1623 | case TARGET_SO_BROADCAST: |
| 1624 | optname = SO_BROADCAST; |
| 1625 | goto int_case; |
| 1626 | case TARGET_SO_SNDBUF: |
| 1627 | optname = SO_SNDBUF; |
| 1628 | goto int_case; |
| 1629 | case TARGET_SO_RCVBUF: |
| 1630 | optname = SO_RCVBUF; |
| 1631 | goto int_case; |
| 1632 | case TARGET_SO_KEEPALIVE: |
| 1633 | optname = SO_KEEPALIVE; |
| 1634 | goto int_case; |
| 1635 | case TARGET_SO_OOBINLINE: |
| 1636 | optname = SO_OOBINLINE; |
| 1637 | goto int_case; |
| 1638 | case TARGET_SO_NO_CHECK: |
| 1639 | optname = SO_NO_CHECK; |
| 1640 | goto int_case; |
| 1641 | case TARGET_SO_PRIORITY: |
| 1642 | optname = SO_PRIORITY; |
| 1643 | goto int_case; |
| 1644 | #ifdef SO_BSDCOMPAT |
| 1645 | case TARGET_SO_BSDCOMPAT: |
| 1646 | optname = SO_BSDCOMPAT; |
| 1647 | goto int_case; |
| 1648 | #endif |
| 1649 | case TARGET_SO_PASSCRED: |
| 1650 | optname = SO_PASSCRED; |
| 1651 | goto int_case; |
| 1652 | case TARGET_SO_TIMESTAMP: |
| 1653 | optname = SO_TIMESTAMP; |
| 1654 | goto int_case; |
| 1655 | case TARGET_SO_RCVLOWAT: |
| 1656 | optname = SO_RCVLOWAT; |
| 1657 | goto int_case; |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1658 | default: |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1659 | goto int_case; |
| 1660 | } |
| 1661 | break; |
| 1662 | case SOL_TCP: |
| 1663 | /* TCP options all take an 'int' value. */ |
| 1664 | int_case: |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1665 | if (get_user_u32(len, optlen)) |
| 1666 | return -TARGET_EFAULT; |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1667 | if (len < 0) |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 1668 | return -TARGET_EINVAL; |
Mike Frysinger | 73160d9 | 2011-02-07 01:05:49 -0500 | [diff] [blame] | 1669 | lv = sizeof(lv); |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1670 | ret = get_errno(getsockopt(sockfd, level, optname, &val, &lv)); |
| 1671 | if (ret < 0) |
| 1672 | return ret; |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1673 | if (len > lv) |
| 1674 | len = lv; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1675 | if (len == 4) { |
| 1676 | if (put_user_u32(val, optval_addr)) |
| 1677 | return -TARGET_EFAULT; |
| 1678 | } else { |
| 1679 | if (put_user_u8(val, optval_addr)) |
| 1680 | return -TARGET_EFAULT; |
Jamie Lentin | f3b974c | 2010-11-26 15:04:08 +0200 | [diff] [blame] | 1681 | } |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1682 | if (put_user_u32(len, optlen)) |
| 1683 | return -TARGET_EFAULT; |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1684 | break; |
| 1685 | case SOL_IP: |
| 1686 | switch(optname) { |
| 1687 | case IP_TOS: |
| 1688 | case IP_TTL: |
| 1689 | case IP_HDRINCL: |
| 1690 | case IP_ROUTER_ALERT: |
| 1691 | case IP_RECVOPTS: |
| 1692 | case IP_RETOPTS: |
| 1693 | case IP_PKTINFO: |
| 1694 | case IP_MTU_DISCOVER: |
| 1695 | case IP_RECVERR: |
| 1696 | case IP_RECVTOS: |
| 1697 | #ifdef IP_FREEBIND |
| 1698 | case IP_FREEBIND: |
| 1699 | #endif |
| 1700 | case IP_MULTICAST_TTL: |
| 1701 | case IP_MULTICAST_LOOP: |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1702 | if (get_user_u32(len, optlen)) |
| 1703 | return -TARGET_EFAULT; |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1704 | if (len < 0) |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 1705 | return -TARGET_EINVAL; |
Mike Frysinger | 73160d9 | 2011-02-07 01:05:49 -0500 | [diff] [blame] | 1706 | lv = sizeof(lv); |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1707 | ret = get_errno(getsockopt(sockfd, level, optname, &val, &lv)); |
| 1708 | if (ret < 0) |
| 1709 | return ret; |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1710 | if (len < sizeof(int) && len > 0 && val >= 0 && val < 255) { |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1711 | len = 1; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1712 | if (put_user_u32(len, optlen) |
| 1713 | || put_user_u8(val, optval_addr)) |
| 1714 | return -TARGET_EFAULT; |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1715 | } else { |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1716 | if (len > sizeof(int)) |
| 1717 | len = sizeof(int); |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1718 | if (put_user_u32(len, optlen) |
| 1719 | || put_user_u32(val, optval_addr)) |
| 1720 | return -TARGET_EFAULT; |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1721 | } |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1722 | break; |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1723 | default: |
ths | c02f499 | 2007-12-18 02:39:59 +0000 | [diff] [blame] | 1724 | ret = -TARGET_ENOPROTOOPT; |
| 1725 | break; |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1726 | } |
| 1727 | break; |
| 1728 | default: |
| 1729 | unimplemented: |
| 1730 | gemu_log("getsockopt level=%d optname=%d not yet supported\n", |
| 1731 | level, optname); |
ths | c02f499 | 2007-12-18 02:39:59 +0000 | [diff] [blame] | 1732 | ret = -TARGET_EOPNOTSUPP; |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1733 | break; |
| 1734 | } |
| 1735 | return ret; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1736 | } |
| 1737 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1738 | /* FIXME |
| 1739 | * lock_iovec()/unlock_iovec() have a return code of 0 for success where |
| 1740 | * other lock functions have a return code of 0 for failure. |
| 1741 | */ |
| 1742 | static abi_long lock_iovec(int type, struct iovec *vec, abi_ulong target_addr, |
| 1743 | int count, int copy) |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1744 | { |
| 1745 | struct target_iovec *target_vec; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 1746 | abi_ulong base; |
balrog | d732dcb | 2008-10-28 10:21:03 +0000 | [diff] [blame] | 1747 | int i; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1748 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1749 | target_vec = lock_user(VERIFY_READ, target_addr, count * sizeof(struct target_iovec), 1); |
| 1750 | if (!target_vec) |
| 1751 | return -TARGET_EFAULT; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1752 | for(i = 0;i < count; i++) { |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 1753 | base = tswapal(target_vec[i].iov_base); |
| 1754 | vec[i].iov_len = tswapal(target_vec[i].iov_len); |
bellard | 41df841 | 2008-02-04 22:26:57 +0000 | [diff] [blame] | 1755 | if (vec[i].iov_len != 0) { |
| 1756 | vec[i].iov_base = lock_user(type, base, vec[i].iov_len, copy); |
balrog | d732dcb | 2008-10-28 10:21:03 +0000 | [diff] [blame] | 1757 | /* Don't check lock_user return value. We must call writev even |
| 1758 | if a element has invalid base address. */ |
bellard | 41df841 | 2008-02-04 22:26:57 +0000 | [diff] [blame] | 1759 | } else { |
| 1760 | /* zero length pointer is ignored */ |
| 1761 | vec[i].iov_base = NULL; |
| 1762 | } |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1763 | } |
| 1764 | unlock_user (target_vec, target_addr, 0); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1765 | return 0; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1766 | } |
| 1767 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1768 | static abi_long unlock_iovec(struct iovec *vec, abi_ulong target_addr, |
| 1769 | int count, int copy) |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1770 | { |
| 1771 | struct target_iovec *target_vec; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 1772 | abi_ulong base; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1773 | int i; |
| 1774 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1775 | target_vec = lock_user(VERIFY_READ, target_addr, count * sizeof(struct target_iovec), 1); |
| 1776 | if (!target_vec) |
| 1777 | return -TARGET_EFAULT; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1778 | for(i = 0;i < count; i++) { |
balrog | d732dcb | 2008-10-28 10:21:03 +0000 | [diff] [blame] | 1779 | if (target_vec[i].iov_base) { |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 1780 | base = tswapal(target_vec[i].iov_base); |
balrog | d732dcb | 2008-10-28 10:21:03 +0000 | [diff] [blame] | 1781 | unlock_user(vec[i].iov_base, base, copy ? vec[i].iov_len : 0); |
| 1782 | } |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1783 | } |
| 1784 | unlock_user (target_vec, target_addr, 0); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1785 | |
| 1786 | return 0; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1787 | } |
| 1788 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 1789 | /* do_socket() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 1790 | static abi_long do_socket(int domain, int type, int protocol) |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1791 | { |
| 1792 | #if defined(TARGET_MIPS) |
| 1793 | switch(type) { |
| 1794 | case TARGET_SOCK_DGRAM: |
| 1795 | type = SOCK_DGRAM; |
| 1796 | break; |
| 1797 | case TARGET_SOCK_STREAM: |
| 1798 | type = SOCK_STREAM; |
| 1799 | break; |
| 1800 | case TARGET_SOCK_RAW: |
| 1801 | type = SOCK_RAW; |
| 1802 | break; |
| 1803 | case TARGET_SOCK_RDM: |
| 1804 | type = SOCK_RDM; |
| 1805 | break; |
| 1806 | case TARGET_SOCK_SEQPACKET: |
| 1807 | type = SOCK_SEQPACKET; |
| 1808 | break; |
| 1809 | case TARGET_SOCK_PACKET: |
| 1810 | type = SOCK_PACKET; |
| 1811 | break; |
| 1812 | } |
| 1813 | #endif |
balrog | 12bc92a | 2007-10-30 21:06:14 +0000 | [diff] [blame] | 1814 | if (domain == PF_NETLINK) |
| 1815 | return -EAFNOSUPPORT; /* do not NETLINK socket connections possible */ |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1816 | return get_errno(socket(domain, type, protocol)); |
| 1817 | } |
| 1818 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 1819 | /* do_bind() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 1820 | static abi_long do_bind(int sockfd, abi_ulong target_addr, |
| 1821 | socklen_t addrlen) |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1822 | { |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 1823 | void *addr; |
Arnaud Patard | 917507b | 2009-06-19 10:44:45 +0300 | [diff] [blame] | 1824 | abi_long ret; |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 1825 | |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 1826 | if ((int)addrlen < 0) { |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 1827 | return -TARGET_EINVAL; |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 1828 | } |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 1829 | |
aurel32 | 607175e | 2009-04-15 16:11:59 +0000 | [diff] [blame] | 1830 | addr = alloca(addrlen+1); |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1831 | |
Arnaud Patard | 917507b | 2009-06-19 10:44:45 +0300 | [diff] [blame] | 1832 | ret = target_to_host_sockaddr(addr, target_addr, addrlen); |
| 1833 | if (ret) |
| 1834 | return ret; |
| 1835 | |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1836 | return get_errno(bind(sockfd, addr, addrlen)); |
| 1837 | } |
| 1838 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 1839 | /* do_connect() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 1840 | static abi_long do_connect(int sockfd, abi_ulong target_addr, |
| 1841 | socklen_t addrlen) |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1842 | { |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 1843 | void *addr; |
Arnaud Patard | 917507b | 2009-06-19 10:44:45 +0300 | [diff] [blame] | 1844 | abi_long ret; |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 1845 | |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 1846 | if ((int)addrlen < 0) { |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 1847 | return -TARGET_EINVAL; |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 1848 | } |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 1849 | |
| 1850 | addr = alloca(addrlen); |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1851 | |
Arnaud Patard | 917507b | 2009-06-19 10:44:45 +0300 | [diff] [blame] | 1852 | ret = target_to_host_sockaddr(addr, target_addr, addrlen); |
| 1853 | if (ret) |
| 1854 | return ret; |
| 1855 | |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1856 | return get_errno(connect(sockfd, addr, addrlen)); |
| 1857 | } |
| 1858 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 1859 | /* do_sendrecvmsg() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 1860 | static abi_long do_sendrecvmsg(int fd, abi_ulong target_msg, |
| 1861 | int flags, int send) |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1862 | { |
balrog | 6de645c | 2008-10-28 10:26:29 +0000 | [diff] [blame] | 1863 | abi_long ret, len; |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1864 | struct target_msghdr *msgp; |
| 1865 | struct msghdr msg; |
| 1866 | int count; |
| 1867 | struct iovec *vec; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 1868 | abi_ulong target_vec; |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1869 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1870 | /* FIXME */ |
| 1871 | if (!lock_user_struct(send ? VERIFY_READ : VERIFY_WRITE, |
| 1872 | msgp, |
| 1873 | target_msg, |
| 1874 | send ? 1 : 0)) |
| 1875 | return -TARGET_EFAULT; |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1876 | if (msgp->msg_name) { |
| 1877 | msg.msg_namelen = tswap32(msgp->msg_namelen); |
| 1878 | msg.msg_name = alloca(msg.msg_namelen); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 1879 | ret = target_to_host_sockaddr(msg.msg_name, tswapal(msgp->msg_name), |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1880 | msg.msg_namelen); |
Arnaud Patard | 917507b | 2009-06-19 10:44:45 +0300 | [diff] [blame] | 1881 | if (ret) { |
| 1882 | unlock_user_struct(msgp, target_msg, send ? 0 : 1); |
| 1883 | return ret; |
| 1884 | } |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1885 | } else { |
| 1886 | msg.msg_name = NULL; |
| 1887 | msg.msg_namelen = 0; |
| 1888 | } |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 1889 | msg.msg_controllen = 2 * tswapal(msgp->msg_controllen); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1890 | msg.msg_control = alloca(msg.msg_controllen); |
| 1891 | msg.msg_flags = tswap32(msgp->msg_flags); |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1892 | |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 1893 | count = tswapal(msgp->msg_iovlen); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1894 | vec = alloca(count * sizeof(struct iovec)); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 1895 | target_vec = tswapal(msgp->msg_iov); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1896 | lock_iovec(send ? VERIFY_READ : VERIFY_WRITE, vec, target_vec, count, send); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1897 | msg.msg_iovlen = count; |
| 1898 | msg.msg_iov = vec; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1899 | |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1900 | if (send) { |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1901 | ret = target_to_host_cmsg(&msg, msgp); |
| 1902 | if (ret == 0) |
| 1903 | ret = get_errno(sendmsg(fd, &msg, flags)); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1904 | } else { |
| 1905 | ret = get_errno(recvmsg(fd, &msg, flags)); |
balrog | 6de645c | 2008-10-28 10:26:29 +0000 | [diff] [blame] | 1906 | if (!is_error(ret)) { |
| 1907 | len = ret; |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1908 | ret = host_to_target_cmsg(msgp, &msg); |
Jing Huang | a5e98f3 | 2012-07-23 13:49:24 +0000 | [diff] [blame] | 1909 | if (!is_error(ret)) { |
| 1910 | msgp->msg_namelen = tswap32(msg.msg_namelen); |
| 1911 | if (msg.msg_name != NULL) { |
| 1912 | ret = host_to_target_sockaddr(tswapal(msgp->msg_name), |
| 1913 | msg.msg_name, msg.msg_namelen); |
| 1914 | if (ret) { |
| 1915 | goto out; |
| 1916 | } |
| 1917 | } |
| 1918 | |
balrog | 6de645c | 2008-10-28 10:26:29 +0000 | [diff] [blame] | 1919 | ret = len; |
Jing Huang | a5e98f3 | 2012-07-23 13:49:24 +0000 | [diff] [blame] | 1920 | } |
balrog | 6de645c | 2008-10-28 10:26:29 +0000 | [diff] [blame] | 1921 | } |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1922 | } |
Jing Huang | a5e98f3 | 2012-07-23 13:49:24 +0000 | [diff] [blame] | 1923 | |
| 1924 | out: |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1925 | unlock_iovec(vec, target_vec, count, !send); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1926 | unlock_user_struct(msgp, target_msg, send ? 0 : 1); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1927 | return ret; |
| 1928 | } |
| 1929 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 1930 | /* do_accept() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 1931 | static abi_long do_accept(int fd, abi_ulong target_addr, |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1932 | abi_ulong target_addrlen_addr) |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 1933 | { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1934 | socklen_t addrlen; |
| 1935 | void *addr; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 1936 | abi_long ret; |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 1937 | |
Arnaud Patard | 917507b | 2009-06-19 10:44:45 +0300 | [diff] [blame] | 1938 | if (target_addr == 0) |
| 1939 | return get_errno(accept(fd, NULL, NULL)); |
| 1940 | |
| 1941 | /* linux returns EINVAL if addrlen pointer is invalid */ |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1942 | if (get_user_u32(addrlen, target_addrlen_addr)) |
Arnaud Patard | 917507b | 2009-06-19 10:44:45 +0300 | [diff] [blame] | 1943 | return -TARGET_EINVAL; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1944 | |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 1945 | if ((int)addrlen < 0) { |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 1946 | return -TARGET_EINVAL; |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 1947 | } |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 1948 | |
Arnaud Patard | 917507b | 2009-06-19 10:44:45 +0300 | [diff] [blame] | 1949 | if (!access_ok(VERIFY_WRITE, target_addr, addrlen)) |
| 1950 | return -TARGET_EINVAL; |
| 1951 | |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1952 | addr = alloca(addrlen); |
| 1953 | |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 1954 | ret = get_errno(accept(fd, addr, &addrlen)); |
| 1955 | if (!is_error(ret)) { |
| 1956 | host_to_target_sockaddr(target_addr, addr, addrlen); |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1957 | if (put_user_u32(addrlen, target_addrlen_addr)) |
| 1958 | ret = -TARGET_EFAULT; |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 1959 | } |
| 1960 | return ret; |
| 1961 | } |
| 1962 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 1963 | /* do_getpeername() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 1964 | static abi_long do_getpeername(int fd, abi_ulong target_addr, |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1965 | abi_ulong target_addrlen_addr) |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 1966 | { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1967 | socklen_t addrlen; |
| 1968 | void *addr; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 1969 | abi_long ret; |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 1970 | |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1971 | if (get_user_u32(addrlen, target_addrlen_addr)) |
| 1972 | return -TARGET_EFAULT; |
| 1973 | |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 1974 | if ((int)addrlen < 0) { |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 1975 | return -TARGET_EINVAL; |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 1976 | } |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 1977 | |
Arnaud Patard | 917507b | 2009-06-19 10:44:45 +0300 | [diff] [blame] | 1978 | if (!access_ok(VERIFY_WRITE, target_addr, addrlen)) |
| 1979 | return -TARGET_EFAULT; |
| 1980 | |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1981 | addr = alloca(addrlen); |
| 1982 | |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 1983 | ret = get_errno(getpeername(fd, addr, &addrlen)); |
| 1984 | if (!is_error(ret)) { |
| 1985 | host_to_target_sockaddr(target_addr, addr, addrlen); |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1986 | if (put_user_u32(addrlen, target_addrlen_addr)) |
| 1987 | ret = -TARGET_EFAULT; |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 1988 | } |
| 1989 | return ret; |
| 1990 | } |
| 1991 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 1992 | /* do_getsockname() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 1993 | static abi_long do_getsockname(int fd, abi_ulong target_addr, |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1994 | abi_ulong target_addrlen_addr) |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 1995 | { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1996 | socklen_t addrlen; |
| 1997 | void *addr; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 1998 | abi_long ret; |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 1999 | |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2000 | if (get_user_u32(addrlen, target_addrlen_addr)) |
| 2001 | return -TARGET_EFAULT; |
| 2002 | |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 2003 | if ((int)addrlen < 0) { |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 2004 | return -TARGET_EINVAL; |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 2005 | } |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 2006 | |
Arnaud Patard | 917507b | 2009-06-19 10:44:45 +0300 | [diff] [blame] | 2007 | if (!access_ok(VERIFY_WRITE, target_addr, addrlen)) |
| 2008 | return -TARGET_EFAULT; |
| 2009 | |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2010 | addr = alloca(addrlen); |
| 2011 | |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2012 | ret = get_errno(getsockname(fd, addr, &addrlen)); |
| 2013 | if (!is_error(ret)) { |
| 2014 | host_to_target_sockaddr(target_addr, addr, addrlen); |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2015 | if (put_user_u32(addrlen, target_addrlen_addr)) |
| 2016 | ret = -TARGET_EFAULT; |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2017 | } |
| 2018 | return ret; |
| 2019 | } |
| 2020 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 2021 | /* do_socketpair() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2022 | static abi_long do_socketpair(int domain, int type, int protocol, |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2023 | abi_ulong target_tab_addr) |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2024 | { |
| 2025 | int tab[2]; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2026 | abi_long ret; |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2027 | |
| 2028 | ret = get_errno(socketpair(domain, type, protocol, tab)); |
| 2029 | if (!is_error(ret)) { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2030 | if (put_user_s32(tab[0], target_tab_addr) |
| 2031 | || put_user_s32(tab[1], target_tab_addr + sizeof(tab[0]))) |
| 2032 | ret = -TARGET_EFAULT; |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2033 | } |
| 2034 | return ret; |
| 2035 | } |
| 2036 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 2037 | /* do_sendto() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2038 | static abi_long do_sendto(int fd, abi_ulong msg, size_t len, int flags, |
| 2039 | abi_ulong target_addr, socklen_t addrlen) |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2040 | { |
| 2041 | void *addr; |
| 2042 | void *host_msg; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2043 | abi_long ret; |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2044 | |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 2045 | if ((int)addrlen < 0) { |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 2046 | return -TARGET_EINVAL; |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 2047 | } |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 2048 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2049 | host_msg = lock_user(VERIFY_READ, msg, len, 1); |
| 2050 | if (!host_msg) |
| 2051 | return -TARGET_EFAULT; |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2052 | if (target_addr) { |
| 2053 | addr = alloca(addrlen); |
Arnaud Patard | 917507b | 2009-06-19 10:44:45 +0300 | [diff] [blame] | 2054 | ret = target_to_host_sockaddr(addr, target_addr, addrlen); |
| 2055 | if (ret) { |
| 2056 | unlock_user(host_msg, msg, 0); |
| 2057 | return ret; |
| 2058 | } |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2059 | ret = get_errno(sendto(fd, host_msg, len, flags, addr, addrlen)); |
| 2060 | } else { |
| 2061 | ret = get_errno(send(fd, host_msg, len, flags)); |
| 2062 | } |
| 2063 | unlock_user(host_msg, msg, 0); |
| 2064 | return ret; |
| 2065 | } |
| 2066 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 2067 | /* do_recvfrom() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2068 | static abi_long do_recvfrom(int fd, abi_ulong msg, size_t len, int flags, |
| 2069 | abi_ulong target_addr, |
| 2070 | abi_ulong target_addrlen) |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2071 | { |
| 2072 | socklen_t addrlen; |
| 2073 | void *addr; |
| 2074 | void *host_msg; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2075 | abi_long ret; |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2076 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2077 | host_msg = lock_user(VERIFY_WRITE, msg, len, 0); |
| 2078 | if (!host_msg) |
| 2079 | return -TARGET_EFAULT; |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2080 | if (target_addr) { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2081 | if (get_user_u32(addrlen, target_addrlen)) { |
| 2082 | ret = -TARGET_EFAULT; |
| 2083 | goto fail; |
| 2084 | } |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 2085 | if ((int)addrlen < 0) { |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 2086 | ret = -TARGET_EINVAL; |
| 2087 | goto fail; |
| 2088 | } |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2089 | addr = alloca(addrlen); |
| 2090 | ret = get_errno(recvfrom(fd, host_msg, len, flags, addr, &addrlen)); |
| 2091 | } else { |
| 2092 | addr = NULL; /* To keep compiler quiet. */ |
Blue Swirl | 00aa004 | 2011-07-23 20:04:29 +0000 | [diff] [blame] | 2093 | ret = get_errno(qemu_recv(fd, host_msg, len, flags)); |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2094 | } |
| 2095 | if (!is_error(ret)) { |
| 2096 | if (target_addr) { |
| 2097 | host_to_target_sockaddr(target_addr, addr, addrlen); |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2098 | if (put_user_u32(addrlen, target_addrlen)) { |
| 2099 | ret = -TARGET_EFAULT; |
| 2100 | goto fail; |
| 2101 | } |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2102 | } |
| 2103 | unlock_user(host_msg, msg, len); |
| 2104 | } else { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2105 | fail: |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2106 | unlock_user(host_msg, msg, 0); |
| 2107 | } |
| 2108 | return ret; |
| 2109 | } |
| 2110 | |
j_mayer | 3240710 | 2007-09-26 23:01:49 +0000 | [diff] [blame] | 2111 | #ifdef TARGET_NR_socketcall |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 2112 | /* do_socketcall() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2113 | static abi_long do_socketcall(int num, abi_ulong vptr) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2114 | { |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2115 | abi_long ret; |
| 2116 | const int n = sizeof(abi_ulong); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2117 | |
| 2118 | switch(num) { |
| 2119 | case SOCKOP_socket: |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2120 | { |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2121 | abi_ulong domain, type, protocol; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2122 | |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2123 | if (get_user_ual(domain, vptr) |
| 2124 | || get_user_ual(type, vptr + n) |
| 2125 | || get_user_ual(protocol, vptr + 2 * n)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2126 | return -TARGET_EFAULT; |
| 2127 | |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 2128 | ret = do_socket(domain, type, protocol); |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2129 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2130 | break; |
| 2131 | case SOCKOP_bind: |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2132 | { |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2133 | abi_ulong sockfd; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2134 | abi_ulong target_addr; |
| 2135 | socklen_t addrlen; |
| 2136 | |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2137 | if (get_user_ual(sockfd, vptr) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2138 | || get_user_ual(target_addr, vptr + n) |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2139 | || get_user_ual(addrlen, vptr + 2 * n)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2140 | return -TARGET_EFAULT; |
| 2141 | |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 2142 | ret = do_bind(sockfd, target_addr, addrlen); |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2143 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2144 | break; |
| 2145 | case SOCKOP_connect: |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2146 | { |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2147 | abi_ulong sockfd; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2148 | abi_ulong target_addr; |
| 2149 | socklen_t addrlen; |
| 2150 | |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2151 | if (get_user_ual(sockfd, vptr) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2152 | || get_user_ual(target_addr, vptr + n) |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2153 | || get_user_ual(addrlen, vptr + 2 * n)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2154 | return -TARGET_EFAULT; |
| 2155 | |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 2156 | ret = do_connect(sockfd, target_addr, addrlen); |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2157 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2158 | break; |
| 2159 | case SOCKOP_listen: |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2160 | { |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2161 | abi_ulong sockfd, backlog; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2162 | |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2163 | if (get_user_ual(sockfd, vptr) |
| 2164 | || get_user_ual(backlog, vptr + n)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2165 | return -TARGET_EFAULT; |
| 2166 | |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2167 | ret = get_errno(listen(sockfd, backlog)); |
| 2168 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2169 | break; |
| 2170 | case SOCKOP_accept: |
| 2171 | { |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2172 | abi_ulong sockfd; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2173 | abi_ulong target_addr, target_addrlen; |
| 2174 | |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2175 | if (get_user_ual(sockfd, vptr) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2176 | || get_user_ual(target_addr, vptr + n) |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2177 | || get_user_ual(target_addrlen, vptr + 2 * n)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2178 | return -TARGET_EFAULT; |
| 2179 | |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2180 | ret = do_accept(sockfd, target_addr, target_addrlen); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2181 | } |
| 2182 | break; |
| 2183 | case SOCKOP_getsockname: |
| 2184 | { |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2185 | abi_ulong sockfd; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2186 | abi_ulong target_addr, target_addrlen; |
| 2187 | |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2188 | if (get_user_ual(sockfd, vptr) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2189 | || get_user_ual(target_addr, vptr + n) |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2190 | || get_user_ual(target_addrlen, vptr + 2 * n)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2191 | return -TARGET_EFAULT; |
| 2192 | |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2193 | ret = do_getsockname(sockfd, target_addr, target_addrlen); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2194 | } |
| 2195 | break; |
| 2196 | case SOCKOP_getpeername: |
| 2197 | { |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2198 | abi_ulong sockfd; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2199 | abi_ulong target_addr, target_addrlen; |
| 2200 | |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2201 | if (get_user_ual(sockfd, vptr) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2202 | || get_user_ual(target_addr, vptr + n) |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2203 | || get_user_ual(target_addrlen, vptr + 2 * n)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2204 | return -TARGET_EFAULT; |
| 2205 | |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2206 | ret = do_getpeername(sockfd, target_addr, target_addrlen); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2207 | } |
| 2208 | break; |
| 2209 | case SOCKOP_socketpair: |
| 2210 | { |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2211 | abi_ulong domain, type, protocol; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2212 | abi_ulong tab; |
| 2213 | |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2214 | if (get_user_ual(domain, vptr) |
| 2215 | || get_user_ual(type, vptr + n) |
| 2216 | || get_user_ual(protocol, vptr + 2 * n) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2217 | || get_user_ual(tab, vptr + 3 * n)) |
| 2218 | return -TARGET_EFAULT; |
| 2219 | |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2220 | ret = do_socketpair(domain, type, protocol, tab); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2221 | } |
| 2222 | break; |
| 2223 | case SOCKOP_send: |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2224 | { |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2225 | abi_ulong sockfd; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2226 | abi_ulong msg; |
| 2227 | size_t len; |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2228 | abi_ulong flags; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2229 | |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2230 | if (get_user_ual(sockfd, vptr) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2231 | || get_user_ual(msg, vptr + n) |
| 2232 | || get_user_ual(len, vptr + 2 * n) |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2233 | || get_user_ual(flags, vptr + 3 * n)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2234 | return -TARGET_EFAULT; |
| 2235 | |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2236 | ret = do_sendto(sockfd, msg, len, flags, 0, 0); |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2237 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2238 | break; |
| 2239 | case SOCKOP_recv: |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2240 | { |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2241 | abi_ulong sockfd; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2242 | abi_ulong msg; |
| 2243 | size_t len; |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2244 | abi_ulong flags; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2245 | |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2246 | if (get_user_ual(sockfd, vptr) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2247 | || get_user_ual(msg, vptr + n) |
| 2248 | || get_user_ual(len, vptr + 2 * n) |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2249 | || get_user_ual(flags, vptr + 3 * 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_recvfrom(sockfd, msg, len, flags, 0, 0); |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2253 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2254 | break; |
| 2255 | case SOCKOP_sendto: |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 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 msg; |
| 2259 | size_t len; |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2260 | abi_ulong flags; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2261 | abi_ulong addr; |
| 2262 | socklen_t addrlen; |
| 2263 | |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2264 | if (get_user_ual(sockfd, vptr) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2265 | || get_user_ual(msg, vptr + n) |
| 2266 | || get_user_ual(len, vptr + 2 * n) |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2267 | || get_user_ual(flags, vptr + 3 * n) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2268 | || get_user_ual(addr, vptr + 4 * n) |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2269 | || get_user_ual(addrlen, vptr + 5 * n)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2270 | return -TARGET_EFAULT; |
| 2271 | |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2272 | ret = do_sendto(sockfd, msg, len, flags, addr, addrlen); |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2273 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2274 | break; |
| 2275 | case SOCKOP_recvfrom: |
| 2276 | { |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2277 | abi_ulong sockfd; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2278 | abi_ulong msg; |
| 2279 | size_t len; |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2280 | abi_ulong flags; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2281 | abi_ulong addr; |
| 2282 | socklen_t addrlen; |
| 2283 | |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2284 | if (get_user_ual(sockfd, vptr) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2285 | || get_user_ual(msg, vptr + n) |
| 2286 | || get_user_ual(len, vptr + 2 * n) |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2287 | || get_user_ual(flags, vptr + 3 * n) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2288 | || get_user_ual(addr, vptr + 4 * n) |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2289 | || get_user_ual(addrlen, vptr + 5 * n)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2290 | return -TARGET_EFAULT; |
| 2291 | |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2292 | ret = do_recvfrom(sockfd, msg, len, flags, addr, addrlen); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2293 | } |
| 2294 | break; |
| 2295 | case SOCKOP_shutdown: |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2296 | { |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2297 | abi_ulong sockfd, how; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2298 | |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2299 | if (get_user_ual(sockfd, vptr) |
| 2300 | || get_user_ual(how, vptr + n)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2301 | return -TARGET_EFAULT; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2302 | |
| 2303 | ret = get_errno(shutdown(sockfd, how)); |
| 2304 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2305 | break; |
| 2306 | case SOCKOP_sendmsg: |
| 2307 | case SOCKOP_recvmsg: |
bellard | 1a9353d | 2003-03-16 20:28:50 +0000 | [diff] [blame] | 2308 | { |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2309 | abi_ulong fd; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2310 | abi_ulong target_msg; |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2311 | abi_ulong flags; |
bellard | 1a9353d | 2003-03-16 20:28:50 +0000 | [diff] [blame] | 2312 | |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2313 | if (get_user_ual(fd, vptr) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2314 | || get_user_ual(target_msg, vptr + n) |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2315 | || get_user_ual(flags, vptr + 2 * n)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2316 | return -TARGET_EFAULT; |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 2317 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 2318 | ret = do_sendrecvmsg(fd, target_msg, flags, |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 2319 | (num == SOCKOP_sendmsg)); |
bellard | 1a9353d | 2003-03-16 20:28:50 +0000 | [diff] [blame] | 2320 | } |
| 2321 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2322 | case SOCKOP_setsockopt: |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2323 | { |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2324 | abi_ulong sockfd; |
| 2325 | abi_ulong level; |
| 2326 | abi_ulong optname; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2327 | abi_ulong optval; |
| 2328 | socklen_t optlen; |
| 2329 | |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2330 | if (get_user_ual(sockfd, vptr) |
| 2331 | || get_user_ual(level, vptr + n) |
| 2332 | || get_user_ual(optname, vptr + 2 * n) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2333 | || get_user_ual(optval, vptr + 3 * n) |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2334 | || get_user_ual(optlen, vptr + 4 * n)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2335 | return -TARGET_EFAULT; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2336 | |
| 2337 | ret = do_setsockopt(sockfd, level, optname, optval, optlen); |
| 2338 | } |
| 2339 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2340 | case SOCKOP_getsockopt: |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2341 | { |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2342 | abi_ulong sockfd; |
| 2343 | abi_ulong level; |
| 2344 | abi_ulong optname; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2345 | abi_ulong optval; |
| 2346 | socklen_t optlen; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2347 | |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2348 | if (get_user_ual(sockfd, vptr) |
| 2349 | || get_user_ual(level, vptr + n) |
| 2350 | || get_user_ual(optname, vptr + 2 * n) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2351 | || get_user_ual(optval, vptr + 3 * n) |
Ulrich Hecht | 9881818 | 2009-07-03 17:09:28 +0200 | [diff] [blame] | 2352 | || get_user_ual(optlen, vptr + 4 * n)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2353 | return -TARGET_EFAULT; |
| 2354 | |
| 2355 | ret = do_getsockopt(sockfd, level, optname, optval, optlen); |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 2356 | } |
| 2357 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2358 | default: |
| 2359 | gemu_log("Unsupported socketcall: %d\n", num); |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 2360 | ret = -TARGET_ENOSYS; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2361 | break; |
| 2362 | } |
| 2363 | return ret; |
| 2364 | } |
j_mayer | 3240710 | 2007-09-26 23:01:49 +0000 | [diff] [blame] | 2365 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2366 | |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 2367 | #define N_SHM_REGIONS 32 |
| 2368 | |
| 2369 | static struct shm_region { |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 2370 | abi_ulong start; |
| 2371 | abi_ulong size; |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 2372 | } shm_regions[N_SHM_REGIONS]; |
| 2373 | |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2374 | struct target_ipc_perm |
| 2375 | { |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2376 | abi_long __key; |
| 2377 | abi_ulong uid; |
| 2378 | abi_ulong gid; |
| 2379 | abi_ulong cuid; |
| 2380 | abi_ulong cgid; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2381 | unsigned short int mode; |
| 2382 | unsigned short int __pad1; |
| 2383 | unsigned short int __seq; |
| 2384 | unsigned short int __pad2; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2385 | abi_ulong __unused1; |
| 2386 | abi_ulong __unused2; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2387 | }; |
| 2388 | |
| 2389 | struct target_semid_ds |
| 2390 | { |
| 2391 | struct target_ipc_perm sem_perm; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2392 | abi_ulong sem_otime; |
| 2393 | abi_ulong __unused1; |
| 2394 | abi_ulong sem_ctime; |
| 2395 | abi_ulong __unused2; |
| 2396 | abi_ulong sem_nsems; |
| 2397 | abi_ulong __unused3; |
| 2398 | abi_ulong __unused4; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2399 | }; |
| 2400 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2401 | static inline abi_long target_to_host_ipc_perm(struct ipc_perm *host_ip, |
| 2402 | abi_ulong target_addr) |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2403 | { |
| 2404 | struct target_ipc_perm *target_ip; |
| 2405 | struct target_semid_ds *target_sd; |
| 2406 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2407 | if (!lock_user_struct(VERIFY_READ, target_sd, target_addr, 1)) |
| 2408 | return -TARGET_EFAULT; |
Michael S. Tsirkin | e8bbe36 | 2009-09-30 18:56:44 +0000 | [diff] [blame] | 2409 | target_ip = &(target_sd->sem_perm); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 2410 | host_ip->__key = tswapal(target_ip->__key); |
| 2411 | host_ip->uid = tswapal(target_ip->uid); |
| 2412 | host_ip->gid = tswapal(target_ip->gid); |
| 2413 | host_ip->cuid = tswapal(target_ip->cuid); |
| 2414 | host_ip->cgid = tswapal(target_ip->cgid); |
| 2415 | host_ip->mode = tswap16(target_ip->mode); |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2416 | unlock_user_struct(target_sd, target_addr, 0); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2417 | return 0; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2418 | } |
| 2419 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2420 | static inline abi_long host_to_target_ipc_perm(abi_ulong target_addr, |
| 2421 | struct ipc_perm *host_ip) |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2422 | { |
| 2423 | struct target_ipc_perm *target_ip; |
| 2424 | struct target_semid_ds *target_sd; |
| 2425 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2426 | if (!lock_user_struct(VERIFY_WRITE, target_sd, target_addr, 0)) |
| 2427 | return -TARGET_EFAULT; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2428 | target_ip = &(target_sd->sem_perm); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 2429 | target_ip->__key = tswapal(host_ip->__key); |
| 2430 | target_ip->uid = tswapal(host_ip->uid); |
| 2431 | target_ip->gid = tswapal(host_ip->gid); |
| 2432 | target_ip->cuid = tswapal(host_ip->cuid); |
| 2433 | target_ip->cgid = tswapal(host_ip->cgid); |
| 2434 | target_ip->mode = tswap16(host_ip->mode); |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2435 | unlock_user_struct(target_sd, target_addr, 1); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2436 | return 0; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2437 | } |
| 2438 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2439 | static inline abi_long target_to_host_semid_ds(struct semid_ds *host_sd, |
| 2440 | abi_ulong target_addr) |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2441 | { |
| 2442 | struct target_semid_ds *target_sd; |
| 2443 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2444 | if (!lock_user_struct(VERIFY_READ, target_sd, target_addr, 1)) |
| 2445 | return -TARGET_EFAULT; |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2446 | if (target_to_host_ipc_perm(&(host_sd->sem_perm),target_addr)) |
| 2447 | return -TARGET_EFAULT; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 2448 | host_sd->sem_nsems = tswapal(target_sd->sem_nsems); |
| 2449 | host_sd->sem_otime = tswapal(target_sd->sem_otime); |
| 2450 | host_sd->sem_ctime = tswapal(target_sd->sem_ctime); |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2451 | unlock_user_struct(target_sd, target_addr, 0); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2452 | return 0; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2453 | } |
| 2454 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2455 | static inline abi_long host_to_target_semid_ds(abi_ulong target_addr, |
| 2456 | struct semid_ds *host_sd) |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2457 | { |
| 2458 | struct target_semid_ds *target_sd; |
| 2459 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2460 | if (!lock_user_struct(VERIFY_WRITE, target_sd, target_addr, 0)) |
| 2461 | return -TARGET_EFAULT; |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2462 | 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] | 2463 | return -TARGET_EFAULT; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 2464 | target_sd->sem_nsems = tswapal(host_sd->sem_nsems); |
| 2465 | target_sd->sem_otime = tswapal(host_sd->sem_otime); |
| 2466 | target_sd->sem_ctime = tswapal(host_sd->sem_ctime); |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2467 | unlock_user_struct(target_sd, target_addr, 1); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2468 | return 0; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2469 | } |
| 2470 | |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2471 | struct target_seminfo { |
| 2472 | int semmap; |
| 2473 | int semmni; |
| 2474 | int semmns; |
| 2475 | int semmnu; |
| 2476 | int semmsl; |
| 2477 | int semopm; |
| 2478 | int semume; |
| 2479 | int semusz; |
| 2480 | int semvmx; |
| 2481 | int semaem; |
| 2482 | }; |
| 2483 | |
| 2484 | static inline abi_long host_to_target_seminfo(abi_ulong target_addr, |
| 2485 | struct seminfo *host_seminfo) |
| 2486 | { |
| 2487 | struct target_seminfo *target_seminfo; |
| 2488 | if (!lock_user_struct(VERIFY_WRITE, target_seminfo, target_addr, 0)) |
| 2489 | return -TARGET_EFAULT; |
| 2490 | __put_user(host_seminfo->semmap, &target_seminfo->semmap); |
| 2491 | __put_user(host_seminfo->semmni, &target_seminfo->semmni); |
| 2492 | __put_user(host_seminfo->semmns, &target_seminfo->semmns); |
| 2493 | __put_user(host_seminfo->semmnu, &target_seminfo->semmnu); |
| 2494 | __put_user(host_seminfo->semmsl, &target_seminfo->semmsl); |
| 2495 | __put_user(host_seminfo->semopm, &target_seminfo->semopm); |
| 2496 | __put_user(host_seminfo->semume, &target_seminfo->semume); |
| 2497 | __put_user(host_seminfo->semusz, &target_seminfo->semusz); |
| 2498 | __put_user(host_seminfo->semvmx, &target_seminfo->semvmx); |
| 2499 | __put_user(host_seminfo->semaem, &target_seminfo->semaem); |
| 2500 | unlock_user_struct(target_seminfo, target_addr, 1); |
| 2501 | return 0; |
| 2502 | } |
| 2503 | |
ths | fa29481 | 2007-02-02 22:05:00 +0000 | [diff] [blame] | 2504 | union semun { |
| 2505 | int val; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2506 | struct semid_ds *buf; |
ths | fa29481 | 2007-02-02 22:05:00 +0000 | [diff] [blame] | 2507 | unsigned short *array; |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2508 | struct seminfo *__buf; |
ths | fa29481 | 2007-02-02 22:05:00 +0000 | [diff] [blame] | 2509 | }; |
| 2510 | |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2511 | union target_semun { |
| 2512 | int val; |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2513 | abi_ulong buf; |
| 2514 | abi_ulong array; |
| 2515 | abi_ulong __buf; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2516 | }; |
| 2517 | |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2518 | static inline abi_long target_to_host_semarray(int semid, unsigned short **host_array, |
| 2519 | abi_ulong target_addr) |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2520 | { |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2521 | int nsems; |
| 2522 | unsigned short *array; |
| 2523 | union semun semun; |
| 2524 | struct semid_ds semid_ds; |
| 2525 | int i, ret; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2526 | |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2527 | semun.buf = &semid_ds; |
| 2528 | |
| 2529 | ret = semctl(semid, 0, IPC_STAT, semun); |
| 2530 | if (ret == -1) |
| 2531 | return get_errno(ret); |
| 2532 | |
| 2533 | nsems = semid_ds.sem_nsems; |
| 2534 | |
| 2535 | *host_array = malloc(nsems*sizeof(unsigned short)); |
| 2536 | array = lock_user(VERIFY_READ, target_addr, |
| 2537 | nsems*sizeof(unsigned short), 1); |
| 2538 | if (!array) |
| 2539 | return -TARGET_EFAULT; |
| 2540 | |
| 2541 | for(i=0; i<nsems; i++) { |
| 2542 | __get_user((*host_array)[i], &array[i]); |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2543 | } |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2544 | unlock_user(array, target_addr, 0); |
| 2545 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2546 | return 0; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2547 | } |
| 2548 | |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2549 | static inline abi_long host_to_target_semarray(int semid, abi_ulong target_addr, |
| 2550 | unsigned short **host_array) |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2551 | { |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2552 | int nsems; |
| 2553 | unsigned short *array; |
| 2554 | union semun semun; |
| 2555 | struct semid_ds semid_ds; |
| 2556 | int i, ret; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2557 | |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2558 | semun.buf = &semid_ds; |
| 2559 | |
| 2560 | ret = semctl(semid, 0, IPC_STAT, semun); |
| 2561 | if (ret == -1) |
| 2562 | return get_errno(ret); |
| 2563 | |
| 2564 | nsems = semid_ds.sem_nsems; |
| 2565 | |
| 2566 | array = lock_user(VERIFY_WRITE, target_addr, |
| 2567 | nsems*sizeof(unsigned short), 0); |
| 2568 | if (!array) |
| 2569 | return -TARGET_EFAULT; |
| 2570 | |
| 2571 | for(i=0; i<nsems; i++) { |
| 2572 | __put_user((*host_array)[i], &array[i]); |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2573 | } |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2574 | free(*host_array); |
| 2575 | unlock_user(array, target_addr, 1); |
| 2576 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2577 | return 0; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2578 | } |
| 2579 | |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2580 | static inline abi_long do_semctl(int semid, int semnum, int cmd, |
| 2581 | union target_semun target_su) |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2582 | { |
| 2583 | union semun arg; |
| 2584 | struct semid_ds dsarg; |
vibi sreenivasan | 7b8118e | 2009-06-19 13:34:39 +0530 | [diff] [blame] | 2585 | unsigned short *array = NULL; |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2586 | struct seminfo seminfo; |
| 2587 | abi_long ret = -TARGET_EINVAL; |
| 2588 | abi_long err; |
| 2589 | cmd &= 0xff; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2590 | |
| 2591 | switch( cmd ) { |
| 2592 | case GETVAL: |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2593 | case SETVAL: |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 2594 | arg.val = tswap32(target_su.val); |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2595 | ret = get_errno(semctl(semid, semnum, cmd, arg)); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 2596 | target_su.val = tswap32(arg.val); |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2597 | break; |
| 2598 | case GETALL: |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2599 | case SETALL: |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2600 | err = target_to_host_semarray(semid, &array, target_su.array); |
| 2601 | if (err) |
| 2602 | return err; |
| 2603 | arg.array = array; |
| 2604 | ret = get_errno(semctl(semid, semnum, cmd, arg)); |
| 2605 | err = host_to_target_semarray(semid, target_su.array, &array); |
| 2606 | if (err) |
| 2607 | return err; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2608 | break; |
| 2609 | case IPC_STAT: |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2610 | case IPC_SET: |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2611 | case SEM_STAT: |
| 2612 | err = target_to_host_semid_ds(&dsarg, target_su.buf); |
| 2613 | if (err) |
| 2614 | return err; |
| 2615 | arg.buf = &dsarg; |
| 2616 | ret = get_errno(semctl(semid, semnum, cmd, arg)); |
| 2617 | err = host_to_target_semid_ds(target_su.buf, &dsarg); |
| 2618 | if (err) |
| 2619 | return err; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2620 | break; |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2621 | case IPC_INFO: |
| 2622 | case SEM_INFO: |
| 2623 | arg.__buf = &seminfo; |
| 2624 | ret = get_errno(semctl(semid, semnum, cmd, arg)); |
| 2625 | err = host_to_target_seminfo(target_su.__buf, &seminfo); |
| 2626 | if (err) |
| 2627 | return err; |
| 2628 | break; |
| 2629 | case IPC_RMID: |
| 2630 | case GETPID: |
| 2631 | case GETNCNT: |
| 2632 | case GETZCNT: |
| 2633 | ret = get_errno(semctl(semid, semnum, cmd, NULL)); |
| 2634 | break; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2635 | } |
| 2636 | |
| 2637 | return ret; |
| 2638 | } |
| 2639 | |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2640 | struct target_sembuf { |
| 2641 | unsigned short sem_num; |
| 2642 | short sem_op; |
| 2643 | short sem_flg; |
| 2644 | }; |
| 2645 | |
| 2646 | static inline abi_long target_to_host_sembuf(struct sembuf *host_sembuf, |
| 2647 | abi_ulong target_addr, |
| 2648 | unsigned nsops) |
| 2649 | { |
| 2650 | struct target_sembuf *target_sembuf; |
| 2651 | int i; |
| 2652 | |
| 2653 | target_sembuf = lock_user(VERIFY_READ, target_addr, |
| 2654 | nsops*sizeof(struct target_sembuf), 1); |
| 2655 | if (!target_sembuf) |
| 2656 | return -TARGET_EFAULT; |
| 2657 | |
| 2658 | for(i=0; i<nsops; i++) { |
| 2659 | __get_user(host_sembuf[i].sem_num, &target_sembuf[i].sem_num); |
| 2660 | __get_user(host_sembuf[i].sem_op, &target_sembuf[i].sem_op); |
| 2661 | __get_user(host_sembuf[i].sem_flg, &target_sembuf[i].sem_flg); |
| 2662 | } |
| 2663 | |
| 2664 | unlock_user(target_sembuf, target_addr, 0); |
| 2665 | |
| 2666 | return 0; |
| 2667 | } |
| 2668 | |
| 2669 | static inline abi_long do_semop(int semid, abi_long ptr, unsigned nsops) |
| 2670 | { |
| 2671 | struct sembuf sops[nsops]; |
| 2672 | |
| 2673 | if (target_to_host_sembuf(sops, ptr, nsops)) |
| 2674 | return -TARGET_EFAULT; |
| 2675 | |
| 2676 | return semop(semid, sops, nsops); |
| 2677 | } |
| 2678 | |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2679 | struct target_msqid_ds |
| 2680 | { |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 2681 | struct target_ipc_perm msg_perm; |
| 2682 | abi_ulong msg_stime; |
| 2683 | #if TARGET_ABI_BITS == 32 |
| 2684 | abi_ulong __unused1; |
| 2685 | #endif |
| 2686 | abi_ulong msg_rtime; |
| 2687 | #if TARGET_ABI_BITS == 32 |
| 2688 | abi_ulong __unused2; |
| 2689 | #endif |
| 2690 | abi_ulong msg_ctime; |
| 2691 | #if TARGET_ABI_BITS == 32 |
| 2692 | abi_ulong __unused3; |
| 2693 | #endif |
| 2694 | abi_ulong __msg_cbytes; |
| 2695 | abi_ulong msg_qnum; |
| 2696 | abi_ulong msg_qbytes; |
| 2697 | abi_ulong msg_lspid; |
| 2698 | abi_ulong msg_lrpid; |
| 2699 | abi_ulong __unused4; |
| 2700 | abi_ulong __unused5; |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2701 | }; |
| 2702 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2703 | static inline abi_long target_to_host_msqid_ds(struct msqid_ds *host_md, |
| 2704 | abi_ulong target_addr) |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2705 | { |
| 2706 | struct target_msqid_ds *target_md; |
| 2707 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2708 | if (!lock_user_struct(VERIFY_READ, target_md, target_addr, 1)) |
| 2709 | return -TARGET_EFAULT; |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 2710 | if (target_to_host_ipc_perm(&(host_md->msg_perm),target_addr)) |
| 2711 | return -TARGET_EFAULT; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 2712 | host_md->msg_stime = tswapal(target_md->msg_stime); |
| 2713 | host_md->msg_rtime = tswapal(target_md->msg_rtime); |
| 2714 | host_md->msg_ctime = tswapal(target_md->msg_ctime); |
| 2715 | host_md->__msg_cbytes = tswapal(target_md->__msg_cbytes); |
| 2716 | host_md->msg_qnum = tswapal(target_md->msg_qnum); |
| 2717 | host_md->msg_qbytes = tswapal(target_md->msg_qbytes); |
| 2718 | host_md->msg_lspid = tswapal(target_md->msg_lspid); |
| 2719 | host_md->msg_lrpid = tswapal(target_md->msg_lrpid); |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2720 | unlock_user_struct(target_md, target_addr, 0); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2721 | return 0; |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2722 | } |
| 2723 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2724 | static inline abi_long host_to_target_msqid_ds(abi_ulong target_addr, |
| 2725 | struct msqid_ds *host_md) |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2726 | { |
| 2727 | struct target_msqid_ds *target_md; |
| 2728 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2729 | if (!lock_user_struct(VERIFY_WRITE, target_md, target_addr, 0)) |
| 2730 | return -TARGET_EFAULT; |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 2731 | if (host_to_target_ipc_perm(target_addr,&(host_md->msg_perm))) |
| 2732 | return -TARGET_EFAULT; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 2733 | target_md->msg_stime = tswapal(host_md->msg_stime); |
| 2734 | target_md->msg_rtime = tswapal(host_md->msg_rtime); |
| 2735 | target_md->msg_ctime = tswapal(host_md->msg_ctime); |
| 2736 | target_md->__msg_cbytes = tswapal(host_md->__msg_cbytes); |
| 2737 | target_md->msg_qnum = tswapal(host_md->msg_qnum); |
| 2738 | target_md->msg_qbytes = tswapal(host_md->msg_qbytes); |
| 2739 | target_md->msg_lspid = tswapal(host_md->msg_lspid); |
| 2740 | target_md->msg_lrpid = tswapal(host_md->msg_lrpid); |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2741 | unlock_user_struct(target_md, target_addr, 1); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2742 | return 0; |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2743 | } |
| 2744 | |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 2745 | struct target_msginfo { |
| 2746 | int msgpool; |
| 2747 | int msgmap; |
| 2748 | int msgmax; |
| 2749 | int msgmnb; |
| 2750 | int msgmni; |
| 2751 | int msgssz; |
| 2752 | int msgtql; |
| 2753 | unsigned short int msgseg; |
| 2754 | }; |
| 2755 | |
| 2756 | static inline abi_long host_to_target_msginfo(abi_ulong target_addr, |
| 2757 | struct msginfo *host_msginfo) |
| 2758 | { |
| 2759 | struct target_msginfo *target_msginfo; |
| 2760 | if (!lock_user_struct(VERIFY_WRITE, target_msginfo, target_addr, 0)) |
| 2761 | return -TARGET_EFAULT; |
| 2762 | __put_user(host_msginfo->msgpool, &target_msginfo->msgpool); |
| 2763 | __put_user(host_msginfo->msgmap, &target_msginfo->msgmap); |
| 2764 | __put_user(host_msginfo->msgmax, &target_msginfo->msgmax); |
| 2765 | __put_user(host_msginfo->msgmnb, &target_msginfo->msgmnb); |
| 2766 | __put_user(host_msginfo->msgmni, &target_msginfo->msgmni); |
| 2767 | __put_user(host_msginfo->msgssz, &target_msginfo->msgssz); |
| 2768 | __put_user(host_msginfo->msgtql, &target_msginfo->msgtql); |
| 2769 | __put_user(host_msginfo->msgseg, &target_msginfo->msgseg); |
| 2770 | unlock_user_struct(target_msginfo, target_addr, 1); |
aurel32 | 00b229a | 2008-10-24 13:12:52 +0000 | [diff] [blame] | 2771 | return 0; |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 2772 | } |
| 2773 | |
| 2774 | static inline abi_long do_msgctl(int msgid, int cmd, abi_long ptr) |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2775 | { |
| 2776 | struct msqid_ds dsarg; |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 2777 | struct msginfo msginfo; |
| 2778 | abi_long ret = -TARGET_EINVAL; |
| 2779 | |
| 2780 | cmd &= 0xff; |
| 2781 | |
| 2782 | switch (cmd) { |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2783 | case IPC_STAT: |
| 2784 | case IPC_SET: |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 2785 | case MSG_STAT: |
| 2786 | if (target_to_host_msqid_ds(&dsarg,ptr)) |
| 2787 | return -TARGET_EFAULT; |
| 2788 | ret = get_errno(msgctl(msgid, cmd, &dsarg)); |
| 2789 | if (host_to_target_msqid_ds(ptr,&dsarg)) |
| 2790 | return -TARGET_EFAULT; |
| 2791 | break; |
| 2792 | case IPC_RMID: |
| 2793 | ret = get_errno(msgctl(msgid, cmd, NULL)); |
| 2794 | break; |
| 2795 | case IPC_INFO: |
| 2796 | case MSG_INFO: |
| 2797 | ret = get_errno(msgctl(msgid, cmd, (struct msqid_ds *)&msginfo)); |
| 2798 | if (host_to_target_msginfo(ptr, &msginfo)) |
| 2799 | return -TARGET_EFAULT; |
| 2800 | break; |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2801 | } |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 2802 | |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2803 | return ret; |
| 2804 | } |
| 2805 | |
| 2806 | struct target_msgbuf { |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 2807 | abi_long mtype; |
| 2808 | char mtext[1]; |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2809 | }; |
| 2810 | |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2811 | static inline abi_long do_msgsnd(int msqid, abi_long msgp, |
| 2812 | unsigned int msgsz, int msgflg) |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2813 | { |
| 2814 | struct target_msgbuf *target_mb; |
| 2815 | struct msgbuf *host_mb; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2816 | abi_long ret = 0; |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2817 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2818 | if (!lock_user_struct(VERIFY_READ, target_mb, msgp, 0)) |
| 2819 | return -TARGET_EFAULT; |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2820 | host_mb = malloc(msgsz+sizeof(long)); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 2821 | host_mb->mtype = (abi_long) tswapal(target_mb->mtype); |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 2822 | memcpy(host_mb->mtext, target_mb->mtext, msgsz); |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2823 | ret = get_errno(msgsnd(msqid, host_mb, msgsz, msgflg)); |
| 2824 | free(host_mb); |
| 2825 | unlock_user_struct(target_mb, msgp, 0); |
| 2826 | |
| 2827 | return ret; |
| 2828 | } |
| 2829 | |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2830 | static inline abi_long do_msgrcv(int msqid, abi_long msgp, |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 2831 | unsigned int msgsz, abi_long msgtyp, |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2832 | int msgflg) |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2833 | { |
| 2834 | struct target_msgbuf *target_mb; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2835 | char *target_mtext; |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2836 | struct msgbuf *host_mb; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2837 | abi_long ret = 0; |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2838 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2839 | if (!lock_user_struct(VERIFY_WRITE, target_mb, msgp, 0)) |
| 2840 | return -TARGET_EFAULT; |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 2841 | |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2842 | host_mb = malloc(msgsz+sizeof(long)); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 2843 | ret = get_errno(msgrcv(msqid, host_mb, msgsz, tswapal(msgtyp), msgflg)); |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 2844 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2845 | if (ret > 0) { |
| 2846 | abi_ulong target_mtext_addr = msgp + sizeof(abi_ulong); |
| 2847 | target_mtext = lock_user(VERIFY_WRITE, target_mtext_addr, ret, 0); |
| 2848 | if (!target_mtext) { |
| 2849 | ret = -TARGET_EFAULT; |
| 2850 | goto end; |
| 2851 | } |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 2852 | memcpy(target_mb->mtext, host_mb->mtext, ret); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2853 | unlock_user(target_mtext, target_mtext_addr, ret); |
| 2854 | } |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 2855 | |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 2856 | target_mb->mtype = tswapal(host_mb->mtype); |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2857 | free(host_mb); |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2858 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2859 | end: |
| 2860 | if (target_mb) |
| 2861 | unlock_user_struct(target_mb, msgp, 1); |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2862 | return ret; |
| 2863 | } |
| 2864 | |
Riku Voipio | 88a8c98 | 2009-04-03 10:42:00 +0300 | [diff] [blame] | 2865 | struct target_shmid_ds |
| 2866 | { |
| 2867 | struct target_ipc_perm shm_perm; |
| 2868 | abi_ulong shm_segsz; |
| 2869 | abi_ulong shm_atime; |
| 2870 | #if TARGET_ABI_BITS == 32 |
| 2871 | abi_ulong __unused1; |
| 2872 | #endif |
| 2873 | abi_ulong shm_dtime; |
| 2874 | #if TARGET_ABI_BITS == 32 |
| 2875 | abi_ulong __unused2; |
| 2876 | #endif |
| 2877 | abi_ulong shm_ctime; |
| 2878 | #if TARGET_ABI_BITS == 32 |
| 2879 | abi_ulong __unused3; |
| 2880 | #endif |
| 2881 | int shm_cpid; |
| 2882 | int shm_lpid; |
| 2883 | abi_ulong shm_nattch; |
| 2884 | unsigned long int __unused4; |
| 2885 | unsigned long int __unused5; |
| 2886 | }; |
| 2887 | |
| 2888 | static inline abi_long target_to_host_shmid_ds(struct shmid_ds *host_sd, |
| 2889 | abi_ulong target_addr) |
| 2890 | { |
| 2891 | struct target_shmid_ds *target_sd; |
| 2892 | |
| 2893 | if (!lock_user_struct(VERIFY_READ, target_sd, target_addr, 1)) |
| 2894 | return -TARGET_EFAULT; |
| 2895 | if (target_to_host_ipc_perm(&(host_sd->shm_perm), target_addr)) |
| 2896 | return -TARGET_EFAULT; |
| 2897 | __get_user(host_sd->shm_segsz, &target_sd->shm_segsz); |
| 2898 | __get_user(host_sd->shm_atime, &target_sd->shm_atime); |
| 2899 | __get_user(host_sd->shm_dtime, &target_sd->shm_dtime); |
| 2900 | __get_user(host_sd->shm_ctime, &target_sd->shm_ctime); |
| 2901 | __get_user(host_sd->shm_cpid, &target_sd->shm_cpid); |
| 2902 | __get_user(host_sd->shm_lpid, &target_sd->shm_lpid); |
| 2903 | __get_user(host_sd->shm_nattch, &target_sd->shm_nattch); |
| 2904 | unlock_user_struct(target_sd, target_addr, 0); |
| 2905 | return 0; |
| 2906 | } |
| 2907 | |
| 2908 | static inline abi_long host_to_target_shmid_ds(abi_ulong target_addr, |
| 2909 | struct shmid_ds *host_sd) |
| 2910 | { |
| 2911 | struct target_shmid_ds *target_sd; |
| 2912 | |
| 2913 | if (!lock_user_struct(VERIFY_WRITE, target_sd, target_addr, 0)) |
| 2914 | return -TARGET_EFAULT; |
| 2915 | if (host_to_target_ipc_perm(target_addr, &(host_sd->shm_perm))) |
| 2916 | return -TARGET_EFAULT; |
| 2917 | __put_user(host_sd->shm_segsz, &target_sd->shm_segsz); |
| 2918 | __put_user(host_sd->shm_atime, &target_sd->shm_atime); |
| 2919 | __put_user(host_sd->shm_dtime, &target_sd->shm_dtime); |
| 2920 | __put_user(host_sd->shm_ctime, &target_sd->shm_ctime); |
| 2921 | __put_user(host_sd->shm_cpid, &target_sd->shm_cpid); |
| 2922 | __put_user(host_sd->shm_lpid, &target_sd->shm_lpid); |
| 2923 | __put_user(host_sd->shm_nattch, &target_sd->shm_nattch); |
| 2924 | unlock_user_struct(target_sd, target_addr, 1); |
| 2925 | return 0; |
| 2926 | } |
| 2927 | |
| 2928 | struct target_shminfo { |
| 2929 | abi_ulong shmmax; |
| 2930 | abi_ulong shmmin; |
| 2931 | abi_ulong shmmni; |
| 2932 | abi_ulong shmseg; |
| 2933 | abi_ulong shmall; |
| 2934 | }; |
| 2935 | |
| 2936 | static inline abi_long host_to_target_shminfo(abi_ulong target_addr, |
| 2937 | struct shminfo *host_shminfo) |
| 2938 | { |
| 2939 | struct target_shminfo *target_shminfo; |
| 2940 | if (!lock_user_struct(VERIFY_WRITE, target_shminfo, target_addr, 0)) |
| 2941 | return -TARGET_EFAULT; |
| 2942 | __put_user(host_shminfo->shmmax, &target_shminfo->shmmax); |
| 2943 | __put_user(host_shminfo->shmmin, &target_shminfo->shmmin); |
| 2944 | __put_user(host_shminfo->shmmni, &target_shminfo->shmmni); |
| 2945 | __put_user(host_shminfo->shmseg, &target_shminfo->shmseg); |
| 2946 | __put_user(host_shminfo->shmall, &target_shminfo->shmall); |
| 2947 | unlock_user_struct(target_shminfo, target_addr, 1); |
| 2948 | return 0; |
| 2949 | } |
| 2950 | |
| 2951 | struct target_shm_info { |
| 2952 | int used_ids; |
| 2953 | abi_ulong shm_tot; |
| 2954 | abi_ulong shm_rss; |
| 2955 | abi_ulong shm_swp; |
| 2956 | abi_ulong swap_attempts; |
| 2957 | abi_ulong swap_successes; |
| 2958 | }; |
| 2959 | |
| 2960 | static inline abi_long host_to_target_shm_info(abi_ulong target_addr, |
| 2961 | struct shm_info *host_shm_info) |
| 2962 | { |
| 2963 | struct target_shm_info *target_shm_info; |
| 2964 | if (!lock_user_struct(VERIFY_WRITE, target_shm_info, target_addr, 0)) |
| 2965 | return -TARGET_EFAULT; |
| 2966 | __put_user(host_shm_info->used_ids, &target_shm_info->used_ids); |
| 2967 | __put_user(host_shm_info->shm_tot, &target_shm_info->shm_tot); |
| 2968 | __put_user(host_shm_info->shm_rss, &target_shm_info->shm_rss); |
| 2969 | __put_user(host_shm_info->shm_swp, &target_shm_info->shm_swp); |
| 2970 | __put_user(host_shm_info->swap_attempts, &target_shm_info->swap_attempts); |
| 2971 | __put_user(host_shm_info->swap_successes, &target_shm_info->swap_successes); |
| 2972 | unlock_user_struct(target_shm_info, target_addr, 1); |
| 2973 | return 0; |
| 2974 | } |
| 2975 | |
| 2976 | static inline abi_long do_shmctl(int shmid, int cmd, abi_long buf) |
| 2977 | { |
| 2978 | struct shmid_ds dsarg; |
| 2979 | struct shminfo shminfo; |
| 2980 | struct shm_info shm_info; |
| 2981 | abi_long ret = -TARGET_EINVAL; |
| 2982 | |
| 2983 | cmd &= 0xff; |
| 2984 | |
| 2985 | switch(cmd) { |
| 2986 | case IPC_STAT: |
| 2987 | case IPC_SET: |
| 2988 | case SHM_STAT: |
| 2989 | if (target_to_host_shmid_ds(&dsarg, buf)) |
| 2990 | return -TARGET_EFAULT; |
| 2991 | ret = get_errno(shmctl(shmid, cmd, &dsarg)); |
| 2992 | if (host_to_target_shmid_ds(buf, &dsarg)) |
| 2993 | return -TARGET_EFAULT; |
| 2994 | break; |
| 2995 | case IPC_INFO: |
| 2996 | ret = get_errno(shmctl(shmid, cmd, (struct shmid_ds *)&shminfo)); |
| 2997 | if (host_to_target_shminfo(buf, &shminfo)) |
| 2998 | return -TARGET_EFAULT; |
| 2999 | break; |
| 3000 | case SHM_INFO: |
| 3001 | ret = get_errno(shmctl(shmid, cmd, (struct shmid_ds *)&shm_info)); |
| 3002 | if (host_to_target_shm_info(buf, &shm_info)) |
| 3003 | return -TARGET_EFAULT; |
| 3004 | break; |
| 3005 | case IPC_RMID: |
| 3006 | case SHM_LOCK: |
| 3007 | case SHM_UNLOCK: |
| 3008 | ret = get_errno(shmctl(shmid, cmd, NULL)); |
| 3009 | break; |
| 3010 | } |
| 3011 | |
| 3012 | return ret; |
| 3013 | } |
| 3014 | |
| 3015 | static inline abi_ulong do_shmat(int shmid, abi_ulong shmaddr, int shmflg) |
| 3016 | { |
| 3017 | abi_long raddr; |
| 3018 | void *host_raddr; |
| 3019 | struct shmid_ds shm_info; |
| 3020 | int i,ret; |
| 3021 | |
| 3022 | /* find out the length of the shared memory segment */ |
| 3023 | ret = get_errno(shmctl(shmid, IPC_STAT, &shm_info)); |
| 3024 | if (is_error(ret)) { |
| 3025 | /* can't get length, bail out */ |
| 3026 | return ret; |
| 3027 | } |
| 3028 | |
| 3029 | mmap_lock(); |
| 3030 | |
| 3031 | if (shmaddr) |
| 3032 | host_raddr = shmat(shmid, (void *)g2h(shmaddr), shmflg); |
| 3033 | else { |
| 3034 | abi_ulong mmap_start; |
| 3035 | |
| 3036 | mmap_start = mmap_find_vma(0, shm_info.shm_segsz); |
| 3037 | |
| 3038 | if (mmap_start == -1) { |
| 3039 | errno = ENOMEM; |
| 3040 | host_raddr = (void *)-1; |
| 3041 | } else |
| 3042 | host_raddr = shmat(shmid, g2h(mmap_start), shmflg | SHM_REMAP); |
| 3043 | } |
| 3044 | |
| 3045 | if (host_raddr == (void *)-1) { |
| 3046 | mmap_unlock(); |
| 3047 | return get_errno((long)host_raddr); |
| 3048 | } |
| 3049 | raddr=h2g((unsigned long)host_raddr); |
| 3050 | |
| 3051 | page_set_flags(raddr, raddr + shm_info.shm_segsz, |
| 3052 | PAGE_VALID | PAGE_READ | |
| 3053 | ((shmflg & SHM_RDONLY)? 0 : PAGE_WRITE)); |
| 3054 | |
| 3055 | for (i = 0; i < N_SHM_REGIONS; i++) { |
| 3056 | if (shm_regions[i].start == 0) { |
| 3057 | shm_regions[i].start = raddr; |
| 3058 | shm_regions[i].size = shm_info.shm_segsz; |
| 3059 | break; |
| 3060 | } |
| 3061 | } |
| 3062 | |
| 3063 | mmap_unlock(); |
| 3064 | return raddr; |
| 3065 | |
| 3066 | } |
| 3067 | |
| 3068 | static inline abi_long do_shmdt(abi_ulong shmaddr) |
| 3069 | { |
| 3070 | int i; |
| 3071 | |
| 3072 | for (i = 0; i < N_SHM_REGIONS; ++i) { |
| 3073 | if (shm_regions[i].start == shmaddr) { |
| 3074 | shm_regions[i].start = 0; |
takasi-y@ops.dti.ne.jp | e00ac24 | 2010-04-11 02:09:57 +0900 | [diff] [blame] | 3075 | page_set_flags(shmaddr, shmaddr + shm_regions[i].size, 0); |
Riku Voipio | 88a8c98 | 2009-04-03 10:42:00 +0300 | [diff] [blame] | 3076 | break; |
| 3077 | } |
| 3078 | } |
| 3079 | |
| 3080 | return get_errno(shmdt(g2h(shmaddr))); |
| 3081 | } |
| 3082 | |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 3083 | #ifdef TARGET_NR_ipc |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 3084 | /* ??? This only works with linear mappings. */ |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 3085 | /* do_ipc() must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 3086 | static abi_long do_ipc(unsigned int call, int first, |
| 3087 | int second, int third, |
| 3088 | abi_long ptr, abi_long fifth) |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 3089 | { |
| 3090 | int version; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 3091 | abi_long ret = 0; |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 3092 | |
| 3093 | version = call >> 16; |
| 3094 | call &= 0xffff; |
| 3095 | |
| 3096 | switch (call) { |
ths | fa29481 | 2007-02-02 22:05:00 +0000 | [diff] [blame] | 3097 | case IPCOP_semop: |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 3098 | ret = do_semop(first, ptr, second); |
ths | fa29481 | 2007-02-02 22:05:00 +0000 | [diff] [blame] | 3099 | break; |
| 3100 | |
| 3101 | case IPCOP_semget: |
| 3102 | ret = get_errno(semget(first, second, third)); |
| 3103 | break; |
| 3104 | |
| 3105 | case IPCOP_semctl: |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 3106 | ret = do_semctl(first, second, third, (union target_semun)(abi_ulong) ptr); |
ths | fa29481 | 2007-02-02 22:05:00 +0000 | [diff] [blame] | 3107 | break; |
ths | d96372e | 2007-02-02 22:05:44 +0000 | [diff] [blame] | 3108 | |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 3109 | case IPCOP_msgget: |
| 3110 | ret = get_errno(msgget(first, second)); |
| 3111 | break; |
ths | d96372e | 2007-02-02 22:05:44 +0000 | [diff] [blame] | 3112 | |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 3113 | case IPCOP_msgsnd: |
| 3114 | ret = do_msgsnd(first, ptr, second, third); |
| 3115 | break; |
ths | d96372e | 2007-02-02 22:05:44 +0000 | [diff] [blame] | 3116 | |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 3117 | case IPCOP_msgctl: |
| 3118 | ret = do_msgctl(first, second, ptr); |
| 3119 | break; |
ths | d96372e | 2007-02-02 22:05:44 +0000 | [diff] [blame] | 3120 | |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 3121 | case IPCOP_msgrcv: |
| 3122 | switch (version) { |
| 3123 | case 0: |
| 3124 | { |
| 3125 | struct target_ipc_kludge { |
| 3126 | abi_long msgp; |
| 3127 | abi_long msgtyp; |
| 3128 | } *tmp; |
ths | d96372e | 2007-02-02 22:05:44 +0000 | [diff] [blame] | 3129 | |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 3130 | if (!lock_user_struct(VERIFY_READ, tmp, ptr, 1)) { |
| 3131 | ret = -TARGET_EFAULT; |
| 3132 | break; |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 3133 | } |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 3134 | |
| 3135 | ret = do_msgrcv(first, tmp->msgp, second, tmp->msgtyp, third); |
| 3136 | |
| 3137 | unlock_user_struct(tmp, ptr, 0); |
| 3138 | break; |
| 3139 | } |
| 3140 | default: |
| 3141 | ret = do_msgrcv(first, ptr, second, fifth, third); |
| 3142 | } |
| 3143 | break; |
ths | d96372e | 2007-02-02 22:05:44 +0000 | [diff] [blame] | 3144 | |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 3145 | case IPCOP_shmat: |
Riku Voipio | 88a8c98 | 2009-04-03 10:42:00 +0300 | [diff] [blame] | 3146 | switch (version) { |
| 3147 | default: |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 3148 | { |
| 3149 | abi_ulong raddr; |
Riku Voipio | 88a8c98 | 2009-04-03 10:42:00 +0300 | [diff] [blame] | 3150 | raddr = do_shmat(first, ptr, second); |
| 3151 | if (is_error(raddr)) |
| 3152 | return get_errno(raddr); |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 3153 | if (put_user_ual(raddr, third)) |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 3154 | return -TARGET_EFAULT; |
Riku Voipio | 88a8c98 | 2009-04-03 10:42:00 +0300 | [diff] [blame] | 3155 | break; |
| 3156 | } |
| 3157 | case 1: |
| 3158 | ret = -TARGET_EINVAL; |
| 3159 | break; |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 3160 | } |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 3161 | break; |
| 3162 | case IPCOP_shmdt: |
Riku Voipio | 88a8c98 | 2009-04-03 10:42:00 +0300 | [diff] [blame] | 3163 | ret = do_shmdt(ptr); |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 3164 | break; |
| 3165 | |
| 3166 | case IPCOP_shmget: |
| 3167 | /* IPC_* flag values are the same on all linux platforms */ |
| 3168 | ret = get_errno(shmget(first, second, third)); |
| 3169 | break; |
| 3170 | |
| 3171 | /* IPC_* and SHM_* command values are the same on all linux platforms */ |
| 3172 | case IPCOP_shmctl: |
Riku Voipio | 88a8c98 | 2009-04-03 10:42:00 +0300 | [diff] [blame] | 3173 | ret = do_shmctl(first, second, third); |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 3174 | break; |
| 3175 | default: |
j_mayer | 3240710 | 2007-09-26 23:01:49 +0000 | [diff] [blame] | 3176 | gemu_log("Unsupported ipc call: %d (version %d)\n", call, version); |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 3177 | ret = -TARGET_ENOSYS; |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 3178 | break; |
| 3179 | } |
| 3180 | return ret; |
| 3181 | } |
j_mayer | 3240710 | 2007-09-26 23:01:49 +0000 | [diff] [blame] | 3182 | #endif |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 3183 | |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3184 | /* kernel structure types definitions */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3185 | |
Blue Swirl | 001faf3 | 2009-05-13 17:53:17 +0000 | [diff] [blame] | 3186 | #define STRUCT(name, ...) STRUCT_ ## name, |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3187 | #define STRUCT_SPECIAL(name) STRUCT_ ## name, |
| 3188 | enum { |
| 3189 | #include "syscall_types.h" |
| 3190 | }; |
| 3191 | #undef STRUCT |
| 3192 | #undef STRUCT_SPECIAL |
| 3193 | |
Blue Swirl | 001faf3 | 2009-05-13 17:53:17 +0000 | [diff] [blame] | 3194 | #define STRUCT(name, ...) static const argtype struct_ ## name ## _def[] = { __VA_ARGS__, TYPE_NULL }; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3195 | #define STRUCT_SPECIAL(name) |
| 3196 | #include "syscall_types.h" |
| 3197 | #undef STRUCT |
| 3198 | #undef STRUCT_SPECIAL |
| 3199 | |
Peter Maydell | d2ef05b | 2011-01-06 15:04:17 +0000 | [diff] [blame] | 3200 | typedef struct IOCTLEntry IOCTLEntry; |
| 3201 | |
| 3202 | typedef abi_long do_ioctl_fn(const IOCTLEntry *ie, uint8_t *buf_temp, |
| 3203 | int fd, abi_long cmd, abi_long arg); |
| 3204 | |
| 3205 | struct IOCTLEntry { |
bellard | 2ab83ea | 2003-06-15 19:56:46 +0000 | [diff] [blame] | 3206 | unsigned int target_cmd; |
| 3207 | unsigned int host_cmd; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3208 | const char *name; |
| 3209 | int access; |
Peter Maydell | d2ef05b | 2011-01-06 15:04:17 +0000 | [diff] [blame] | 3210 | do_ioctl_fn *do_ioctl; |
bellard | 1a9353d | 2003-03-16 20:28:50 +0000 | [diff] [blame] | 3211 | const argtype arg_type[5]; |
Peter Maydell | d2ef05b | 2011-01-06 15:04:17 +0000 | [diff] [blame] | 3212 | }; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3213 | |
| 3214 | #define IOC_R 0x0001 |
| 3215 | #define IOC_W 0x0002 |
| 3216 | #define IOC_RW (IOC_R | IOC_W) |
| 3217 | |
| 3218 | #define MAX_STRUCT_SIZE 4096 |
| 3219 | |
Peter Maydell | dace20d | 2011-01-10 13:11:24 +0000 | [diff] [blame] | 3220 | #ifdef CONFIG_FIEMAP |
Peter Maydell | 285da2b | 2011-01-06 15:04:18 +0000 | [diff] [blame] | 3221 | /* So fiemap access checks don't overflow on 32 bit systems. |
| 3222 | * This is very slightly smaller than the limit imposed by |
| 3223 | * the underlying kernel. |
| 3224 | */ |
| 3225 | #define FIEMAP_MAX_EXTENTS ((UINT_MAX - sizeof(struct fiemap)) \ |
| 3226 | / sizeof(struct fiemap_extent)) |
| 3227 | |
| 3228 | static abi_long do_ioctl_fs_ioc_fiemap(const IOCTLEntry *ie, uint8_t *buf_temp, |
| 3229 | int fd, abi_long cmd, abi_long arg) |
| 3230 | { |
| 3231 | /* The parameter for this ioctl is a struct fiemap followed |
| 3232 | * by an array of struct fiemap_extent whose size is set |
| 3233 | * in fiemap->fm_extent_count. The array is filled in by the |
| 3234 | * ioctl. |
| 3235 | */ |
| 3236 | int target_size_in, target_size_out; |
| 3237 | struct fiemap *fm; |
| 3238 | const argtype *arg_type = ie->arg_type; |
| 3239 | const argtype extent_arg_type[] = { MK_STRUCT(STRUCT_fiemap_extent) }; |
| 3240 | void *argptr, *p; |
| 3241 | abi_long ret; |
| 3242 | int i, extent_size = thunk_type_size(extent_arg_type, 0); |
| 3243 | uint32_t outbufsz; |
| 3244 | int free_fm = 0; |
| 3245 | |
| 3246 | assert(arg_type[0] == TYPE_PTR); |
| 3247 | assert(ie->access == IOC_RW); |
| 3248 | arg_type++; |
| 3249 | target_size_in = thunk_type_size(arg_type, 0); |
| 3250 | argptr = lock_user(VERIFY_READ, arg, target_size_in, 1); |
| 3251 | if (!argptr) { |
| 3252 | return -TARGET_EFAULT; |
| 3253 | } |
| 3254 | thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST); |
| 3255 | unlock_user(argptr, arg, 0); |
| 3256 | fm = (struct fiemap *)buf_temp; |
| 3257 | if (fm->fm_extent_count > FIEMAP_MAX_EXTENTS) { |
| 3258 | return -TARGET_EINVAL; |
| 3259 | } |
| 3260 | |
| 3261 | outbufsz = sizeof (*fm) + |
| 3262 | (sizeof(struct fiemap_extent) * fm->fm_extent_count); |
| 3263 | |
| 3264 | if (outbufsz > MAX_STRUCT_SIZE) { |
| 3265 | /* We can't fit all the extents into the fixed size buffer. |
| 3266 | * Allocate one that is large enough and use it instead. |
| 3267 | */ |
| 3268 | fm = malloc(outbufsz); |
| 3269 | if (!fm) { |
| 3270 | return -TARGET_ENOMEM; |
| 3271 | } |
| 3272 | memcpy(fm, buf_temp, sizeof(struct fiemap)); |
| 3273 | free_fm = 1; |
| 3274 | } |
| 3275 | ret = get_errno(ioctl(fd, ie->host_cmd, fm)); |
| 3276 | if (!is_error(ret)) { |
| 3277 | target_size_out = target_size_in; |
| 3278 | /* An extent_count of 0 means we were only counting the extents |
| 3279 | * so there are no structs to copy |
| 3280 | */ |
| 3281 | if (fm->fm_extent_count != 0) { |
| 3282 | target_size_out += fm->fm_mapped_extents * extent_size; |
| 3283 | } |
| 3284 | argptr = lock_user(VERIFY_WRITE, arg, target_size_out, 0); |
| 3285 | if (!argptr) { |
| 3286 | ret = -TARGET_EFAULT; |
| 3287 | } else { |
| 3288 | /* Convert the struct fiemap */ |
| 3289 | thunk_convert(argptr, fm, arg_type, THUNK_TARGET); |
| 3290 | if (fm->fm_extent_count != 0) { |
| 3291 | p = argptr + target_size_in; |
| 3292 | /* ...and then all the struct fiemap_extents */ |
| 3293 | for (i = 0; i < fm->fm_mapped_extents; i++) { |
| 3294 | thunk_convert(p, &fm->fm_extents[i], extent_arg_type, |
| 3295 | THUNK_TARGET); |
| 3296 | p += extent_size; |
| 3297 | } |
| 3298 | } |
| 3299 | unlock_user(argptr, arg, target_size_out); |
| 3300 | } |
| 3301 | } |
| 3302 | if (free_fm) { |
| 3303 | free(fm); |
| 3304 | } |
| 3305 | return ret; |
| 3306 | } |
Peter Maydell | dace20d | 2011-01-10 13:11:24 +0000 | [diff] [blame] | 3307 | #endif |
Peter Maydell | 285da2b | 2011-01-06 15:04:18 +0000 | [diff] [blame] | 3308 | |
Laurent Vivier | 059c2f2 | 2011-03-30 00:12:12 +0200 | [diff] [blame] | 3309 | static abi_long do_ioctl_ifconf(const IOCTLEntry *ie, uint8_t *buf_temp, |
| 3310 | int fd, abi_long cmd, abi_long arg) |
| 3311 | { |
| 3312 | const argtype *arg_type = ie->arg_type; |
| 3313 | int target_size; |
| 3314 | void *argptr; |
| 3315 | int ret; |
| 3316 | struct ifconf *host_ifconf; |
| 3317 | uint32_t outbufsz; |
| 3318 | const argtype ifreq_arg_type[] = { MK_STRUCT(STRUCT_sockaddr_ifreq) }; |
| 3319 | int target_ifreq_size; |
| 3320 | int nb_ifreq; |
| 3321 | int free_buf = 0; |
| 3322 | int i; |
| 3323 | int target_ifc_len; |
| 3324 | abi_long target_ifc_buf; |
| 3325 | int host_ifc_len; |
| 3326 | char *host_ifc_buf; |
| 3327 | |
| 3328 | assert(arg_type[0] == TYPE_PTR); |
| 3329 | assert(ie->access == IOC_RW); |
| 3330 | |
| 3331 | arg_type++; |
| 3332 | target_size = thunk_type_size(arg_type, 0); |
| 3333 | |
| 3334 | argptr = lock_user(VERIFY_READ, arg, target_size, 1); |
| 3335 | if (!argptr) |
| 3336 | return -TARGET_EFAULT; |
| 3337 | thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST); |
| 3338 | unlock_user(argptr, arg, 0); |
| 3339 | |
| 3340 | host_ifconf = (struct ifconf *)(unsigned long)buf_temp; |
| 3341 | target_ifc_len = host_ifconf->ifc_len; |
| 3342 | target_ifc_buf = (abi_long)(unsigned long)host_ifconf->ifc_buf; |
| 3343 | |
| 3344 | target_ifreq_size = thunk_type_size(ifreq_arg_type, 0); |
| 3345 | nb_ifreq = target_ifc_len / target_ifreq_size; |
| 3346 | host_ifc_len = nb_ifreq * sizeof(struct ifreq); |
| 3347 | |
| 3348 | outbufsz = sizeof(*host_ifconf) + host_ifc_len; |
| 3349 | if (outbufsz > MAX_STRUCT_SIZE) { |
| 3350 | /* We can't fit all the extents into the fixed size buffer. |
| 3351 | * Allocate one that is large enough and use it instead. |
| 3352 | */ |
| 3353 | host_ifconf = malloc(outbufsz); |
| 3354 | if (!host_ifconf) { |
| 3355 | return -TARGET_ENOMEM; |
| 3356 | } |
| 3357 | memcpy(host_ifconf, buf_temp, sizeof(*host_ifconf)); |
| 3358 | free_buf = 1; |
| 3359 | } |
| 3360 | host_ifc_buf = (char*)host_ifconf + sizeof(*host_ifconf); |
| 3361 | |
| 3362 | host_ifconf->ifc_len = host_ifc_len; |
| 3363 | host_ifconf->ifc_buf = host_ifc_buf; |
| 3364 | |
| 3365 | ret = get_errno(ioctl(fd, ie->host_cmd, host_ifconf)); |
| 3366 | if (!is_error(ret)) { |
| 3367 | /* convert host ifc_len to target ifc_len */ |
| 3368 | |
| 3369 | nb_ifreq = host_ifconf->ifc_len / sizeof(struct ifreq); |
| 3370 | target_ifc_len = nb_ifreq * target_ifreq_size; |
| 3371 | host_ifconf->ifc_len = target_ifc_len; |
| 3372 | |
| 3373 | /* restore target ifc_buf */ |
| 3374 | |
| 3375 | host_ifconf->ifc_buf = (char *)(unsigned long)target_ifc_buf; |
| 3376 | |
| 3377 | /* copy struct ifconf to target user */ |
| 3378 | |
| 3379 | argptr = lock_user(VERIFY_WRITE, arg, target_size, 0); |
| 3380 | if (!argptr) |
| 3381 | return -TARGET_EFAULT; |
| 3382 | thunk_convert(argptr, host_ifconf, arg_type, THUNK_TARGET); |
| 3383 | unlock_user(argptr, arg, target_size); |
| 3384 | |
| 3385 | /* copy ifreq[] to target user */ |
| 3386 | |
| 3387 | argptr = lock_user(VERIFY_WRITE, target_ifc_buf, target_ifc_len, 0); |
| 3388 | for (i = 0; i < nb_ifreq ; i++) { |
| 3389 | thunk_convert(argptr + i * target_ifreq_size, |
| 3390 | host_ifc_buf + i * sizeof(struct ifreq), |
| 3391 | ifreq_arg_type, THUNK_TARGET); |
| 3392 | } |
| 3393 | unlock_user(argptr, target_ifc_buf, target_ifc_len); |
| 3394 | } |
| 3395 | |
| 3396 | if (free_buf) { |
| 3397 | free(host_ifconf); |
| 3398 | } |
| 3399 | |
| 3400 | return ret; |
| 3401 | } |
| 3402 | |
Alexander Graf | 56e904e | 2012-01-31 18:42:06 +0100 | [diff] [blame] | 3403 | static abi_long do_ioctl_dm(const IOCTLEntry *ie, uint8_t *buf_temp, int fd, |
| 3404 | abi_long cmd, abi_long arg) |
| 3405 | { |
| 3406 | void *argptr; |
| 3407 | struct dm_ioctl *host_dm; |
| 3408 | abi_long guest_data; |
| 3409 | uint32_t guest_data_size; |
| 3410 | int target_size; |
| 3411 | const argtype *arg_type = ie->arg_type; |
| 3412 | abi_long ret; |
| 3413 | void *big_buf = NULL; |
| 3414 | char *host_data; |
| 3415 | |
| 3416 | arg_type++; |
| 3417 | target_size = thunk_type_size(arg_type, 0); |
| 3418 | argptr = lock_user(VERIFY_READ, arg, target_size, 1); |
| 3419 | if (!argptr) { |
| 3420 | ret = -TARGET_EFAULT; |
| 3421 | goto out; |
| 3422 | } |
| 3423 | thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST); |
| 3424 | unlock_user(argptr, arg, 0); |
| 3425 | |
| 3426 | /* buf_temp is too small, so fetch things into a bigger buffer */ |
| 3427 | big_buf = g_malloc0(((struct dm_ioctl*)buf_temp)->data_size * 2); |
| 3428 | memcpy(big_buf, buf_temp, target_size); |
| 3429 | buf_temp = big_buf; |
| 3430 | host_dm = big_buf; |
| 3431 | |
| 3432 | guest_data = arg + host_dm->data_start; |
| 3433 | if ((guest_data - arg) < 0) { |
| 3434 | ret = -EINVAL; |
| 3435 | goto out; |
| 3436 | } |
| 3437 | guest_data_size = host_dm->data_size - host_dm->data_start; |
| 3438 | host_data = (char*)host_dm + host_dm->data_start; |
| 3439 | |
| 3440 | argptr = lock_user(VERIFY_READ, guest_data, guest_data_size, 1); |
| 3441 | switch (ie->host_cmd) { |
| 3442 | case DM_REMOVE_ALL: |
| 3443 | case DM_LIST_DEVICES: |
| 3444 | case DM_DEV_CREATE: |
| 3445 | case DM_DEV_REMOVE: |
| 3446 | case DM_DEV_SUSPEND: |
| 3447 | case DM_DEV_STATUS: |
| 3448 | case DM_DEV_WAIT: |
| 3449 | case DM_TABLE_STATUS: |
| 3450 | case DM_TABLE_CLEAR: |
| 3451 | case DM_TABLE_DEPS: |
| 3452 | case DM_LIST_VERSIONS: |
| 3453 | /* no input data */ |
| 3454 | break; |
| 3455 | case DM_DEV_RENAME: |
| 3456 | case DM_DEV_SET_GEOMETRY: |
| 3457 | /* data contains only strings */ |
| 3458 | memcpy(host_data, argptr, guest_data_size); |
| 3459 | break; |
| 3460 | case DM_TARGET_MSG: |
| 3461 | memcpy(host_data, argptr, guest_data_size); |
| 3462 | *(uint64_t*)host_data = tswap64(*(uint64_t*)argptr); |
| 3463 | break; |
| 3464 | case DM_TABLE_LOAD: |
| 3465 | { |
| 3466 | void *gspec = argptr; |
| 3467 | void *cur_data = host_data; |
| 3468 | const argtype arg_type[] = { MK_STRUCT(STRUCT_dm_target_spec) }; |
| 3469 | int spec_size = thunk_type_size(arg_type, 0); |
| 3470 | int i; |
| 3471 | |
| 3472 | for (i = 0; i < host_dm->target_count; i++) { |
| 3473 | struct dm_target_spec *spec = cur_data; |
| 3474 | uint32_t next; |
| 3475 | int slen; |
| 3476 | |
| 3477 | thunk_convert(spec, gspec, arg_type, THUNK_HOST); |
| 3478 | slen = strlen((char*)gspec + spec_size) + 1; |
| 3479 | next = spec->next; |
| 3480 | spec->next = sizeof(*spec) + slen; |
| 3481 | strcpy((char*)&spec[1], gspec + spec_size); |
| 3482 | gspec += next; |
| 3483 | cur_data += spec->next; |
| 3484 | } |
| 3485 | break; |
| 3486 | } |
| 3487 | default: |
| 3488 | ret = -TARGET_EINVAL; |
| 3489 | goto out; |
| 3490 | } |
| 3491 | unlock_user(argptr, guest_data, 0); |
| 3492 | |
| 3493 | ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp)); |
| 3494 | if (!is_error(ret)) { |
| 3495 | guest_data = arg + host_dm->data_start; |
| 3496 | guest_data_size = host_dm->data_size - host_dm->data_start; |
| 3497 | argptr = lock_user(VERIFY_WRITE, guest_data, guest_data_size, 0); |
| 3498 | switch (ie->host_cmd) { |
| 3499 | case DM_REMOVE_ALL: |
| 3500 | case DM_DEV_CREATE: |
| 3501 | case DM_DEV_REMOVE: |
| 3502 | case DM_DEV_RENAME: |
| 3503 | case DM_DEV_SUSPEND: |
| 3504 | case DM_DEV_STATUS: |
| 3505 | case DM_TABLE_LOAD: |
| 3506 | case DM_TABLE_CLEAR: |
| 3507 | case DM_TARGET_MSG: |
| 3508 | case DM_DEV_SET_GEOMETRY: |
| 3509 | /* no return data */ |
| 3510 | break; |
| 3511 | case DM_LIST_DEVICES: |
| 3512 | { |
| 3513 | struct dm_name_list *nl = (void*)host_dm + host_dm->data_start; |
| 3514 | uint32_t remaining_data = guest_data_size; |
| 3515 | void *cur_data = argptr; |
| 3516 | const argtype arg_type[] = { MK_STRUCT(STRUCT_dm_name_list) }; |
| 3517 | int nl_size = 12; /* can't use thunk_size due to alignment */ |
| 3518 | |
| 3519 | while (1) { |
| 3520 | uint32_t next = nl->next; |
| 3521 | if (next) { |
| 3522 | nl->next = nl_size + (strlen(nl->name) + 1); |
| 3523 | } |
| 3524 | if (remaining_data < nl->next) { |
| 3525 | host_dm->flags |= DM_BUFFER_FULL_FLAG; |
| 3526 | break; |
| 3527 | } |
| 3528 | thunk_convert(cur_data, nl, arg_type, THUNK_TARGET); |
| 3529 | strcpy(cur_data + nl_size, nl->name); |
| 3530 | cur_data += nl->next; |
| 3531 | remaining_data -= nl->next; |
| 3532 | if (!next) { |
| 3533 | break; |
| 3534 | } |
| 3535 | nl = (void*)nl + next; |
| 3536 | } |
| 3537 | break; |
| 3538 | } |
| 3539 | case DM_DEV_WAIT: |
| 3540 | case DM_TABLE_STATUS: |
| 3541 | { |
| 3542 | struct dm_target_spec *spec = (void*)host_dm + host_dm->data_start; |
| 3543 | void *cur_data = argptr; |
| 3544 | const argtype arg_type[] = { MK_STRUCT(STRUCT_dm_target_spec) }; |
| 3545 | int spec_size = thunk_type_size(arg_type, 0); |
| 3546 | int i; |
| 3547 | |
| 3548 | for (i = 0; i < host_dm->target_count; i++) { |
| 3549 | uint32_t next = spec->next; |
| 3550 | int slen = strlen((char*)&spec[1]) + 1; |
| 3551 | spec->next = (cur_data - argptr) + spec_size + slen; |
| 3552 | if (guest_data_size < spec->next) { |
| 3553 | host_dm->flags |= DM_BUFFER_FULL_FLAG; |
| 3554 | break; |
| 3555 | } |
| 3556 | thunk_convert(cur_data, spec, arg_type, THUNK_TARGET); |
| 3557 | strcpy(cur_data + spec_size, (char*)&spec[1]); |
| 3558 | cur_data = argptr + spec->next; |
| 3559 | spec = (void*)host_dm + host_dm->data_start + next; |
| 3560 | } |
| 3561 | break; |
| 3562 | } |
| 3563 | case DM_TABLE_DEPS: |
| 3564 | { |
| 3565 | void *hdata = (void*)host_dm + host_dm->data_start; |
| 3566 | int count = *(uint32_t*)hdata; |
| 3567 | uint64_t *hdev = hdata + 8; |
| 3568 | uint64_t *gdev = argptr + 8; |
| 3569 | int i; |
| 3570 | |
| 3571 | *(uint32_t*)argptr = tswap32(count); |
| 3572 | for (i = 0; i < count; i++) { |
| 3573 | *gdev = tswap64(*hdev); |
| 3574 | gdev++; |
| 3575 | hdev++; |
| 3576 | } |
| 3577 | break; |
| 3578 | } |
| 3579 | case DM_LIST_VERSIONS: |
| 3580 | { |
| 3581 | struct dm_target_versions *vers = (void*)host_dm + host_dm->data_start; |
| 3582 | uint32_t remaining_data = guest_data_size; |
| 3583 | void *cur_data = argptr; |
| 3584 | const argtype arg_type[] = { MK_STRUCT(STRUCT_dm_target_versions) }; |
| 3585 | int vers_size = thunk_type_size(arg_type, 0); |
| 3586 | |
| 3587 | while (1) { |
| 3588 | uint32_t next = vers->next; |
| 3589 | if (next) { |
| 3590 | vers->next = vers_size + (strlen(vers->name) + 1); |
| 3591 | } |
| 3592 | if (remaining_data < vers->next) { |
| 3593 | host_dm->flags |= DM_BUFFER_FULL_FLAG; |
| 3594 | break; |
| 3595 | } |
| 3596 | thunk_convert(cur_data, vers, arg_type, THUNK_TARGET); |
| 3597 | strcpy(cur_data + vers_size, vers->name); |
| 3598 | cur_data += vers->next; |
| 3599 | remaining_data -= vers->next; |
| 3600 | if (!next) { |
| 3601 | break; |
| 3602 | } |
| 3603 | vers = (void*)vers + next; |
| 3604 | } |
| 3605 | break; |
| 3606 | } |
| 3607 | default: |
| 3608 | ret = -TARGET_EINVAL; |
| 3609 | goto out; |
| 3610 | } |
| 3611 | unlock_user(argptr, guest_data, guest_data_size); |
| 3612 | |
| 3613 | argptr = lock_user(VERIFY_WRITE, arg, target_size, 0); |
| 3614 | if (!argptr) { |
| 3615 | ret = -TARGET_EFAULT; |
| 3616 | goto out; |
| 3617 | } |
| 3618 | thunk_convert(argptr, buf_temp, arg_type, THUNK_TARGET); |
| 3619 | unlock_user(argptr, arg, target_size); |
| 3620 | } |
| 3621 | out: |
| 3622 | if (big_buf) { |
| 3623 | free(big_buf); |
| 3624 | } |
| 3625 | return ret; |
| 3626 | } |
| 3627 | |
blueswir1 | 9f106a7 | 2008-10-05 10:52:52 +0000 | [diff] [blame] | 3628 | static IOCTLEntry ioctl_entries[] = { |
Blue Swirl | 001faf3 | 2009-05-13 17:53:17 +0000 | [diff] [blame] | 3629 | #define IOCTL(cmd, access, ...) \ |
Peter Maydell | d2ef05b | 2011-01-06 15:04:17 +0000 | [diff] [blame] | 3630 | { TARGET_ ## cmd, cmd, #cmd, access, 0, { __VA_ARGS__ } }, |
| 3631 | #define IOCTL_SPECIAL(cmd, access, dofn, ...) \ |
| 3632 | { TARGET_ ## cmd, cmd, #cmd, access, dofn, { __VA_ARGS__ } }, |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3633 | #include "ioctls.h" |
| 3634 | { 0, 0, }, |
| 3635 | }; |
| 3636 | |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 3637 | /* ??? Implement proper locking for ioctls. */ |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 3638 | /* do_ioctl() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 3639 | static abi_long do_ioctl(int fd, abi_long cmd, abi_long arg) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3640 | { |
| 3641 | const IOCTLEntry *ie; |
| 3642 | const argtype *arg_type; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 3643 | abi_long ret; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3644 | uint8_t buf_temp[MAX_STRUCT_SIZE]; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 3645 | int target_size; |
| 3646 | void *argptr; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3647 | |
| 3648 | ie = ioctl_entries; |
| 3649 | for(;;) { |
| 3650 | if (ie->target_cmd == 0) { |
j_mayer | 3240710 | 2007-09-26 23:01:49 +0000 | [diff] [blame] | 3651 | gemu_log("Unsupported ioctl: cmd=0x%04lx\n", (long)cmd); |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 3652 | return -TARGET_ENOSYS; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3653 | } |
| 3654 | if (ie->target_cmd == cmd) |
| 3655 | break; |
| 3656 | ie++; |
| 3657 | } |
| 3658 | arg_type = ie->arg_type; |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 3659 | #if defined(DEBUG) |
j_mayer | 3240710 | 2007-09-26 23:01:49 +0000 | [diff] [blame] | 3660 | gemu_log("ioctl: cmd=0x%04lx (%s)\n", (long)cmd, ie->name); |
bellard | 72f0390 | 2003-02-18 23:33:18 +0000 | [diff] [blame] | 3661 | #endif |
Peter Maydell | d2ef05b | 2011-01-06 15:04:17 +0000 | [diff] [blame] | 3662 | if (ie->do_ioctl) { |
| 3663 | return ie->do_ioctl(ie, buf_temp, fd, cmd, arg); |
| 3664 | } |
| 3665 | |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3666 | switch(arg_type[0]) { |
| 3667 | case TYPE_NULL: |
| 3668 | /* no argument */ |
| 3669 | ret = get_errno(ioctl(fd, ie->host_cmd)); |
| 3670 | break; |
| 3671 | case TYPE_PTRVOID: |
| 3672 | case TYPE_INT: |
| 3673 | /* int argment */ |
| 3674 | ret = get_errno(ioctl(fd, ie->host_cmd, arg)); |
| 3675 | break; |
| 3676 | case TYPE_PTR: |
| 3677 | arg_type++; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 3678 | target_size = thunk_type_size(arg_type, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3679 | switch(ie->access) { |
| 3680 | case IOC_R: |
| 3681 | ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp)); |
| 3682 | if (!is_error(ret)) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 3683 | argptr = lock_user(VERIFY_WRITE, arg, target_size, 0); |
| 3684 | if (!argptr) |
| 3685 | return -TARGET_EFAULT; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 3686 | thunk_convert(argptr, buf_temp, arg_type, THUNK_TARGET); |
| 3687 | unlock_user(argptr, arg, target_size); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3688 | } |
| 3689 | break; |
| 3690 | case IOC_W: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 3691 | argptr = lock_user(VERIFY_READ, arg, target_size, 1); |
| 3692 | if (!argptr) |
| 3693 | return -TARGET_EFAULT; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 3694 | thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST); |
| 3695 | unlock_user(argptr, arg, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3696 | ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp)); |
| 3697 | break; |
| 3698 | default: |
| 3699 | case IOC_RW: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 3700 | argptr = lock_user(VERIFY_READ, arg, target_size, 1); |
| 3701 | if (!argptr) |
| 3702 | return -TARGET_EFAULT; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 3703 | thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST); |
| 3704 | unlock_user(argptr, arg, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3705 | ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp)); |
| 3706 | if (!is_error(ret)) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 3707 | argptr = lock_user(VERIFY_WRITE, arg, target_size, 0); |
| 3708 | if (!argptr) |
| 3709 | return -TARGET_EFAULT; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 3710 | thunk_convert(argptr, buf_temp, arg_type, THUNK_TARGET); |
| 3711 | unlock_user(argptr, arg, target_size); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3712 | } |
| 3713 | break; |
| 3714 | } |
| 3715 | break; |
| 3716 | default: |
j_mayer | 3240710 | 2007-09-26 23:01:49 +0000 | [diff] [blame] | 3717 | gemu_log("Unsupported ioctl type: cmd=0x%04lx type=%d\n", |
| 3718 | (long)cmd, arg_type[0]); |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 3719 | ret = -TARGET_ENOSYS; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3720 | break; |
| 3721 | } |
| 3722 | return ret; |
| 3723 | } |
| 3724 | |
blueswir1 | b39bc50 | 2008-10-05 10:51:10 +0000 | [diff] [blame] | 3725 | static const bitmask_transtbl iflag_tbl[] = { |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3726 | { TARGET_IGNBRK, TARGET_IGNBRK, IGNBRK, IGNBRK }, |
| 3727 | { TARGET_BRKINT, TARGET_BRKINT, BRKINT, BRKINT }, |
| 3728 | { TARGET_IGNPAR, TARGET_IGNPAR, IGNPAR, IGNPAR }, |
| 3729 | { TARGET_PARMRK, TARGET_PARMRK, PARMRK, PARMRK }, |
| 3730 | { TARGET_INPCK, TARGET_INPCK, INPCK, INPCK }, |
| 3731 | { TARGET_ISTRIP, TARGET_ISTRIP, ISTRIP, ISTRIP }, |
| 3732 | { TARGET_INLCR, TARGET_INLCR, INLCR, INLCR }, |
| 3733 | { TARGET_IGNCR, TARGET_IGNCR, IGNCR, IGNCR }, |
| 3734 | { TARGET_ICRNL, TARGET_ICRNL, ICRNL, ICRNL }, |
| 3735 | { TARGET_IUCLC, TARGET_IUCLC, IUCLC, IUCLC }, |
| 3736 | { TARGET_IXON, TARGET_IXON, IXON, IXON }, |
| 3737 | { TARGET_IXANY, TARGET_IXANY, IXANY, IXANY }, |
| 3738 | { TARGET_IXOFF, TARGET_IXOFF, IXOFF, IXOFF }, |
| 3739 | { TARGET_IMAXBEL, TARGET_IMAXBEL, IMAXBEL, IMAXBEL }, |
| 3740 | { 0, 0, 0, 0 } |
| 3741 | }; |
| 3742 | |
blueswir1 | b39bc50 | 2008-10-05 10:51:10 +0000 | [diff] [blame] | 3743 | static const bitmask_transtbl oflag_tbl[] = { |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3744 | { TARGET_OPOST, TARGET_OPOST, OPOST, OPOST }, |
| 3745 | { TARGET_OLCUC, TARGET_OLCUC, OLCUC, OLCUC }, |
| 3746 | { TARGET_ONLCR, TARGET_ONLCR, ONLCR, ONLCR }, |
| 3747 | { TARGET_OCRNL, TARGET_OCRNL, OCRNL, OCRNL }, |
| 3748 | { TARGET_ONOCR, TARGET_ONOCR, ONOCR, ONOCR }, |
| 3749 | { TARGET_ONLRET, TARGET_ONLRET, ONLRET, ONLRET }, |
| 3750 | { TARGET_OFILL, TARGET_OFILL, OFILL, OFILL }, |
| 3751 | { TARGET_OFDEL, TARGET_OFDEL, OFDEL, OFDEL }, |
| 3752 | { TARGET_NLDLY, TARGET_NL0, NLDLY, NL0 }, |
| 3753 | { TARGET_NLDLY, TARGET_NL1, NLDLY, NL1 }, |
| 3754 | { TARGET_CRDLY, TARGET_CR0, CRDLY, CR0 }, |
| 3755 | { TARGET_CRDLY, TARGET_CR1, CRDLY, CR1 }, |
| 3756 | { TARGET_CRDLY, TARGET_CR2, CRDLY, CR2 }, |
| 3757 | { TARGET_CRDLY, TARGET_CR3, CRDLY, CR3 }, |
| 3758 | { TARGET_TABDLY, TARGET_TAB0, TABDLY, TAB0 }, |
| 3759 | { TARGET_TABDLY, TARGET_TAB1, TABDLY, TAB1 }, |
| 3760 | { TARGET_TABDLY, TARGET_TAB2, TABDLY, TAB2 }, |
| 3761 | { TARGET_TABDLY, TARGET_TAB3, TABDLY, TAB3 }, |
| 3762 | { TARGET_BSDLY, TARGET_BS0, BSDLY, BS0 }, |
| 3763 | { TARGET_BSDLY, TARGET_BS1, BSDLY, BS1 }, |
| 3764 | { TARGET_VTDLY, TARGET_VT0, VTDLY, VT0 }, |
| 3765 | { TARGET_VTDLY, TARGET_VT1, VTDLY, VT1 }, |
| 3766 | { TARGET_FFDLY, TARGET_FF0, FFDLY, FF0 }, |
| 3767 | { TARGET_FFDLY, TARGET_FF1, FFDLY, FF1 }, |
| 3768 | { 0, 0, 0, 0 } |
| 3769 | }; |
| 3770 | |
blueswir1 | b39bc50 | 2008-10-05 10:51:10 +0000 | [diff] [blame] | 3771 | static const bitmask_transtbl cflag_tbl[] = { |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3772 | { TARGET_CBAUD, TARGET_B0, CBAUD, B0 }, |
| 3773 | { TARGET_CBAUD, TARGET_B50, CBAUD, B50 }, |
| 3774 | { TARGET_CBAUD, TARGET_B75, CBAUD, B75 }, |
| 3775 | { TARGET_CBAUD, TARGET_B110, CBAUD, B110 }, |
| 3776 | { TARGET_CBAUD, TARGET_B134, CBAUD, B134 }, |
| 3777 | { TARGET_CBAUD, TARGET_B150, CBAUD, B150 }, |
| 3778 | { TARGET_CBAUD, TARGET_B200, CBAUD, B200 }, |
| 3779 | { TARGET_CBAUD, TARGET_B300, CBAUD, B300 }, |
| 3780 | { TARGET_CBAUD, TARGET_B600, CBAUD, B600 }, |
| 3781 | { TARGET_CBAUD, TARGET_B1200, CBAUD, B1200 }, |
| 3782 | { TARGET_CBAUD, TARGET_B1800, CBAUD, B1800 }, |
| 3783 | { TARGET_CBAUD, TARGET_B2400, CBAUD, B2400 }, |
| 3784 | { TARGET_CBAUD, TARGET_B4800, CBAUD, B4800 }, |
| 3785 | { TARGET_CBAUD, TARGET_B9600, CBAUD, B9600 }, |
| 3786 | { TARGET_CBAUD, TARGET_B19200, CBAUD, B19200 }, |
| 3787 | { TARGET_CBAUD, TARGET_B38400, CBAUD, B38400 }, |
| 3788 | { TARGET_CBAUD, TARGET_B57600, CBAUD, B57600 }, |
| 3789 | { TARGET_CBAUD, TARGET_B115200, CBAUD, B115200 }, |
| 3790 | { TARGET_CBAUD, TARGET_B230400, CBAUD, B230400 }, |
| 3791 | { TARGET_CBAUD, TARGET_B460800, CBAUD, B460800 }, |
| 3792 | { TARGET_CSIZE, TARGET_CS5, CSIZE, CS5 }, |
| 3793 | { TARGET_CSIZE, TARGET_CS6, CSIZE, CS6 }, |
| 3794 | { TARGET_CSIZE, TARGET_CS7, CSIZE, CS7 }, |
| 3795 | { TARGET_CSIZE, TARGET_CS8, CSIZE, CS8 }, |
| 3796 | { TARGET_CSTOPB, TARGET_CSTOPB, CSTOPB, CSTOPB }, |
| 3797 | { TARGET_CREAD, TARGET_CREAD, CREAD, CREAD }, |
| 3798 | { TARGET_PARENB, TARGET_PARENB, PARENB, PARENB }, |
| 3799 | { TARGET_PARODD, TARGET_PARODD, PARODD, PARODD }, |
| 3800 | { TARGET_HUPCL, TARGET_HUPCL, HUPCL, HUPCL }, |
| 3801 | { TARGET_CLOCAL, TARGET_CLOCAL, CLOCAL, CLOCAL }, |
| 3802 | { TARGET_CRTSCTS, TARGET_CRTSCTS, CRTSCTS, CRTSCTS }, |
| 3803 | { 0, 0, 0, 0 } |
| 3804 | }; |
| 3805 | |
blueswir1 | b39bc50 | 2008-10-05 10:51:10 +0000 | [diff] [blame] | 3806 | static const bitmask_transtbl lflag_tbl[] = { |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3807 | { TARGET_ISIG, TARGET_ISIG, ISIG, ISIG }, |
| 3808 | { TARGET_ICANON, TARGET_ICANON, ICANON, ICANON }, |
| 3809 | { TARGET_XCASE, TARGET_XCASE, XCASE, XCASE }, |
| 3810 | { TARGET_ECHO, TARGET_ECHO, ECHO, ECHO }, |
| 3811 | { TARGET_ECHOE, TARGET_ECHOE, ECHOE, ECHOE }, |
| 3812 | { TARGET_ECHOK, TARGET_ECHOK, ECHOK, ECHOK }, |
| 3813 | { TARGET_ECHONL, TARGET_ECHONL, ECHONL, ECHONL }, |
| 3814 | { TARGET_NOFLSH, TARGET_NOFLSH, NOFLSH, NOFLSH }, |
| 3815 | { TARGET_TOSTOP, TARGET_TOSTOP, TOSTOP, TOSTOP }, |
| 3816 | { TARGET_ECHOCTL, TARGET_ECHOCTL, ECHOCTL, ECHOCTL }, |
| 3817 | { TARGET_ECHOPRT, TARGET_ECHOPRT, ECHOPRT, ECHOPRT }, |
| 3818 | { TARGET_ECHOKE, TARGET_ECHOKE, ECHOKE, ECHOKE }, |
| 3819 | { TARGET_FLUSHO, TARGET_FLUSHO, FLUSHO, FLUSHO }, |
| 3820 | { TARGET_PENDIN, TARGET_PENDIN, PENDIN, PENDIN }, |
| 3821 | { TARGET_IEXTEN, TARGET_IEXTEN, IEXTEN, IEXTEN }, |
| 3822 | { 0, 0, 0, 0 } |
| 3823 | }; |
| 3824 | |
| 3825 | static void target_to_host_termios (void *dst, const void *src) |
| 3826 | { |
| 3827 | struct host_termios *host = dst; |
| 3828 | const struct target_termios *target = src; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 3829 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3830 | host->c_iflag = |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3831 | target_to_host_bitmask(tswap32(target->c_iflag), iflag_tbl); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3832 | host->c_oflag = |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3833 | target_to_host_bitmask(tswap32(target->c_oflag), oflag_tbl); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3834 | host->c_cflag = |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3835 | target_to_host_bitmask(tswap32(target->c_cflag), cflag_tbl); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3836 | host->c_lflag = |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3837 | target_to_host_bitmask(tswap32(target->c_lflag), lflag_tbl); |
| 3838 | host->c_line = target->c_line; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 3839 | |
Arnaud Patard | 4460712 | 2009-04-21 17:39:08 +0300 | [diff] [blame] | 3840 | memset(host->c_cc, 0, sizeof(host->c_cc)); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3841 | host->c_cc[VINTR] = target->c_cc[TARGET_VINTR]; |
| 3842 | host->c_cc[VQUIT] = target->c_cc[TARGET_VQUIT]; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 3843 | host->c_cc[VERASE] = target->c_cc[TARGET_VERASE]; |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3844 | host->c_cc[VKILL] = target->c_cc[TARGET_VKILL]; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 3845 | host->c_cc[VEOF] = target->c_cc[TARGET_VEOF]; |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3846 | host->c_cc[VTIME] = target->c_cc[TARGET_VTIME]; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 3847 | host->c_cc[VMIN] = target->c_cc[TARGET_VMIN]; |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3848 | host->c_cc[VSWTC] = target->c_cc[TARGET_VSWTC]; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 3849 | host->c_cc[VSTART] = target->c_cc[TARGET_VSTART]; |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3850 | host->c_cc[VSTOP] = target->c_cc[TARGET_VSTOP]; |
| 3851 | host->c_cc[VSUSP] = target->c_cc[TARGET_VSUSP]; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 3852 | host->c_cc[VEOL] = target->c_cc[TARGET_VEOL]; |
| 3853 | host->c_cc[VREPRINT] = target->c_cc[TARGET_VREPRINT]; |
| 3854 | host->c_cc[VDISCARD] = target->c_cc[TARGET_VDISCARD]; |
| 3855 | host->c_cc[VWERASE] = target->c_cc[TARGET_VWERASE]; |
| 3856 | host->c_cc[VLNEXT] = target->c_cc[TARGET_VLNEXT]; |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3857 | host->c_cc[VEOL2] = target->c_cc[TARGET_VEOL2]; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3858 | } |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 3859 | |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3860 | static void host_to_target_termios (void *dst, const void *src) |
| 3861 | { |
| 3862 | struct target_termios *target = dst; |
| 3863 | const struct host_termios *host = src; |
| 3864 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3865 | target->c_iflag = |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3866 | tswap32(host_to_target_bitmask(host->c_iflag, iflag_tbl)); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3867 | target->c_oflag = |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3868 | tswap32(host_to_target_bitmask(host->c_oflag, oflag_tbl)); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3869 | target->c_cflag = |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3870 | tswap32(host_to_target_bitmask(host->c_cflag, cflag_tbl)); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3871 | target->c_lflag = |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3872 | tswap32(host_to_target_bitmask(host->c_lflag, lflag_tbl)); |
| 3873 | target->c_line = host->c_line; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 3874 | |
Arnaud Patard | 4460712 | 2009-04-21 17:39:08 +0300 | [diff] [blame] | 3875 | memset(target->c_cc, 0, sizeof(target->c_cc)); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3876 | target->c_cc[TARGET_VINTR] = host->c_cc[VINTR]; |
| 3877 | target->c_cc[TARGET_VQUIT] = host->c_cc[VQUIT]; |
| 3878 | target->c_cc[TARGET_VERASE] = host->c_cc[VERASE]; |
| 3879 | target->c_cc[TARGET_VKILL] = host->c_cc[VKILL]; |
| 3880 | target->c_cc[TARGET_VEOF] = host->c_cc[VEOF]; |
| 3881 | target->c_cc[TARGET_VTIME] = host->c_cc[VTIME]; |
| 3882 | target->c_cc[TARGET_VMIN] = host->c_cc[VMIN]; |
| 3883 | target->c_cc[TARGET_VSWTC] = host->c_cc[VSWTC]; |
| 3884 | target->c_cc[TARGET_VSTART] = host->c_cc[VSTART]; |
| 3885 | target->c_cc[TARGET_VSTOP] = host->c_cc[VSTOP]; |
| 3886 | target->c_cc[TARGET_VSUSP] = host->c_cc[VSUSP]; |
| 3887 | target->c_cc[TARGET_VEOL] = host->c_cc[VEOL]; |
| 3888 | target->c_cc[TARGET_VREPRINT] = host->c_cc[VREPRINT]; |
| 3889 | target->c_cc[TARGET_VDISCARD] = host->c_cc[VDISCARD]; |
| 3890 | target->c_cc[TARGET_VWERASE] = host->c_cc[VWERASE]; |
| 3891 | target->c_cc[TARGET_VLNEXT] = host->c_cc[VLNEXT]; |
| 3892 | target->c_cc[TARGET_VEOL2] = host->c_cc[VEOL2]; |
| 3893 | } |
| 3894 | |
blueswir1 | 8e853dc | 2008-10-05 10:49:32 +0000 | [diff] [blame] | 3895 | static const StructEntry struct_termios_def = { |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3896 | .convert = { host_to_target_termios, target_to_host_termios }, |
| 3897 | .size = { sizeof(struct target_termios), sizeof(struct host_termios) }, |
| 3898 | .align = { __alignof__(struct target_termios), __alignof__(struct host_termios) }, |
| 3899 | }; |
| 3900 | |
bellard | 5286db7 | 2003-06-05 00:57:30 +0000 | [diff] [blame] | 3901 | static bitmask_transtbl mmap_flags_tbl[] = { |
| 3902 | { TARGET_MAP_SHARED, TARGET_MAP_SHARED, MAP_SHARED, MAP_SHARED }, |
| 3903 | { TARGET_MAP_PRIVATE, TARGET_MAP_PRIVATE, MAP_PRIVATE, MAP_PRIVATE }, |
| 3904 | { TARGET_MAP_FIXED, TARGET_MAP_FIXED, MAP_FIXED, MAP_FIXED }, |
| 3905 | { TARGET_MAP_ANONYMOUS, TARGET_MAP_ANONYMOUS, MAP_ANONYMOUS, MAP_ANONYMOUS }, |
| 3906 | { TARGET_MAP_GROWSDOWN, TARGET_MAP_GROWSDOWN, MAP_GROWSDOWN, MAP_GROWSDOWN }, |
| 3907 | { TARGET_MAP_DENYWRITE, TARGET_MAP_DENYWRITE, MAP_DENYWRITE, MAP_DENYWRITE }, |
| 3908 | { TARGET_MAP_EXECUTABLE, TARGET_MAP_EXECUTABLE, MAP_EXECUTABLE, MAP_EXECUTABLE }, |
| 3909 | { TARGET_MAP_LOCKED, TARGET_MAP_LOCKED, MAP_LOCKED, MAP_LOCKED }, |
| 3910 | { 0, 0, 0, 0 } |
| 3911 | }; |
| 3912 | |
bellard | 2ab83ea | 2003-06-15 19:56:46 +0000 | [diff] [blame] | 3913 | #if defined(TARGET_I386) |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 3914 | |
| 3915 | /* NOTE: there is really one LDT for all the threads */ |
blueswir1 | b1d8e52 | 2008-10-26 13:43:07 +0000 | [diff] [blame] | 3916 | static uint8_t *ldt_table; |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 3917 | |
bellard | 03acab6 | 2007-11-11 14:57:14 +0000 | [diff] [blame] | 3918 | static abi_long read_ldt(abi_ulong ptr, unsigned long bytecount) |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 3919 | { |
| 3920 | int size; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 3921 | void *p; |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 3922 | |
| 3923 | if (!ldt_table) |
| 3924 | return 0; |
| 3925 | size = TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE; |
| 3926 | if (size > bytecount) |
| 3927 | size = bytecount; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 3928 | p = lock_user(VERIFY_WRITE, ptr, size, 0); |
| 3929 | if (!p) |
bellard | 03acab6 | 2007-11-11 14:57:14 +0000 | [diff] [blame] | 3930 | return -TARGET_EFAULT; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 3931 | /* ??? Should this by byteswapped? */ |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 3932 | memcpy(p, ldt_table, size); |
| 3933 | unlock_user(p, ptr, size); |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 3934 | return size; |
| 3935 | } |
| 3936 | |
| 3937 | /* XXX: add locking support */ |
bellard | 03acab6 | 2007-11-11 14:57:14 +0000 | [diff] [blame] | 3938 | static abi_long write_ldt(CPUX86State *env, |
| 3939 | abi_ulong ptr, unsigned long bytecount, int oldmode) |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 3940 | { |
| 3941 | struct target_modify_ldt_ldt_s ldt_info; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 3942 | struct target_modify_ldt_ldt_s *target_ldt_info; |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 3943 | int seg_32bit, contents, read_exec_only, limit_in_pages; |
bellard | 8d18e89 | 2007-11-14 15:18:40 +0000 | [diff] [blame] | 3944 | int seg_not_present, useable, lm; |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 3945 | uint32_t *lp, entry_1, entry_2; |
| 3946 | |
| 3947 | if (bytecount != sizeof(ldt_info)) |
bellard | 03acab6 | 2007-11-11 14:57:14 +0000 | [diff] [blame] | 3948 | return -TARGET_EINVAL; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 3949 | if (!lock_user_struct(VERIFY_READ, target_ldt_info, ptr, 1)) |
bellard | 03acab6 | 2007-11-11 14:57:14 +0000 | [diff] [blame] | 3950 | return -TARGET_EFAULT; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 3951 | ldt_info.entry_number = tswap32(target_ldt_info->entry_number); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 3952 | ldt_info.base_addr = tswapal(target_ldt_info->base_addr); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 3953 | ldt_info.limit = tswap32(target_ldt_info->limit); |
| 3954 | ldt_info.flags = tswap32(target_ldt_info->flags); |
| 3955 | unlock_user_struct(target_ldt_info, ptr, 0); |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 3956 | |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 3957 | if (ldt_info.entry_number >= TARGET_LDT_ENTRIES) |
bellard | 03acab6 | 2007-11-11 14:57:14 +0000 | [diff] [blame] | 3958 | return -TARGET_EINVAL; |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 3959 | seg_32bit = ldt_info.flags & 1; |
| 3960 | contents = (ldt_info.flags >> 1) & 3; |
| 3961 | read_exec_only = (ldt_info.flags >> 3) & 1; |
| 3962 | limit_in_pages = (ldt_info.flags >> 4) & 1; |
| 3963 | seg_not_present = (ldt_info.flags >> 5) & 1; |
| 3964 | useable = (ldt_info.flags >> 6) & 1; |
bellard | 8d18e89 | 2007-11-14 15:18:40 +0000 | [diff] [blame] | 3965 | #ifdef TARGET_ABI32 |
| 3966 | lm = 0; |
| 3967 | #else |
| 3968 | lm = (ldt_info.flags >> 7) & 1; |
| 3969 | #endif |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 3970 | if (contents == 3) { |
| 3971 | if (oldmode) |
bellard | 03acab6 | 2007-11-11 14:57:14 +0000 | [diff] [blame] | 3972 | return -TARGET_EINVAL; |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 3973 | if (seg_not_present == 0) |
bellard | 03acab6 | 2007-11-11 14:57:14 +0000 | [diff] [blame] | 3974 | return -TARGET_EINVAL; |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 3975 | } |
| 3976 | /* allocate the LDT */ |
| 3977 | if (!ldt_table) { |
balrog | e441570 | 2008-11-10 02:55:33 +0000 | [diff] [blame] | 3978 | env->ldt.base = target_mmap(0, |
| 3979 | TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE, |
| 3980 | PROT_READ|PROT_WRITE, |
| 3981 | MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); |
| 3982 | if (env->ldt.base == -1) |
bellard | 03acab6 | 2007-11-11 14:57:14 +0000 | [diff] [blame] | 3983 | return -TARGET_ENOMEM; |
balrog | e441570 | 2008-11-10 02:55:33 +0000 | [diff] [blame] | 3984 | memset(g2h(env->ldt.base), 0, |
| 3985 | TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE); |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 3986 | env->ldt.limit = 0xffff; |
balrog | e441570 | 2008-11-10 02:55:33 +0000 | [diff] [blame] | 3987 | ldt_table = g2h(env->ldt.base); |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 3988 | } |
| 3989 | |
| 3990 | /* NOTE: same code as Linux kernel */ |
| 3991 | /* Allow LDTs to be cleared by the user. */ |
| 3992 | if (ldt_info.base_addr == 0 && ldt_info.limit == 0) { |
| 3993 | if (oldmode || |
| 3994 | (contents == 0 && |
| 3995 | read_exec_only == 1 && |
| 3996 | seg_32bit == 0 && |
| 3997 | limit_in_pages == 0 && |
| 3998 | seg_not_present == 1 && |
| 3999 | useable == 0 )) { |
| 4000 | entry_1 = 0; |
| 4001 | entry_2 = 0; |
| 4002 | goto install; |
| 4003 | } |
| 4004 | } |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 4005 | |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4006 | entry_1 = ((ldt_info.base_addr & 0x0000ffff) << 16) | |
| 4007 | (ldt_info.limit & 0x0ffff); |
| 4008 | entry_2 = (ldt_info.base_addr & 0xff000000) | |
| 4009 | ((ldt_info.base_addr & 0x00ff0000) >> 16) | |
| 4010 | (ldt_info.limit & 0xf0000) | |
| 4011 | ((read_exec_only ^ 1) << 9) | |
| 4012 | (contents << 10) | |
| 4013 | ((seg_not_present ^ 1) << 15) | |
| 4014 | (seg_32bit << 22) | |
| 4015 | (limit_in_pages << 23) | |
bellard | 8d18e89 | 2007-11-14 15:18:40 +0000 | [diff] [blame] | 4016 | (lm << 21) | |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4017 | 0x7000; |
| 4018 | if (!oldmode) |
| 4019 | entry_2 |= (useable << 20); |
bellard | 14ae3ba | 2003-05-27 23:25:06 +0000 | [diff] [blame] | 4020 | |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4021 | /* Install the new entry ... */ |
| 4022 | install: |
| 4023 | lp = (uint32_t *)(ldt_table + (ldt_info.entry_number << 3)); |
| 4024 | lp[0] = tswap32(entry_1); |
| 4025 | lp[1] = tswap32(entry_2); |
| 4026 | return 0; |
| 4027 | } |
| 4028 | |
| 4029 | /* specific and weird i386 syscalls */ |
blueswir1 | 8fcd369 | 2008-08-17 20:26:25 +0000 | [diff] [blame] | 4030 | static abi_long do_modify_ldt(CPUX86State *env, int func, abi_ulong ptr, |
| 4031 | unsigned long bytecount) |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4032 | { |
bellard | 03acab6 | 2007-11-11 14:57:14 +0000 | [diff] [blame] | 4033 | abi_long ret; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 4034 | |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4035 | switch (func) { |
| 4036 | case 0: |
| 4037 | ret = read_ldt(ptr, bytecount); |
| 4038 | break; |
| 4039 | case 1: |
| 4040 | ret = write_ldt(env, ptr, bytecount, 1); |
| 4041 | break; |
| 4042 | case 0x11: |
| 4043 | ret = write_ldt(env, ptr, bytecount, 0); |
| 4044 | break; |
bellard | 03acab6 | 2007-11-11 14:57:14 +0000 | [diff] [blame] | 4045 | default: |
| 4046 | ret = -TARGET_ENOSYS; |
| 4047 | break; |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4048 | } |
| 4049 | return ret; |
| 4050 | } |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 4051 | |
blueswir1 | 4583f58 | 2008-08-24 10:35:55 +0000 | [diff] [blame] | 4052 | #if defined(TARGET_I386) && defined(TARGET_ABI32) |
blueswir1 | 8fcd369 | 2008-08-17 20:26:25 +0000 | [diff] [blame] | 4053 | static abi_long do_set_thread_area(CPUX86State *env, abi_ulong ptr) |
bellard | 8d18e89 | 2007-11-14 15:18:40 +0000 | [diff] [blame] | 4054 | { |
| 4055 | uint64_t *gdt_table = g2h(env->gdt.base); |
| 4056 | struct target_modify_ldt_ldt_s ldt_info; |
| 4057 | struct target_modify_ldt_ldt_s *target_ldt_info; |
| 4058 | int seg_32bit, contents, read_exec_only, limit_in_pages; |
| 4059 | int seg_not_present, useable, lm; |
| 4060 | uint32_t *lp, entry_1, entry_2; |
| 4061 | int i; |
| 4062 | |
| 4063 | lock_user_struct(VERIFY_WRITE, target_ldt_info, ptr, 1); |
| 4064 | if (!target_ldt_info) |
| 4065 | return -TARGET_EFAULT; |
| 4066 | ldt_info.entry_number = tswap32(target_ldt_info->entry_number); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 4067 | ldt_info.base_addr = tswapal(target_ldt_info->base_addr); |
bellard | 8d18e89 | 2007-11-14 15:18:40 +0000 | [diff] [blame] | 4068 | ldt_info.limit = tswap32(target_ldt_info->limit); |
| 4069 | ldt_info.flags = tswap32(target_ldt_info->flags); |
| 4070 | if (ldt_info.entry_number == -1) { |
| 4071 | for (i=TARGET_GDT_ENTRY_TLS_MIN; i<=TARGET_GDT_ENTRY_TLS_MAX; i++) { |
| 4072 | if (gdt_table[i] == 0) { |
| 4073 | ldt_info.entry_number = i; |
| 4074 | target_ldt_info->entry_number = tswap32(i); |
| 4075 | break; |
| 4076 | } |
| 4077 | } |
| 4078 | } |
| 4079 | unlock_user_struct(target_ldt_info, ptr, 1); |
| 4080 | |
| 4081 | if (ldt_info.entry_number < TARGET_GDT_ENTRY_TLS_MIN || |
| 4082 | ldt_info.entry_number > TARGET_GDT_ENTRY_TLS_MAX) |
| 4083 | return -TARGET_EINVAL; |
| 4084 | seg_32bit = ldt_info.flags & 1; |
| 4085 | contents = (ldt_info.flags >> 1) & 3; |
| 4086 | read_exec_only = (ldt_info.flags >> 3) & 1; |
| 4087 | limit_in_pages = (ldt_info.flags >> 4) & 1; |
| 4088 | seg_not_present = (ldt_info.flags >> 5) & 1; |
| 4089 | useable = (ldt_info.flags >> 6) & 1; |
| 4090 | #ifdef TARGET_ABI32 |
| 4091 | lm = 0; |
| 4092 | #else |
| 4093 | lm = (ldt_info.flags >> 7) & 1; |
| 4094 | #endif |
| 4095 | |
| 4096 | if (contents == 3) { |
| 4097 | if (seg_not_present == 0) |
| 4098 | return -TARGET_EINVAL; |
| 4099 | } |
| 4100 | |
| 4101 | /* NOTE: same code as Linux kernel */ |
| 4102 | /* Allow LDTs to be cleared by the user. */ |
| 4103 | if (ldt_info.base_addr == 0 && ldt_info.limit == 0) { |
| 4104 | if ((contents == 0 && |
| 4105 | read_exec_only == 1 && |
| 4106 | seg_32bit == 0 && |
| 4107 | limit_in_pages == 0 && |
| 4108 | seg_not_present == 1 && |
| 4109 | useable == 0 )) { |
| 4110 | entry_1 = 0; |
| 4111 | entry_2 = 0; |
| 4112 | goto install; |
| 4113 | } |
| 4114 | } |
| 4115 | |
| 4116 | entry_1 = ((ldt_info.base_addr & 0x0000ffff) << 16) | |
| 4117 | (ldt_info.limit & 0x0ffff); |
| 4118 | entry_2 = (ldt_info.base_addr & 0xff000000) | |
| 4119 | ((ldt_info.base_addr & 0x00ff0000) >> 16) | |
| 4120 | (ldt_info.limit & 0xf0000) | |
| 4121 | ((read_exec_only ^ 1) << 9) | |
| 4122 | (contents << 10) | |
| 4123 | ((seg_not_present ^ 1) << 15) | |
| 4124 | (seg_32bit << 22) | |
| 4125 | (limit_in_pages << 23) | |
| 4126 | (useable << 20) | |
| 4127 | (lm << 21) | |
| 4128 | 0x7000; |
| 4129 | |
| 4130 | /* Install the new entry ... */ |
| 4131 | install: |
| 4132 | lp = (uint32_t *)(gdt_table + ldt_info.entry_number); |
| 4133 | lp[0] = tswap32(entry_1); |
| 4134 | lp[1] = tswap32(entry_2); |
| 4135 | return 0; |
| 4136 | } |
| 4137 | |
blueswir1 | 8fcd369 | 2008-08-17 20:26:25 +0000 | [diff] [blame] | 4138 | static abi_long do_get_thread_area(CPUX86State *env, abi_ulong ptr) |
bellard | 8d18e89 | 2007-11-14 15:18:40 +0000 | [diff] [blame] | 4139 | { |
| 4140 | struct target_modify_ldt_ldt_s *target_ldt_info; |
| 4141 | uint64_t *gdt_table = g2h(env->gdt.base); |
| 4142 | uint32_t base_addr, limit, flags; |
| 4143 | int seg_32bit, contents, read_exec_only, limit_in_pages, idx; |
| 4144 | int seg_not_present, useable, lm; |
| 4145 | uint32_t *lp, entry_1, entry_2; |
| 4146 | |
| 4147 | lock_user_struct(VERIFY_WRITE, target_ldt_info, ptr, 1); |
| 4148 | if (!target_ldt_info) |
| 4149 | return -TARGET_EFAULT; |
| 4150 | idx = tswap32(target_ldt_info->entry_number); |
| 4151 | if (idx < TARGET_GDT_ENTRY_TLS_MIN || |
| 4152 | idx > TARGET_GDT_ENTRY_TLS_MAX) { |
| 4153 | unlock_user_struct(target_ldt_info, ptr, 1); |
| 4154 | return -TARGET_EINVAL; |
| 4155 | } |
| 4156 | lp = (uint32_t *)(gdt_table + idx); |
| 4157 | entry_1 = tswap32(lp[0]); |
| 4158 | entry_2 = tswap32(lp[1]); |
| 4159 | |
| 4160 | read_exec_only = ((entry_2 >> 9) & 1) ^ 1; |
| 4161 | contents = (entry_2 >> 10) & 3; |
| 4162 | seg_not_present = ((entry_2 >> 15) & 1) ^ 1; |
| 4163 | seg_32bit = (entry_2 >> 22) & 1; |
| 4164 | limit_in_pages = (entry_2 >> 23) & 1; |
| 4165 | useable = (entry_2 >> 20) & 1; |
| 4166 | #ifdef TARGET_ABI32 |
| 4167 | lm = 0; |
| 4168 | #else |
| 4169 | lm = (entry_2 >> 21) & 1; |
| 4170 | #endif |
| 4171 | flags = (seg_32bit << 0) | (contents << 1) | |
| 4172 | (read_exec_only << 3) | (limit_in_pages << 4) | |
| 4173 | (seg_not_present << 5) | (useable << 6) | (lm << 7); |
| 4174 | limit = (entry_1 & 0xffff) | (entry_2 & 0xf0000); |
| 4175 | base_addr = (entry_1 >> 16) | |
| 4176 | (entry_2 & 0xff000000) | |
| 4177 | ((entry_2 & 0xff) << 16); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 4178 | target_ldt_info->base_addr = tswapal(base_addr); |
bellard | 8d18e89 | 2007-11-14 15:18:40 +0000 | [diff] [blame] | 4179 | target_ldt_info->limit = tswap32(limit); |
| 4180 | target_ldt_info->flags = tswap32(flags); |
| 4181 | unlock_user_struct(target_ldt_info, ptr, 1); |
| 4182 | return 0; |
| 4183 | } |
blueswir1 | 4583f58 | 2008-08-24 10:35:55 +0000 | [diff] [blame] | 4184 | #endif /* TARGET_I386 && TARGET_ABI32 */ |
bellard | 8d18e89 | 2007-11-14 15:18:40 +0000 | [diff] [blame] | 4185 | |
bellard | d2fd1af | 2007-11-14 18:08:56 +0000 | [diff] [blame] | 4186 | #ifndef TARGET_ABI32 |
blueswir1 | 8fcd369 | 2008-08-17 20:26:25 +0000 | [diff] [blame] | 4187 | static abi_long do_arch_prctl(CPUX86State *env, int code, abi_ulong addr) |
bellard | d2fd1af | 2007-11-14 18:08:56 +0000 | [diff] [blame] | 4188 | { |
Juan Quintela | 1add869 | 2011-06-16 17:37:09 +0100 | [diff] [blame] | 4189 | abi_long ret = 0; |
bellard | d2fd1af | 2007-11-14 18:08:56 +0000 | [diff] [blame] | 4190 | abi_ulong val; |
| 4191 | int idx; |
Juan Quintela | 1add869 | 2011-06-16 17:37:09 +0100 | [diff] [blame] | 4192 | |
bellard | d2fd1af | 2007-11-14 18:08:56 +0000 | [diff] [blame] | 4193 | switch(code) { |
| 4194 | case TARGET_ARCH_SET_GS: |
| 4195 | case TARGET_ARCH_SET_FS: |
| 4196 | if (code == TARGET_ARCH_SET_GS) |
| 4197 | idx = R_GS; |
| 4198 | else |
| 4199 | idx = R_FS; |
| 4200 | cpu_x86_load_seg(env, idx, 0); |
| 4201 | env->segs[idx].base = addr; |
| 4202 | break; |
| 4203 | case TARGET_ARCH_GET_GS: |
| 4204 | case TARGET_ARCH_GET_FS: |
| 4205 | if (code == TARGET_ARCH_GET_GS) |
| 4206 | idx = R_GS; |
| 4207 | else |
| 4208 | idx = R_FS; |
| 4209 | val = env->segs[idx].base; |
| 4210 | if (put_user(val, addr, abi_ulong)) |
Juan Quintela | 1add869 | 2011-06-16 17:37:09 +0100 | [diff] [blame] | 4211 | ret = -TARGET_EFAULT; |
bellard | d2fd1af | 2007-11-14 18:08:56 +0000 | [diff] [blame] | 4212 | break; |
| 4213 | default: |
| 4214 | ret = -TARGET_EINVAL; |
| 4215 | break; |
| 4216 | } |
Juan Quintela | 1add869 | 2011-06-16 17:37:09 +0100 | [diff] [blame] | 4217 | return ret; |
bellard | d2fd1af | 2007-11-14 18:08:56 +0000 | [diff] [blame] | 4218 | } |
| 4219 | #endif |
| 4220 | |
bellard | 2ab83ea | 2003-06-15 19:56:46 +0000 | [diff] [blame] | 4221 | #endif /* defined(TARGET_I386) */ |
| 4222 | |
Riku Voipio | 05098a9 | 2011-03-04 15:27:29 +0200 | [diff] [blame] | 4223 | #define NEW_STACK_SIZE 0x40000 |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4224 | |
Riku Voipio | 05098a9 | 2011-03-04 15:27:29 +0200 | [diff] [blame] | 4225 | #if defined(CONFIG_USE_NPTL) |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4226 | |
| 4227 | static pthread_mutex_t clone_lock = PTHREAD_MUTEX_INITIALIZER; |
| 4228 | typedef struct { |
Andreas Färber | 9349b4f | 2012-03-14 01:38:32 +0100 | [diff] [blame] | 4229 | CPUArchState *env; |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4230 | pthread_mutex_t mutex; |
| 4231 | pthread_cond_t cond; |
| 4232 | pthread_t thread; |
| 4233 | uint32_t tid; |
| 4234 | abi_ulong child_tidptr; |
| 4235 | abi_ulong parent_tidptr; |
| 4236 | sigset_t sigmask; |
| 4237 | } new_thread_info; |
| 4238 | |
| 4239 | static void *clone_func(void *arg) |
| 4240 | { |
| 4241 | new_thread_info *info = arg; |
Andreas Färber | 9349b4f | 2012-03-14 01:38:32 +0100 | [diff] [blame] | 4242 | CPUArchState *env; |
Mika Westerberg | edf8e2a | 2009-04-07 09:57:11 +0300 | [diff] [blame] | 4243 | TaskState *ts; |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4244 | |
| 4245 | env = info->env; |
| 4246 | thread_env = env; |
Mika Westerberg | edf8e2a | 2009-04-07 09:57:11 +0300 | [diff] [blame] | 4247 | ts = (TaskState *)thread_env->opaque; |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4248 | info->tid = gettid(); |
Nathan Froyd | 1e9fa73 | 2009-06-03 11:33:08 -0700 | [diff] [blame] | 4249 | env->host_tid = info->tid; |
Mika Westerberg | edf8e2a | 2009-04-07 09:57:11 +0300 | [diff] [blame] | 4250 | task_settid(ts); |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4251 | if (info->child_tidptr) |
| 4252 | put_user_u32(info->tid, info->child_tidptr); |
| 4253 | if (info->parent_tidptr) |
| 4254 | put_user_u32(info->tid, info->parent_tidptr); |
| 4255 | /* Enable signals. */ |
| 4256 | sigprocmask(SIG_SETMASK, &info->sigmask, NULL); |
| 4257 | /* Signal to the parent that we're ready. */ |
| 4258 | pthread_mutex_lock(&info->mutex); |
| 4259 | pthread_cond_broadcast(&info->cond); |
| 4260 | pthread_mutex_unlock(&info->mutex); |
| 4261 | /* Wait until the parent has finshed initializing the tls state. */ |
| 4262 | pthread_mutex_lock(&clone_lock); |
| 4263 | pthread_mutex_unlock(&clone_lock); |
| 4264 | cpu_loop(env); |
| 4265 | /* never exits */ |
| 4266 | return NULL; |
| 4267 | } |
| 4268 | #else |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 4269 | |
| 4270 | static int clone_func(void *arg) |
| 4271 | { |
Andreas Färber | 9349b4f | 2012-03-14 01:38:32 +0100 | [diff] [blame] | 4272 | CPUArchState *env = arg; |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 4273 | cpu_loop(env); |
| 4274 | /* never exits */ |
| 4275 | return 0; |
| 4276 | } |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4277 | #endif |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 4278 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 4279 | /* do_fork() Must return host values and target errnos (unlike most |
| 4280 | do_*() functions). */ |
Andreas Färber | 9349b4f | 2012-03-14 01:38:32 +0100 | [diff] [blame] | 4281 | static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp, |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4282 | abi_ulong parent_tidptr, target_ulong newtls, |
| 4283 | abi_ulong child_tidptr) |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 4284 | { |
| 4285 | int ret; |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 4286 | TaskState *ts; |
Andreas Färber | 9349b4f | 2012-03-14 01:38:32 +0100 | [diff] [blame] | 4287 | CPUArchState *new_env; |
Juan Quintela | 2f7bb87 | 2009-07-27 16:13:24 +0200 | [diff] [blame] | 4288 | #if defined(CONFIG_USE_NPTL) |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4289 | unsigned int nptl_flags; |
| 4290 | sigset_t sigmask; |
Riku Voipio | 9190749 | 2010-11-26 16:21:34 +0200 | [diff] [blame] | 4291 | #else |
| 4292 | uint8_t *new_stack; |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4293 | #endif |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 4294 | |
balrog | 436d124 | 2008-09-21 02:39:45 +0000 | [diff] [blame] | 4295 | /* Emulate vfork() with fork() */ |
| 4296 | if (flags & CLONE_VFORK) |
| 4297 | flags &= ~(CLONE_VFORK | CLONE_VM); |
| 4298 | |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 4299 | if (flags & CLONE_VM) { |
Mika Westerberg | edf8e2a | 2009-04-07 09:57:11 +0300 | [diff] [blame] | 4300 | TaskState *parent_ts = (TaskState *)env->opaque; |
Juan Quintela | 2f7bb87 | 2009-07-27 16:13:24 +0200 | [diff] [blame] | 4301 | #if defined(CONFIG_USE_NPTL) |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4302 | new_thread_info info; |
| 4303 | pthread_attr_t attr; |
pbrook | bd0c566 | 2008-05-29 14:34:11 +0000 | [diff] [blame] | 4304 | #endif |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 4305 | ts = g_malloc0(sizeof(TaskState)); |
pbrook | 624f797 | 2008-05-31 16:11:38 +0000 | [diff] [blame] | 4306 | init_task_state(ts); |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 4307 | /* we create a new CPU instance. */ |
ths | c5be9f0 | 2007-02-28 20:20:53 +0000 | [diff] [blame] | 4308 | new_env = cpu_copy(env); |
Blue Swirl | b4558d7 | 2009-11-07 16:34:12 +0000 | [diff] [blame] | 4309 | #if defined(TARGET_I386) || defined(TARGET_SPARC) || defined(TARGET_PPC) |
Andreas Färber | ff18b76 | 2012-05-05 14:47:34 +0200 | [diff] [blame] | 4310 | cpu_reset(ENV_GET_CPU(new_env)); |
Blue Swirl | b4558d7 | 2009-11-07 16:34:12 +0000 | [diff] [blame] | 4311 | #endif |
pbrook | 6e68e07 | 2008-05-30 17:22:15 +0000 | [diff] [blame] | 4312 | /* Init regs that differ from the parent. */ |
| 4313 | cpu_clone_regs(new_env, newsp); |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 4314 | new_env->opaque = ts; |
Mika Westerberg | edf8e2a | 2009-04-07 09:57:11 +0300 | [diff] [blame] | 4315 | ts->bprm = parent_ts->bprm; |
| 4316 | ts->info = parent_ts->info; |
Juan Quintela | 2f7bb87 | 2009-07-27 16:13:24 +0200 | [diff] [blame] | 4317 | #if defined(CONFIG_USE_NPTL) |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4318 | nptl_flags = flags; |
| 4319 | flags &= ~CLONE_NPTL_FLAGS2; |
| 4320 | |
pbrook | c276471 | 2009-03-07 15:24:59 +0000 | [diff] [blame] | 4321 | if (nptl_flags & CLONE_CHILD_CLEARTID) { |
| 4322 | ts->child_tidptr = child_tidptr; |
| 4323 | } |
| 4324 | |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4325 | if (nptl_flags & CLONE_SETTLS) |
| 4326 | cpu_set_tls (new_env, newtls); |
| 4327 | |
| 4328 | /* Grab a mutex so that thread setup appears atomic. */ |
| 4329 | pthread_mutex_lock(&clone_lock); |
| 4330 | |
| 4331 | memset(&info, 0, sizeof(info)); |
| 4332 | pthread_mutex_init(&info.mutex, NULL); |
| 4333 | pthread_mutex_lock(&info.mutex); |
| 4334 | pthread_cond_init(&info.cond, NULL); |
| 4335 | info.env = new_env; |
| 4336 | if (nptl_flags & CLONE_CHILD_SETTID) |
| 4337 | info.child_tidptr = child_tidptr; |
| 4338 | if (nptl_flags & CLONE_PARENT_SETTID) |
| 4339 | info.parent_tidptr = parent_tidptr; |
| 4340 | |
| 4341 | ret = pthread_attr_init(&attr); |
Nathan Froyd | 48e15fc | 2010-10-29 07:48:57 -0700 | [diff] [blame] | 4342 | ret = pthread_attr_setstacksize(&attr, NEW_STACK_SIZE); |
| 4343 | ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4344 | /* It is not safe to deliver signals until the child has finished |
| 4345 | initializing, so temporarily block all signals. */ |
| 4346 | sigfillset(&sigmask); |
| 4347 | sigprocmask(SIG_BLOCK, &sigmask, &info.sigmask); |
| 4348 | |
| 4349 | ret = pthread_create(&info.thread, &attr, clone_func, &info); |
pbrook | c276471 | 2009-03-07 15:24:59 +0000 | [diff] [blame] | 4350 | /* TODO: Free new CPU state if thread creation failed. */ |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4351 | |
| 4352 | sigprocmask(SIG_SETMASK, &info.sigmask, NULL); |
| 4353 | pthread_attr_destroy(&attr); |
| 4354 | if (ret == 0) { |
| 4355 | /* Wait for the child to initialize. */ |
| 4356 | pthread_cond_wait(&info.cond, &info.mutex); |
| 4357 | ret = info.tid; |
| 4358 | if (flags & CLONE_PARENT_SETTID) |
| 4359 | put_user_u32(ret, parent_tidptr); |
| 4360 | } else { |
| 4361 | ret = -1; |
| 4362 | } |
| 4363 | pthread_mutex_unlock(&info.mutex); |
| 4364 | pthread_cond_destroy(&info.cond); |
| 4365 | pthread_mutex_destroy(&info.mutex); |
| 4366 | pthread_mutex_unlock(&clone_lock); |
| 4367 | #else |
| 4368 | if (flags & CLONE_NPTL_FLAGS2) |
| 4369 | return -EINVAL; |
| 4370 | /* This is probably going to die very quickly, but do it anyway. */ |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 4371 | new_stack = g_malloc0 (NEW_STACK_SIZE); |
bellard | 27725c1 | 2003-04-29 21:08:18 +0000 | [diff] [blame] | 4372 | #ifdef __ia64__ |
Aurelien Jarno | 60e9924 | 2010-03-29 02:12:51 +0200 | [diff] [blame] | 4373 | ret = __clone2(clone_func, new_stack, NEW_STACK_SIZE, flags, new_env); |
bellard | 27725c1 | 2003-04-29 21:08:18 +0000 | [diff] [blame] | 4374 | #else |
| 4375 | ret = clone(clone_func, new_stack + NEW_STACK_SIZE, flags, new_env); |
| 4376 | #endif |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4377 | #endif |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 4378 | } else { |
| 4379 | /* if no CLONE_VM, we consider it is a fork */ |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4380 | if ((flags & ~(CSIGNAL | CLONE_NPTL_FLAGS2)) != 0) |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 4381 | return -EINVAL; |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4382 | fork_start(); |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 4383 | ret = fork(); |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4384 | if (ret == 0) { |
aurel32 | 2b1319c | 2008-12-18 22:44:04 +0000 | [diff] [blame] | 4385 | /* Child Process. */ |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4386 | cpu_clone_regs(env, newsp); |
| 4387 | fork_end(1); |
Juan Quintela | 2f7bb87 | 2009-07-27 16:13:24 +0200 | [diff] [blame] | 4388 | #if defined(CONFIG_USE_NPTL) |
aurel32 | 2b1319c | 2008-12-18 22:44:04 +0000 | [diff] [blame] | 4389 | /* There is a race condition here. The parent process could |
| 4390 | theoretically read the TID in the child process before the child |
| 4391 | tid is set. This would require using either ptrace |
| 4392 | (not implemented) or having *_tidptr to point at a shared memory |
| 4393 | mapping. We can't repeat the spinlock hack used above because |
| 4394 | the child process gets its own copy of the lock. */ |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4395 | if (flags & CLONE_CHILD_SETTID) |
| 4396 | put_user_u32(gettid(), child_tidptr); |
| 4397 | if (flags & CLONE_PARENT_SETTID) |
| 4398 | put_user_u32(gettid(), parent_tidptr); |
| 4399 | ts = (TaskState *)env->opaque; |
| 4400 | if (flags & CLONE_SETTLS) |
| 4401 | cpu_set_tls (env, newtls); |
pbrook | c276471 | 2009-03-07 15:24:59 +0000 | [diff] [blame] | 4402 | if (flags & CLONE_CHILD_CLEARTID) |
| 4403 | ts->child_tidptr = child_tidptr; |
aurel32 | 2b1319c | 2008-12-18 22:44:04 +0000 | [diff] [blame] | 4404 | #endif |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4405 | } else { |
| 4406 | fork_end(0); |
| 4407 | } |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 4408 | } |
| 4409 | return ret; |
| 4410 | } |
| 4411 | |
Arnaud Patard (Rtp) | 5f10681 | 2009-06-03 14:35:04 +0200 | [diff] [blame] | 4412 | /* warning : doesn't handle linux specific flags... */ |
| 4413 | static int target_to_host_fcntl_cmd(int cmd) |
| 4414 | { |
| 4415 | switch(cmd) { |
| 4416 | case TARGET_F_DUPFD: |
| 4417 | case TARGET_F_GETFD: |
| 4418 | case TARGET_F_SETFD: |
| 4419 | case TARGET_F_GETFL: |
| 4420 | case TARGET_F_SETFL: |
| 4421 | return cmd; |
| 4422 | case TARGET_F_GETLK: |
| 4423 | return F_GETLK; |
| 4424 | case TARGET_F_SETLK: |
| 4425 | return F_SETLK; |
| 4426 | case TARGET_F_SETLKW: |
| 4427 | return F_SETLKW; |
| 4428 | case TARGET_F_GETOWN: |
| 4429 | return F_GETOWN; |
| 4430 | case TARGET_F_SETOWN: |
| 4431 | return F_SETOWN; |
| 4432 | case TARGET_F_GETSIG: |
| 4433 | return F_GETSIG; |
| 4434 | case TARGET_F_SETSIG: |
| 4435 | return F_SETSIG; |
| 4436 | #if TARGET_ABI_BITS == 32 |
| 4437 | case TARGET_F_GETLK64: |
| 4438 | return F_GETLK64; |
| 4439 | case TARGET_F_SETLK64: |
| 4440 | return F_SETLK64; |
| 4441 | case TARGET_F_SETLKW64: |
| 4442 | return F_SETLKW64; |
| 4443 | #endif |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 4444 | case TARGET_F_SETLEASE: |
| 4445 | return F_SETLEASE; |
| 4446 | case TARGET_F_GETLEASE: |
| 4447 | return F_GETLEASE; |
malc | fbd5de9 | 2009-09-06 06:31:59 +0400 | [diff] [blame] | 4448 | #ifdef F_DUPFD_CLOEXEC |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 4449 | case TARGET_F_DUPFD_CLOEXEC: |
| 4450 | return F_DUPFD_CLOEXEC; |
malc | fbd5de9 | 2009-09-06 06:31:59 +0400 | [diff] [blame] | 4451 | #endif |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 4452 | case TARGET_F_NOTIFY: |
| 4453 | return F_NOTIFY; |
Arnaud Patard (Rtp) | 5f10681 | 2009-06-03 14:35:04 +0200 | [diff] [blame] | 4454 | default: |
| 4455 | return -TARGET_EINVAL; |
| 4456 | } |
| 4457 | return -TARGET_EINVAL; |
| 4458 | } |
| 4459 | |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 4460 | static abi_long do_fcntl(int fd, int cmd, abi_ulong arg) |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4461 | { |
| 4462 | struct flock fl; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 4463 | struct target_flock *target_fl; |
ths | 43f238d | 2007-01-05 20:55:49 +0000 | [diff] [blame] | 4464 | struct flock64 fl64; |
| 4465 | struct target_flock64 *target_fl64; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 4466 | abi_long ret; |
Arnaud Patard (Rtp) | 5f10681 | 2009-06-03 14:35:04 +0200 | [diff] [blame] | 4467 | int host_cmd = target_to_host_fcntl_cmd(cmd); |
| 4468 | |
| 4469 | if (host_cmd == -TARGET_EINVAL) |
| 4470 | return host_cmd; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 4471 | |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4472 | switch(cmd) { |
| 4473 | case TARGET_F_GETLK: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 4474 | if (!lock_user_struct(VERIFY_READ, target_fl, arg, 1)) |
| 4475 | return -TARGET_EFAULT; |
ths | 5813427 | 2007-03-31 18:59:32 +0000 | [diff] [blame] | 4476 | fl.l_type = tswap16(target_fl->l_type); |
| 4477 | fl.l_whence = tswap16(target_fl->l_whence); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 4478 | fl.l_start = tswapal(target_fl->l_start); |
| 4479 | fl.l_len = tswapal(target_fl->l_len); |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 4480 | fl.l_pid = tswap32(target_fl->l_pid); |
ths | 5813427 | 2007-03-31 18:59:32 +0000 | [diff] [blame] | 4481 | unlock_user_struct(target_fl, arg, 0); |
Arnaud Patard (Rtp) | 5f10681 | 2009-06-03 14:35:04 +0200 | [diff] [blame] | 4482 | ret = get_errno(fcntl(fd, host_cmd, &fl)); |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4483 | if (ret == 0) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 4484 | if (!lock_user_struct(VERIFY_WRITE, target_fl, arg, 0)) |
| 4485 | return -TARGET_EFAULT; |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4486 | target_fl->l_type = tswap16(fl.l_type); |
| 4487 | target_fl->l_whence = tswap16(fl.l_whence); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 4488 | target_fl->l_start = tswapal(fl.l_start); |
| 4489 | target_fl->l_len = tswapal(fl.l_len); |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 4490 | target_fl->l_pid = tswap32(fl.l_pid); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 4491 | unlock_user_struct(target_fl, arg, 1); |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4492 | } |
| 4493 | break; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 4494 | |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4495 | case TARGET_F_SETLK: |
| 4496 | case TARGET_F_SETLKW: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 4497 | if (!lock_user_struct(VERIFY_READ, target_fl, arg, 1)) |
| 4498 | return -TARGET_EFAULT; |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4499 | fl.l_type = tswap16(target_fl->l_type); |
| 4500 | fl.l_whence = tswap16(target_fl->l_whence); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 4501 | fl.l_start = tswapal(target_fl->l_start); |
| 4502 | fl.l_len = tswapal(target_fl->l_len); |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 4503 | fl.l_pid = tswap32(target_fl->l_pid); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 4504 | unlock_user_struct(target_fl, arg, 0); |
Arnaud Patard (Rtp) | 5f10681 | 2009-06-03 14:35:04 +0200 | [diff] [blame] | 4505 | ret = get_errno(fcntl(fd, host_cmd, &fl)); |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4506 | break; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 4507 | |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4508 | case TARGET_F_GETLK64: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 4509 | if (!lock_user_struct(VERIFY_READ, target_fl64, arg, 1)) |
| 4510 | return -TARGET_EFAULT; |
ths | 5813427 | 2007-03-31 18:59:32 +0000 | [diff] [blame] | 4511 | fl64.l_type = tswap16(target_fl64->l_type) >> 1; |
| 4512 | fl64.l_whence = tswap16(target_fl64->l_whence); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 4513 | fl64.l_start = tswap64(target_fl64->l_start); |
| 4514 | fl64.l_len = tswap64(target_fl64->l_len); |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 4515 | fl64.l_pid = tswap32(target_fl64->l_pid); |
ths | 5813427 | 2007-03-31 18:59:32 +0000 | [diff] [blame] | 4516 | unlock_user_struct(target_fl64, arg, 0); |
Arnaud Patard (Rtp) | 5f10681 | 2009-06-03 14:35:04 +0200 | [diff] [blame] | 4517 | ret = get_errno(fcntl(fd, host_cmd, &fl64)); |
ths | 43f238d | 2007-01-05 20:55:49 +0000 | [diff] [blame] | 4518 | if (ret == 0) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 4519 | if (!lock_user_struct(VERIFY_WRITE, target_fl64, arg, 0)) |
| 4520 | return -TARGET_EFAULT; |
ths | 43f238d | 2007-01-05 20:55:49 +0000 | [diff] [blame] | 4521 | target_fl64->l_type = tswap16(fl64.l_type) >> 1; |
| 4522 | target_fl64->l_whence = tswap16(fl64.l_whence); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 4523 | target_fl64->l_start = tswap64(fl64.l_start); |
| 4524 | target_fl64->l_len = tswap64(fl64.l_len); |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 4525 | target_fl64->l_pid = tswap32(fl64.l_pid); |
ths | 43f238d | 2007-01-05 20:55:49 +0000 | [diff] [blame] | 4526 | unlock_user_struct(target_fl64, arg, 1); |
| 4527 | } |
bellard | 9ee1fa2 | 2007-11-11 15:11:19 +0000 | [diff] [blame] | 4528 | break; |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4529 | case TARGET_F_SETLK64: |
| 4530 | case TARGET_F_SETLKW64: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 4531 | if (!lock_user_struct(VERIFY_READ, target_fl64, arg, 1)) |
| 4532 | return -TARGET_EFAULT; |
ths | 43f238d | 2007-01-05 20:55:49 +0000 | [diff] [blame] | 4533 | fl64.l_type = tswap16(target_fl64->l_type) >> 1; |
| 4534 | fl64.l_whence = tswap16(target_fl64->l_whence); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 4535 | fl64.l_start = tswap64(target_fl64->l_start); |
| 4536 | fl64.l_len = tswap64(target_fl64->l_len); |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 4537 | fl64.l_pid = tswap32(target_fl64->l_pid); |
ths | 43f238d | 2007-01-05 20:55:49 +0000 | [diff] [blame] | 4538 | unlock_user_struct(target_fl64, arg, 0); |
Arnaud Patard (Rtp) | 5f10681 | 2009-06-03 14:35:04 +0200 | [diff] [blame] | 4539 | ret = get_errno(fcntl(fd, host_cmd, &fl64)); |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4540 | break; |
| 4541 | |
Arnaud Patard (Rtp) | 5f10681 | 2009-06-03 14:35:04 +0200 | [diff] [blame] | 4542 | case TARGET_F_GETFL: |
| 4543 | ret = get_errno(fcntl(fd, host_cmd, arg)); |
bellard | 9ee1fa2 | 2007-11-11 15:11:19 +0000 | [diff] [blame] | 4544 | if (ret >= 0) { |
| 4545 | ret = host_to_target_bitmask(ret, fcntl_flags_tbl); |
| 4546 | } |
bellard | ffa65c3 | 2004-01-04 23:57:22 +0000 | [diff] [blame] | 4547 | break; |
| 4548 | |
Arnaud Patard (Rtp) | 5f10681 | 2009-06-03 14:35:04 +0200 | [diff] [blame] | 4549 | case TARGET_F_SETFL: |
| 4550 | ret = get_errno(fcntl(fd, host_cmd, target_to_host_bitmask(arg, fcntl_flags_tbl))); |
| 4551 | break; |
| 4552 | |
| 4553 | case TARGET_F_SETOWN: |
| 4554 | case TARGET_F_GETOWN: |
| 4555 | case TARGET_F_SETSIG: |
| 4556 | case TARGET_F_GETSIG: |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 4557 | case TARGET_F_SETLEASE: |
| 4558 | case TARGET_F_GETLEASE: |
Arnaud Patard (Rtp) | 5f10681 | 2009-06-03 14:35:04 +0200 | [diff] [blame] | 4559 | ret = get_errno(fcntl(fd, host_cmd, arg)); |
bellard | ffa65c3 | 2004-01-04 23:57:22 +0000 | [diff] [blame] | 4560 | break; |
| 4561 | |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4562 | default: |
bellard | 9ee1fa2 | 2007-11-11 15:11:19 +0000 | [diff] [blame] | 4563 | ret = get_errno(fcntl(fd, cmd, arg)); |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4564 | break; |
| 4565 | } |
| 4566 | return ret; |
| 4567 | } |
| 4568 | |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 4569 | #ifdef USE_UID16 |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4570 | |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 4571 | static inline int high2lowuid(int uid) |
| 4572 | { |
| 4573 | if (uid > 65535) |
| 4574 | return 65534; |
| 4575 | else |
| 4576 | return uid; |
| 4577 | } |
| 4578 | |
| 4579 | static inline int high2lowgid(int gid) |
| 4580 | { |
| 4581 | if (gid > 65535) |
| 4582 | return 65534; |
| 4583 | else |
| 4584 | return gid; |
| 4585 | } |
| 4586 | |
| 4587 | static inline int low2highuid(int uid) |
| 4588 | { |
| 4589 | if ((int16_t)uid == -1) |
| 4590 | return -1; |
| 4591 | else |
| 4592 | return uid; |
| 4593 | } |
| 4594 | |
| 4595 | static inline int low2highgid(int gid) |
| 4596 | { |
| 4597 | if ((int16_t)gid == -1) |
| 4598 | return -1; |
| 4599 | else |
| 4600 | return gid; |
| 4601 | } |
Riku Voipio | 0c866a7 | 2011-04-18 15:23:06 +0300 | [diff] [blame] | 4602 | static inline int tswapid(int id) |
| 4603 | { |
| 4604 | return tswap16(id); |
| 4605 | } |
| 4606 | #else /* !USE_UID16 */ |
| 4607 | static inline int high2lowuid(int uid) |
| 4608 | { |
| 4609 | return uid; |
| 4610 | } |
| 4611 | static inline int high2lowgid(int gid) |
| 4612 | { |
| 4613 | return gid; |
| 4614 | } |
| 4615 | static inline int low2highuid(int uid) |
| 4616 | { |
| 4617 | return uid; |
| 4618 | } |
| 4619 | static inline int low2highgid(int gid) |
| 4620 | { |
| 4621 | return gid; |
| 4622 | } |
| 4623 | static inline int tswapid(int id) |
| 4624 | { |
| 4625 | return tswap32(id); |
| 4626 | } |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 4627 | #endif /* USE_UID16 */ |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 4628 | |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 4629 | void syscall_init(void) |
| 4630 | { |
bellard | 2ab83ea | 2003-06-15 19:56:46 +0000 | [diff] [blame] | 4631 | IOCTLEntry *ie; |
| 4632 | const argtype *arg_type; |
| 4633 | int size; |
ths | b92c47c | 2007-11-01 00:07:38 +0000 | [diff] [blame] | 4634 | int i; |
bellard | 2ab83ea | 2003-06-15 19:56:46 +0000 | [diff] [blame] | 4635 | |
Blue Swirl | 001faf3 | 2009-05-13 17:53:17 +0000 | [diff] [blame] | 4636 | #define STRUCT(name, ...) thunk_register_struct(STRUCT_ ## name, #name, struct_ ## name ## _def); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 4637 | #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] | 4638 | #include "syscall_types.h" |
| 4639 | #undef STRUCT |
| 4640 | #undef STRUCT_SPECIAL |
bellard | 2ab83ea | 2003-06-15 19:56:46 +0000 | [diff] [blame] | 4641 | |
Peter Maydell | 9df109b | 2012-07-23 18:54:00 +0100 | [diff] [blame] | 4642 | /* Build target_to_host_errno_table[] table from |
| 4643 | * host_to_target_errno_table[]. */ |
| 4644 | for (i=0; i < ERRNO_TABLE_SIZE; i++) |
| 4645 | target_to_host_errno_table[host_to_target_errno_table[i]] = i; |
| 4646 | |
bellard | 2ab83ea | 2003-06-15 19:56:46 +0000 | [diff] [blame] | 4647 | /* we patch the ioctl size if necessary. We rely on the fact that |
| 4648 | no ioctl has all the bits at '1' in the size field */ |
| 4649 | ie = ioctl_entries; |
| 4650 | while (ie->target_cmd != 0) { |
| 4651 | if (((ie->target_cmd >> TARGET_IOC_SIZESHIFT) & TARGET_IOC_SIZEMASK) == |
| 4652 | TARGET_IOC_SIZEMASK) { |
| 4653 | arg_type = ie->arg_type; |
| 4654 | if (arg_type[0] != TYPE_PTR) { |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 4655 | fprintf(stderr, "cannot patch size for ioctl 0x%x\n", |
bellard | 2ab83ea | 2003-06-15 19:56:46 +0000 | [diff] [blame] | 4656 | ie->target_cmd); |
| 4657 | exit(1); |
| 4658 | } |
| 4659 | arg_type++; |
| 4660 | size = thunk_type_size(arg_type, 0); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 4661 | ie->target_cmd = (ie->target_cmd & |
bellard | 2ab83ea | 2003-06-15 19:56:46 +0000 | [diff] [blame] | 4662 | ~(TARGET_IOC_SIZEMASK << TARGET_IOC_SIZESHIFT)) | |
| 4663 | (size << TARGET_IOC_SIZESHIFT); |
| 4664 | } |
ths | b92c47c | 2007-11-01 00:07:38 +0000 | [diff] [blame] | 4665 | |
bellard | 2ab83ea | 2003-06-15 19:56:46 +0000 | [diff] [blame] | 4666 | /* automatic consistency check if same arch */ |
balrog | 872ea0c | 2008-09-21 02:31:19 +0000 | [diff] [blame] | 4667 | #if (defined(__i386__) && defined(TARGET_I386) && defined(TARGET_ABI32)) || \ |
| 4668 | (defined(__x86_64__) && defined(TARGET_X86_64)) |
| 4669 | if (unlikely(ie->target_cmd != ie->host_cmd)) { |
| 4670 | fprintf(stderr, "ERROR: ioctl(%s): target=0x%x host=0x%x\n", |
| 4671 | ie->name, ie->target_cmd, ie->host_cmd); |
bellard | 2ab83ea | 2003-06-15 19:56:46 +0000 | [diff] [blame] | 4672 | } |
| 4673 | #endif |
| 4674 | ie++; |
| 4675 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 4676 | } |
bellard | c573ff6 | 2004-01-04 15:51:36 +0000 | [diff] [blame] | 4677 | |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 4678 | #if TARGET_ABI_BITS == 32 |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 4679 | static inline uint64_t target_offset64(uint32_t word0, uint32_t word1) |
| 4680 | { |
ths | af325d3 | 2008-06-10 15:29:15 +0000 | [diff] [blame] | 4681 | #ifdef TARGET_WORDS_BIGENDIAN |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 4682 | return ((uint64_t)word0 << 32) | word1; |
| 4683 | #else |
| 4684 | return ((uint64_t)word1 << 32) | word0; |
| 4685 | #endif |
| 4686 | } |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 4687 | #else /* TARGET_ABI_BITS == 32 */ |
j_mayer | 3240710 | 2007-09-26 23:01:49 +0000 | [diff] [blame] | 4688 | static inline uint64_t target_offset64(uint64_t word0, uint64_t word1) |
| 4689 | { |
| 4690 | return word0; |
| 4691 | } |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 4692 | #endif /* TARGET_ABI_BITS != 32 */ |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 4693 | |
| 4694 | #ifdef TARGET_NR_truncate64 |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 4695 | static inline abi_long target_truncate64(void *cpu_env, const char *arg1, |
| 4696 | abi_long arg2, |
| 4697 | abi_long arg3, |
| 4698 | abi_long arg4) |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 4699 | { |
Riku Voipio | 48e515d | 2011-07-12 15:40:51 +0300 | [diff] [blame] | 4700 | if (regpairs_aligned(cpu_env)) { |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 4701 | arg2 = arg3; |
| 4702 | arg3 = arg4; |
Riku Voipio | 48e515d | 2011-07-12 15:40:51 +0300 | [diff] [blame] | 4703 | } |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 4704 | return get_errno(truncate64(arg1, target_offset64(arg2, arg3))); |
| 4705 | } |
| 4706 | #endif |
| 4707 | |
| 4708 | #ifdef TARGET_NR_ftruncate64 |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 4709 | static inline abi_long target_ftruncate64(void *cpu_env, abi_long arg1, |
| 4710 | abi_long arg2, |
| 4711 | abi_long arg3, |
| 4712 | abi_long arg4) |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 4713 | { |
Riku Voipio | 48e515d | 2011-07-12 15:40:51 +0300 | [diff] [blame] | 4714 | if (regpairs_aligned(cpu_env)) { |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 4715 | arg2 = arg3; |
| 4716 | arg3 = arg4; |
Riku Voipio | 48e515d | 2011-07-12 15:40:51 +0300 | [diff] [blame] | 4717 | } |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 4718 | return get_errno(ftruncate64(arg1, target_offset64(arg2, arg3))); |
| 4719 | } |
| 4720 | #endif |
| 4721 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 4722 | static inline abi_long target_to_host_timespec(struct timespec *host_ts, |
| 4723 | abi_ulong target_addr) |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 4724 | { |
| 4725 | struct target_timespec *target_ts; |
| 4726 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 4727 | if (!lock_user_struct(VERIFY_READ, target_ts, target_addr, 1)) |
| 4728 | return -TARGET_EFAULT; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 4729 | host_ts->tv_sec = tswapal(target_ts->tv_sec); |
| 4730 | host_ts->tv_nsec = tswapal(target_ts->tv_nsec); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 4731 | unlock_user_struct(target_ts, target_addr, 0); |
bellard | b255bfa | 2008-05-10 21:51:02 +0000 | [diff] [blame] | 4732 | return 0; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 4733 | } |
| 4734 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 4735 | static inline abi_long host_to_target_timespec(abi_ulong target_addr, |
| 4736 | struct timespec *host_ts) |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 4737 | { |
| 4738 | struct target_timespec *target_ts; |
| 4739 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 4740 | if (!lock_user_struct(VERIFY_WRITE, target_ts, target_addr, 0)) |
| 4741 | return -TARGET_EFAULT; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 4742 | target_ts->tv_sec = tswapal(host_ts->tv_sec); |
| 4743 | target_ts->tv_nsec = tswapal(host_ts->tv_nsec); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 4744 | unlock_user_struct(target_ts, target_addr, 1); |
bellard | b255bfa | 2008-05-10 21:51:02 +0000 | [diff] [blame] | 4745 | return 0; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 4746 | } |
| 4747 | |
aurel32 | 9d33b76 | 2009-04-08 23:07:05 +0000 | [diff] [blame] | 4748 | #if defined(TARGET_NR_stat64) || defined(TARGET_NR_newfstatat) |
balrog | 6a24a77 | 2008-09-20 02:23:36 +0000 | [diff] [blame] | 4749 | static inline abi_long host_to_target_stat64(void *cpu_env, |
| 4750 | abi_ulong target_addr, |
| 4751 | struct stat *host_st) |
| 4752 | { |
| 4753 | #ifdef TARGET_ARM |
| 4754 | if (((CPUARMState *)cpu_env)->eabi) { |
| 4755 | struct target_eabi_stat64 *target_st; |
| 4756 | |
| 4757 | if (!lock_user_struct(VERIFY_WRITE, target_st, target_addr, 0)) |
| 4758 | return -TARGET_EFAULT; |
| 4759 | memset(target_st, 0, sizeof(struct target_eabi_stat64)); |
| 4760 | __put_user(host_st->st_dev, &target_st->st_dev); |
| 4761 | __put_user(host_st->st_ino, &target_st->st_ino); |
| 4762 | #ifdef TARGET_STAT64_HAS_BROKEN_ST_INO |
| 4763 | __put_user(host_st->st_ino, &target_st->__st_ino); |
| 4764 | #endif |
| 4765 | __put_user(host_st->st_mode, &target_st->st_mode); |
| 4766 | __put_user(host_st->st_nlink, &target_st->st_nlink); |
| 4767 | __put_user(host_st->st_uid, &target_st->st_uid); |
| 4768 | __put_user(host_st->st_gid, &target_st->st_gid); |
| 4769 | __put_user(host_st->st_rdev, &target_st->st_rdev); |
| 4770 | __put_user(host_st->st_size, &target_st->st_size); |
| 4771 | __put_user(host_st->st_blksize, &target_st->st_blksize); |
| 4772 | __put_user(host_st->st_blocks, &target_st->st_blocks); |
| 4773 | __put_user(host_st->st_atime, &target_st->target_st_atime); |
| 4774 | __put_user(host_st->st_mtime, &target_st->target_st_mtime); |
| 4775 | __put_user(host_st->st_ctime, &target_st->target_st_ctime); |
| 4776 | unlock_user_struct(target_st, target_addr, 1); |
| 4777 | } else |
| 4778 | #endif |
| 4779 | { |
Richard Henderson | ed18c5c | 2010-04-26 10:27:22 -0700 | [diff] [blame] | 4780 | #if TARGET_ABI_BITS == 64 && !defined(TARGET_ALPHA) |
aurel32 | 9d33b76 | 2009-04-08 23:07:05 +0000 | [diff] [blame] | 4781 | struct target_stat *target_st; |
| 4782 | #else |
balrog | 6a24a77 | 2008-09-20 02:23:36 +0000 | [diff] [blame] | 4783 | struct target_stat64 *target_st; |
aurel32 | 9d33b76 | 2009-04-08 23:07:05 +0000 | [diff] [blame] | 4784 | #endif |
balrog | 6a24a77 | 2008-09-20 02:23:36 +0000 | [diff] [blame] | 4785 | |
| 4786 | if (!lock_user_struct(VERIFY_WRITE, target_st, target_addr, 0)) |
| 4787 | return -TARGET_EFAULT; |
aurel32 | 9d33b76 | 2009-04-08 23:07:05 +0000 | [diff] [blame] | 4788 | memset(target_st, 0, sizeof(*target_st)); |
balrog | 6a24a77 | 2008-09-20 02:23:36 +0000 | [diff] [blame] | 4789 | __put_user(host_st->st_dev, &target_st->st_dev); |
| 4790 | __put_user(host_st->st_ino, &target_st->st_ino); |
| 4791 | #ifdef TARGET_STAT64_HAS_BROKEN_ST_INO |
| 4792 | __put_user(host_st->st_ino, &target_st->__st_ino); |
| 4793 | #endif |
| 4794 | __put_user(host_st->st_mode, &target_st->st_mode); |
| 4795 | __put_user(host_st->st_nlink, &target_st->st_nlink); |
| 4796 | __put_user(host_st->st_uid, &target_st->st_uid); |
| 4797 | __put_user(host_st->st_gid, &target_st->st_gid); |
| 4798 | __put_user(host_st->st_rdev, &target_st->st_rdev); |
| 4799 | /* XXX: better use of kernel struct */ |
| 4800 | __put_user(host_st->st_size, &target_st->st_size); |
| 4801 | __put_user(host_st->st_blksize, &target_st->st_blksize); |
| 4802 | __put_user(host_st->st_blocks, &target_st->st_blocks); |
| 4803 | __put_user(host_st->st_atime, &target_st->target_st_atime); |
| 4804 | __put_user(host_st->st_mtime, &target_st->target_st_mtime); |
| 4805 | __put_user(host_st->st_ctime, &target_st->target_st_ctime); |
| 4806 | unlock_user_struct(target_st, target_addr, 1); |
| 4807 | } |
| 4808 | |
| 4809 | return 0; |
| 4810 | } |
| 4811 | #endif |
| 4812 | |
Juan Quintela | 2f7bb87 | 2009-07-27 16:13:24 +0200 | [diff] [blame] | 4813 | #if defined(CONFIG_USE_NPTL) |
pbrook | bd0c566 | 2008-05-29 14:34:11 +0000 | [diff] [blame] | 4814 | /* ??? Using host futex calls even when target atomic operations |
| 4815 | are not really atomic probably breaks things. However implementing |
| 4816 | futexes locally would make futexes shared between multiple processes |
| 4817 | tricky. However they're probably useless because guest atomic |
| 4818 | operations won't work either. */ |
blueswir1 | 8fcd369 | 2008-08-17 20:26:25 +0000 | [diff] [blame] | 4819 | static int do_futex(target_ulong uaddr, int op, int val, target_ulong timeout, |
| 4820 | target_ulong uaddr2, int val3) |
pbrook | bd0c566 | 2008-05-29 14:34:11 +0000 | [diff] [blame] | 4821 | { |
| 4822 | struct timespec ts, *pts; |
Nathan Froyd | a16aae0 | 2009-08-03 08:43:29 -0700 | [diff] [blame] | 4823 | int base_op; |
pbrook | bd0c566 | 2008-05-29 14:34:11 +0000 | [diff] [blame] | 4824 | |
| 4825 | /* ??? We assume FUTEX_* constants are the same on both host |
| 4826 | and target. */ |
Martin Mohring | a29ccd6 | 2009-05-04 21:34:56 +0300 | [diff] [blame] | 4827 | #ifdef FUTEX_CMD_MASK |
Nathan Froyd | a16aae0 | 2009-08-03 08:43:29 -0700 | [diff] [blame] | 4828 | base_op = op & FUTEX_CMD_MASK; |
Martin Mohring | a29ccd6 | 2009-05-04 21:34:56 +0300 | [diff] [blame] | 4829 | #else |
Nathan Froyd | a16aae0 | 2009-08-03 08:43:29 -0700 | [diff] [blame] | 4830 | base_op = op; |
Martin Mohring | a29ccd6 | 2009-05-04 21:34:56 +0300 | [diff] [blame] | 4831 | #endif |
Nathan Froyd | a16aae0 | 2009-08-03 08:43:29 -0700 | [diff] [blame] | 4832 | switch (base_op) { |
pbrook | bd0c566 | 2008-05-29 14:34:11 +0000 | [diff] [blame] | 4833 | case FUTEX_WAIT: |
| 4834 | if (timeout) { |
| 4835 | pts = &ts; |
| 4836 | target_to_host_timespec(pts, timeout); |
| 4837 | } else { |
| 4838 | pts = NULL; |
| 4839 | } |
Martin Mohring | a29ccd6 | 2009-05-04 21:34:56 +0300 | [diff] [blame] | 4840 | return get_errno(sys_futex(g2h(uaddr), op, tswap32(val), |
pbrook | bd0c566 | 2008-05-29 14:34:11 +0000 | [diff] [blame] | 4841 | pts, NULL, 0)); |
| 4842 | case FUTEX_WAKE: |
Martin Mohring | a29ccd6 | 2009-05-04 21:34:56 +0300 | [diff] [blame] | 4843 | return get_errno(sys_futex(g2h(uaddr), op, val, NULL, NULL, 0)); |
pbrook | bd0c566 | 2008-05-29 14:34:11 +0000 | [diff] [blame] | 4844 | case FUTEX_FD: |
Martin Mohring | a29ccd6 | 2009-05-04 21:34:56 +0300 | [diff] [blame] | 4845 | return get_errno(sys_futex(g2h(uaddr), op, val, NULL, NULL, 0)); |
pbrook | bd0c566 | 2008-05-29 14:34:11 +0000 | [diff] [blame] | 4846 | case FUTEX_REQUEUE: |
pbrook | bd0c566 | 2008-05-29 14:34:11 +0000 | [diff] [blame] | 4847 | case FUTEX_CMP_REQUEUE: |
Nathan Froyd | a16aae0 | 2009-08-03 08:43:29 -0700 | [diff] [blame] | 4848 | case FUTEX_WAKE_OP: |
| 4849 | /* For FUTEX_REQUEUE, FUTEX_CMP_REQUEUE, and FUTEX_WAKE_OP, the |
| 4850 | TIMEOUT parameter is interpreted as a uint32_t by the kernel. |
| 4851 | But the prototype takes a `struct timespec *'; insert casts |
| 4852 | to satisfy the compiler. We do not need to tswap TIMEOUT |
| 4853 | since it's not compared to guest memory. */ |
| 4854 | pts = (struct timespec *)(uintptr_t) timeout; |
| 4855 | return get_errno(sys_futex(g2h(uaddr), op, val, pts, |
| 4856 | g2h(uaddr2), |
| 4857 | (base_op == FUTEX_CMP_REQUEUE |
| 4858 | ? tswap32(val3) |
| 4859 | : val3))); |
pbrook | bd0c566 | 2008-05-29 14:34:11 +0000 | [diff] [blame] | 4860 | default: |
| 4861 | return -TARGET_ENOSYS; |
| 4862 | } |
| 4863 | } |
| 4864 | #endif |
| 4865 | |
pbrook | 1d9d8b5 | 2009-04-16 15:17:02 +0000 | [diff] [blame] | 4866 | /* Map host to target signal numbers for the wait family of syscalls. |
| 4867 | Assume all other status bits are the same. */ |
| 4868 | static int host_to_target_waitstatus(int status) |
| 4869 | { |
| 4870 | if (WIFSIGNALED(status)) { |
| 4871 | return host_to_target_signal(WTERMSIG(status)) | (status & ~0x7f); |
| 4872 | } |
| 4873 | if (WIFSTOPPED(status)) { |
| 4874 | return (host_to_target_signal(WSTOPSIG(status)) << 8) |
| 4875 | | (status & 0xff); |
| 4876 | } |
| 4877 | return status; |
| 4878 | } |
| 4879 | |
pbrook | a745ec6 | 2008-05-06 15:36:17 +0000 | [diff] [blame] | 4880 | int get_osversion(void) |
| 4881 | { |
| 4882 | static int osversion; |
| 4883 | struct new_utsname buf; |
| 4884 | const char *s; |
| 4885 | int i, n, tmp; |
| 4886 | if (osversion) |
| 4887 | return osversion; |
| 4888 | if (qemu_uname_release && *qemu_uname_release) { |
| 4889 | s = qemu_uname_release; |
| 4890 | } else { |
| 4891 | if (sys_uname(&buf)) |
| 4892 | return 0; |
| 4893 | s = buf.release; |
| 4894 | } |
| 4895 | tmp = 0; |
| 4896 | for (i = 0; i < 3; i++) { |
| 4897 | n = 0; |
| 4898 | while (*s >= '0' && *s <= '9') { |
| 4899 | n *= 10; |
| 4900 | n += *s - '0'; |
| 4901 | s++; |
| 4902 | } |
| 4903 | tmp = (tmp << 8) + n; |
| 4904 | if (*s == '.') |
| 4905 | s++; |
| 4906 | } |
| 4907 | osversion = tmp; |
| 4908 | return osversion; |
| 4909 | } |
| 4910 | |
Alexander Graf | 36c08d4 | 2011-11-02 20:23:24 +0100 | [diff] [blame] | 4911 | |
| 4912 | static int open_self_maps(void *cpu_env, int fd) |
| 4913 | { |
Alexander Graf | 1a49ef2 | 2012-05-01 16:30:28 +0100 | [diff] [blame] | 4914 | #if defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_UNICORE32) |
Andreas Färber | 9349b4f | 2012-03-14 01:38:32 +0100 | [diff] [blame] | 4915 | TaskState *ts = ((CPUArchState *)cpu_env)->opaque; |
Alexander Graf | 1a49ef2 | 2012-05-01 16:30:28 +0100 | [diff] [blame] | 4916 | #endif |
| 4917 | FILE *fp; |
| 4918 | char *line = NULL; |
| 4919 | size_t len = 0; |
| 4920 | ssize_t read; |
Alexander Graf | 36c08d4 | 2011-11-02 20:23:24 +0100 | [diff] [blame] | 4921 | |
Alexander Graf | 1a49ef2 | 2012-05-01 16:30:28 +0100 | [diff] [blame] | 4922 | fp = fopen("/proc/self/maps", "r"); |
| 4923 | if (fp == NULL) { |
| 4924 | return -EACCES; |
| 4925 | } |
| 4926 | |
| 4927 | while ((read = getline(&line, &len, fp)) != -1) { |
| 4928 | int fields, dev_maj, dev_min, inode; |
| 4929 | uint64_t min, max, offset; |
| 4930 | char flag_r, flag_w, flag_x, flag_p; |
| 4931 | char path[512] = ""; |
| 4932 | fields = sscanf(line, "%"PRIx64"-%"PRIx64" %c%c%c%c %"PRIx64" %x:%x %d" |
| 4933 | " %512s", &min, &max, &flag_r, &flag_w, &flag_x, |
| 4934 | &flag_p, &offset, &dev_maj, &dev_min, &inode, path); |
| 4935 | |
| 4936 | if ((fields < 10) || (fields > 11)) { |
| 4937 | continue; |
| 4938 | } |
| 4939 | if (!strncmp(path, "[stack]", 7)) { |
| 4940 | continue; |
| 4941 | } |
| 4942 | if (h2g_valid(min) && h2g_valid(max)) { |
| 4943 | dprintf(fd, TARGET_ABI_FMT_lx "-" TARGET_ABI_FMT_lx |
| 4944 | " %c%c%c%c %08" PRIx64 " %02x:%02x %d%s%s\n", |
| 4945 | h2g(min), h2g(max), flag_r, flag_w, |
| 4946 | flag_x, flag_p, offset, dev_maj, dev_min, inode, |
| 4947 | path[0] ? " " : "", path); |
| 4948 | } |
| 4949 | } |
| 4950 | |
| 4951 | free(line); |
| 4952 | fclose(fp); |
| 4953 | |
| 4954 | #if defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_UNICORE32) |
Alexander Graf | 36c08d4 | 2011-11-02 20:23:24 +0100 | [diff] [blame] | 4955 | dprintf(fd, "%08llx-%08llx rw-p %08llx 00:00 0 [stack]\n", |
| 4956 | (unsigned long long)ts->info->stack_limit, |
| 4957 | (unsigned long long)(ts->stack_base + (TARGET_PAGE_SIZE - 1)) |
| 4958 | & TARGET_PAGE_MASK, |
Alexander Graf | 1a49ef2 | 2012-05-01 16:30:28 +0100 | [diff] [blame] | 4959 | (unsigned long long)0); |
| 4960 | #endif |
Alexander Graf | 36c08d4 | 2011-11-02 20:23:24 +0100 | [diff] [blame] | 4961 | |
| 4962 | return 0; |
| 4963 | } |
| 4964 | |
Alexander Graf | 480b8e7 | 2011-11-02 20:23:25 +0100 | [diff] [blame] | 4965 | static int open_self_stat(void *cpu_env, int fd) |
| 4966 | { |
Andreas Färber | 9349b4f | 2012-03-14 01:38:32 +0100 | [diff] [blame] | 4967 | TaskState *ts = ((CPUArchState *)cpu_env)->opaque; |
Alexander Graf | 480b8e7 | 2011-11-02 20:23:25 +0100 | [diff] [blame] | 4968 | abi_ulong start_stack = ts->info->start_stack; |
| 4969 | int i; |
| 4970 | |
| 4971 | for (i = 0; i < 44; i++) { |
| 4972 | char buf[128]; |
| 4973 | int len; |
| 4974 | uint64_t val = 0; |
| 4975 | |
Fabio Erculiani | e0e65be | 2012-01-03 09:38:34 +0000 | [diff] [blame] | 4976 | if (i == 0) { |
| 4977 | /* pid */ |
| 4978 | val = getpid(); |
| 4979 | snprintf(buf, sizeof(buf), "%"PRId64 " ", val); |
| 4980 | } else if (i == 1) { |
| 4981 | /* app name */ |
| 4982 | snprintf(buf, sizeof(buf), "(%s) ", ts->bprm->argv[0]); |
| 4983 | } else if (i == 27) { |
| 4984 | /* stack bottom */ |
| 4985 | val = start_stack; |
| 4986 | snprintf(buf, sizeof(buf), "%"PRId64 " ", val); |
| 4987 | } else { |
| 4988 | /* for the rest, there is MasterCard */ |
| 4989 | snprintf(buf, sizeof(buf), "0%c", i == 43 ? '\n' : ' '); |
Alexander Graf | 480b8e7 | 2011-11-02 20:23:25 +0100 | [diff] [blame] | 4990 | } |
Fabio Erculiani | e0e65be | 2012-01-03 09:38:34 +0000 | [diff] [blame] | 4991 | |
Alexander Graf | 480b8e7 | 2011-11-02 20:23:25 +0100 | [diff] [blame] | 4992 | len = strlen(buf); |
| 4993 | if (write(fd, buf, len) != len) { |
| 4994 | return -1; |
| 4995 | } |
| 4996 | } |
| 4997 | |
| 4998 | return 0; |
| 4999 | } |
| 5000 | |
Alexander Graf | 257450e | 2011-11-02 20:23:26 +0100 | [diff] [blame] | 5001 | static int open_self_auxv(void *cpu_env, int fd) |
| 5002 | { |
Andreas Färber | 9349b4f | 2012-03-14 01:38:32 +0100 | [diff] [blame] | 5003 | TaskState *ts = ((CPUArchState *)cpu_env)->opaque; |
Alexander Graf | 257450e | 2011-11-02 20:23:26 +0100 | [diff] [blame] | 5004 | abi_ulong auxv = ts->info->saved_auxv; |
| 5005 | abi_ulong len = ts->info->auxv_len; |
| 5006 | char *ptr; |
| 5007 | |
| 5008 | /* |
| 5009 | * Auxiliary vector is stored in target process stack. |
| 5010 | * read in whole auxv vector and copy it to file |
| 5011 | */ |
| 5012 | ptr = lock_user(VERIFY_READ, auxv, len, 0); |
| 5013 | if (ptr != NULL) { |
| 5014 | while (len > 0) { |
| 5015 | ssize_t r; |
| 5016 | r = write(fd, ptr, len); |
| 5017 | if (r <= 0) { |
| 5018 | break; |
| 5019 | } |
| 5020 | len -= r; |
| 5021 | ptr += r; |
| 5022 | } |
| 5023 | lseek(fd, 0, SEEK_SET); |
| 5024 | unlock_user(ptr, auxv, len); |
| 5025 | } |
| 5026 | |
| 5027 | return 0; |
| 5028 | } |
| 5029 | |
Alexander Graf | 3be14d0 | 2011-11-02 20:23:23 +0100 | [diff] [blame] | 5030 | static int do_open(void *cpu_env, const char *pathname, int flags, mode_t mode) |
| 5031 | { |
| 5032 | struct fake_open { |
| 5033 | const char *filename; |
| 5034 | int (*fill)(void *cpu_env, int fd); |
| 5035 | }; |
| 5036 | const struct fake_open *fake_open; |
| 5037 | static const struct fake_open fakes[] = { |
Alexander Graf | 36c08d4 | 2011-11-02 20:23:24 +0100 | [diff] [blame] | 5038 | { "/proc/self/maps", open_self_maps }, |
Alexander Graf | 480b8e7 | 2011-11-02 20:23:25 +0100 | [diff] [blame] | 5039 | { "/proc/self/stat", open_self_stat }, |
Alexander Graf | 257450e | 2011-11-02 20:23:26 +0100 | [diff] [blame] | 5040 | { "/proc/self/auxv", open_self_auxv }, |
Alexander Graf | 3be14d0 | 2011-11-02 20:23:23 +0100 | [diff] [blame] | 5041 | { NULL, NULL } |
| 5042 | }; |
| 5043 | |
| 5044 | for (fake_open = fakes; fake_open->filename; fake_open++) { |
| 5045 | if (!strncmp(pathname, fake_open->filename, |
| 5046 | strlen(fake_open->filename))) { |
| 5047 | break; |
| 5048 | } |
| 5049 | } |
| 5050 | |
| 5051 | if (fake_open->filename) { |
| 5052 | const char *tmpdir; |
| 5053 | char filename[PATH_MAX]; |
| 5054 | int fd, r; |
| 5055 | |
| 5056 | /* create temporary file to map stat to */ |
| 5057 | tmpdir = getenv("TMPDIR"); |
| 5058 | if (!tmpdir) |
| 5059 | tmpdir = "/tmp"; |
| 5060 | snprintf(filename, sizeof(filename), "%s/qemu-open.XXXXXX", tmpdir); |
| 5061 | fd = mkstemp(filename); |
| 5062 | if (fd < 0) { |
| 5063 | return fd; |
| 5064 | } |
| 5065 | unlink(filename); |
| 5066 | |
| 5067 | if ((r = fake_open->fill(cpu_env, fd))) { |
| 5068 | close(fd); |
| 5069 | return r; |
| 5070 | } |
| 5071 | lseek(fd, 0, SEEK_SET); |
| 5072 | |
| 5073 | return fd; |
| 5074 | } |
| 5075 | |
| 5076 | return get_errno(open(path(pathname), flags, mode)); |
| 5077 | } |
| 5078 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 5079 | /* do_syscall() should always have a single exit point at the end so |
| 5080 | that actions, such as logging of syscall results, can be performed. |
| 5081 | All errnos that do_syscall() returns must be -TARGET_<errcode>. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 5082 | abi_long do_syscall(void *cpu_env, int num, abi_long arg1, |
| 5083 | abi_long arg2, abi_long arg3, abi_long arg4, |
Peter Maydell | 5945cfc | 2011-06-16 17:37:13 +0100 | [diff] [blame] | 5084 | abi_long arg5, abi_long arg6, abi_long arg7, |
| 5085 | abi_long arg8) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5086 | { |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 5087 | abi_long ret; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5088 | struct stat st; |
bellard | 56c8f68 | 2005-11-28 22:28:41 +0000 | [diff] [blame] | 5089 | struct statfs stfs; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5090 | void *p; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 5091 | |
bellard | 72f0390 | 2003-02-18 23:33:18 +0000 | [diff] [blame] | 5092 | #ifdef DEBUG |
bellard | c573ff6 | 2004-01-04 15:51:36 +0000 | [diff] [blame] | 5093 | gemu_log("syscall %d", num); |
bellard | 72f0390 | 2003-02-18 23:33:18 +0000 | [diff] [blame] | 5094 | #endif |
ths | b92c47c | 2007-11-01 00:07:38 +0000 | [diff] [blame] | 5095 | if(do_strace) |
| 5096 | print_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6); |
| 5097 | |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5098 | switch(num) { |
| 5099 | case TARGET_NR_exit: |
Juan Quintela | 2f7bb87 | 2009-07-27 16:13:24 +0200 | [diff] [blame] | 5100 | #ifdef CONFIG_USE_NPTL |
pbrook | c276471 | 2009-03-07 15:24:59 +0000 | [diff] [blame] | 5101 | /* In old applications this may be used to implement _exit(2). |
| 5102 | However in threaded applictions it is used for thread termination, |
| 5103 | and _exit_group is used for application termination. |
| 5104 | Do thread termination if we have more then one thread. */ |
| 5105 | /* FIXME: This probably breaks if a signal arrives. We should probably |
| 5106 | be disabling signals. */ |
| 5107 | if (first_cpu->next_cpu) { |
Nathan Froyd | 1e9fa73 | 2009-06-03 11:33:08 -0700 | [diff] [blame] | 5108 | TaskState *ts; |
Andreas Färber | 9349b4f | 2012-03-14 01:38:32 +0100 | [diff] [blame] | 5109 | CPUArchState **lastp; |
| 5110 | CPUArchState *p; |
pbrook | c276471 | 2009-03-07 15:24:59 +0000 | [diff] [blame] | 5111 | |
| 5112 | cpu_list_lock(); |
| 5113 | lastp = &first_cpu; |
| 5114 | p = first_cpu; |
Andreas Färber | 9349b4f | 2012-03-14 01:38:32 +0100 | [diff] [blame] | 5115 | while (p && p != (CPUArchState *)cpu_env) { |
pbrook | c276471 | 2009-03-07 15:24:59 +0000 | [diff] [blame] | 5116 | lastp = &p->next_cpu; |
| 5117 | p = p->next_cpu; |
| 5118 | } |
| 5119 | /* If we didn't find the CPU for this thread then something is |
| 5120 | horribly wrong. */ |
| 5121 | if (!p) |
| 5122 | abort(); |
| 5123 | /* Remove the CPU from the list. */ |
| 5124 | *lastp = p->next_cpu; |
| 5125 | cpu_list_unlock(); |
Andreas Färber | 9349b4f | 2012-03-14 01:38:32 +0100 | [diff] [blame] | 5126 | ts = ((CPUArchState *)cpu_env)->opaque; |
pbrook | c276471 | 2009-03-07 15:24:59 +0000 | [diff] [blame] | 5127 | if (ts->child_tidptr) { |
| 5128 | put_user_u32(0, ts->child_tidptr); |
| 5129 | sys_futex(g2h(ts->child_tidptr), FUTEX_WAKE, INT_MAX, |
| 5130 | NULL, NULL, 0); |
| 5131 | } |
Nathan Froyd | 48e15fc | 2010-10-29 07:48:57 -0700 | [diff] [blame] | 5132 | thread_env = NULL; |
Andreas Färber | 11ea409 | 2012-04-15 18:51:01 +0200 | [diff] [blame] | 5133 | object_delete(OBJECT(ENV_GET_CPU(cpu_env))); |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 5134 | g_free(ts); |
pbrook | c276471 | 2009-03-07 15:24:59 +0000 | [diff] [blame] | 5135 | pthread_exit(NULL); |
| 5136 | } |
| 5137 | #endif |
Juan Quintela | 9788c9c | 2009-07-27 16:13:02 +0200 | [diff] [blame] | 5138 | #ifdef TARGET_GPROF |
bellard | 7d13299 | 2003-03-06 23:23:54 +0000 | [diff] [blame] | 5139 | _mcleanup(); |
| 5140 | #endif |
bellard | e900967 | 2005-04-26 20:42:36 +0000 | [diff] [blame] | 5141 | gdb_exit(cpu_env, arg1); |
pbrook | c276471 | 2009-03-07 15:24:59 +0000 | [diff] [blame] | 5142 | _exit(arg1); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5143 | ret = 0; /* avoid warning */ |
| 5144 | break; |
| 5145 | case TARGET_NR_read: |
aurel32 | 38d840e | 2009-01-30 19:48:17 +0000 | [diff] [blame] | 5146 | if (arg3 == 0) |
| 5147 | ret = 0; |
| 5148 | else { |
| 5149 | if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0))) |
| 5150 | goto efault; |
| 5151 | ret = get_errno(read(arg1, p, arg3)); |
| 5152 | unlock_user(p, arg2, ret); |
| 5153 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5154 | break; |
| 5155 | case TARGET_NR_write: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5156 | if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1))) |
| 5157 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5158 | ret = get_errno(write(arg1, p, arg3)); |
| 5159 | unlock_user(p, arg2, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5160 | break; |
| 5161 | case TARGET_NR_open: |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 5162 | if (!(p = lock_user_string(arg1))) |
| 5163 | goto efault; |
Alexander Graf | 3be14d0 | 2011-11-02 20:23:23 +0100 | [diff] [blame] | 5164 | ret = get_errno(do_open(cpu_env, p, |
| 5165 | target_to_host_bitmask(arg2, fcntl_flags_tbl), |
| 5166 | arg3)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5167 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5168 | break; |
ths | 8242483 | 2007-09-24 09:21:55 +0000 | [diff] [blame] | 5169 | #if defined(TARGET_NR_openat) && defined(__NR_openat) |
| 5170 | case TARGET_NR_openat: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5171 | if (!(p = lock_user_string(arg2))) |
| 5172 | goto efault; |
| 5173 | ret = get_errno(sys_openat(arg1, |
| 5174 | path(p), |
| 5175 | target_to_host_bitmask(arg3, fcntl_flags_tbl), |
| 5176 | arg4)); |
| 5177 | unlock_user(p, arg2, 0); |
ths | 8242483 | 2007-09-24 09:21:55 +0000 | [diff] [blame] | 5178 | break; |
| 5179 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5180 | case TARGET_NR_close: |
| 5181 | ret = get_errno(close(arg1)); |
| 5182 | break; |
| 5183 | case TARGET_NR_brk: |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5184 | ret = do_brk(arg1); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5185 | break; |
| 5186 | case TARGET_NR_fork: |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 5187 | ret = get_errno(do_fork(cpu_env, SIGCHLD, 0, 0, 0, 0)); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5188 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 5189 | #ifdef TARGET_NR_waitpid |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5190 | case TARGET_NR_waitpid: |
| 5191 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5192 | int status; |
| 5193 | ret = get_errno(waitpid(arg1, &status, arg3)); |
Alexander Graf | 5379557 | 2011-11-24 00:44:43 +0100 | [diff] [blame] | 5194 | if (!is_error(ret) && arg2 && ret |
pbrook | 1d9d8b5 | 2009-04-16 15:17:02 +0000 | [diff] [blame] | 5195 | && put_user_s32(host_to_target_waitstatus(status), arg2)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 5196 | goto efault; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5197 | } |
| 5198 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 5199 | #endif |
pbrook | f0cbb61 | 2008-05-30 18:20:05 +0000 | [diff] [blame] | 5200 | #ifdef TARGET_NR_waitid |
| 5201 | case TARGET_NR_waitid: |
| 5202 | { |
| 5203 | siginfo_t info; |
| 5204 | info.si_pid = 0; |
| 5205 | ret = get_errno(waitid(arg1, arg2, &info, arg4)); |
| 5206 | if (!is_error(ret) && arg3 && info.si_pid != 0) { |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 5207 | if (!(p = lock_user(VERIFY_WRITE, arg3, sizeof(target_siginfo_t), 0))) |
pbrook | f0cbb61 | 2008-05-30 18:20:05 +0000 | [diff] [blame] | 5208 | goto efault; |
| 5209 | host_to_target_siginfo(p, &info); |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 5210 | unlock_user(p, arg3, sizeof(target_siginfo_t)); |
pbrook | f0cbb61 | 2008-05-30 18:20:05 +0000 | [diff] [blame] | 5211 | } |
| 5212 | } |
| 5213 | break; |
| 5214 | #endif |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 5215 | #ifdef TARGET_NR_creat /* not on alpha */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5216 | case TARGET_NR_creat: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5217 | if (!(p = lock_user_string(arg1))) |
| 5218 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5219 | ret = get_errno(creat(p, arg2)); |
| 5220 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5221 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 5222 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5223 | case TARGET_NR_link: |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5224 | { |
| 5225 | void * p2; |
| 5226 | p = lock_user_string(arg1); |
| 5227 | p2 = lock_user_string(arg2); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5228 | if (!p || !p2) |
| 5229 | ret = -TARGET_EFAULT; |
| 5230 | else |
| 5231 | ret = get_errno(link(p, p2)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5232 | unlock_user(p2, arg2, 0); |
| 5233 | unlock_user(p, arg1, 0); |
| 5234 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5235 | break; |
ths | 64f0ce4 | 2007-09-24 09:25:06 +0000 | [diff] [blame] | 5236 | #if defined(TARGET_NR_linkat) && defined(__NR_linkat) |
| 5237 | case TARGET_NR_linkat: |
ths | 64f0ce4 | 2007-09-24 09:25:06 +0000 | [diff] [blame] | 5238 | { |
| 5239 | void * p2 = NULL; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5240 | if (!arg2 || !arg4) |
| 5241 | goto efault; |
ths | 64f0ce4 | 2007-09-24 09:25:06 +0000 | [diff] [blame] | 5242 | p = lock_user_string(arg2); |
| 5243 | p2 = lock_user_string(arg4); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5244 | if (!p || !p2) |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 5245 | ret = -TARGET_EFAULT; |
ths | 64f0ce4 | 2007-09-24 09:25:06 +0000 | [diff] [blame] | 5246 | else |
| 5247 | ret = get_errno(sys_linkat(arg1, p, arg3, p2, arg5)); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5248 | unlock_user(p, arg2, 0); |
| 5249 | unlock_user(p2, arg4, 0); |
ths | 64f0ce4 | 2007-09-24 09:25:06 +0000 | [diff] [blame] | 5250 | } |
| 5251 | break; |
| 5252 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5253 | case TARGET_NR_unlink: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5254 | if (!(p = lock_user_string(arg1))) |
| 5255 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5256 | ret = get_errno(unlink(p)); |
| 5257 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5258 | break; |
ths | 8170f56 | 2007-09-24 09:24:11 +0000 | [diff] [blame] | 5259 | #if defined(TARGET_NR_unlinkat) && defined(__NR_unlinkat) |
| 5260 | case TARGET_NR_unlinkat: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5261 | if (!(p = lock_user_string(arg2))) |
| 5262 | goto efault; |
| 5263 | ret = get_errno(sys_unlinkat(arg1, p, arg3)); |
| 5264 | unlock_user(p, arg2, 0); |
balrog | ed494d8 | 2007-12-11 23:23:52 +0000 | [diff] [blame] | 5265 | break; |
balrog | b7d35e6 | 2007-12-12 00:40:24 +0000 | [diff] [blame] | 5266 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5267 | case TARGET_NR_execve: |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 5268 | { |
| 5269 | char **argp, **envp; |
bellard | f7341ff | 2003-03-30 21:00:25 +0000 | [diff] [blame] | 5270 | int argc, envc; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 5271 | abi_ulong gp; |
| 5272 | abi_ulong guest_argp; |
| 5273 | abi_ulong guest_envp; |
| 5274 | abi_ulong addr; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 5275 | char **q; |
Ulrich Hecht | a6f79cc | 2012-01-31 12:43:16 +0100 | [diff] [blame] | 5276 | int total_size = 0; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 5277 | |
bellard | f7341ff | 2003-03-30 21:00:25 +0000 | [diff] [blame] | 5278 | argc = 0; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5279 | guest_argp = arg2; |
pbrook | da94d26 | 2008-05-30 18:24:00 +0000 | [diff] [blame] | 5280 | for (gp = guest_argp; gp; gp += sizeof(abi_ulong)) { |
ths | 03aa197 | 2007-12-02 06:28:08 +0000 | [diff] [blame] | 5281 | if (get_user_ual(addr, gp)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 5282 | goto efault; |
ths | 03aa197 | 2007-12-02 06:28:08 +0000 | [diff] [blame] | 5283 | if (!addr) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 5284 | break; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 5285 | argc++; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 5286 | } |
bellard | f7341ff | 2003-03-30 21:00:25 +0000 | [diff] [blame] | 5287 | envc = 0; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5288 | guest_envp = arg3; |
pbrook | da94d26 | 2008-05-30 18:24:00 +0000 | [diff] [blame] | 5289 | for (gp = guest_envp; gp; gp += sizeof(abi_ulong)) { |
ths | 03aa197 | 2007-12-02 06:28:08 +0000 | [diff] [blame] | 5290 | if (get_user_ual(addr, gp)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 5291 | goto efault; |
ths | 03aa197 | 2007-12-02 06:28:08 +0000 | [diff] [blame] | 5292 | if (!addr) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 5293 | break; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 5294 | envc++; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 5295 | } |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 5296 | |
bellard | f7341ff | 2003-03-30 21:00:25 +0000 | [diff] [blame] | 5297 | argp = alloca((argc + 1) * sizeof(void *)); |
| 5298 | envp = alloca((envc + 1) * sizeof(void *)); |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 5299 | |
pbrook | da94d26 | 2008-05-30 18:24:00 +0000 | [diff] [blame] | 5300 | for (gp = guest_argp, q = argp; gp; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 5301 | gp += sizeof(abi_ulong), q++) { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 5302 | if (get_user_ual(addr, gp)) |
| 5303 | goto execve_efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5304 | if (!addr) |
| 5305 | break; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 5306 | if (!(*q = lock_user_string(addr))) |
| 5307 | goto execve_efault; |
Ulrich Hecht | a6f79cc | 2012-01-31 12:43:16 +0100 | [diff] [blame] | 5308 | total_size += strlen(*q) + 1; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5309 | } |
bellard | f7341ff | 2003-03-30 21:00:25 +0000 | [diff] [blame] | 5310 | *q = NULL; |
| 5311 | |
pbrook | da94d26 | 2008-05-30 18:24:00 +0000 | [diff] [blame] | 5312 | for (gp = guest_envp, q = envp; gp; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 5313 | gp += sizeof(abi_ulong), q++) { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 5314 | if (get_user_ual(addr, gp)) |
| 5315 | goto execve_efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5316 | if (!addr) |
| 5317 | break; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 5318 | if (!(*q = lock_user_string(addr))) |
| 5319 | goto execve_efault; |
Ulrich Hecht | a6f79cc | 2012-01-31 12:43:16 +0100 | [diff] [blame] | 5320 | total_size += strlen(*q) + 1; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5321 | } |
bellard | f7341ff | 2003-03-30 21:00:25 +0000 | [diff] [blame] | 5322 | *q = NULL; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 5323 | |
Ulrich Hecht | a6f79cc | 2012-01-31 12:43:16 +0100 | [diff] [blame] | 5324 | /* This case will not be caught by the host's execve() if its |
| 5325 | page size is bigger than the target's. */ |
| 5326 | if (total_size > MAX_ARG_PAGES * TARGET_PAGE_SIZE) { |
| 5327 | ret = -TARGET_E2BIG; |
| 5328 | goto execve_end; |
| 5329 | } |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 5330 | if (!(p = lock_user_string(arg1))) |
| 5331 | goto execve_efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5332 | ret = get_errno(execve(p, argp, envp)); |
| 5333 | unlock_user(p, arg1, 0); |
| 5334 | |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 5335 | goto execve_end; |
| 5336 | |
| 5337 | execve_efault: |
| 5338 | ret = -TARGET_EFAULT; |
| 5339 | |
| 5340 | execve_end: |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5341 | for (gp = guest_argp, q = argp; *q; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 5342 | gp += sizeof(abi_ulong), q++) { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 5343 | if (get_user_ual(addr, gp) |
| 5344 | || !addr) |
| 5345 | break; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5346 | unlock_user(*q, addr, 0); |
| 5347 | } |
| 5348 | for (gp = guest_envp, q = envp; *q; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 5349 | gp += sizeof(abi_ulong), q++) { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 5350 | if (get_user_ual(addr, gp) |
| 5351 | || !addr) |
| 5352 | break; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5353 | unlock_user(*q, addr, 0); |
| 5354 | } |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 5355 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5356 | break; |
| 5357 | case TARGET_NR_chdir: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5358 | if (!(p = lock_user_string(arg1))) |
| 5359 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5360 | ret = get_errno(chdir(p)); |
| 5361 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5362 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 5363 | #ifdef TARGET_NR_time |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5364 | case TARGET_NR_time: |
| 5365 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5366 | time_t host_time; |
| 5367 | ret = get_errno(time(&host_time)); |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 5368 | if (!is_error(ret) |
| 5369 | && arg1 |
| 5370 | && put_user_sal(host_time, arg1)) |
| 5371 | goto efault; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5372 | } |
| 5373 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 5374 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5375 | case TARGET_NR_mknod: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5376 | if (!(p = lock_user_string(arg1))) |
| 5377 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5378 | ret = get_errno(mknod(p, arg2, arg3)); |
| 5379 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5380 | break; |
ths | 75ac37a | 2007-09-24 09:23:05 +0000 | [diff] [blame] | 5381 | #if defined(TARGET_NR_mknodat) && defined(__NR_mknodat) |
| 5382 | case TARGET_NR_mknodat: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5383 | if (!(p = lock_user_string(arg2))) |
| 5384 | goto efault; |
| 5385 | ret = get_errno(sys_mknodat(arg1, p, arg3, arg4)); |
| 5386 | unlock_user(p, arg2, 0); |
ths | 75ac37a | 2007-09-24 09:23:05 +0000 | [diff] [blame] | 5387 | break; |
| 5388 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5389 | case TARGET_NR_chmod: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5390 | if (!(p = lock_user_string(arg1))) |
| 5391 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5392 | ret = get_errno(chmod(p, arg2)); |
| 5393 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5394 | break; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5395 | #ifdef TARGET_NR_break |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5396 | case TARGET_NR_break: |
| 5397 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5398 | #endif |
| 5399 | #ifdef TARGET_NR_oldstat |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5400 | case TARGET_NR_oldstat: |
| 5401 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5402 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5403 | case TARGET_NR_lseek: |
| 5404 | ret = get_errno(lseek(arg1, arg2, arg3)); |
| 5405 | break; |
Richard Henderson | 9231733 | 2010-05-03 10:07:53 -0700 | [diff] [blame] | 5406 | #if defined(TARGET_NR_getxpid) && defined(TARGET_ALPHA) |
| 5407 | /* Alpha specific */ |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 5408 | case TARGET_NR_getxpid: |
Richard Henderson | 9231733 | 2010-05-03 10:07:53 -0700 | [diff] [blame] | 5409 | ((CPUAlphaState *)cpu_env)->ir[IR_A4] = getppid(); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5410 | ret = get_errno(getpid()); |
| 5411 | break; |
Richard Henderson | 9231733 | 2010-05-03 10:07:53 -0700 | [diff] [blame] | 5412 | #endif |
| 5413 | #ifdef TARGET_NR_getpid |
| 5414 | case TARGET_NR_getpid: |
| 5415 | ret = get_errno(getpid()); |
| 5416 | break; |
| 5417 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5418 | case TARGET_NR_mount: |
ths | 8026591 | 2007-02-17 22:25:41 +0000 | [diff] [blame] | 5419 | { |
| 5420 | /* need to look at the data field */ |
| 5421 | void *p2, *p3; |
| 5422 | p = lock_user_string(arg1); |
| 5423 | p2 = lock_user_string(arg2); |
| 5424 | p3 = lock_user_string(arg3); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5425 | if (!p || !p2 || !p3) |
| 5426 | ret = -TARGET_EFAULT; |
Jan-Simon Möller | dab4640 | 2009-10-17 21:52:43 +0300 | [diff] [blame] | 5427 | else { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5428 | /* FIXME - arg5 should be locked, but it isn't clear how to |
| 5429 | * do that since it's not guaranteed to be a NULL-terminated |
| 5430 | * string. |
| 5431 | */ |
Jan-Simon Möller | dab4640 | 2009-10-17 21:52:43 +0300 | [diff] [blame] | 5432 | if ( ! arg5 ) |
| 5433 | ret = get_errno(mount(p, p2, p3, (unsigned long)arg4, NULL)); |
| 5434 | else |
| 5435 | ret = get_errno(mount(p, p2, p3, (unsigned long)arg4, g2h(arg5))); |
| 5436 | } |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5437 | unlock_user(p, arg1, 0); |
| 5438 | unlock_user(p2, arg2, 0); |
| 5439 | unlock_user(p3, arg3, 0); |
ths | 8026591 | 2007-02-17 22:25:41 +0000 | [diff] [blame] | 5440 | break; |
| 5441 | } |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 5442 | #ifdef TARGET_NR_umount |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5443 | case TARGET_NR_umount: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5444 | if (!(p = lock_user_string(arg1))) |
| 5445 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5446 | ret = get_errno(umount(p)); |
| 5447 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5448 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 5449 | #endif |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 5450 | #ifdef TARGET_NR_stime /* not on alpha */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5451 | case TARGET_NR_stime: |
| 5452 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5453 | time_t host_time; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 5454 | if (get_user_sal(host_time, arg1)) |
| 5455 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5456 | ret = get_errno(stime(&host_time)); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5457 | } |
| 5458 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 5459 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5460 | case TARGET_NR_ptrace: |
| 5461 | goto unimplemented; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 5462 | #ifdef TARGET_NR_alarm /* not on alpha */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5463 | case TARGET_NR_alarm: |
| 5464 | ret = alarm(arg1); |
| 5465 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 5466 | #endif |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5467 | #ifdef TARGET_NR_oldfstat |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5468 | case TARGET_NR_oldfstat: |
| 5469 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5470 | #endif |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 5471 | #ifdef TARGET_NR_pause /* not on alpha */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5472 | case TARGET_NR_pause: |
| 5473 | ret = get_errno(pause()); |
| 5474 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 5475 | #endif |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 5476 | #ifdef TARGET_NR_utime |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5477 | case TARGET_NR_utime: |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5478 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5479 | struct utimbuf tbuf, *host_tbuf; |
| 5480 | struct target_utimbuf *target_tbuf; |
| 5481 | if (arg2) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5482 | if (!lock_user_struct(VERIFY_READ, target_tbuf, arg2, 1)) |
| 5483 | goto efault; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 5484 | tbuf.actime = tswapal(target_tbuf->actime); |
| 5485 | tbuf.modtime = tswapal(target_tbuf->modtime); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5486 | unlock_user_struct(target_tbuf, arg2, 0); |
| 5487 | host_tbuf = &tbuf; |
bellard | f72e8ff | 2004-05-03 19:23:07 +0000 | [diff] [blame] | 5488 | } else { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5489 | host_tbuf = NULL; |
bellard | f72e8ff | 2004-05-03 19:23:07 +0000 | [diff] [blame] | 5490 | } |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5491 | if (!(p = lock_user_string(arg1))) |
| 5492 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5493 | ret = get_errno(utime(p, host_tbuf)); |
| 5494 | unlock_user(p, arg1, 0); |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5495 | } |
| 5496 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 5497 | #endif |
bellard | 978a66f | 2004-12-06 22:58:05 +0000 | [diff] [blame] | 5498 | case TARGET_NR_utimes: |
| 5499 | { |
bellard | 978a66f | 2004-12-06 22:58:05 +0000 | [diff] [blame] | 5500 | struct timeval *tvp, tv[2]; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5501 | if (arg2) { |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 5502 | if (copy_from_user_timeval(&tv[0], arg2) |
| 5503 | || copy_from_user_timeval(&tv[1], |
| 5504 | arg2 + sizeof(struct target_timeval))) |
| 5505 | goto efault; |
bellard | 978a66f | 2004-12-06 22:58:05 +0000 | [diff] [blame] | 5506 | tvp = tv; |
| 5507 | } else { |
| 5508 | tvp = NULL; |
| 5509 | } |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5510 | if (!(p = lock_user_string(arg1))) |
| 5511 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5512 | ret = get_errno(utimes(p, tvp)); |
| 5513 | unlock_user(p, arg1, 0); |
bellard | 978a66f | 2004-12-06 22:58:05 +0000 | [diff] [blame] | 5514 | } |
| 5515 | break; |
balrog | ac8a655 | 2008-09-20 02:25:39 +0000 | [diff] [blame] | 5516 | #if defined(TARGET_NR_futimesat) && defined(__NR_futimesat) |
| 5517 | case TARGET_NR_futimesat: |
| 5518 | { |
| 5519 | struct timeval *tvp, tv[2]; |
| 5520 | if (arg3) { |
| 5521 | if (copy_from_user_timeval(&tv[0], arg3) |
| 5522 | || copy_from_user_timeval(&tv[1], |
| 5523 | arg3 + sizeof(struct target_timeval))) |
| 5524 | goto efault; |
| 5525 | tvp = tv; |
| 5526 | } else { |
| 5527 | tvp = NULL; |
| 5528 | } |
| 5529 | if (!(p = lock_user_string(arg2))) |
| 5530 | goto efault; |
| 5531 | ret = get_errno(sys_futimesat(arg1, path(p), tvp)); |
| 5532 | unlock_user(p, arg2, 0); |
| 5533 | } |
| 5534 | break; |
| 5535 | #endif |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5536 | #ifdef TARGET_NR_stty |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5537 | case TARGET_NR_stty: |
| 5538 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5539 | #endif |
| 5540 | #ifdef TARGET_NR_gtty |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5541 | case TARGET_NR_gtty: |
| 5542 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5543 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5544 | case TARGET_NR_access: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5545 | if (!(p = lock_user_string(arg1))) |
| 5546 | goto efault; |
Ulrich Hecht | 719f908 | 2009-07-03 17:09:29 +0200 | [diff] [blame] | 5547 | ret = get_errno(access(path(p), arg2)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5548 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5549 | break; |
ths | 92a34c1 | 2007-09-24 09:27:49 +0000 | [diff] [blame] | 5550 | #if defined(TARGET_NR_faccessat) && defined(__NR_faccessat) |
| 5551 | case TARGET_NR_faccessat: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5552 | if (!(p = lock_user_string(arg2))) |
| 5553 | goto efault; |
aurel32 | 465c9f0 | 2009-04-19 08:52:17 +0000 | [diff] [blame] | 5554 | ret = get_errno(sys_faccessat(arg1, p, arg3)); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5555 | unlock_user(p, arg2, 0); |
ths | 92a34c1 | 2007-09-24 09:27:49 +0000 | [diff] [blame] | 5556 | break; |
| 5557 | #endif |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 5558 | #ifdef TARGET_NR_nice /* not on alpha */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5559 | case TARGET_NR_nice: |
| 5560 | ret = get_errno(nice(arg1)); |
| 5561 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 5562 | #endif |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5563 | #ifdef TARGET_NR_ftime |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5564 | case TARGET_NR_ftime: |
| 5565 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5566 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5567 | case TARGET_NR_sync: |
bellard | 04369ff | 2003-03-20 22:33:23 +0000 | [diff] [blame] | 5568 | sync(); |
| 5569 | ret = 0; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5570 | break; |
| 5571 | case TARGET_NR_kill: |
pbrook | 4cb0596 | 2008-05-30 18:05:19 +0000 | [diff] [blame] | 5572 | ret = get_errno(kill(arg1, target_to_host_signal(arg2))); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5573 | break; |
| 5574 | case TARGET_NR_rename: |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5575 | { |
| 5576 | void *p2; |
| 5577 | p = lock_user_string(arg1); |
| 5578 | p2 = lock_user_string(arg2); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5579 | if (!p || !p2) |
| 5580 | ret = -TARGET_EFAULT; |
| 5581 | else |
| 5582 | ret = get_errno(rename(p, p2)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5583 | unlock_user(p2, arg2, 0); |
| 5584 | unlock_user(p, arg1, 0); |
| 5585 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5586 | break; |
ths | 722183f | 2007-09-24 09:24:37 +0000 | [diff] [blame] | 5587 | #if defined(TARGET_NR_renameat) && defined(__NR_renameat) |
| 5588 | case TARGET_NR_renameat: |
ths | 722183f | 2007-09-24 09:24:37 +0000 | [diff] [blame] | 5589 | { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5590 | void *p2; |
ths | 722183f | 2007-09-24 09:24:37 +0000 | [diff] [blame] | 5591 | p = lock_user_string(arg2); |
| 5592 | p2 = lock_user_string(arg4); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5593 | if (!p || !p2) |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 5594 | ret = -TARGET_EFAULT; |
ths | 722183f | 2007-09-24 09:24:37 +0000 | [diff] [blame] | 5595 | else |
| 5596 | ret = get_errno(sys_renameat(arg1, p, arg3, p2)); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5597 | unlock_user(p2, arg4, 0); |
| 5598 | unlock_user(p, arg2, 0); |
ths | 722183f | 2007-09-24 09:24:37 +0000 | [diff] [blame] | 5599 | } |
| 5600 | break; |
| 5601 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5602 | case TARGET_NR_mkdir: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5603 | if (!(p = lock_user_string(arg1))) |
| 5604 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5605 | ret = get_errno(mkdir(p, arg2)); |
| 5606 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5607 | break; |
ths | 4472ad0 | 2007-09-24 09:22:32 +0000 | [diff] [blame] | 5608 | #if defined(TARGET_NR_mkdirat) && defined(__NR_mkdirat) |
| 5609 | case TARGET_NR_mkdirat: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5610 | if (!(p = lock_user_string(arg2))) |
| 5611 | goto efault; |
| 5612 | ret = get_errno(sys_mkdirat(arg1, p, arg3)); |
| 5613 | unlock_user(p, arg2, 0); |
ths | 4472ad0 | 2007-09-24 09:22:32 +0000 | [diff] [blame] | 5614 | break; |
| 5615 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5616 | case TARGET_NR_rmdir: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5617 | if (!(p = lock_user_string(arg1))) |
| 5618 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5619 | ret = get_errno(rmdir(p)); |
| 5620 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5621 | break; |
| 5622 | case TARGET_NR_dup: |
| 5623 | ret = get_errno(dup(arg1)); |
| 5624 | break; |
| 5625 | case TARGET_NR_pipe: |
Richard Henderson | fb41a66 | 2010-05-03 10:07:52 -0700 | [diff] [blame] | 5626 | ret = do_pipe(cpu_env, arg1, 0, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5627 | break; |
Riku Voipio | 099d6b0 | 2009-05-05 12:10:04 +0300 | [diff] [blame] | 5628 | #ifdef TARGET_NR_pipe2 |
| 5629 | case TARGET_NR_pipe2: |
Richard Henderson | fb41a66 | 2010-05-03 10:07:52 -0700 | [diff] [blame] | 5630 | ret = do_pipe(cpu_env, arg1, arg2, 1); |
Riku Voipio | 099d6b0 | 2009-05-05 12:10:04 +0300 | [diff] [blame] | 5631 | break; |
| 5632 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5633 | case TARGET_NR_times: |
bellard | 32f36bc | 2003-03-30 21:29:48 +0000 | [diff] [blame] | 5634 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5635 | struct target_tms *tmsp; |
bellard | 32f36bc | 2003-03-30 21:29:48 +0000 | [diff] [blame] | 5636 | struct tms tms; |
| 5637 | ret = get_errno(times(&tms)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5638 | if (arg1) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5639 | tmsp = lock_user(VERIFY_WRITE, arg1, sizeof(struct target_tms), 0); |
| 5640 | if (!tmsp) |
| 5641 | goto efault; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 5642 | tmsp->tms_utime = tswapal(host_to_target_clock_t(tms.tms_utime)); |
| 5643 | tmsp->tms_stime = tswapal(host_to_target_clock_t(tms.tms_stime)); |
| 5644 | tmsp->tms_cutime = tswapal(host_to_target_clock_t(tms.tms_cutime)); |
| 5645 | tmsp->tms_cstime = tswapal(host_to_target_clock_t(tms.tms_cstime)); |
bellard | 32f36bc | 2003-03-30 21:29:48 +0000 | [diff] [blame] | 5646 | } |
bellard | c596ed1 | 2003-07-13 17:32:31 +0000 | [diff] [blame] | 5647 | if (!is_error(ret)) |
| 5648 | ret = host_to_target_clock_t(ret); |
bellard | 32f36bc | 2003-03-30 21:29:48 +0000 | [diff] [blame] | 5649 | } |
| 5650 | break; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5651 | #ifdef TARGET_NR_prof |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5652 | case TARGET_NR_prof: |
| 5653 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5654 | #endif |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 5655 | #ifdef TARGET_NR_signal |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5656 | case TARGET_NR_signal: |
| 5657 | goto unimplemented; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 5658 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5659 | case TARGET_NR_acct: |
aurel32 | 38d840e | 2009-01-30 19:48:17 +0000 | [diff] [blame] | 5660 | if (arg1 == 0) { |
| 5661 | ret = get_errno(acct(NULL)); |
| 5662 | } else { |
| 5663 | if (!(p = lock_user_string(arg1))) |
| 5664 | goto efault; |
| 5665 | ret = get_errno(acct(path(p))); |
| 5666 | unlock_user(p, arg1, 0); |
| 5667 | } |
pbrook | 2483668 | 2006-04-16 14:14:53 +0000 | [diff] [blame] | 5668 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 5669 | #ifdef TARGET_NR_umount2 /* not on alpha */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5670 | case TARGET_NR_umount2: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5671 | if (!(p = lock_user_string(arg1))) |
| 5672 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5673 | ret = get_errno(umount2(p, arg2)); |
| 5674 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5675 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 5676 | #endif |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5677 | #ifdef TARGET_NR_lock |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5678 | case TARGET_NR_lock: |
| 5679 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5680 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5681 | case TARGET_NR_ioctl: |
| 5682 | ret = do_ioctl(arg1, arg2, arg3); |
| 5683 | break; |
| 5684 | case TARGET_NR_fcntl: |
bellard | 9ee1fa2 | 2007-11-11 15:11:19 +0000 | [diff] [blame] | 5685 | ret = do_fcntl(arg1, arg2, arg3); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5686 | break; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5687 | #ifdef TARGET_NR_mpx |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5688 | case TARGET_NR_mpx: |
| 5689 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5690 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5691 | case TARGET_NR_setpgid: |
| 5692 | ret = get_errno(setpgid(arg1, arg2)); |
| 5693 | break; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5694 | #ifdef TARGET_NR_ulimit |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5695 | case TARGET_NR_ulimit: |
| 5696 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5697 | #endif |
| 5698 | #ifdef TARGET_NR_oldolduname |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5699 | case TARGET_NR_oldolduname: |
| 5700 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 5701 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5702 | case TARGET_NR_umask: |
| 5703 | ret = get_errno(umask(arg1)); |
| 5704 | break; |
| 5705 | case TARGET_NR_chroot: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5706 | if (!(p = lock_user_string(arg1))) |
| 5707 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5708 | ret = get_errno(chroot(p)); |
| 5709 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5710 | break; |
| 5711 | case TARGET_NR_ustat: |
| 5712 | goto unimplemented; |
| 5713 | case TARGET_NR_dup2: |
| 5714 | ret = get_errno(dup2(arg1, arg2)); |
| 5715 | break; |
Ulrich Hecht | d092793 | 2009-09-17 20:22:14 +0300 | [diff] [blame] | 5716 | #if defined(CONFIG_DUP3) && defined(TARGET_NR_dup3) |
| 5717 | case TARGET_NR_dup3: |
| 5718 | ret = get_errno(dup3(arg1, arg2, arg3)); |
| 5719 | break; |
| 5720 | #endif |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 5721 | #ifdef TARGET_NR_getppid /* not on alpha */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5722 | case TARGET_NR_getppid: |
| 5723 | ret = get_errno(getppid()); |
| 5724 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 5725 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5726 | case TARGET_NR_getpgrp: |
| 5727 | ret = get_errno(getpgrp()); |
| 5728 | break; |
| 5729 | case TARGET_NR_setsid: |
| 5730 | ret = get_errno(setsid()); |
| 5731 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 5732 | #ifdef TARGET_NR_sigaction |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5733 | case TARGET_NR_sigaction: |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5734 | { |
Richard Henderson | 6049f4f | 2009-12-27 18:30:03 -0800 | [diff] [blame] | 5735 | #if defined(TARGET_ALPHA) |
| 5736 | struct target_sigaction act, oact, *pact = 0; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5737 | struct target_old_sigaction *old_act; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5738 | if (arg2) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5739 | if (!lock_user_struct(VERIFY_READ, old_act, arg2, 1)) |
| 5740 | goto efault; |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 5741 | act._sa_handler = old_act->_sa_handler; |
| 5742 | target_siginitset(&act.sa_mask, old_act->sa_mask); |
| 5743 | act.sa_flags = old_act->sa_flags; |
Richard Henderson | 6049f4f | 2009-12-27 18:30:03 -0800 | [diff] [blame] | 5744 | act.sa_restorer = 0; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5745 | unlock_user_struct(old_act, arg2, 0); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 5746 | pact = &act; |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 5747 | } |
| 5748 | ret = get_errno(do_sigaction(arg1, pact, &oact)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5749 | if (!is_error(ret) && arg3) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5750 | if (!lock_user_struct(VERIFY_WRITE, old_act, arg3, 0)) |
| 5751 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5752 | old_act->_sa_handler = oact._sa_handler; |
| 5753 | old_act->sa_mask = oact.sa_mask.sig[0]; |
| 5754 | old_act->sa_flags = oact.sa_flags; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5755 | unlock_user_struct(old_act, arg3, 1); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 5756 | } |
Richard Henderson | 6049f4f | 2009-12-27 18:30:03 -0800 | [diff] [blame] | 5757 | #elif defined(TARGET_MIPS) |
bellard | 106ec87 | 2006-06-27 21:08:10 +0000 | [diff] [blame] | 5758 | struct target_sigaction act, oact, *pact, *old_act; |
| 5759 | |
| 5760 | if (arg2) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5761 | if (!lock_user_struct(VERIFY_READ, old_act, arg2, 1)) |
| 5762 | goto efault; |
bellard | 106ec87 | 2006-06-27 21:08:10 +0000 | [diff] [blame] | 5763 | act._sa_handler = old_act->_sa_handler; |
| 5764 | target_siginitset(&act.sa_mask, old_act->sa_mask.sig[0]); |
| 5765 | act.sa_flags = old_act->sa_flags; |
| 5766 | unlock_user_struct(old_act, arg2, 0); |
| 5767 | pact = &act; |
| 5768 | } else { |
| 5769 | pact = NULL; |
| 5770 | } |
| 5771 | |
| 5772 | ret = get_errno(do_sigaction(arg1, pact, &oact)); |
| 5773 | |
| 5774 | if (!is_error(ret) && arg3) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5775 | if (!lock_user_struct(VERIFY_WRITE, old_act, arg3, 0)) |
| 5776 | goto efault; |
bellard | 106ec87 | 2006-06-27 21:08:10 +0000 | [diff] [blame] | 5777 | old_act->_sa_handler = oact._sa_handler; |
| 5778 | old_act->sa_flags = oact.sa_flags; |
| 5779 | old_act->sa_mask.sig[0] = oact.sa_mask.sig[0]; |
| 5780 | old_act->sa_mask.sig[1] = 0; |
| 5781 | old_act->sa_mask.sig[2] = 0; |
| 5782 | old_act->sa_mask.sig[3] = 0; |
| 5783 | unlock_user_struct(old_act, arg3, 1); |
| 5784 | } |
Richard Henderson | 6049f4f | 2009-12-27 18:30:03 -0800 | [diff] [blame] | 5785 | #else |
| 5786 | struct target_old_sigaction *old_act; |
| 5787 | struct target_sigaction act, oact, *pact; |
| 5788 | if (arg2) { |
| 5789 | if (!lock_user_struct(VERIFY_READ, old_act, arg2, 1)) |
| 5790 | goto efault; |
| 5791 | act._sa_handler = old_act->_sa_handler; |
| 5792 | target_siginitset(&act.sa_mask, old_act->sa_mask); |
| 5793 | act.sa_flags = old_act->sa_flags; |
| 5794 | act.sa_restorer = old_act->sa_restorer; |
| 5795 | unlock_user_struct(old_act, arg2, 0); |
| 5796 | pact = &act; |
| 5797 | } else { |
| 5798 | pact = NULL; |
| 5799 | } |
| 5800 | ret = get_errno(do_sigaction(arg1, pact, &oact)); |
| 5801 | if (!is_error(ret) && arg3) { |
| 5802 | if (!lock_user_struct(VERIFY_WRITE, old_act, arg3, 0)) |
| 5803 | goto efault; |
| 5804 | old_act->_sa_handler = oact._sa_handler; |
| 5805 | old_act->sa_mask = oact.sa_mask.sig[0]; |
| 5806 | old_act->sa_flags = oact.sa_flags; |
| 5807 | old_act->sa_restorer = oact.sa_restorer; |
| 5808 | unlock_user_struct(old_act, arg3, 1); |
| 5809 | } |
ths | 388bb21 | 2007-05-13 13:58:00 +0000 | [diff] [blame] | 5810 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5811 | } |
| 5812 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 5813 | #endif |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 5814 | case TARGET_NR_rt_sigaction: |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5815 | { |
Richard Henderson | 6049f4f | 2009-12-27 18:30:03 -0800 | [diff] [blame] | 5816 | #if defined(TARGET_ALPHA) |
| 5817 | struct target_sigaction act, oact, *pact = 0; |
| 5818 | struct target_rt_sigaction *rt_act; |
| 5819 | /* ??? arg4 == sizeof(sigset_t). */ |
| 5820 | if (arg2) { |
| 5821 | if (!lock_user_struct(VERIFY_READ, rt_act, arg2, 1)) |
| 5822 | goto efault; |
| 5823 | act._sa_handler = rt_act->_sa_handler; |
| 5824 | act.sa_mask = rt_act->sa_mask; |
| 5825 | act.sa_flags = rt_act->sa_flags; |
| 5826 | act.sa_restorer = arg5; |
| 5827 | unlock_user_struct(rt_act, arg2, 0); |
| 5828 | pact = &act; |
| 5829 | } |
| 5830 | ret = get_errno(do_sigaction(arg1, pact, &oact)); |
| 5831 | if (!is_error(ret) && arg3) { |
| 5832 | if (!lock_user_struct(VERIFY_WRITE, rt_act, arg3, 0)) |
| 5833 | goto efault; |
| 5834 | rt_act->_sa_handler = oact._sa_handler; |
| 5835 | rt_act->sa_mask = oact.sa_mask; |
| 5836 | rt_act->sa_flags = oact.sa_flags; |
| 5837 | unlock_user_struct(rt_act, arg3, 1); |
| 5838 | } |
| 5839 | #else |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5840 | struct target_sigaction *act; |
| 5841 | struct target_sigaction *oact; |
| 5842 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5843 | if (arg2) { |
| 5844 | if (!lock_user_struct(VERIFY_READ, act, arg2, 1)) |
| 5845 | goto efault; |
| 5846 | } else |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5847 | act = NULL; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5848 | if (arg3) { |
| 5849 | if (!lock_user_struct(VERIFY_WRITE, oact, arg3, 0)) { |
| 5850 | ret = -TARGET_EFAULT; |
| 5851 | goto rt_sigaction_fail; |
| 5852 | } |
| 5853 | } else |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5854 | oact = NULL; |
| 5855 | ret = get_errno(do_sigaction(arg1, act, oact)); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5856 | rt_sigaction_fail: |
| 5857 | if (act) |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5858 | unlock_user_struct(act, arg2, 0); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5859 | if (oact) |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5860 | unlock_user_struct(oact, arg3, 1); |
Richard Henderson | 6049f4f | 2009-12-27 18:30:03 -0800 | [diff] [blame] | 5861 | #endif |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5862 | } |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 5863 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 5864 | #ifdef TARGET_NR_sgetmask /* not on alpha */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5865 | case TARGET_NR_sgetmask: |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 5866 | { |
| 5867 | sigset_t cur_set; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 5868 | abi_ulong target_set; |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 5869 | sigprocmask(0, NULL, &cur_set); |
| 5870 | host_to_target_old_sigset(&target_set, &cur_set); |
| 5871 | ret = target_set; |
| 5872 | } |
| 5873 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 5874 | #endif |
| 5875 | #ifdef TARGET_NR_ssetmask /* not on alpha */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5876 | case TARGET_NR_ssetmask: |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 5877 | { |
| 5878 | sigset_t set, oset, cur_set; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 5879 | abi_ulong target_set = arg1; |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 5880 | sigprocmask(0, NULL, &cur_set); |
| 5881 | target_to_host_old_sigset(&set, &target_set); |
| 5882 | sigorset(&set, &set, &cur_set); |
| 5883 | sigprocmask(SIG_SETMASK, &set, &oset); |
| 5884 | host_to_target_old_sigset(&target_set, &oset); |
| 5885 | ret = target_set; |
| 5886 | } |
| 5887 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 5888 | #endif |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 5889 | #ifdef TARGET_NR_sigprocmask |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 5890 | case TARGET_NR_sigprocmask: |
| 5891 | { |
Richard Henderson | a5b3b13 | 2010-05-03 10:07:55 -0700 | [diff] [blame] | 5892 | #if defined(TARGET_ALPHA) |
| 5893 | sigset_t set, oldset; |
| 5894 | abi_ulong mask; |
| 5895 | int how; |
| 5896 | |
| 5897 | switch (arg1) { |
| 5898 | case TARGET_SIG_BLOCK: |
| 5899 | how = SIG_BLOCK; |
| 5900 | break; |
| 5901 | case TARGET_SIG_UNBLOCK: |
| 5902 | how = SIG_UNBLOCK; |
| 5903 | break; |
| 5904 | case TARGET_SIG_SETMASK: |
| 5905 | how = SIG_SETMASK; |
| 5906 | break; |
| 5907 | default: |
| 5908 | ret = -TARGET_EINVAL; |
| 5909 | goto fail; |
| 5910 | } |
| 5911 | mask = arg2; |
| 5912 | target_to_host_old_sigset(&set, &mask); |
| 5913 | |
| 5914 | ret = get_errno(sigprocmask(how, &set, &oldset)); |
| 5915 | |
| 5916 | if (!is_error(ret)) { |
| 5917 | host_to_target_old_sigset(&mask, &oldset); |
| 5918 | ret = mask; |
| 5919 | ((CPUAlphaState *)cpu_env)->[IR_V0] = 0; /* force no error */ |
| 5920 | } |
| 5921 | #else |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 5922 | sigset_t set, oldset, *set_ptr; |
Richard Henderson | a5b3b13 | 2010-05-03 10:07:55 -0700 | [diff] [blame] | 5923 | int how; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 5924 | |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5925 | if (arg2) { |
Richard Henderson | a5b3b13 | 2010-05-03 10:07:55 -0700 | [diff] [blame] | 5926 | switch (arg1) { |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 5927 | case TARGET_SIG_BLOCK: |
| 5928 | how = SIG_BLOCK; |
| 5929 | break; |
| 5930 | case TARGET_SIG_UNBLOCK: |
| 5931 | how = SIG_UNBLOCK; |
| 5932 | break; |
| 5933 | case TARGET_SIG_SETMASK: |
| 5934 | how = SIG_SETMASK; |
| 5935 | break; |
| 5936 | default: |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 5937 | ret = -TARGET_EINVAL; |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 5938 | goto fail; |
| 5939 | } |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 5940 | if (!(p = lock_user(VERIFY_READ, arg2, sizeof(target_sigset_t), 1))) |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5941 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5942 | target_to_host_old_sigset(&set, p); |
| 5943 | unlock_user(p, arg2, 0); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 5944 | set_ptr = &set; |
| 5945 | } else { |
| 5946 | how = 0; |
| 5947 | set_ptr = NULL; |
| 5948 | } |
Richard Henderson | a5b3b13 | 2010-05-03 10:07:55 -0700 | [diff] [blame] | 5949 | ret = get_errno(sigprocmask(how, set_ptr, &oldset)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5950 | if (!is_error(ret) && arg3) { |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 5951 | if (!(p = lock_user(VERIFY_WRITE, arg3, sizeof(target_sigset_t), 0))) |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5952 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5953 | host_to_target_old_sigset(p, &oldset); |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 5954 | unlock_user(p, arg3, sizeof(target_sigset_t)); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 5955 | } |
Richard Henderson | a5b3b13 | 2010-05-03 10:07:55 -0700 | [diff] [blame] | 5956 | #endif |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 5957 | } |
| 5958 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 5959 | #endif |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 5960 | case TARGET_NR_rt_sigprocmask: |
| 5961 | { |
| 5962 | int how = arg1; |
| 5963 | sigset_t set, oldset, *set_ptr; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 5964 | |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5965 | if (arg2) { |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 5966 | switch(how) { |
| 5967 | case TARGET_SIG_BLOCK: |
| 5968 | how = SIG_BLOCK; |
| 5969 | break; |
| 5970 | case TARGET_SIG_UNBLOCK: |
| 5971 | how = SIG_UNBLOCK; |
| 5972 | break; |
| 5973 | case TARGET_SIG_SETMASK: |
| 5974 | how = SIG_SETMASK; |
| 5975 | break; |
| 5976 | default: |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 5977 | ret = -TARGET_EINVAL; |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 5978 | goto fail; |
| 5979 | } |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 5980 | if (!(p = lock_user(VERIFY_READ, arg2, sizeof(target_sigset_t), 1))) |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5981 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5982 | target_to_host_sigset(&set, p); |
| 5983 | unlock_user(p, arg2, 0); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 5984 | set_ptr = &set; |
| 5985 | } else { |
| 5986 | how = 0; |
| 5987 | set_ptr = NULL; |
| 5988 | } |
| 5989 | ret = get_errno(sigprocmask(how, set_ptr, &oldset)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5990 | if (!is_error(ret) && arg3) { |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 5991 | if (!(p = lock_user(VERIFY_WRITE, arg3, sizeof(target_sigset_t), 0))) |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5992 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5993 | host_to_target_sigset(p, &oldset); |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 5994 | unlock_user(p, arg3, sizeof(target_sigset_t)); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 5995 | } |
| 5996 | } |
| 5997 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 5998 | #ifdef TARGET_NR_sigpending |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 5999 | case TARGET_NR_sigpending: |
| 6000 | { |
| 6001 | sigset_t set; |
| 6002 | ret = get_errno(sigpending(&set)); |
| 6003 | if (!is_error(ret)) { |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6004 | if (!(p = lock_user(VERIFY_WRITE, arg1, sizeof(target_sigset_t), 0))) |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6005 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6006 | host_to_target_old_sigset(p, &set); |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6007 | unlock_user(p, arg1, sizeof(target_sigset_t)); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6008 | } |
| 6009 | } |
| 6010 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6011 | #endif |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6012 | case TARGET_NR_rt_sigpending: |
| 6013 | { |
| 6014 | sigset_t set; |
| 6015 | ret = get_errno(sigpending(&set)); |
| 6016 | if (!is_error(ret)) { |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6017 | if (!(p = lock_user(VERIFY_WRITE, arg1, sizeof(target_sigset_t), 0))) |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6018 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6019 | host_to_target_sigset(p, &set); |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6020 | unlock_user(p, arg1, sizeof(target_sigset_t)); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6021 | } |
| 6022 | } |
| 6023 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6024 | #ifdef TARGET_NR_sigsuspend |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6025 | case TARGET_NR_sigsuspend: |
| 6026 | { |
| 6027 | sigset_t set; |
Richard Henderson | f43ce12 | 2010-05-03 10:07:54 -0700 | [diff] [blame] | 6028 | #if defined(TARGET_ALPHA) |
| 6029 | abi_ulong mask = arg1; |
| 6030 | target_to_host_old_sigset(&set, &mask); |
| 6031 | #else |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6032 | if (!(p = lock_user(VERIFY_READ, arg1, sizeof(target_sigset_t), 1))) |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6033 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6034 | target_to_host_old_sigset(&set, p); |
| 6035 | unlock_user(p, arg1, 0); |
Richard Henderson | f43ce12 | 2010-05-03 10:07:54 -0700 | [diff] [blame] | 6036 | #endif |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6037 | ret = get_errno(sigsuspend(&set)); |
| 6038 | } |
| 6039 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6040 | #endif |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6041 | case TARGET_NR_rt_sigsuspend: |
| 6042 | { |
| 6043 | sigset_t set; |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6044 | if (!(p = lock_user(VERIFY_READ, arg1, sizeof(target_sigset_t), 1))) |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6045 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6046 | target_to_host_sigset(&set, p); |
| 6047 | unlock_user(p, arg1, 0); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6048 | ret = get_errno(sigsuspend(&set)); |
| 6049 | } |
| 6050 | break; |
| 6051 | case TARGET_NR_rt_sigtimedwait: |
| 6052 | { |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6053 | sigset_t set; |
| 6054 | struct timespec uts, *puts; |
| 6055 | siginfo_t uinfo; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 6056 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6057 | if (!(p = lock_user(VERIFY_READ, arg1, sizeof(target_sigset_t), 1))) |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6058 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6059 | target_to_host_sigset(&set, p); |
| 6060 | unlock_user(p, arg1, 0); |
| 6061 | if (arg3) { |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6062 | puts = &uts; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6063 | target_to_host_timespec(puts, arg3); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6064 | } else { |
| 6065 | puts = NULL; |
| 6066 | } |
| 6067 | ret = get_errno(sigtimedwait(&set, &uinfo, puts)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6068 | if (!is_error(ret) && arg2) { |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6069 | if (!(p = lock_user(VERIFY_WRITE, arg2, sizeof(target_siginfo_t), 0))) |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6070 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6071 | host_to_target_siginfo(p, &uinfo); |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6072 | unlock_user(p, arg2, sizeof(target_siginfo_t)); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6073 | } |
| 6074 | } |
| 6075 | break; |
| 6076 | case TARGET_NR_rt_sigqueueinfo: |
| 6077 | { |
| 6078 | siginfo_t uinfo; |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6079 | if (!(p = lock_user(VERIFY_READ, arg3, sizeof(target_sigset_t), 1))) |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6080 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6081 | target_to_host_siginfo(&uinfo, p); |
| 6082 | unlock_user(p, arg1, 0); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6083 | ret = get_errno(sys_rt_sigqueueinfo(arg1, arg2, &uinfo)); |
| 6084 | } |
| 6085 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6086 | #ifdef TARGET_NR_sigreturn |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6087 | case TARGET_NR_sigreturn: |
| 6088 | /* NOTE: ret is eax, so not transcoding must be done */ |
| 6089 | ret = do_sigreturn(cpu_env); |
| 6090 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6091 | #endif |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6092 | case TARGET_NR_rt_sigreturn: |
| 6093 | /* NOTE: ret is eax, so not transcoding must be done */ |
| 6094 | ret = do_rt_sigreturn(cpu_env); |
| 6095 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6096 | case TARGET_NR_sethostname: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6097 | if (!(p = lock_user_string(arg1))) |
| 6098 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6099 | ret = get_errno(sethostname(p, arg2)); |
| 6100 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6101 | break; |
| 6102 | case TARGET_NR_setrlimit: |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6103 | { |
Wesley W. Terpstra | e22b701 | 2011-07-12 14:42:00 +0300 | [diff] [blame] | 6104 | int resource = target_to_host_resource(arg1); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6105 | struct target_rlimit *target_rlim; |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6106 | struct rlimit rlim; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6107 | if (!lock_user_struct(VERIFY_READ, target_rlim, arg2, 1)) |
| 6108 | goto efault; |
takasi-y@ops.dti.ne.jp | 81bbe90 | 2010-04-12 04:07:35 +0900 | [diff] [blame] | 6109 | rlim.rlim_cur = target_to_host_rlim(target_rlim->rlim_cur); |
| 6110 | rlim.rlim_max = target_to_host_rlim(target_rlim->rlim_max); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6111 | unlock_user_struct(target_rlim, arg2, 0); |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6112 | ret = get_errno(setrlimit(resource, &rlim)); |
| 6113 | } |
| 6114 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6115 | case TARGET_NR_getrlimit: |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6116 | { |
Wesley W. Terpstra | e22b701 | 2011-07-12 14:42:00 +0300 | [diff] [blame] | 6117 | int resource = target_to_host_resource(arg1); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6118 | struct target_rlimit *target_rlim; |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6119 | struct rlimit rlim; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 6120 | |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6121 | ret = get_errno(getrlimit(resource, &rlim)); |
| 6122 | if (!is_error(ret)) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6123 | if (!lock_user_struct(VERIFY_WRITE, target_rlim, arg2, 0)) |
| 6124 | goto efault; |
takasi-y@ops.dti.ne.jp | 81bbe90 | 2010-04-12 04:07:35 +0900 | [diff] [blame] | 6125 | target_rlim->rlim_cur = host_to_target_rlim(rlim.rlim_cur); |
| 6126 | target_rlim->rlim_max = host_to_target_rlim(rlim.rlim_max); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6127 | unlock_user_struct(target_rlim, arg2, 1); |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6128 | } |
| 6129 | } |
| 6130 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6131 | case TARGET_NR_getrusage: |
bellard | b409186 | 2003-05-16 15:39:34 +0000 | [diff] [blame] | 6132 | { |
| 6133 | struct rusage rusage; |
bellard | b409186 | 2003-05-16 15:39:34 +0000 | [diff] [blame] | 6134 | ret = get_errno(getrusage(arg1, &rusage)); |
| 6135 | if (!is_error(ret)) { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6136 | host_to_target_rusage(arg2, &rusage); |
bellard | b409186 | 2003-05-16 15:39:34 +0000 | [diff] [blame] | 6137 | } |
| 6138 | } |
| 6139 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6140 | case TARGET_NR_gettimeofday: |
| 6141 | { |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6142 | struct timeval tv; |
| 6143 | ret = get_errno(gettimeofday(&tv, NULL)); |
| 6144 | if (!is_error(ret)) { |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 6145 | if (copy_to_user_timeval(arg1, &tv)) |
| 6146 | goto efault; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6147 | } |
| 6148 | } |
| 6149 | break; |
| 6150 | case TARGET_NR_settimeofday: |
| 6151 | { |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6152 | struct timeval tv; |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 6153 | if (copy_from_user_timeval(&tv, arg1)) |
| 6154 | goto efault; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6155 | ret = get_errno(settimeofday(&tv, NULL)); |
| 6156 | } |
| 6157 | break; |
Ulrich Hecht | a4c075f | 2009-07-24 16:57:31 +0200 | [diff] [blame] | 6158 | #if defined(TARGET_NR_select) && !defined(TARGET_S390X) && !defined(TARGET_S390) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6159 | case TARGET_NR_select: |
bellard | f2674e3 | 2003-07-09 12:26:09 +0000 | [diff] [blame] | 6160 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6161 | struct target_sel_arg_struct *sel; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 6162 | abi_ulong inp, outp, exp, tvp; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6163 | long nsel; |
| 6164 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6165 | if (!lock_user_struct(VERIFY_READ, sel, arg1, 1)) |
| 6166 | goto efault; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 6167 | nsel = tswapal(sel->n); |
| 6168 | inp = tswapal(sel->inp); |
| 6169 | outp = tswapal(sel->outp); |
| 6170 | exp = tswapal(sel->exp); |
| 6171 | tvp = tswapal(sel->tvp); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6172 | unlock_user_struct(sel, arg1, 0); |
| 6173 | ret = do_select(nsel, inp, outp, exp, tvp); |
bellard | f2674e3 | 2003-07-09 12:26:09 +0000 | [diff] [blame] | 6174 | } |
| 6175 | break; |
bellard | 048f6b4 | 2005-11-26 18:47:20 +0000 | [diff] [blame] | 6176 | #endif |
Riku Voipio | 9e42382 | 2010-05-07 12:28:05 +0000 | [diff] [blame] | 6177 | #ifdef TARGET_NR_pselect6 |
| 6178 | case TARGET_NR_pselect6: |
Mike Frysinger | 055e090 | 2011-06-03 17:01:49 -0400 | [diff] [blame] | 6179 | { |
| 6180 | abi_long rfd_addr, wfd_addr, efd_addr, n, ts_addr; |
| 6181 | fd_set rfds, wfds, efds; |
| 6182 | fd_set *rfds_ptr, *wfds_ptr, *efds_ptr; |
| 6183 | struct timespec ts, *ts_ptr; |
| 6184 | |
| 6185 | /* |
| 6186 | * The 6th arg is actually two args smashed together, |
| 6187 | * so we cannot use the C library. |
| 6188 | */ |
| 6189 | sigset_t set; |
| 6190 | struct { |
| 6191 | sigset_t *set; |
| 6192 | size_t size; |
| 6193 | } sig, *sig_ptr; |
| 6194 | |
| 6195 | abi_ulong arg_sigset, arg_sigsize, *arg7; |
| 6196 | target_sigset_t *target_sigset; |
| 6197 | |
| 6198 | n = arg1; |
| 6199 | rfd_addr = arg2; |
| 6200 | wfd_addr = arg3; |
| 6201 | efd_addr = arg4; |
| 6202 | ts_addr = arg5; |
| 6203 | |
| 6204 | ret = copy_from_user_fdset_ptr(&rfds, &rfds_ptr, rfd_addr, n); |
| 6205 | if (ret) { |
| 6206 | goto fail; |
| 6207 | } |
| 6208 | ret = copy_from_user_fdset_ptr(&wfds, &wfds_ptr, wfd_addr, n); |
| 6209 | if (ret) { |
| 6210 | goto fail; |
| 6211 | } |
| 6212 | ret = copy_from_user_fdset_ptr(&efds, &efds_ptr, efd_addr, n); |
| 6213 | if (ret) { |
| 6214 | goto fail; |
| 6215 | } |
| 6216 | |
| 6217 | /* |
| 6218 | * This takes a timespec, and not a timeval, so we cannot |
| 6219 | * use the do_select() helper ... |
| 6220 | */ |
| 6221 | if (ts_addr) { |
| 6222 | if (target_to_host_timespec(&ts, ts_addr)) { |
| 6223 | goto efault; |
| 6224 | } |
| 6225 | ts_ptr = &ts; |
| 6226 | } else { |
| 6227 | ts_ptr = NULL; |
| 6228 | } |
| 6229 | |
| 6230 | /* Extract the two packed args for the sigset */ |
| 6231 | if (arg6) { |
| 6232 | sig_ptr = &sig; |
| 6233 | sig.size = _NSIG / 8; |
| 6234 | |
| 6235 | arg7 = lock_user(VERIFY_READ, arg6, sizeof(*arg7) * 2, 1); |
| 6236 | if (!arg7) { |
| 6237 | goto efault; |
| 6238 | } |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 6239 | arg_sigset = tswapal(arg7[0]); |
| 6240 | arg_sigsize = tswapal(arg7[1]); |
Mike Frysinger | 055e090 | 2011-06-03 17:01:49 -0400 | [diff] [blame] | 6241 | unlock_user(arg7, arg6, 0); |
| 6242 | |
| 6243 | if (arg_sigset) { |
| 6244 | sig.set = &set; |
Peter Maydell | 8f04eeb | 2011-06-28 12:21:57 +0100 | [diff] [blame] | 6245 | if (arg_sigsize != sizeof(*target_sigset)) { |
| 6246 | /* Like the kernel, we enforce correct size sigsets */ |
| 6247 | ret = -TARGET_EINVAL; |
| 6248 | goto fail; |
| 6249 | } |
Mike Frysinger | 055e090 | 2011-06-03 17:01:49 -0400 | [diff] [blame] | 6250 | target_sigset = lock_user(VERIFY_READ, arg_sigset, |
| 6251 | sizeof(*target_sigset), 1); |
| 6252 | if (!target_sigset) { |
| 6253 | goto efault; |
| 6254 | } |
| 6255 | target_to_host_sigset(&set, target_sigset); |
| 6256 | unlock_user(target_sigset, arg_sigset, 0); |
| 6257 | } else { |
| 6258 | sig.set = NULL; |
| 6259 | } |
| 6260 | } else { |
| 6261 | sig_ptr = NULL; |
| 6262 | } |
| 6263 | |
| 6264 | ret = get_errno(sys_pselect6(n, rfds_ptr, wfds_ptr, efds_ptr, |
| 6265 | ts_ptr, sig_ptr)); |
| 6266 | |
| 6267 | if (!is_error(ret)) { |
| 6268 | if (rfd_addr && copy_to_user_fdset(rfd_addr, &rfds, n)) |
| 6269 | goto efault; |
| 6270 | if (wfd_addr && copy_to_user_fdset(wfd_addr, &wfds, n)) |
| 6271 | goto efault; |
| 6272 | if (efd_addr && copy_to_user_fdset(efd_addr, &efds, n)) |
| 6273 | goto efault; |
| 6274 | |
| 6275 | if (ts_addr && host_to_target_timespec(ts_addr, &ts)) |
| 6276 | goto efault; |
| 6277 | } |
| 6278 | } |
| 6279 | break; |
Riku Voipio | 9e42382 | 2010-05-07 12:28:05 +0000 | [diff] [blame] | 6280 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6281 | case TARGET_NR_symlink: |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6282 | { |
| 6283 | void *p2; |
| 6284 | p = lock_user_string(arg1); |
| 6285 | p2 = lock_user_string(arg2); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6286 | if (!p || !p2) |
| 6287 | ret = -TARGET_EFAULT; |
| 6288 | else |
| 6289 | ret = get_errno(symlink(p, p2)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6290 | unlock_user(p2, arg2, 0); |
| 6291 | unlock_user(p, arg1, 0); |
| 6292 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6293 | break; |
ths | f0b6243 | 2007-09-24 09:25:40 +0000 | [diff] [blame] | 6294 | #if defined(TARGET_NR_symlinkat) && defined(__NR_symlinkat) |
| 6295 | case TARGET_NR_symlinkat: |
ths | f0b6243 | 2007-09-24 09:25:40 +0000 | [diff] [blame] | 6296 | { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6297 | void *p2; |
ths | f0b6243 | 2007-09-24 09:25:40 +0000 | [diff] [blame] | 6298 | p = lock_user_string(arg1); |
| 6299 | p2 = lock_user_string(arg3); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6300 | if (!p || !p2) |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 6301 | ret = -TARGET_EFAULT; |
ths | f0b6243 | 2007-09-24 09:25:40 +0000 | [diff] [blame] | 6302 | else |
| 6303 | ret = get_errno(sys_symlinkat(p, arg2, p2)); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6304 | unlock_user(p2, arg3, 0); |
| 6305 | unlock_user(p, arg1, 0); |
ths | f0b6243 | 2007-09-24 09:25:40 +0000 | [diff] [blame] | 6306 | } |
| 6307 | break; |
| 6308 | #endif |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6309 | #ifdef TARGET_NR_oldlstat |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6310 | case TARGET_NR_oldlstat: |
| 6311 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6312 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6313 | case TARGET_NR_readlink: |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6314 | { |
aurel32 | d088d66 | 2009-01-30 20:09:01 +0000 | [diff] [blame] | 6315 | void *p2, *temp; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6316 | p = lock_user_string(arg1); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6317 | p2 = lock_user(VERIFY_WRITE, arg2, arg3, 0); |
| 6318 | if (!p || !p2) |
| 6319 | ret = -TARGET_EFAULT; |
aurel32 | d088d66 | 2009-01-30 20:09:01 +0000 | [diff] [blame] | 6320 | else { |
| 6321 | if (strncmp((const char *)p, "/proc/self/exe", 14) == 0) { |
| 6322 | char real[PATH_MAX]; |
| 6323 | temp = realpath(exec_path,real); |
| 6324 | ret = (temp==NULL) ? get_errno(-1) : strlen(real) ; |
| 6325 | snprintf((char *)p2, arg3, "%s", real); |
| 6326 | } |
| 6327 | else |
| 6328 | ret = get_errno(readlink(path(p), p2, arg3)); |
aurel32 | d088d66 | 2009-01-30 20:09:01 +0000 | [diff] [blame] | 6329 | } |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6330 | unlock_user(p2, arg2, ret); |
| 6331 | unlock_user(p, arg1, 0); |
| 6332 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6333 | break; |
ths | 5e0ccb1 | 2007-09-24 09:26:10 +0000 | [diff] [blame] | 6334 | #if defined(TARGET_NR_readlinkat) && defined(__NR_readlinkat) |
| 6335 | case TARGET_NR_readlinkat: |
ths | 5e0ccb1 | 2007-09-24 09:26:10 +0000 | [diff] [blame] | 6336 | { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6337 | void *p2; |
ths | 5e0ccb1 | 2007-09-24 09:26:10 +0000 | [diff] [blame] | 6338 | p = lock_user_string(arg2); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6339 | p2 = lock_user(VERIFY_WRITE, arg3, arg4, 0); |
| 6340 | if (!p || !p2) |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 6341 | ret = -TARGET_EFAULT; |
ths | 5e0ccb1 | 2007-09-24 09:26:10 +0000 | [diff] [blame] | 6342 | else |
| 6343 | ret = get_errno(sys_readlinkat(arg1, path(p), p2, arg4)); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6344 | unlock_user(p2, arg3, ret); |
| 6345 | unlock_user(p, arg2, 0); |
ths | 5e0ccb1 | 2007-09-24 09:26:10 +0000 | [diff] [blame] | 6346 | } |
| 6347 | break; |
| 6348 | #endif |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6349 | #ifdef TARGET_NR_uselib |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6350 | case TARGET_NR_uselib: |
| 6351 | goto unimplemented; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6352 | #endif |
| 6353 | #ifdef TARGET_NR_swapon |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6354 | case TARGET_NR_swapon: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6355 | if (!(p = lock_user_string(arg1))) |
| 6356 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6357 | ret = get_errno(swapon(p, arg2)); |
| 6358 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6359 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6360 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6361 | case TARGET_NR_reboot: |
Alexander Graf | 0f6b4d2 | 2011-09-27 14:39:42 +0200 | [diff] [blame] | 6362 | if (!(p = lock_user_string(arg4))) |
| 6363 | goto efault; |
| 6364 | ret = reboot(arg1, arg2, arg3, p); |
| 6365 | unlock_user(p, arg4, 0); |
| 6366 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6367 | #ifdef TARGET_NR_readdir |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6368 | case TARGET_NR_readdir: |
| 6369 | goto unimplemented; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6370 | #endif |
| 6371 | #ifdef TARGET_NR_mmap |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6372 | case TARGET_NR_mmap: |
Ulrich Hecht | a4c075f | 2009-07-24 16:57:31 +0200 | [diff] [blame] | 6373 | #if (defined(TARGET_I386) && defined(TARGET_ABI32)) || defined(TARGET_ARM) || \ |
| 6374 | defined(TARGET_M68K) || defined(TARGET_CRIS) || defined(TARGET_MICROBLAZE) \ |
| 6375 | || defined(TARGET_S390X) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6376 | { |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 6377 | abi_ulong *v; |
| 6378 | abi_ulong v1, v2, v3, v4, v5, v6; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6379 | if (!(v = lock_user(VERIFY_READ, arg1, 6 * sizeof(abi_ulong), 1))) |
| 6380 | goto efault; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 6381 | v1 = tswapal(v[0]); |
| 6382 | v2 = tswapal(v[1]); |
| 6383 | v3 = tswapal(v[2]); |
| 6384 | v4 = tswapal(v[3]); |
| 6385 | v5 = tswapal(v[4]); |
| 6386 | v6 = tswapal(v[5]); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6387 | unlock_user(v, arg1, 0); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 6388 | ret = get_errno(target_mmap(v1, v2, v3, |
bellard | 5286db7 | 2003-06-05 00:57:30 +0000 | [diff] [blame] | 6389 | target_to_host_bitmask(v4, mmap_flags_tbl), |
| 6390 | v5, v6)); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6391 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6392 | #else |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 6393 | ret = get_errno(target_mmap(arg1, arg2, arg3, |
| 6394 | target_to_host_bitmask(arg4, mmap_flags_tbl), |
bellard | 6fb883e | 2003-07-09 17:12:39 +0000 | [diff] [blame] | 6395 | arg5, |
| 6396 | arg6)); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6397 | #endif |
bellard | 6fb883e | 2003-07-09 17:12:39 +0000 | [diff] [blame] | 6398 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6399 | #endif |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 6400 | #ifdef TARGET_NR_mmap2 |
bellard | 6fb883e | 2003-07-09 17:12:39 +0000 | [diff] [blame] | 6401 | case TARGET_NR_mmap2: |
pbrook | bb7ec04 | 2008-03-25 22:28:25 +0000 | [diff] [blame] | 6402 | #ifndef MMAP_SHIFT |
bellard | c573ff6 | 2004-01-04 15:51:36 +0000 | [diff] [blame] | 6403 | #define MMAP_SHIFT 12 |
bellard | c573ff6 | 2004-01-04 15:51:36 +0000 | [diff] [blame] | 6404 | #endif |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 6405 | ret = get_errno(target_mmap(arg1, arg2, arg3, |
| 6406 | target_to_host_bitmask(arg4, mmap_flags_tbl), |
bellard | 5286db7 | 2003-06-05 00:57:30 +0000 | [diff] [blame] | 6407 | arg5, |
bellard | c573ff6 | 2004-01-04 15:51:36 +0000 | [diff] [blame] | 6408 | arg6 << MMAP_SHIFT)); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6409 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 6410 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6411 | case TARGET_NR_munmap: |
bellard | 5493600 | 2003-05-13 00:25:15 +0000 | [diff] [blame] | 6412 | ret = get_errno(target_munmap(arg1, arg2)); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6413 | break; |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6414 | case TARGET_NR_mprotect: |
Paul Brook | 97374d3 | 2010-06-16 13:03:51 +0100 | [diff] [blame] | 6415 | { |
Andreas Färber | 9349b4f | 2012-03-14 01:38:32 +0100 | [diff] [blame] | 6416 | TaskState *ts = ((CPUArchState *)cpu_env)->opaque; |
Paul Brook | 97374d3 | 2010-06-16 13:03:51 +0100 | [diff] [blame] | 6417 | /* Special hack to detect libc making the stack executable. */ |
| 6418 | if ((arg3 & PROT_GROWSDOWN) |
| 6419 | && arg1 >= ts->info->stack_limit |
| 6420 | && arg1 <= ts->info->start_stack) { |
| 6421 | arg3 &= ~PROT_GROWSDOWN; |
| 6422 | arg2 = arg2 + arg1 - ts->info->stack_limit; |
| 6423 | arg1 = ts->info->stack_limit; |
| 6424 | } |
| 6425 | } |
bellard | 5493600 | 2003-05-13 00:25:15 +0000 | [diff] [blame] | 6426 | ret = get_errno(target_mprotect(arg1, arg2, arg3)); |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6427 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6428 | #ifdef TARGET_NR_mremap |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6429 | case TARGET_NR_mremap: |
bellard | 5493600 | 2003-05-13 00:25:15 +0000 | [diff] [blame] | 6430 | ret = get_errno(target_mremap(arg1, arg2, arg3, arg4, arg5)); |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6431 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6432 | #endif |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6433 | /* ??? msync/mlock/munlock are broken for softmmu. */ |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6434 | #ifdef TARGET_NR_msync |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6435 | case TARGET_NR_msync: |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6436 | ret = get_errno(msync(g2h(arg1), arg2, arg3)); |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6437 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6438 | #endif |
| 6439 | #ifdef TARGET_NR_mlock |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6440 | case TARGET_NR_mlock: |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6441 | ret = get_errno(mlock(g2h(arg1), arg2)); |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6442 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6443 | #endif |
| 6444 | #ifdef TARGET_NR_munlock |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6445 | case TARGET_NR_munlock: |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6446 | ret = get_errno(munlock(g2h(arg1), arg2)); |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6447 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6448 | #endif |
| 6449 | #ifdef TARGET_NR_mlockall |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6450 | case TARGET_NR_mlockall: |
| 6451 | ret = get_errno(mlockall(arg1)); |
| 6452 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6453 | #endif |
| 6454 | #ifdef TARGET_NR_munlockall |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6455 | case TARGET_NR_munlockall: |
| 6456 | ret = get_errno(munlockall()); |
| 6457 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6458 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6459 | case TARGET_NR_truncate: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6460 | if (!(p = lock_user_string(arg1))) |
| 6461 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6462 | ret = get_errno(truncate(p, arg2)); |
| 6463 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6464 | break; |
| 6465 | case TARGET_NR_ftruncate: |
| 6466 | ret = get_errno(ftruncate(arg1, arg2)); |
| 6467 | break; |
| 6468 | case TARGET_NR_fchmod: |
| 6469 | ret = get_errno(fchmod(arg1, arg2)); |
| 6470 | break; |
ths | 814d797 | 2007-09-24 09:26:51 +0000 | [diff] [blame] | 6471 | #if defined(TARGET_NR_fchmodat) && defined(__NR_fchmodat) |
| 6472 | case TARGET_NR_fchmodat: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6473 | if (!(p = lock_user_string(arg2))) |
| 6474 | goto efault; |
aurel32 | 465c9f0 | 2009-04-19 08:52:17 +0000 | [diff] [blame] | 6475 | ret = get_errno(sys_fchmodat(arg1, p, arg3)); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6476 | unlock_user(p, arg2, 0); |
ths | 814d797 | 2007-09-24 09:26:51 +0000 | [diff] [blame] | 6477 | break; |
| 6478 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6479 | case TARGET_NR_getpriority: |
ths | c6cda17 | 2007-10-09 03:42:34 +0000 | [diff] [blame] | 6480 | /* libc does special remapping of the return value of |
| 6481 | * sys_getpriority() so it's just easiest to call |
| 6482 | * sys_getpriority() directly rather than through libc. */ |
Ulrich Hecht | 6913720 | 2009-09-17 21:08:37 +0300 | [diff] [blame] | 6483 | ret = get_errno(sys_getpriority(arg1, arg2)); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6484 | break; |
| 6485 | case TARGET_NR_setpriority: |
| 6486 | ret = get_errno(setpriority(arg1, arg2, arg3)); |
| 6487 | break; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6488 | #ifdef TARGET_NR_profil |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6489 | case TARGET_NR_profil: |
| 6490 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6491 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6492 | case TARGET_NR_statfs: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6493 | if (!(p = lock_user_string(arg1))) |
| 6494 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6495 | ret = get_errno(statfs(path(p), &stfs)); |
| 6496 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6497 | convert_statfs: |
| 6498 | if (!is_error(ret)) { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6499 | struct target_statfs *target_stfs; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 6500 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6501 | if (!lock_user_struct(VERIFY_WRITE, target_stfs, arg2, 0)) |
| 6502 | goto efault; |
| 6503 | __put_user(stfs.f_type, &target_stfs->f_type); |
| 6504 | __put_user(stfs.f_bsize, &target_stfs->f_bsize); |
| 6505 | __put_user(stfs.f_blocks, &target_stfs->f_blocks); |
| 6506 | __put_user(stfs.f_bfree, &target_stfs->f_bfree); |
| 6507 | __put_user(stfs.f_bavail, &target_stfs->f_bavail); |
| 6508 | __put_user(stfs.f_files, &target_stfs->f_files); |
| 6509 | __put_user(stfs.f_ffree, &target_stfs->f_ffree); |
| 6510 | __put_user(stfs.f_fsid.__val[0], &target_stfs->f_fsid.val[0]); |
| 6511 | __put_user(stfs.f_fsid.__val[1], &target_stfs->f_fsid.val[1]); |
| 6512 | __put_user(stfs.f_namelen, &target_stfs->f_namelen); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6513 | unlock_user_struct(target_stfs, arg2, 1); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6514 | } |
| 6515 | break; |
| 6516 | case TARGET_NR_fstatfs: |
bellard | 56c8f68 | 2005-11-28 22:28:41 +0000 | [diff] [blame] | 6517 | ret = get_errno(fstatfs(arg1, &stfs)); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6518 | goto convert_statfs; |
bellard | 56c8f68 | 2005-11-28 22:28:41 +0000 | [diff] [blame] | 6519 | #ifdef TARGET_NR_statfs64 |
| 6520 | case TARGET_NR_statfs64: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6521 | if (!(p = lock_user_string(arg1))) |
| 6522 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6523 | ret = get_errno(statfs(path(p), &stfs)); |
| 6524 | unlock_user(p, arg1, 0); |
bellard | 56c8f68 | 2005-11-28 22:28:41 +0000 | [diff] [blame] | 6525 | convert_statfs64: |
| 6526 | if (!is_error(ret)) { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6527 | struct target_statfs64 *target_stfs; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 6528 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6529 | if (!lock_user_struct(VERIFY_WRITE, target_stfs, arg3, 0)) |
| 6530 | goto efault; |
| 6531 | __put_user(stfs.f_type, &target_stfs->f_type); |
| 6532 | __put_user(stfs.f_bsize, &target_stfs->f_bsize); |
| 6533 | __put_user(stfs.f_blocks, &target_stfs->f_blocks); |
| 6534 | __put_user(stfs.f_bfree, &target_stfs->f_bfree); |
| 6535 | __put_user(stfs.f_bavail, &target_stfs->f_bavail); |
| 6536 | __put_user(stfs.f_files, &target_stfs->f_files); |
| 6537 | __put_user(stfs.f_ffree, &target_stfs->f_ffree); |
| 6538 | __put_user(stfs.f_fsid.__val[0], &target_stfs->f_fsid.val[0]); |
| 6539 | __put_user(stfs.f_fsid.__val[1], &target_stfs->f_fsid.val[1]); |
| 6540 | __put_user(stfs.f_namelen, &target_stfs->f_namelen); |
| 6541 | unlock_user_struct(target_stfs, arg3, 1); |
bellard | 56c8f68 | 2005-11-28 22:28:41 +0000 | [diff] [blame] | 6542 | } |
| 6543 | break; |
| 6544 | case TARGET_NR_fstatfs64: |
| 6545 | ret = get_errno(fstatfs(arg1, &stfs)); |
| 6546 | goto convert_statfs64; |
| 6547 | #endif |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6548 | #ifdef TARGET_NR_ioperm |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6549 | case TARGET_NR_ioperm: |
| 6550 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6551 | #endif |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6552 | #ifdef TARGET_NR_socketcall |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6553 | case TARGET_NR_socketcall: |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6554 | ret = do_socketcall(arg1, arg2); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6555 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6556 | #endif |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 6557 | #ifdef TARGET_NR_accept |
| 6558 | case TARGET_NR_accept: |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 6559 | ret = do_accept(arg1, arg2, arg3); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 6560 | break; |
| 6561 | #endif |
| 6562 | #ifdef TARGET_NR_bind |
| 6563 | case TARGET_NR_bind: |
| 6564 | ret = do_bind(arg1, arg2, arg3); |
| 6565 | break; |
| 6566 | #endif |
| 6567 | #ifdef TARGET_NR_connect |
| 6568 | case TARGET_NR_connect: |
| 6569 | ret = do_connect(arg1, arg2, arg3); |
| 6570 | break; |
| 6571 | #endif |
| 6572 | #ifdef TARGET_NR_getpeername |
| 6573 | case TARGET_NR_getpeername: |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 6574 | ret = do_getpeername(arg1, arg2, arg3); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 6575 | break; |
| 6576 | #endif |
| 6577 | #ifdef TARGET_NR_getsockname |
| 6578 | case TARGET_NR_getsockname: |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 6579 | ret = do_getsockname(arg1, arg2, arg3); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 6580 | break; |
| 6581 | #endif |
| 6582 | #ifdef TARGET_NR_getsockopt |
| 6583 | case TARGET_NR_getsockopt: |
| 6584 | ret = do_getsockopt(arg1, arg2, arg3, arg4, arg5); |
| 6585 | break; |
| 6586 | #endif |
| 6587 | #ifdef TARGET_NR_listen |
| 6588 | case TARGET_NR_listen: |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 6589 | ret = get_errno(listen(arg1, arg2)); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 6590 | break; |
| 6591 | #endif |
| 6592 | #ifdef TARGET_NR_recv |
| 6593 | case TARGET_NR_recv: |
pbrook | 214201b | 2007-03-17 01:27:24 +0000 | [diff] [blame] | 6594 | ret = do_recvfrom(arg1, arg2, arg3, arg4, 0, 0); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 6595 | break; |
| 6596 | #endif |
| 6597 | #ifdef TARGET_NR_recvfrom |
| 6598 | case TARGET_NR_recvfrom: |
pbrook | 214201b | 2007-03-17 01:27:24 +0000 | [diff] [blame] | 6599 | ret = do_recvfrom(arg1, arg2, arg3, arg4, arg5, arg6); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 6600 | break; |
| 6601 | #endif |
| 6602 | #ifdef TARGET_NR_recvmsg |
| 6603 | case TARGET_NR_recvmsg: |
| 6604 | ret = do_sendrecvmsg(arg1, arg2, arg3, 0); |
| 6605 | break; |
| 6606 | #endif |
| 6607 | #ifdef TARGET_NR_send |
| 6608 | case TARGET_NR_send: |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 6609 | ret = do_sendto(arg1, arg2, arg3, arg4, 0, 0); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 6610 | break; |
| 6611 | #endif |
| 6612 | #ifdef TARGET_NR_sendmsg |
| 6613 | case TARGET_NR_sendmsg: |
| 6614 | ret = do_sendrecvmsg(arg1, arg2, arg3, 1); |
| 6615 | break; |
| 6616 | #endif |
| 6617 | #ifdef TARGET_NR_sendto |
| 6618 | case TARGET_NR_sendto: |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 6619 | ret = do_sendto(arg1, arg2, arg3, arg4, arg5, arg6); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 6620 | break; |
| 6621 | #endif |
| 6622 | #ifdef TARGET_NR_shutdown |
| 6623 | case TARGET_NR_shutdown: |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 6624 | ret = get_errno(shutdown(arg1, arg2)); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 6625 | break; |
| 6626 | #endif |
| 6627 | #ifdef TARGET_NR_socket |
| 6628 | case TARGET_NR_socket: |
| 6629 | ret = do_socket(arg1, arg2, arg3); |
| 6630 | break; |
| 6631 | #endif |
| 6632 | #ifdef TARGET_NR_socketpair |
| 6633 | case TARGET_NR_socketpair: |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 6634 | ret = do_socketpair(arg1, arg2, arg3, arg4); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 6635 | break; |
| 6636 | #endif |
| 6637 | #ifdef TARGET_NR_setsockopt |
| 6638 | case TARGET_NR_setsockopt: |
| 6639 | ret = do_setsockopt(arg1, arg2, arg3, arg4, (socklen_t) arg5); |
| 6640 | break; |
| 6641 | #endif |
ths | 7494b0f | 2007-02-11 18:26:53 +0000 | [diff] [blame] | 6642 | |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6643 | case TARGET_NR_syslog: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6644 | if (!(p = lock_user_string(arg2))) |
| 6645 | goto efault; |
ths | e557448 | 2007-02-11 20:03:13 +0000 | [diff] [blame] | 6646 | ret = get_errno(sys_syslog((int)arg1, p, (int)arg3)); |
| 6647 | unlock_user(p, arg2, 0); |
ths | 7494b0f | 2007-02-11 18:26:53 +0000 | [diff] [blame] | 6648 | break; |
| 6649 | |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6650 | case TARGET_NR_setitimer: |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6651 | { |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6652 | struct itimerval value, ovalue, *pvalue; |
| 6653 | |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6654 | if (arg2) { |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6655 | pvalue = &value; |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 6656 | if (copy_from_user_timeval(&pvalue->it_interval, arg2) |
| 6657 | || copy_from_user_timeval(&pvalue->it_value, |
| 6658 | arg2 + sizeof(struct target_timeval))) |
| 6659 | goto efault; |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6660 | } else { |
| 6661 | pvalue = NULL; |
| 6662 | } |
| 6663 | ret = get_errno(setitimer(arg1, pvalue, &ovalue)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6664 | if (!is_error(ret) && arg3) { |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 6665 | if (copy_to_user_timeval(arg3, |
| 6666 | &ovalue.it_interval) |
| 6667 | || copy_to_user_timeval(arg3 + sizeof(struct target_timeval), |
| 6668 | &ovalue.it_value)) |
| 6669 | goto efault; |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6670 | } |
| 6671 | } |
| 6672 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6673 | case TARGET_NR_getitimer: |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6674 | { |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6675 | struct itimerval value; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 6676 | |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6677 | ret = get_errno(getitimer(arg1, &value)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6678 | if (!is_error(ret) && arg2) { |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 6679 | if (copy_to_user_timeval(arg2, |
| 6680 | &value.it_interval) |
| 6681 | || copy_to_user_timeval(arg2 + sizeof(struct target_timeval), |
| 6682 | &value.it_value)) |
| 6683 | goto efault; |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6684 | } |
| 6685 | } |
| 6686 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6687 | case TARGET_NR_stat: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6688 | if (!(p = lock_user_string(arg1))) |
| 6689 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6690 | ret = get_errno(stat(path(p), &st)); |
| 6691 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6692 | goto do_stat; |
| 6693 | case TARGET_NR_lstat: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6694 | if (!(p = lock_user_string(arg1))) |
| 6695 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6696 | ret = get_errno(lstat(path(p), &st)); |
| 6697 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6698 | goto do_stat; |
| 6699 | case TARGET_NR_fstat: |
| 6700 | { |
| 6701 | ret = get_errno(fstat(arg1, &st)); |
| 6702 | do_stat: |
| 6703 | if (!is_error(ret)) { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6704 | struct target_stat *target_st; |
ths | e358465 | 2007-06-01 11:49:38 +0000 | [diff] [blame] | 6705 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6706 | if (!lock_user_struct(VERIFY_WRITE, target_st, arg2, 0)) |
| 6707 | goto efault; |
Ulrich Hecht | 1272791 | 2009-07-24 19:10:32 +0200 | [diff] [blame] | 6708 | memset(target_st, 0, sizeof(*target_st)); |
bellard | d2fd1af | 2007-11-14 18:08:56 +0000 | [diff] [blame] | 6709 | __put_user(st.st_dev, &target_st->st_dev); |
| 6710 | __put_user(st.st_ino, &target_st->st_ino); |
| 6711 | __put_user(st.st_mode, &target_st->st_mode); |
| 6712 | __put_user(st.st_uid, &target_st->st_uid); |
| 6713 | __put_user(st.st_gid, &target_st->st_gid); |
| 6714 | __put_user(st.st_nlink, &target_st->st_nlink); |
| 6715 | __put_user(st.st_rdev, &target_st->st_rdev); |
| 6716 | __put_user(st.st_size, &target_st->st_size); |
| 6717 | __put_user(st.st_blksize, &target_st->st_blksize); |
| 6718 | __put_user(st.st_blocks, &target_st->st_blocks); |
| 6719 | __put_user(st.st_atime, &target_st->target_st_atime); |
| 6720 | __put_user(st.st_mtime, &target_st->target_st_mtime); |
| 6721 | __put_user(st.st_ctime, &target_st->target_st_ctime); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6722 | unlock_user_struct(target_st, arg2, 1); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6723 | } |
| 6724 | } |
| 6725 | break; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6726 | #ifdef TARGET_NR_olduname |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6727 | case TARGET_NR_olduname: |
| 6728 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6729 | #endif |
| 6730 | #ifdef TARGET_NR_iopl |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6731 | case TARGET_NR_iopl: |
| 6732 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6733 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6734 | case TARGET_NR_vhangup: |
| 6735 | ret = get_errno(vhangup()); |
| 6736 | break; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6737 | #ifdef TARGET_NR_idle |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6738 | case TARGET_NR_idle: |
| 6739 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6740 | #endif |
bellard | 42ad6ae | 2005-01-03 22:48:11 +0000 | [diff] [blame] | 6741 | #ifdef TARGET_NR_syscall |
| 6742 | case TARGET_NR_syscall: |
Peter Maydell | 5945cfc | 2011-06-16 17:37:13 +0100 | [diff] [blame] | 6743 | ret = do_syscall(cpu_env, arg1 & 0xffff, arg2, arg3, arg4, arg5, |
| 6744 | arg6, arg7, arg8, 0); |
| 6745 | break; |
bellard | 42ad6ae | 2005-01-03 22:48:11 +0000 | [diff] [blame] | 6746 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6747 | case TARGET_NR_wait4: |
| 6748 | { |
| 6749 | int status; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 6750 | abi_long status_ptr = arg2; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6751 | struct rusage rusage, *rusage_ptr; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 6752 | abi_ulong target_rusage = arg4; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6753 | if (target_rusage) |
| 6754 | rusage_ptr = &rusage; |
| 6755 | else |
| 6756 | rusage_ptr = NULL; |
| 6757 | ret = get_errno(wait4(arg1, &status, arg3, rusage_ptr)); |
| 6758 | if (!is_error(ret)) { |
Alexander Graf | 5379557 | 2011-11-24 00:44:43 +0100 | [diff] [blame] | 6759 | if (status_ptr && ret) { |
pbrook | 1d9d8b5 | 2009-04-16 15:17:02 +0000 | [diff] [blame] | 6760 | status = host_to_target_waitstatus(status); |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 6761 | if (put_user_s32(status, status_ptr)) |
| 6762 | goto efault; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6763 | } |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 6764 | if (target_rusage) |
| 6765 | host_to_target_rusage(target_rusage, &rusage); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6766 | } |
| 6767 | } |
| 6768 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6769 | #ifdef TARGET_NR_swapoff |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6770 | case TARGET_NR_swapoff: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6771 | if (!(p = lock_user_string(arg1))) |
| 6772 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6773 | ret = get_errno(swapoff(p)); |
| 6774 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6775 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6776 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6777 | case TARGET_NR_sysinfo: |
bellard | a5448a7 | 2004-06-19 16:59:03 +0000 | [diff] [blame] | 6778 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6779 | struct target_sysinfo *target_value; |
bellard | a5448a7 | 2004-06-19 16:59:03 +0000 | [diff] [blame] | 6780 | struct sysinfo value; |
| 6781 | ret = get_errno(sysinfo(&value)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6782 | if (!is_error(ret) && arg1) |
bellard | a5448a7 | 2004-06-19 16:59:03 +0000 | [diff] [blame] | 6783 | { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6784 | if (!lock_user_struct(VERIFY_WRITE, target_value, arg1, 0)) |
| 6785 | goto efault; |
bellard | a5448a7 | 2004-06-19 16:59:03 +0000 | [diff] [blame] | 6786 | __put_user(value.uptime, &target_value->uptime); |
| 6787 | __put_user(value.loads[0], &target_value->loads[0]); |
| 6788 | __put_user(value.loads[1], &target_value->loads[1]); |
| 6789 | __put_user(value.loads[2], &target_value->loads[2]); |
| 6790 | __put_user(value.totalram, &target_value->totalram); |
| 6791 | __put_user(value.freeram, &target_value->freeram); |
| 6792 | __put_user(value.sharedram, &target_value->sharedram); |
| 6793 | __put_user(value.bufferram, &target_value->bufferram); |
| 6794 | __put_user(value.totalswap, &target_value->totalswap); |
| 6795 | __put_user(value.freeswap, &target_value->freeswap); |
| 6796 | __put_user(value.procs, &target_value->procs); |
| 6797 | __put_user(value.totalhigh, &target_value->totalhigh); |
| 6798 | __put_user(value.freehigh, &target_value->freehigh); |
| 6799 | __put_user(value.mem_unit, &target_value->mem_unit); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6800 | unlock_user_struct(target_value, arg1, 1); |
bellard | a5448a7 | 2004-06-19 16:59:03 +0000 | [diff] [blame] | 6801 | } |
| 6802 | } |
| 6803 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6804 | #ifdef TARGET_NR_ipc |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6805 | case TARGET_NR_ipc: |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 6806 | ret = do_ipc(arg1, arg2, arg3, arg4, arg5, arg6); |
| 6807 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6808 | #endif |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 6809 | #ifdef TARGET_NR_semget |
| 6810 | case TARGET_NR_semget: |
| 6811 | ret = get_errno(semget(arg1, arg2, arg3)); |
| 6812 | break; |
| 6813 | #endif |
| 6814 | #ifdef TARGET_NR_semop |
| 6815 | case TARGET_NR_semop: |
| 6816 | ret = get_errno(do_semop(arg1, arg2, arg3)); |
| 6817 | break; |
| 6818 | #endif |
| 6819 | #ifdef TARGET_NR_semctl |
| 6820 | case TARGET_NR_semctl: |
| 6821 | ret = do_semctl(arg1, arg2, arg3, (union target_semun)(abi_ulong)arg4); |
| 6822 | break; |
| 6823 | #endif |
aurel32 | eeb438c | 2008-10-13 21:08:55 +0000 | [diff] [blame] | 6824 | #ifdef TARGET_NR_msgctl |
| 6825 | case TARGET_NR_msgctl: |
| 6826 | ret = do_msgctl(arg1, arg2, arg3); |
| 6827 | break; |
| 6828 | #endif |
| 6829 | #ifdef TARGET_NR_msgget |
| 6830 | case TARGET_NR_msgget: |
| 6831 | ret = get_errno(msgget(arg1, arg2)); |
| 6832 | break; |
| 6833 | #endif |
| 6834 | #ifdef TARGET_NR_msgrcv |
| 6835 | case TARGET_NR_msgrcv: |
| 6836 | ret = do_msgrcv(arg1, arg2, arg3, arg4, arg5); |
| 6837 | break; |
| 6838 | #endif |
| 6839 | #ifdef TARGET_NR_msgsnd |
| 6840 | case TARGET_NR_msgsnd: |
| 6841 | ret = do_msgsnd(arg1, arg2, arg3, arg4); |
| 6842 | break; |
| 6843 | #endif |
Riku Voipio | 88a8c98 | 2009-04-03 10:42:00 +0300 | [diff] [blame] | 6844 | #ifdef TARGET_NR_shmget |
| 6845 | case TARGET_NR_shmget: |
| 6846 | ret = get_errno(shmget(arg1, arg2, arg3)); |
| 6847 | break; |
| 6848 | #endif |
| 6849 | #ifdef TARGET_NR_shmctl |
| 6850 | case TARGET_NR_shmctl: |
| 6851 | ret = do_shmctl(arg1, arg2, arg3); |
| 6852 | break; |
| 6853 | #endif |
| 6854 | #ifdef TARGET_NR_shmat |
| 6855 | case TARGET_NR_shmat: |
| 6856 | ret = do_shmat(arg1, arg2, arg3); |
| 6857 | break; |
| 6858 | #endif |
| 6859 | #ifdef TARGET_NR_shmdt |
| 6860 | case TARGET_NR_shmdt: |
| 6861 | ret = do_shmdt(arg1); |
| 6862 | break; |
| 6863 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6864 | case TARGET_NR_fsync: |
| 6865 | ret = get_errno(fsync(arg1)); |
| 6866 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6867 | case TARGET_NR_clone: |
Richard Henderson | a4b388f | 2010-04-12 16:17:22 -0700 | [diff] [blame] | 6868 | #if defined(TARGET_SH4) || defined(TARGET_ALPHA) |
aurel32 | 0b6d3ae | 2008-09-15 07:43:43 +0000 | [diff] [blame] | 6869 | ret = get_errno(do_fork(cpu_env, arg1, arg2, arg3, arg5, arg4)); |
edgar_igl | b15ad61 | 2009-01-07 19:43:47 +0000 | [diff] [blame] | 6870 | #elif defined(TARGET_CRIS) |
| 6871 | ret = get_errno(do_fork(cpu_env, arg2, arg1, arg3, arg4, arg5)); |
Ulrich Hecht | a4c075f | 2009-07-24 16:57:31 +0200 | [diff] [blame] | 6872 | #elif defined(TARGET_S390X) |
| 6873 | ret = get_errno(do_fork(cpu_env, arg2, arg1, arg3, arg5, arg4)); |
aurel32 | 0b6d3ae | 2008-09-15 07:43:43 +0000 | [diff] [blame] | 6874 | #else |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 6875 | ret = get_errno(do_fork(cpu_env, arg1, arg2, arg3, arg4, arg5)); |
aurel32 | 0b6d3ae | 2008-09-15 07:43:43 +0000 | [diff] [blame] | 6876 | #endif |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 6877 | break; |
bellard | ec86b0f | 2003-04-11 00:15:04 +0000 | [diff] [blame] | 6878 | #ifdef __NR_exit_group |
| 6879 | /* new thread calls */ |
| 6880 | case TARGET_NR_exit_group: |
Juan Quintela | 9788c9c | 2009-07-27 16:13:02 +0200 | [diff] [blame] | 6881 | #ifdef TARGET_GPROF |
aurel32 | 6d946cd | 2008-11-06 16:15:18 +0000 | [diff] [blame] | 6882 | _mcleanup(); |
| 6883 | #endif |
bellard | e900967 | 2005-04-26 20:42:36 +0000 | [diff] [blame] | 6884 | gdb_exit(cpu_env, arg1); |
bellard | ec86b0f | 2003-04-11 00:15:04 +0000 | [diff] [blame] | 6885 | ret = get_errno(exit_group(arg1)); |
| 6886 | break; |
| 6887 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6888 | case TARGET_NR_setdomainname: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6889 | if (!(p = lock_user_string(arg1))) |
| 6890 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6891 | ret = get_errno(setdomainname(p, arg2)); |
| 6892 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6893 | break; |
| 6894 | case TARGET_NR_uname: |
| 6895 | /* no need to transcode because we use the linux syscall */ |
bellard | 29e619b | 2004-09-13 21:41:04 +0000 | [diff] [blame] | 6896 | { |
| 6897 | struct new_utsname * buf; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 6898 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6899 | if (!lock_user_struct(VERIFY_WRITE, buf, arg1, 0)) |
| 6900 | goto efault; |
bellard | 29e619b | 2004-09-13 21:41:04 +0000 | [diff] [blame] | 6901 | ret = get_errno(sys_uname(buf)); |
| 6902 | if (!is_error(ret)) { |
| 6903 | /* Overrite the native machine name with whatever is being |
| 6904 | emulated. */ |
Loïc Minier | da79030 | 2009-12-29 22:06:13 +0100 | [diff] [blame] | 6905 | strcpy (buf->machine, cpu_to_uname_machine(cpu_env)); |
pbrook | c593722 | 2006-05-14 11:30:38 +0000 | [diff] [blame] | 6906 | /* Allow the user to override the reported release. */ |
| 6907 | if (qemu_uname_release && *qemu_uname_release) |
| 6908 | strcpy (buf->release, qemu_uname_release); |
bellard | 29e619b | 2004-09-13 21:41:04 +0000 | [diff] [blame] | 6909 | } |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6910 | unlock_user_struct(buf, arg1, 1); |
bellard | 29e619b | 2004-09-13 21:41:04 +0000 | [diff] [blame] | 6911 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6912 | break; |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 6913 | #ifdef TARGET_I386 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6914 | case TARGET_NR_modify_ldt: |
bellard | 03acab6 | 2007-11-11 14:57:14 +0000 | [diff] [blame] | 6915 | ret = do_modify_ldt(cpu_env, arg1, arg2, arg3); |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 6916 | break; |
j_mayer | 84409dd | 2007-04-06 08:56:50 +0000 | [diff] [blame] | 6917 | #if !defined(TARGET_X86_64) |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 6918 | case TARGET_NR_vm86old: |
| 6919 | goto unimplemented; |
| 6920 | case TARGET_NR_vm86: |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6921 | ret = do_vm86(cpu_env, arg1, arg2); |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 6922 | break; |
| 6923 | #endif |
j_mayer | 84409dd | 2007-04-06 08:56:50 +0000 | [diff] [blame] | 6924 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6925 | case TARGET_NR_adjtimex: |
| 6926 | goto unimplemented; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6927 | #ifdef TARGET_NR_create_module |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6928 | case TARGET_NR_create_module: |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6929 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6930 | case TARGET_NR_init_module: |
| 6931 | case TARGET_NR_delete_module: |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6932 | #ifdef TARGET_NR_get_kernel_syms |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6933 | case TARGET_NR_get_kernel_syms: |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6934 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6935 | goto unimplemented; |
| 6936 | case TARGET_NR_quotactl: |
| 6937 | goto unimplemented; |
| 6938 | case TARGET_NR_getpgid: |
| 6939 | ret = get_errno(getpgid(arg1)); |
| 6940 | break; |
| 6941 | case TARGET_NR_fchdir: |
| 6942 | ret = get_errno(fchdir(arg1)); |
| 6943 | break; |
j_mayer | 84409dd | 2007-04-06 08:56:50 +0000 | [diff] [blame] | 6944 | #ifdef TARGET_NR_bdflush /* not on x86_64 */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6945 | case TARGET_NR_bdflush: |
| 6946 | goto unimplemented; |
j_mayer | 84409dd | 2007-04-06 08:56:50 +0000 | [diff] [blame] | 6947 | #endif |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6948 | #ifdef TARGET_NR_sysfs |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6949 | case TARGET_NR_sysfs: |
| 6950 | goto unimplemented; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6951 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6952 | case TARGET_NR_personality: |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 6953 | ret = get_errno(personality(arg1)); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6954 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6955 | #ifdef TARGET_NR_afs_syscall |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6956 | case TARGET_NR_afs_syscall: |
| 6957 | goto unimplemented; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6958 | #endif |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 6959 | #ifdef TARGET_NR__llseek /* Not on alpha */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6960 | case TARGET_NR__llseek: |
| 6961 | { |
| 6962 | int64_t res; |
Peter Maydell | 0c1592d | 2011-02-22 13:02:26 +0000 | [diff] [blame] | 6963 | #if !defined(__NR_llseek) |
| 6964 | res = lseek(arg1, ((uint64_t)arg2 << 32) | arg3, arg5); |
| 6965 | if (res == -1) { |
| 6966 | ret = get_errno(res); |
| 6967 | } else { |
| 6968 | ret = 0; |
| 6969 | } |
| 6970 | #else |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6971 | ret = get_errno(_llseek(arg1, arg2, arg3, &res, arg5)); |
bellard | 4f2ac23 | 2004-04-26 19:44:02 +0000 | [diff] [blame] | 6972 | #endif |
Peter Maydell | 0c1592d | 2011-02-22 13:02:26 +0000 | [diff] [blame] | 6973 | if ((ret == 0) && put_user_s64(res, arg4)) { |
| 6974 | goto efault; |
| 6975 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6976 | } |
| 6977 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 6978 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6979 | case TARGET_NR_getdents: |
Ulrich Hecht | d83c873 | 2009-07-24 19:10:28 +0200 | [diff] [blame] | 6980 | #if TARGET_ABI_BITS == 32 && HOST_LONG_BITS == 64 |
bellard | 4add45b | 2003-06-05 01:52:59 +0000 | [diff] [blame] | 6981 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6982 | struct target_dirent *target_dirp; |
aurel32 | 6556a83 | 2008-10-13 21:08:17 +0000 | [diff] [blame] | 6983 | struct linux_dirent *dirp; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 6984 | abi_long count = arg3; |
bellard | 4add45b | 2003-06-05 01:52:59 +0000 | [diff] [blame] | 6985 | |
| 6986 | dirp = malloc(count); |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 6987 | if (!dirp) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6988 | ret = -TARGET_ENOMEM; |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 6989 | goto fail; |
| 6990 | } |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 6991 | |
bellard | 4add45b | 2003-06-05 01:52:59 +0000 | [diff] [blame] | 6992 | ret = get_errno(sys_getdents(arg1, dirp, count)); |
| 6993 | if (!is_error(ret)) { |
aurel32 | 6556a83 | 2008-10-13 21:08:17 +0000 | [diff] [blame] | 6994 | struct linux_dirent *de; |
bellard | 4add45b | 2003-06-05 01:52:59 +0000 | [diff] [blame] | 6995 | struct target_dirent *tde; |
| 6996 | int len = ret; |
| 6997 | int reclen, treclen; |
| 6998 | int count1, tnamelen; |
| 6999 | |
| 7000 | count1 = 0; |
| 7001 | de = dirp; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7002 | if (!(target_dirp = lock_user(VERIFY_WRITE, arg2, count, 0))) |
| 7003 | goto efault; |
bellard | 4add45b | 2003-06-05 01:52:59 +0000 | [diff] [blame] | 7004 | tde = target_dirp; |
| 7005 | while (len > 0) { |
| 7006 | reclen = de->d_reclen; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 7007 | treclen = reclen - (2 * (sizeof(long) - sizeof(abi_long))); |
bellard | 4add45b | 2003-06-05 01:52:59 +0000 | [diff] [blame] | 7008 | tde->d_reclen = tswap16(treclen); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 7009 | tde->d_ino = tswapal(de->d_ino); |
| 7010 | tde->d_off = tswapal(de->d_off); |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 7011 | tnamelen = treclen - (2 * sizeof(abi_long) + 2); |
bellard | 4add45b | 2003-06-05 01:52:59 +0000 | [diff] [blame] | 7012 | if (tnamelen > 256) |
| 7013 | tnamelen = 256; |
bellard | 80a9d03 | 2005-01-03 23:31:27 +0000 | [diff] [blame] | 7014 | /* XXX: may not be correct */ |
blueswir1 | be15b14 | 2008-10-25 11:21:28 +0000 | [diff] [blame] | 7015 | pstrcpy(tde->d_name, tnamelen, de->d_name); |
aurel32 | 6556a83 | 2008-10-13 21:08:17 +0000 | [diff] [blame] | 7016 | de = (struct linux_dirent *)((char *)de + reclen); |
bellard | 4add45b | 2003-06-05 01:52:59 +0000 | [diff] [blame] | 7017 | len -= reclen; |
j_mayer | 1c5bf3b | 2007-04-14 12:17:59 +0000 | [diff] [blame] | 7018 | tde = (struct target_dirent *)((char *)tde + treclen); |
bellard | 4add45b | 2003-06-05 01:52:59 +0000 | [diff] [blame] | 7019 | count1 += treclen; |
| 7020 | } |
| 7021 | ret = count1; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7022 | unlock_user(target_dirp, arg2, ret); |
bellard | 4add45b | 2003-06-05 01:52:59 +0000 | [diff] [blame] | 7023 | } |
| 7024 | free(dirp); |
| 7025 | } |
| 7026 | #else |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7027 | { |
aurel32 | 6556a83 | 2008-10-13 21:08:17 +0000 | [diff] [blame] | 7028 | struct linux_dirent *dirp; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 7029 | abi_long count = arg3; |
bellard | dab2ed9 | 2003-03-22 15:23:14 +0000 | [diff] [blame] | 7030 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7031 | if (!(dirp = lock_user(VERIFY_WRITE, arg2, count, 0))) |
| 7032 | goto efault; |
bellard | 72f0390 | 2003-02-18 23:33:18 +0000 | [diff] [blame] | 7033 | ret = get_errno(sys_getdents(arg1, dirp, count)); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7034 | if (!is_error(ret)) { |
aurel32 | 6556a83 | 2008-10-13 21:08:17 +0000 | [diff] [blame] | 7035 | struct linux_dirent *de; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7036 | int len = ret; |
| 7037 | int reclen; |
| 7038 | de = dirp; |
| 7039 | while (len > 0) { |
bellard | 8083a3e | 2003-03-24 23:12:16 +0000 | [diff] [blame] | 7040 | reclen = de->d_reclen; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7041 | if (reclen > len) |
| 7042 | break; |
bellard | 8083a3e | 2003-03-24 23:12:16 +0000 | [diff] [blame] | 7043 | de->d_reclen = tswap16(reclen); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7044 | tswapls(&de->d_ino); |
| 7045 | tswapls(&de->d_off); |
aurel32 | 6556a83 | 2008-10-13 21:08:17 +0000 | [diff] [blame] | 7046 | de = (struct linux_dirent *)((char *)de + reclen); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7047 | len -= reclen; |
| 7048 | } |
| 7049 | } |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7050 | unlock_user(dirp, arg2, ret); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7051 | } |
bellard | 4add45b | 2003-06-05 01:52:59 +0000 | [diff] [blame] | 7052 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7053 | break; |
ths | 3ae4320 | 2007-09-16 21:39:48 +0000 | [diff] [blame] | 7054 | #if defined(TARGET_NR_getdents64) && defined(__NR_getdents64) |
bellard | dab2ed9 | 2003-03-22 15:23:14 +0000 | [diff] [blame] | 7055 | case TARGET_NR_getdents64: |
| 7056 | { |
aurel32 | 6556a83 | 2008-10-13 21:08:17 +0000 | [diff] [blame] | 7057 | struct linux_dirent64 *dirp; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 7058 | abi_long count = arg3; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7059 | if (!(dirp = lock_user(VERIFY_WRITE, arg2, count, 0))) |
| 7060 | goto efault; |
bellard | dab2ed9 | 2003-03-22 15:23:14 +0000 | [diff] [blame] | 7061 | ret = get_errno(sys_getdents64(arg1, dirp, count)); |
| 7062 | if (!is_error(ret)) { |
aurel32 | 6556a83 | 2008-10-13 21:08:17 +0000 | [diff] [blame] | 7063 | struct linux_dirent64 *de; |
bellard | dab2ed9 | 2003-03-22 15:23:14 +0000 | [diff] [blame] | 7064 | int len = ret; |
| 7065 | int reclen; |
| 7066 | de = dirp; |
| 7067 | while (len > 0) { |
bellard | 8083a3e | 2003-03-24 23:12:16 +0000 | [diff] [blame] | 7068 | reclen = de->d_reclen; |
bellard | dab2ed9 | 2003-03-22 15:23:14 +0000 | [diff] [blame] | 7069 | if (reclen > len) |
| 7070 | break; |
bellard | 8083a3e | 2003-03-24 23:12:16 +0000 | [diff] [blame] | 7071 | de->d_reclen = tswap16(reclen); |
bellard | 8582a53 | 2007-11-11 23:11:36 +0000 | [diff] [blame] | 7072 | tswap64s((uint64_t *)&de->d_ino); |
| 7073 | tswap64s((uint64_t *)&de->d_off); |
aurel32 | 6556a83 | 2008-10-13 21:08:17 +0000 | [diff] [blame] | 7074 | de = (struct linux_dirent64 *)((char *)de + reclen); |
bellard | dab2ed9 | 2003-03-22 15:23:14 +0000 | [diff] [blame] | 7075 | len -= reclen; |
| 7076 | } |
| 7077 | } |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7078 | unlock_user(dirp, arg2, ret); |
bellard | dab2ed9 | 2003-03-22 15:23:14 +0000 | [diff] [blame] | 7079 | } |
| 7080 | break; |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 7081 | #endif /* TARGET_NR_getdents64 */ |
Ulrich Hecht | a4c075f | 2009-07-24 16:57:31 +0200 | [diff] [blame] | 7082 | #if defined(TARGET_NR__newselect) || defined(TARGET_S390X) |
| 7083 | #ifdef TARGET_S390X |
| 7084 | case TARGET_NR_select: |
| 7085 | #else |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7086 | case TARGET_NR__newselect: |
Ulrich Hecht | a4c075f | 2009-07-24 16:57:31 +0200 | [diff] [blame] | 7087 | #endif |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7088 | ret = do_select(arg1, arg2, arg3, arg4, arg5); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7089 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7090 | #endif |
Mike Frysinger | d8035d4 | 2011-02-07 01:05:51 -0500 | [diff] [blame] | 7091 | #if defined(TARGET_NR_poll) || defined(TARGET_NR_ppoll) |
| 7092 | # ifdef TARGET_NR_poll |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 7093 | case TARGET_NR_poll: |
Mike Frysinger | d8035d4 | 2011-02-07 01:05:51 -0500 | [diff] [blame] | 7094 | # endif |
| 7095 | # ifdef TARGET_NR_ppoll |
| 7096 | case TARGET_NR_ppoll: |
| 7097 | # endif |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 7098 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7099 | struct target_pollfd *target_pfd; |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 7100 | unsigned int nfds = arg2; |
| 7101 | int timeout = arg3; |
| 7102 | struct pollfd *pfd; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 7103 | unsigned int i; |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 7104 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7105 | target_pfd = lock_user(VERIFY_WRITE, arg1, sizeof(struct target_pollfd) * nfds, 1); |
| 7106 | if (!target_pfd) |
| 7107 | goto efault; |
Mike Frysinger | d8035d4 | 2011-02-07 01:05:51 -0500 | [diff] [blame] | 7108 | |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 7109 | pfd = alloca(sizeof(struct pollfd) * nfds); |
| 7110 | for(i = 0; i < nfds; i++) { |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7111 | pfd[i].fd = tswap32(target_pfd[i].fd); |
| 7112 | pfd[i].events = tswap16(target_pfd[i].events); |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 7113 | } |
Mike Frysinger | d8035d4 | 2011-02-07 01:05:51 -0500 | [diff] [blame] | 7114 | |
| 7115 | # ifdef TARGET_NR_ppoll |
| 7116 | if (num == TARGET_NR_ppoll) { |
| 7117 | struct timespec _timeout_ts, *timeout_ts = &_timeout_ts; |
| 7118 | target_sigset_t *target_set; |
| 7119 | sigset_t _set, *set = &_set; |
| 7120 | |
| 7121 | if (arg3) { |
| 7122 | if (target_to_host_timespec(timeout_ts, arg3)) { |
| 7123 | unlock_user(target_pfd, arg1, 0); |
| 7124 | goto efault; |
| 7125 | } |
| 7126 | } else { |
| 7127 | timeout_ts = NULL; |
| 7128 | } |
| 7129 | |
| 7130 | if (arg4) { |
| 7131 | target_set = lock_user(VERIFY_READ, arg4, sizeof(target_sigset_t), 1); |
| 7132 | if (!target_set) { |
| 7133 | unlock_user(target_pfd, arg1, 0); |
| 7134 | goto efault; |
| 7135 | } |
| 7136 | target_to_host_sigset(set, target_set); |
| 7137 | } else { |
| 7138 | set = NULL; |
| 7139 | } |
| 7140 | |
| 7141 | ret = get_errno(sys_ppoll(pfd, nfds, timeout_ts, set, _NSIG/8)); |
| 7142 | |
| 7143 | if (!is_error(ret) && arg3) { |
| 7144 | host_to_target_timespec(arg3, timeout_ts); |
| 7145 | } |
| 7146 | if (arg4) { |
| 7147 | unlock_user(target_set, arg4, 0); |
| 7148 | } |
| 7149 | } else |
| 7150 | # endif |
| 7151 | ret = get_errno(poll(pfd, nfds, timeout)); |
| 7152 | |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 7153 | if (!is_error(ret)) { |
| 7154 | for(i = 0; i < nfds; i++) { |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7155 | target_pfd[i].revents = tswap16(pfd[i].revents); |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 7156 | } |
| 7157 | } |
Peter Maydell | 30cb4cd | 2011-02-25 10:27:40 +0000 | [diff] [blame] | 7158 | unlock_user(target_pfd, arg1, sizeof(struct target_pollfd) * nfds); |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 7159 | } |
| 7160 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7161 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7162 | case TARGET_NR_flock: |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 7163 | /* NOTE: the flock constant seems to be the same for every |
| 7164 | Linux platform */ |
| 7165 | ret = get_errno(flock(arg1, arg2)); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7166 | break; |
| 7167 | case TARGET_NR_readv: |
| 7168 | { |
| 7169 | int count = arg3; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7170 | struct iovec *vec; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7171 | |
| 7172 | vec = alloca(count * sizeof(struct iovec)); |
bellard | 41df841 | 2008-02-04 22:26:57 +0000 | [diff] [blame] | 7173 | if (lock_iovec(VERIFY_WRITE, vec, arg2, count, 0) < 0) |
| 7174 | goto efault; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7175 | ret = get_errno(readv(arg1, vec, count)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7176 | unlock_iovec(vec, arg2, count, 1); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7177 | } |
| 7178 | break; |
| 7179 | case TARGET_NR_writev: |
| 7180 | { |
| 7181 | int count = arg3; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7182 | struct iovec *vec; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7183 | |
| 7184 | vec = alloca(count * sizeof(struct iovec)); |
bellard | 41df841 | 2008-02-04 22:26:57 +0000 | [diff] [blame] | 7185 | if (lock_iovec(VERIFY_READ, vec, arg2, count, 1) < 0) |
| 7186 | goto efault; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7187 | ret = get_errno(writev(arg1, vec, count)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7188 | unlock_iovec(vec, arg2, count, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7189 | } |
| 7190 | break; |
| 7191 | case TARGET_NR_getsid: |
| 7192 | ret = get_errno(getsid(arg1)); |
| 7193 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 7194 | #if defined(TARGET_NR_fdatasync) /* Not on alpha (osf_datasync ?) */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7195 | case TARGET_NR_fdatasync: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7196 | ret = get_errno(fdatasync(arg1)); |
| 7197 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 7198 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7199 | case TARGET_NR__sysctl: |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 7200 | /* We don't implement this, but ENOTDIR is always a safe |
bellard | 29e619b | 2004-09-13 21:41:04 +0000 | [diff] [blame] | 7201 | return value. */ |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 7202 | ret = -TARGET_ENOTDIR; |
| 7203 | break; |
Mike Frysinger | 737de1d | 2011-02-07 01:05:55 -0500 | [diff] [blame] | 7204 | case TARGET_NR_sched_getaffinity: |
| 7205 | { |
| 7206 | unsigned int mask_size; |
| 7207 | unsigned long *mask; |
| 7208 | |
| 7209 | /* |
| 7210 | * sched_getaffinity needs multiples of ulong, so need to take |
| 7211 | * care of mismatches between target ulong and host ulong sizes. |
| 7212 | */ |
| 7213 | if (arg2 & (sizeof(abi_ulong) - 1)) { |
| 7214 | ret = -TARGET_EINVAL; |
| 7215 | break; |
| 7216 | } |
| 7217 | mask_size = (arg2 + (sizeof(*mask) - 1)) & ~(sizeof(*mask) - 1); |
| 7218 | |
| 7219 | mask = alloca(mask_size); |
| 7220 | ret = get_errno(sys_sched_getaffinity(arg1, mask_size, mask)); |
| 7221 | |
| 7222 | if (!is_error(ret)) { |
Mike McCormack | cd18f05 | 2011-04-18 14:43:36 +0900 | [diff] [blame] | 7223 | if (copy_to_user(arg3, mask, ret)) { |
Mike Frysinger | 737de1d | 2011-02-07 01:05:55 -0500 | [diff] [blame] | 7224 | goto efault; |
| 7225 | } |
Mike Frysinger | 737de1d | 2011-02-07 01:05:55 -0500 | [diff] [blame] | 7226 | } |
| 7227 | } |
| 7228 | break; |
| 7229 | case TARGET_NR_sched_setaffinity: |
| 7230 | { |
| 7231 | unsigned int mask_size; |
| 7232 | unsigned long *mask; |
| 7233 | |
| 7234 | /* |
| 7235 | * sched_setaffinity needs multiples of ulong, so need to take |
| 7236 | * care of mismatches between target ulong and host ulong sizes. |
| 7237 | */ |
| 7238 | if (arg2 & (sizeof(abi_ulong) - 1)) { |
| 7239 | ret = -TARGET_EINVAL; |
| 7240 | break; |
| 7241 | } |
| 7242 | mask_size = (arg2 + (sizeof(*mask) - 1)) & ~(sizeof(*mask) - 1); |
| 7243 | |
| 7244 | mask = alloca(mask_size); |
| 7245 | if (!lock_user_struct(VERIFY_READ, p, arg3, 1)) { |
| 7246 | goto efault; |
| 7247 | } |
| 7248 | memcpy(mask, p, arg2); |
| 7249 | unlock_user_struct(p, arg2, 0); |
| 7250 | |
| 7251 | ret = get_errno(sys_sched_setaffinity(arg1, mask_size, mask)); |
| 7252 | } |
| 7253 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7254 | case TARGET_NR_sched_setparam: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7255 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7256 | struct sched_param *target_schp; |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7257 | struct sched_param schp; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7258 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7259 | if (!lock_user_struct(VERIFY_READ, target_schp, arg2, 1)) |
| 7260 | goto efault; |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7261 | schp.sched_priority = tswap32(target_schp->sched_priority); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7262 | unlock_user_struct(target_schp, arg2, 0); |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7263 | ret = get_errno(sched_setparam(arg1, &schp)); |
| 7264 | } |
| 7265 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7266 | case TARGET_NR_sched_getparam: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7267 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7268 | struct sched_param *target_schp; |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7269 | struct sched_param schp; |
| 7270 | ret = get_errno(sched_getparam(arg1, &schp)); |
| 7271 | if (!is_error(ret)) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7272 | if (!lock_user_struct(VERIFY_WRITE, target_schp, arg2, 0)) |
| 7273 | goto efault; |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7274 | target_schp->sched_priority = tswap32(schp.sched_priority); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7275 | unlock_user_struct(target_schp, arg2, 1); |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7276 | } |
| 7277 | } |
| 7278 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7279 | case TARGET_NR_sched_setscheduler: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7280 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7281 | struct sched_param *target_schp; |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7282 | struct sched_param schp; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7283 | if (!lock_user_struct(VERIFY_READ, target_schp, arg3, 1)) |
| 7284 | goto efault; |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7285 | schp.sched_priority = tswap32(target_schp->sched_priority); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7286 | unlock_user_struct(target_schp, arg3, 0); |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7287 | ret = get_errno(sched_setscheduler(arg1, arg2, &schp)); |
| 7288 | } |
| 7289 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7290 | case TARGET_NR_sched_getscheduler: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7291 | ret = get_errno(sched_getscheduler(arg1)); |
| 7292 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7293 | case TARGET_NR_sched_yield: |
| 7294 | ret = get_errno(sched_yield()); |
| 7295 | break; |
| 7296 | case TARGET_NR_sched_get_priority_max: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7297 | ret = get_errno(sched_get_priority_max(arg1)); |
| 7298 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7299 | case TARGET_NR_sched_get_priority_min: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7300 | ret = get_errno(sched_get_priority_min(arg1)); |
| 7301 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7302 | case TARGET_NR_sched_rr_get_interval: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7303 | { |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7304 | struct timespec ts; |
| 7305 | ret = get_errno(sched_rr_get_interval(arg1, &ts)); |
| 7306 | if (!is_error(ret)) { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7307 | host_to_target_timespec(arg2, &ts); |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7308 | } |
| 7309 | } |
| 7310 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7311 | case TARGET_NR_nanosleep: |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 7312 | { |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 7313 | struct timespec req, rem; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7314 | target_to_host_timespec(&req, arg1); |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 7315 | ret = get_errno(nanosleep(&req, &rem)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7316 | if (is_error(ret) && arg2) { |
| 7317 | host_to_target_timespec(arg2, &rem); |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 7318 | } |
| 7319 | } |
| 7320 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7321 | #ifdef TARGET_NR_query_module |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7322 | case TARGET_NR_query_module: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7323 | goto unimplemented; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7324 | #endif |
| 7325 | #ifdef TARGET_NR_nfsservctl |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7326 | case TARGET_NR_nfsservctl: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7327 | goto unimplemented; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7328 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7329 | case TARGET_NR_prctl: |
Peter Maydell | 1e6722f | 2012-02-03 14:48:03 +0000 | [diff] [blame] | 7330 | switch (arg1) { |
| 7331 | case PR_GET_PDEATHSIG: |
| 7332 | { |
| 7333 | int deathsig; |
| 7334 | ret = get_errno(prctl(arg1, &deathsig, arg3, arg4, arg5)); |
| 7335 | if (!is_error(ret) && arg2 |
| 7336 | && put_user_ual(deathsig, arg2)) { |
| 7337 | goto efault; |
ths | e557448 | 2007-02-11 20:03:13 +0000 | [diff] [blame] | 7338 | } |
Peter Maydell | 1e6722f | 2012-02-03 14:48:03 +0000 | [diff] [blame] | 7339 | break; |
| 7340 | } |
Peter Maydell | db9526b | 2012-02-03 14:48:03 +0000 | [diff] [blame] | 7341 | #ifdef PR_GET_NAME |
| 7342 | case PR_GET_NAME: |
| 7343 | { |
| 7344 | void *name = lock_user(VERIFY_WRITE, arg2, 16, 1); |
| 7345 | if (!name) { |
| 7346 | goto efault; |
| 7347 | } |
| 7348 | ret = get_errno(prctl(arg1, (unsigned long)name, |
| 7349 | arg3, arg4, arg5)); |
| 7350 | unlock_user(name, arg2, 16); |
| 7351 | break; |
| 7352 | } |
| 7353 | case PR_SET_NAME: |
| 7354 | { |
| 7355 | void *name = lock_user(VERIFY_READ, arg2, 16, 1); |
| 7356 | if (!name) { |
| 7357 | goto efault; |
| 7358 | } |
| 7359 | ret = get_errno(prctl(arg1, (unsigned long)name, |
| 7360 | arg3, arg4, arg5)); |
| 7361 | unlock_user(name, arg2, 0); |
| 7362 | break; |
| 7363 | } |
| 7364 | #endif |
Peter Maydell | 1e6722f | 2012-02-03 14:48:03 +0000 | [diff] [blame] | 7365 | default: |
| 7366 | /* Most prctl options have no pointer arguments */ |
| 7367 | ret = get_errno(prctl(arg1, arg2, arg3, arg4, arg5)); |
| 7368 | break; |
| 7369 | } |
ths | 39b9aae | 2007-02-11 18:36:44 +0000 | [diff] [blame] | 7370 | break; |
bellard | d2fd1af | 2007-11-14 18:08:56 +0000 | [diff] [blame] | 7371 | #ifdef TARGET_NR_arch_prctl |
| 7372 | case TARGET_NR_arch_prctl: |
| 7373 | #if defined(TARGET_I386) && !defined(TARGET_ABI32) |
| 7374 | ret = do_arch_prctl(cpu_env, arg1, arg2); |
| 7375 | break; |
| 7376 | #else |
| 7377 | goto unimplemented; |
| 7378 | #endif |
| 7379 | #endif |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7380 | #ifdef TARGET_NR_pread |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7381 | case TARGET_NR_pread: |
Riku Voipio | 48e515d | 2011-07-12 15:40:51 +0300 | [diff] [blame] | 7382 | if (regpairs_aligned(cpu_env)) |
balrog | a4ae00b | 2008-09-20 03:14:14 +0000 | [diff] [blame] | 7383 | arg4 = arg5; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7384 | if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0))) |
| 7385 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7386 | ret = get_errno(pread(arg1, p, arg3, arg4)); |
| 7387 | unlock_user(p, arg2, ret); |
bellard | 206f0fa | 2003-05-14 19:01:56 +0000 | [diff] [blame] | 7388 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7389 | case TARGET_NR_pwrite: |
Riku Voipio | 48e515d | 2011-07-12 15:40:51 +0300 | [diff] [blame] | 7390 | if (regpairs_aligned(cpu_env)) |
balrog | a4ae00b | 2008-09-20 03:14:14 +0000 | [diff] [blame] | 7391 | arg4 = arg5; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7392 | if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1))) |
| 7393 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7394 | ret = get_errno(pwrite(arg1, p, arg3, arg4)); |
| 7395 | unlock_user(p, arg2, 0); |
bellard | 206f0fa | 2003-05-14 19:01:56 +0000 | [diff] [blame] | 7396 | break; |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7397 | #endif |
aurel32 | f2c7ba1 | 2008-03-28 22:32:06 +0000 | [diff] [blame] | 7398 | #ifdef TARGET_NR_pread64 |
| 7399 | case TARGET_NR_pread64: |
| 7400 | if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0))) |
| 7401 | goto efault; |
| 7402 | ret = get_errno(pread64(arg1, p, arg3, target_offset64(arg4, arg5))); |
| 7403 | unlock_user(p, arg2, ret); |
| 7404 | break; |
| 7405 | case TARGET_NR_pwrite64: |
| 7406 | if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1))) |
| 7407 | goto efault; |
| 7408 | ret = get_errno(pwrite64(arg1, p, arg3, target_offset64(arg4, arg5))); |
| 7409 | unlock_user(p, arg2, 0); |
| 7410 | break; |
| 7411 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7412 | case TARGET_NR_getcwd: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7413 | if (!(p = lock_user(VERIFY_WRITE, arg1, arg2, 0))) |
| 7414 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7415 | ret = get_errno(sys_getcwd1(p, arg2)); |
| 7416 | unlock_user(p, arg1, ret); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7417 | break; |
| 7418 | case TARGET_NR_capget: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7419 | goto unimplemented; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7420 | case TARGET_NR_capset: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7421 | goto unimplemented; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7422 | case TARGET_NR_sigaltstack: |
ths | 198a74d | 2007-09-27 16:44:32 +0000 | [diff] [blame] | 7423 | #if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_MIPS) || \ |
Laurent Vivier | c761c15 | 2009-08-03 16:12:19 +0200 | [diff] [blame] | 7424 | defined(TARGET_SPARC) || defined(TARGET_PPC) || defined(TARGET_ALPHA) || \ |
Ulrich Hecht | a4c075f | 2009-07-24 16:57:31 +0200 | [diff] [blame] | 7425 | defined(TARGET_M68K) || defined(TARGET_S390X) |
Andreas Färber | 9349b4f | 2012-03-14 01:38:32 +0100 | [diff] [blame] | 7426 | ret = do_sigaltstack(arg1, arg2, get_sp_from_cpustate((CPUArchState *)cpu_env)); |
ths | a04e134 | 2007-09-27 13:57:58 +0000 | [diff] [blame] | 7427 | break; |
| 7428 | #else |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7429 | goto unimplemented; |
ths | a04e134 | 2007-09-27 13:57:58 +0000 | [diff] [blame] | 7430 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7431 | case TARGET_NR_sendfile: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7432 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 7433 | #ifdef TARGET_NR_getpmsg |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7434 | case TARGET_NR_getpmsg: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7435 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 7436 | #endif |
| 7437 | #ifdef TARGET_NR_putpmsg |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7438 | case TARGET_NR_putpmsg: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7439 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 7440 | #endif |
bellard | 048f6b4 | 2005-11-26 18:47:20 +0000 | [diff] [blame] | 7441 | #ifdef TARGET_NR_vfork |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7442 | case TARGET_NR_vfork: |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 7443 | ret = get_errno(do_fork(cpu_env, CLONE_VFORK | CLONE_VM | SIGCHLD, |
| 7444 | 0, 0, 0, 0)); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7445 | break; |
bellard | 048f6b4 | 2005-11-26 18:47:20 +0000 | [diff] [blame] | 7446 | #endif |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 7447 | #ifdef TARGET_NR_ugetrlimit |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7448 | case TARGET_NR_ugetrlimit: |
bellard | 728584b | 2003-04-29 20:43:36 +0000 | [diff] [blame] | 7449 | { |
| 7450 | struct rlimit rlim; |
Wesley W. Terpstra | e22b701 | 2011-07-12 14:42:00 +0300 | [diff] [blame] | 7451 | int resource = target_to_host_resource(arg1); |
| 7452 | ret = get_errno(getrlimit(resource, &rlim)); |
bellard | 728584b | 2003-04-29 20:43:36 +0000 | [diff] [blame] | 7453 | if (!is_error(ret)) { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7454 | struct target_rlimit *target_rlim; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7455 | if (!lock_user_struct(VERIFY_WRITE, target_rlim, arg2, 0)) |
| 7456 | goto efault; |
takasi-y@ops.dti.ne.jp | 81bbe90 | 2010-04-12 04:07:35 +0900 | [diff] [blame] | 7457 | target_rlim->rlim_cur = host_to_target_rlim(rlim.rlim_cur); |
| 7458 | target_rlim->rlim_max = host_to_target_rlim(rlim.rlim_max); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7459 | unlock_user_struct(target_rlim, arg2, 1); |
bellard | 728584b | 2003-04-29 20:43:36 +0000 | [diff] [blame] | 7460 | } |
| 7461 | break; |
| 7462 | } |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 7463 | #endif |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7464 | #ifdef TARGET_NR_truncate64 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7465 | case TARGET_NR_truncate64: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7466 | if (!(p = lock_user_string(arg1))) |
| 7467 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7468 | ret = target_truncate64(cpu_env, p, arg2, arg3, arg4); |
| 7469 | unlock_user(p, arg1, 0); |
bellard | 667f38b | 2005-07-23 14:46:27 +0000 | [diff] [blame] | 7470 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7471 | #endif |
| 7472 | #ifdef TARGET_NR_ftruncate64 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7473 | case TARGET_NR_ftruncate64: |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 7474 | ret = target_ftruncate64(cpu_env, arg1, arg2, arg3, arg4); |
bellard | 667f38b | 2005-07-23 14:46:27 +0000 | [diff] [blame] | 7475 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7476 | #endif |
| 7477 | #ifdef TARGET_NR_stat64 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7478 | case TARGET_NR_stat64: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7479 | if (!(p = lock_user_string(arg1))) |
| 7480 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7481 | ret = get_errno(stat(path(p), &st)); |
| 7482 | unlock_user(p, arg1, 0); |
balrog | 6a24a77 | 2008-09-20 02:23:36 +0000 | [diff] [blame] | 7483 | if (!is_error(ret)) |
| 7484 | ret = host_to_target_stat64(cpu_env, arg2, &st); |
| 7485 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7486 | #endif |
| 7487 | #ifdef TARGET_NR_lstat64 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7488 | case TARGET_NR_lstat64: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7489 | if (!(p = lock_user_string(arg1))) |
| 7490 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7491 | ret = get_errno(lstat(path(p), &st)); |
| 7492 | unlock_user(p, arg1, 0); |
balrog | 6a24a77 | 2008-09-20 02:23:36 +0000 | [diff] [blame] | 7493 | if (!is_error(ret)) |
| 7494 | ret = host_to_target_stat64(cpu_env, arg2, &st); |
| 7495 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7496 | #endif |
| 7497 | #ifdef TARGET_NR_fstat64 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7498 | case TARGET_NR_fstat64: |
balrog | 6a24a77 | 2008-09-20 02:23:36 +0000 | [diff] [blame] | 7499 | ret = get_errno(fstat(arg1, &st)); |
| 7500 | if (!is_error(ret)) |
| 7501 | ret = host_to_target_stat64(cpu_env, arg2, &st); |
| 7502 | break; |
bellard | ec86b0f | 2003-04-11 00:15:04 +0000 | [diff] [blame] | 7503 | #endif |
aurel32 | 9d33b76 | 2009-04-08 23:07:05 +0000 | [diff] [blame] | 7504 | #if (defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)) && \ |
| 7505 | (defined(__NR_fstatat64) || defined(__NR_newfstatat)) |
| 7506 | #ifdef TARGET_NR_fstatat64 |
balrog | 6a24a77 | 2008-09-20 02:23:36 +0000 | [diff] [blame] | 7507 | case TARGET_NR_fstatat64: |
aurel32 | 9d33b76 | 2009-04-08 23:07:05 +0000 | [diff] [blame] | 7508 | #endif |
| 7509 | #ifdef TARGET_NR_newfstatat |
| 7510 | case TARGET_NR_newfstatat: |
| 7511 | #endif |
balrog | 6a24a77 | 2008-09-20 02:23:36 +0000 | [diff] [blame] | 7512 | if (!(p = lock_user_string(arg2))) |
| 7513 | goto efault; |
aurel32 | 9d33b76 | 2009-04-08 23:07:05 +0000 | [diff] [blame] | 7514 | #ifdef __NR_fstatat64 |
balrog | 6a24a77 | 2008-09-20 02:23:36 +0000 | [diff] [blame] | 7515 | ret = get_errno(sys_fstatat64(arg1, path(p), &st, arg4)); |
aurel32 | 9d33b76 | 2009-04-08 23:07:05 +0000 | [diff] [blame] | 7516 | #else |
| 7517 | ret = get_errno(sys_newfstatat(arg1, path(p), &st, arg4)); |
| 7518 | #endif |
balrog | 6a24a77 | 2008-09-20 02:23:36 +0000 | [diff] [blame] | 7519 | if (!is_error(ret)) |
| 7520 | ret = host_to_target_stat64(cpu_env, arg3, &st); |
bellard | 60cd49d | 2003-03-16 22:53:56 +0000 | [diff] [blame] | 7521 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7522 | #endif |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7523 | case TARGET_NR_lchown: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7524 | if (!(p = lock_user_string(arg1))) |
| 7525 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7526 | ret = get_errno(lchown(p, low2highuid(arg2), low2highgid(arg3))); |
| 7527 | unlock_user(p, arg1, 0); |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7528 | break; |
Riku Voipio | 0c866a7 | 2011-04-18 15:23:06 +0300 | [diff] [blame] | 7529 | #ifdef TARGET_NR_getuid |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7530 | case TARGET_NR_getuid: |
| 7531 | ret = get_errno(high2lowuid(getuid())); |
| 7532 | break; |
Riku Voipio | 0c866a7 | 2011-04-18 15:23:06 +0300 | [diff] [blame] | 7533 | #endif |
| 7534 | #ifdef TARGET_NR_getgid |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7535 | case TARGET_NR_getgid: |
| 7536 | ret = get_errno(high2lowgid(getgid())); |
| 7537 | break; |
Riku Voipio | 0c866a7 | 2011-04-18 15:23:06 +0300 | [diff] [blame] | 7538 | #endif |
| 7539 | #ifdef TARGET_NR_geteuid |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7540 | case TARGET_NR_geteuid: |
| 7541 | ret = get_errno(high2lowuid(geteuid())); |
| 7542 | break; |
Riku Voipio | 0c866a7 | 2011-04-18 15:23:06 +0300 | [diff] [blame] | 7543 | #endif |
| 7544 | #ifdef TARGET_NR_getegid |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7545 | case TARGET_NR_getegid: |
| 7546 | ret = get_errno(high2lowgid(getegid())); |
| 7547 | break; |
Riku Voipio | 0c866a7 | 2011-04-18 15:23:06 +0300 | [diff] [blame] | 7548 | #endif |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7549 | case TARGET_NR_setreuid: |
| 7550 | ret = get_errno(setreuid(low2highuid(arg1), low2highuid(arg2))); |
| 7551 | break; |
| 7552 | case TARGET_NR_setregid: |
| 7553 | ret = get_errno(setregid(low2highgid(arg1), low2highgid(arg2))); |
| 7554 | break; |
| 7555 | case TARGET_NR_getgroups: |
| 7556 | { |
| 7557 | int gidsetsize = arg1; |
Riku Voipio | 0c866a7 | 2011-04-18 15:23:06 +0300 | [diff] [blame] | 7558 | target_id *target_grouplist; |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7559 | gid_t *grouplist; |
| 7560 | int i; |
| 7561 | |
| 7562 | grouplist = alloca(gidsetsize * sizeof(gid_t)); |
| 7563 | ret = get_errno(getgroups(gidsetsize, grouplist)); |
balrog | cb3bc23 | 2008-09-20 02:08:13 +0000 | [diff] [blame] | 7564 | if (gidsetsize == 0) |
| 7565 | break; |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7566 | if (!is_error(ret)) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7567 | target_grouplist = lock_user(VERIFY_WRITE, arg2, gidsetsize * 2, 0); |
| 7568 | if (!target_grouplist) |
| 7569 | goto efault; |
balrog | a2155fc | 2008-09-20 02:12:08 +0000 | [diff] [blame] | 7570 | for(i = 0;i < ret; i++) |
Riku Voipio | 0c866a7 | 2011-04-18 15:23:06 +0300 | [diff] [blame] | 7571 | target_grouplist[i] = tswapid(high2lowgid(grouplist[i])); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7572 | unlock_user(target_grouplist, arg2, gidsetsize * 2); |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7573 | } |
| 7574 | } |
| 7575 | break; |
| 7576 | case TARGET_NR_setgroups: |
| 7577 | { |
| 7578 | int gidsetsize = arg1; |
Riku Voipio | 0c866a7 | 2011-04-18 15:23:06 +0300 | [diff] [blame] | 7579 | target_id *target_grouplist; |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7580 | gid_t *grouplist; |
| 7581 | int i; |
| 7582 | |
| 7583 | grouplist = alloca(gidsetsize * sizeof(gid_t)); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7584 | target_grouplist = lock_user(VERIFY_READ, arg2, gidsetsize * 2, 1); |
| 7585 | if (!target_grouplist) { |
| 7586 | ret = -TARGET_EFAULT; |
| 7587 | goto fail; |
| 7588 | } |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7589 | for(i = 0;i < gidsetsize; i++) |
Riku Voipio | 0c866a7 | 2011-04-18 15:23:06 +0300 | [diff] [blame] | 7590 | grouplist[i] = low2highgid(tswapid(target_grouplist[i])); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7591 | unlock_user(target_grouplist, arg2, 0); |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7592 | ret = get_errno(setgroups(gidsetsize, grouplist)); |
| 7593 | } |
| 7594 | break; |
| 7595 | case TARGET_NR_fchown: |
| 7596 | ret = get_errno(fchown(arg1, low2highuid(arg2), low2highgid(arg3))); |
| 7597 | break; |
ths | ccfa72b | 2007-09-24 09:23:34 +0000 | [diff] [blame] | 7598 | #if defined(TARGET_NR_fchownat) && defined(__NR_fchownat) |
| 7599 | case TARGET_NR_fchownat: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7600 | if (!(p = lock_user_string(arg2))) |
| 7601 | goto efault; |
| 7602 | ret = get_errno(sys_fchownat(arg1, p, low2highuid(arg3), low2highgid(arg4), arg5)); |
| 7603 | unlock_user(p, arg2, 0); |
ths | ccfa72b | 2007-09-24 09:23:34 +0000 | [diff] [blame] | 7604 | break; |
| 7605 | #endif |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7606 | #ifdef TARGET_NR_setresuid |
| 7607 | case TARGET_NR_setresuid: |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 7608 | ret = get_errno(setresuid(low2highuid(arg1), |
| 7609 | low2highuid(arg2), |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7610 | low2highuid(arg3))); |
| 7611 | break; |
| 7612 | #endif |
| 7613 | #ifdef TARGET_NR_getresuid |
| 7614 | case TARGET_NR_getresuid: |
| 7615 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7616 | uid_t ruid, euid, suid; |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7617 | ret = get_errno(getresuid(&ruid, &euid, &suid)); |
| 7618 | if (!is_error(ret)) { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 7619 | if (put_user_u16(high2lowuid(ruid), arg1) |
| 7620 | || put_user_u16(high2lowuid(euid), arg2) |
| 7621 | || put_user_u16(high2lowuid(suid), arg3)) |
| 7622 | goto efault; |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7623 | } |
| 7624 | } |
| 7625 | break; |
| 7626 | #endif |
| 7627 | #ifdef TARGET_NR_getresgid |
| 7628 | case TARGET_NR_setresgid: |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 7629 | ret = get_errno(setresgid(low2highgid(arg1), |
| 7630 | low2highgid(arg2), |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7631 | low2highgid(arg3))); |
| 7632 | break; |
| 7633 | #endif |
| 7634 | #ifdef TARGET_NR_getresgid |
| 7635 | case TARGET_NR_getresgid: |
| 7636 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7637 | gid_t rgid, egid, sgid; |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7638 | ret = get_errno(getresgid(&rgid, &egid, &sgid)); |
| 7639 | if (!is_error(ret)) { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 7640 | if (put_user_u16(high2lowgid(rgid), arg1) |
| 7641 | || put_user_u16(high2lowgid(egid), arg2) |
| 7642 | || put_user_u16(high2lowgid(sgid), arg3)) |
| 7643 | goto efault; |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7644 | } |
| 7645 | } |
| 7646 | break; |
| 7647 | #endif |
| 7648 | case TARGET_NR_chown: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7649 | if (!(p = lock_user_string(arg1))) |
| 7650 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7651 | ret = get_errno(chown(p, low2highuid(arg2), low2highgid(arg3))); |
| 7652 | unlock_user(p, arg1, 0); |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7653 | break; |
| 7654 | case TARGET_NR_setuid: |
| 7655 | ret = get_errno(setuid(low2highuid(arg1))); |
| 7656 | break; |
| 7657 | case TARGET_NR_setgid: |
| 7658 | ret = get_errno(setgid(low2highgid(arg1))); |
| 7659 | break; |
| 7660 | case TARGET_NR_setfsuid: |
| 7661 | ret = get_errno(setfsuid(arg1)); |
| 7662 | break; |
| 7663 | case TARGET_NR_setfsgid: |
| 7664 | ret = get_errno(setfsgid(arg1)); |
| 7665 | break; |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7666 | |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7667 | #ifdef TARGET_NR_lchown32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7668 | case TARGET_NR_lchown32: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7669 | if (!(p = lock_user_string(arg1))) |
| 7670 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7671 | ret = get_errno(lchown(p, arg2, arg3)); |
| 7672 | unlock_user(p, arg1, 0); |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 7673 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7674 | #endif |
| 7675 | #ifdef TARGET_NR_getuid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7676 | case TARGET_NR_getuid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 7677 | ret = get_errno(getuid()); |
| 7678 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7679 | #endif |
aurel32 | 64b4d28 | 2008-11-14 17:20:15 +0000 | [diff] [blame] | 7680 | |
| 7681 | #if defined(TARGET_NR_getxuid) && defined(TARGET_ALPHA) |
| 7682 | /* Alpha specific */ |
| 7683 | case TARGET_NR_getxuid: |
Richard Henderson | ba0e276 | 2009-12-09 15:56:29 -0800 | [diff] [blame] | 7684 | { |
| 7685 | uid_t euid; |
| 7686 | euid=geteuid(); |
| 7687 | ((CPUAlphaState *)cpu_env)->ir[IR_A4]=euid; |
| 7688 | } |
aurel32 | 64b4d28 | 2008-11-14 17:20:15 +0000 | [diff] [blame] | 7689 | ret = get_errno(getuid()); |
| 7690 | break; |
| 7691 | #endif |
| 7692 | #if defined(TARGET_NR_getxgid) && defined(TARGET_ALPHA) |
| 7693 | /* Alpha specific */ |
| 7694 | case TARGET_NR_getxgid: |
Richard Henderson | ba0e276 | 2009-12-09 15:56:29 -0800 | [diff] [blame] | 7695 | { |
| 7696 | uid_t egid; |
| 7697 | egid=getegid(); |
| 7698 | ((CPUAlphaState *)cpu_env)->ir[IR_A4]=egid; |
| 7699 | } |
aurel32 | 64b4d28 | 2008-11-14 17:20:15 +0000 | [diff] [blame] | 7700 | ret = get_errno(getgid()); |
| 7701 | break; |
| 7702 | #endif |
Richard Henderson | ba0e276 | 2009-12-09 15:56:29 -0800 | [diff] [blame] | 7703 | #if defined(TARGET_NR_osf_getsysinfo) && defined(TARGET_ALPHA) |
| 7704 | /* Alpha specific */ |
| 7705 | case TARGET_NR_osf_getsysinfo: |
| 7706 | ret = -TARGET_EOPNOTSUPP; |
| 7707 | switch (arg1) { |
| 7708 | case TARGET_GSI_IEEE_FP_CONTROL: |
| 7709 | { |
| 7710 | uint64_t swcr, fpcr = cpu_alpha_load_fpcr (cpu_env); |
| 7711 | |
| 7712 | /* Copied from linux ieee_fpcr_to_swcr. */ |
| 7713 | swcr = (fpcr >> 35) & SWCR_STATUS_MASK; |
| 7714 | swcr |= (fpcr >> 36) & SWCR_MAP_DMZ; |
| 7715 | swcr |= (~fpcr >> 48) & (SWCR_TRAP_ENABLE_INV |
| 7716 | | SWCR_TRAP_ENABLE_DZE |
| 7717 | | SWCR_TRAP_ENABLE_OVF); |
| 7718 | swcr |= (~fpcr >> 57) & (SWCR_TRAP_ENABLE_UNF |
| 7719 | | SWCR_TRAP_ENABLE_INE); |
| 7720 | swcr |= (fpcr >> 47) & SWCR_MAP_UMZ; |
| 7721 | swcr |= (~fpcr >> 41) & SWCR_TRAP_ENABLE_DNO; |
| 7722 | |
| 7723 | if (put_user_u64 (swcr, arg2)) |
| 7724 | goto efault; |
| 7725 | ret = 0; |
| 7726 | } |
| 7727 | break; |
| 7728 | |
| 7729 | /* case GSI_IEEE_STATE_AT_SIGNAL: |
| 7730 | -- Not implemented in linux kernel. |
| 7731 | case GSI_UACPROC: |
| 7732 | -- Retrieves current unaligned access state; not much used. |
| 7733 | case GSI_PROC_TYPE: |
| 7734 | -- Retrieves implver information; surely not used. |
| 7735 | case GSI_GET_HWRPB: |
| 7736 | -- Grabs a copy of the HWRPB; surely not used. |
| 7737 | */ |
| 7738 | } |
| 7739 | break; |
| 7740 | #endif |
| 7741 | #if defined(TARGET_NR_osf_setsysinfo) && defined(TARGET_ALPHA) |
| 7742 | /* Alpha specific */ |
| 7743 | case TARGET_NR_osf_setsysinfo: |
| 7744 | ret = -TARGET_EOPNOTSUPP; |
| 7745 | switch (arg1) { |
| 7746 | case TARGET_SSI_IEEE_FP_CONTROL: |
| 7747 | case TARGET_SSI_IEEE_RAISE_EXCEPTION: |
| 7748 | { |
| 7749 | uint64_t swcr, fpcr, orig_fpcr; |
| 7750 | |
| 7751 | if (get_user_u64 (swcr, arg2)) |
| 7752 | goto efault; |
| 7753 | orig_fpcr = cpu_alpha_load_fpcr (cpu_env); |
| 7754 | fpcr = orig_fpcr & FPCR_DYN_MASK; |
| 7755 | |
| 7756 | /* Copied from linux ieee_swcr_to_fpcr. */ |
| 7757 | fpcr |= (swcr & SWCR_STATUS_MASK) << 35; |
| 7758 | fpcr |= (swcr & SWCR_MAP_DMZ) << 36; |
| 7759 | fpcr |= (~swcr & (SWCR_TRAP_ENABLE_INV |
| 7760 | | SWCR_TRAP_ENABLE_DZE |
| 7761 | | SWCR_TRAP_ENABLE_OVF)) << 48; |
| 7762 | fpcr |= (~swcr & (SWCR_TRAP_ENABLE_UNF |
| 7763 | | SWCR_TRAP_ENABLE_INE)) << 57; |
| 7764 | fpcr |= (swcr & SWCR_MAP_UMZ ? FPCR_UNDZ | FPCR_UNFD : 0); |
| 7765 | fpcr |= (~swcr & SWCR_TRAP_ENABLE_DNO) << 41; |
| 7766 | |
| 7767 | cpu_alpha_store_fpcr (cpu_env, fpcr); |
| 7768 | ret = 0; |
| 7769 | |
| 7770 | if (arg1 == TARGET_SSI_IEEE_RAISE_EXCEPTION) { |
| 7771 | /* Old exceptions are not signaled. */ |
| 7772 | fpcr &= ~(orig_fpcr & FPCR_STATUS_MASK); |
| 7773 | |
| 7774 | /* If any exceptions set by this call, and are unmasked, |
| 7775 | send a signal. */ |
| 7776 | /* ??? FIXME */ |
| 7777 | } |
| 7778 | } |
| 7779 | break; |
| 7780 | |
| 7781 | /* case SSI_NVPAIRS: |
| 7782 | -- Used with SSIN_UACPROC to enable unaligned accesses. |
| 7783 | case SSI_IEEE_STATE_AT_SIGNAL: |
| 7784 | case SSI_IEEE_IGNORE_STATE_AT_SIGNAL: |
| 7785 | -- Not implemented in linux kernel |
| 7786 | */ |
| 7787 | } |
| 7788 | break; |
| 7789 | #endif |
| 7790 | #ifdef TARGET_NR_osf_sigprocmask |
| 7791 | /* Alpha specific. */ |
| 7792 | case TARGET_NR_osf_sigprocmask: |
| 7793 | { |
| 7794 | abi_ulong mask; |
Juan Quintela | bc088ba | 2011-06-16 17:37:10 +0100 | [diff] [blame] | 7795 | int how; |
Richard Henderson | ba0e276 | 2009-12-09 15:56:29 -0800 | [diff] [blame] | 7796 | sigset_t set, oldset; |
| 7797 | |
| 7798 | switch(arg1) { |
| 7799 | case TARGET_SIG_BLOCK: |
| 7800 | how = SIG_BLOCK; |
| 7801 | break; |
| 7802 | case TARGET_SIG_UNBLOCK: |
| 7803 | how = SIG_UNBLOCK; |
| 7804 | break; |
| 7805 | case TARGET_SIG_SETMASK: |
| 7806 | how = SIG_SETMASK; |
| 7807 | break; |
| 7808 | default: |
| 7809 | ret = -TARGET_EINVAL; |
| 7810 | goto fail; |
| 7811 | } |
| 7812 | mask = arg2; |
| 7813 | target_to_host_old_sigset(&set, &mask); |
Juan Quintela | bc088ba | 2011-06-16 17:37:10 +0100 | [diff] [blame] | 7814 | sigprocmask(how, &set, &oldset); |
Richard Henderson | ba0e276 | 2009-12-09 15:56:29 -0800 | [diff] [blame] | 7815 | host_to_target_old_sigset(&mask, &oldset); |
| 7816 | ret = mask; |
| 7817 | } |
| 7818 | break; |
| 7819 | #endif |
aurel32 | 64b4d28 | 2008-11-14 17:20:15 +0000 | [diff] [blame] | 7820 | |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7821 | #ifdef TARGET_NR_getgid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7822 | case TARGET_NR_getgid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 7823 | ret = get_errno(getgid()); |
| 7824 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7825 | #endif |
| 7826 | #ifdef TARGET_NR_geteuid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7827 | case TARGET_NR_geteuid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 7828 | ret = get_errno(geteuid()); |
| 7829 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7830 | #endif |
| 7831 | #ifdef TARGET_NR_getegid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7832 | case TARGET_NR_getegid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 7833 | ret = get_errno(getegid()); |
| 7834 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7835 | #endif |
| 7836 | #ifdef TARGET_NR_setreuid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7837 | case TARGET_NR_setreuid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 7838 | ret = get_errno(setreuid(arg1, arg2)); |
| 7839 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7840 | #endif |
| 7841 | #ifdef TARGET_NR_setregid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7842 | case TARGET_NR_setregid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 7843 | ret = get_errno(setregid(arg1, arg2)); |
| 7844 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7845 | #endif |
| 7846 | #ifdef TARGET_NR_getgroups32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7847 | case TARGET_NR_getgroups32: |
bellard | 99c475a | 2005-01-31 20:45:13 +0000 | [diff] [blame] | 7848 | { |
| 7849 | int gidsetsize = arg1; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7850 | uint32_t *target_grouplist; |
bellard | 99c475a | 2005-01-31 20:45:13 +0000 | [diff] [blame] | 7851 | gid_t *grouplist; |
| 7852 | int i; |
| 7853 | |
| 7854 | grouplist = alloca(gidsetsize * sizeof(gid_t)); |
| 7855 | ret = get_errno(getgroups(gidsetsize, grouplist)); |
balrog | cb3bc23 | 2008-09-20 02:08:13 +0000 | [diff] [blame] | 7856 | if (gidsetsize == 0) |
| 7857 | break; |
bellard | 99c475a | 2005-01-31 20:45:13 +0000 | [diff] [blame] | 7858 | if (!is_error(ret)) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7859 | target_grouplist = lock_user(VERIFY_WRITE, arg2, gidsetsize * 4, 0); |
| 7860 | if (!target_grouplist) { |
| 7861 | ret = -TARGET_EFAULT; |
| 7862 | goto fail; |
| 7863 | } |
balrog | a2155fc | 2008-09-20 02:12:08 +0000 | [diff] [blame] | 7864 | for(i = 0;i < ret; i++) |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7865 | target_grouplist[i] = tswap32(grouplist[i]); |
| 7866 | unlock_user(target_grouplist, arg2, gidsetsize * 4); |
bellard | 99c475a | 2005-01-31 20:45:13 +0000 | [diff] [blame] | 7867 | } |
| 7868 | } |
| 7869 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7870 | #endif |
| 7871 | #ifdef TARGET_NR_setgroups32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7872 | case TARGET_NR_setgroups32: |
bellard | 99c475a | 2005-01-31 20:45:13 +0000 | [diff] [blame] | 7873 | { |
| 7874 | int gidsetsize = arg1; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7875 | uint32_t *target_grouplist; |
bellard | 99c475a | 2005-01-31 20:45:13 +0000 | [diff] [blame] | 7876 | gid_t *grouplist; |
| 7877 | int i; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 7878 | |
bellard | 99c475a | 2005-01-31 20:45:13 +0000 | [diff] [blame] | 7879 | grouplist = alloca(gidsetsize * sizeof(gid_t)); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7880 | target_grouplist = lock_user(VERIFY_READ, arg2, gidsetsize * 4, 1); |
| 7881 | if (!target_grouplist) { |
| 7882 | ret = -TARGET_EFAULT; |
| 7883 | goto fail; |
| 7884 | } |
bellard | 99c475a | 2005-01-31 20:45:13 +0000 | [diff] [blame] | 7885 | for(i = 0;i < gidsetsize; i++) |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7886 | grouplist[i] = tswap32(target_grouplist[i]); |
| 7887 | unlock_user(target_grouplist, arg2, 0); |
bellard | 99c475a | 2005-01-31 20:45:13 +0000 | [diff] [blame] | 7888 | ret = get_errno(setgroups(gidsetsize, grouplist)); |
| 7889 | } |
| 7890 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7891 | #endif |
| 7892 | #ifdef TARGET_NR_fchown32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7893 | case TARGET_NR_fchown32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 7894 | ret = get_errno(fchown(arg1, arg2, arg3)); |
| 7895 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7896 | #endif |
| 7897 | #ifdef TARGET_NR_setresuid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7898 | case TARGET_NR_setresuid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 7899 | ret = get_errno(setresuid(arg1, arg2, arg3)); |
| 7900 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7901 | #endif |
| 7902 | #ifdef TARGET_NR_getresuid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7903 | case TARGET_NR_getresuid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 7904 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7905 | uid_t ruid, euid, suid; |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 7906 | ret = get_errno(getresuid(&ruid, &euid, &suid)); |
| 7907 | if (!is_error(ret)) { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 7908 | if (put_user_u32(ruid, arg1) |
| 7909 | || put_user_u32(euid, arg2) |
| 7910 | || put_user_u32(suid, arg3)) |
| 7911 | goto efault; |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 7912 | } |
| 7913 | } |
| 7914 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7915 | #endif |
| 7916 | #ifdef TARGET_NR_setresgid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7917 | case TARGET_NR_setresgid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 7918 | ret = get_errno(setresgid(arg1, arg2, arg3)); |
| 7919 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7920 | #endif |
| 7921 | #ifdef TARGET_NR_getresgid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7922 | case TARGET_NR_getresgid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 7923 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7924 | gid_t rgid, egid, sgid; |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 7925 | ret = get_errno(getresgid(&rgid, &egid, &sgid)); |
| 7926 | if (!is_error(ret)) { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 7927 | if (put_user_u32(rgid, arg1) |
| 7928 | || put_user_u32(egid, arg2) |
| 7929 | || put_user_u32(sgid, arg3)) |
| 7930 | goto efault; |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 7931 | } |
| 7932 | } |
| 7933 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7934 | #endif |
| 7935 | #ifdef TARGET_NR_chown32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7936 | case TARGET_NR_chown32: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7937 | if (!(p = lock_user_string(arg1))) |
| 7938 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7939 | ret = get_errno(chown(p, arg2, arg3)); |
| 7940 | unlock_user(p, arg1, 0); |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 7941 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7942 | #endif |
| 7943 | #ifdef TARGET_NR_setuid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7944 | case TARGET_NR_setuid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 7945 | ret = get_errno(setuid(arg1)); |
| 7946 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7947 | #endif |
| 7948 | #ifdef TARGET_NR_setgid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7949 | case TARGET_NR_setgid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 7950 | ret = get_errno(setgid(arg1)); |
| 7951 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7952 | #endif |
| 7953 | #ifdef TARGET_NR_setfsuid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7954 | case TARGET_NR_setfsuid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 7955 | ret = get_errno(setfsuid(arg1)); |
| 7956 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7957 | #endif |
| 7958 | #ifdef TARGET_NR_setfsgid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7959 | case TARGET_NR_setfsgid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 7960 | ret = get_errno(setfsgid(arg1)); |
| 7961 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7962 | #endif |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 7963 | |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7964 | case TARGET_NR_pivot_root: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 7965 | goto unimplemented; |
bellard | ffa65c3 | 2004-01-04 23:57:22 +0000 | [diff] [blame] | 7966 | #ifdef TARGET_NR_mincore |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7967 | case TARGET_NR_mincore: |
aurel32 | 04bb9ac | 2008-10-01 21:46:41 +0000 | [diff] [blame] | 7968 | { |
| 7969 | void *a; |
| 7970 | ret = -TARGET_EFAULT; |
| 7971 | if (!(a = lock_user(VERIFY_READ, arg1,arg2, 0))) |
| 7972 | goto efault; |
| 7973 | if (!(p = lock_user_string(arg3))) |
| 7974 | goto mincore_fail; |
| 7975 | ret = get_errno(mincore(a, arg2, p)); |
| 7976 | unlock_user(p, arg3, ret); |
| 7977 | mincore_fail: |
| 7978 | unlock_user(a, arg1, 0); |
| 7979 | } |
| 7980 | break; |
bellard | ffa65c3 | 2004-01-04 23:57:22 +0000 | [diff] [blame] | 7981 | #endif |
aurel32 | 408321b | 2008-10-01 21:46:32 +0000 | [diff] [blame] | 7982 | #ifdef TARGET_NR_arm_fadvise64_64 |
| 7983 | case TARGET_NR_arm_fadvise64_64: |
| 7984 | { |
| 7985 | /* |
| 7986 | * arm_fadvise64_64 looks like fadvise64_64 but |
| 7987 | * with different argument order |
| 7988 | */ |
| 7989 | abi_long temp; |
| 7990 | temp = arg3; |
| 7991 | arg3 = arg4; |
| 7992 | arg4 = temp; |
| 7993 | } |
| 7994 | #endif |
Ulrich Hecht | e72d2cc | 2009-07-24 19:10:31 +0200 | [diff] [blame] | 7995 | #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] | 7996 | #ifdef TARGET_NR_fadvise64_64 |
| 7997 | case TARGET_NR_fadvise64_64: |
| 7998 | #endif |
Ulrich Hecht | e72d2cc | 2009-07-24 19:10:31 +0200 | [diff] [blame] | 7999 | #ifdef TARGET_NR_fadvise64 |
| 8000 | case TARGET_NR_fadvise64: |
| 8001 | #endif |
| 8002 | #ifdef TARGET_S390X |
| 8003 | switch (arg4) { |
| 8004 | case 4: arg4 = POSIX_FADV_NOREUSE + 1; break; /* make sure it's an invalid value */ |
| 8005 | case 5: arg4 = POSIX_FADV_NOREUSE + 2; break; /* ditto */ |
| 8006 | case 6: arg4 = POSIX_FADV_DONTNEED; break; |
| 8007 | case 7: arg4 = POSIX_FADV_NOREUSE; break; |
| 8008 | default: break; |
| 8009 | } |
| 8010 | #endif |
| 8011 | ret = -posix_fadvise(arg1, arg2, arg3, arg4); |
aurel32 | 408321b | 2008-10-01 21:46:32 +0000 | [diff] [blame] | 8012 | break; |
| 8013 | #endif |
bellard | ffa65c3 | 2004-01-04 23:57:22 +0000 | [diff] [blame] | 8014 | #ifdef TARGET_NR_madvise |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8015 | case TARGET_NR_madvise: |
pbrook | 2483668 | 2006-04-16 14:14:53 +0000 | [diff] [blame] | 8016 | /* A straight passthrough may not be safe because qemu sometimes |
| 8017 | turns private flie-backed mappings into anonymous mappings. |
| 8018 | This will break MADV_DONTNEED. |
| 8019 | This is a hint, so ignoring and returning success is ok. */ |
| 8020 | ret = get_errno(0); |
| 8021 | break; |
bellard | ffa65c3 | 2004-01-04 23:57:22 +0000 | [diff] [blame] | 8022 | #endif |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 8023 | #if TARGET_ABI_BITS == 32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8024 | case TARGET_NR_fcntl64: |
bellard | 77e4672 | 2003-04-29 20:39:06 +0000 | [diff] [blame] | 8025 | { |
ths | b1e341e | 2007-03-20 21:50:52 +0000 | [diff] [blame] | 8026 | int cmd; |
bellard | 77e4672 | 2003-04-29 20:39:06 +0000 | [diff] [blame] | 8027 | struct flock64 fl; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8028 | struct target_flock64 *target_fl; |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 8029 | #ifdef TARGET_ARM |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8030 | struct target_eabi_flock64 *target_efl; |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 8031 | #endif |
bellard | 77e4672 | 2003-04-29 20:39:06 +0000 | [diff] [blame] | 8032 | |
Arnaud Patard (Rtp) | 5f10681 | 2009-06-03 14:35:04 +0200 | [diff] [blame] | 8033 | cmd = target_to_host_fcntl_cmd(arg2); |
Peter Maydell | 31b6319 | 2011-12-05 23:11:50 +0000 | [diff] [blame] | 8034 | if (cmd == -TARGET_EINVAL) { |
| 8035 | ret = cmd; |
| 8036 | break; |
| 8037 | } |
ths | b1e341e | 2007-03-20 21:50:52 +0000 | [diff] [blame] | 8038 | |
bellard | 60cd49d | 2003-03-16 22:53:56 +0000 | [diff] [blame] | 8039 | switch(arg2) { |
ths | b1e341e | 2007-03-20 21:50:52 +0000 | [diff] [blame] | 8040 | case TARGET_F_GETLK64: |
ths | 5813427 | 2007-03-31 18:59:32 +0000 | [diff] [blame] | 8041 | #ifdef TARGET_ARM |
| 8042 | if (((CPUARMState *)cpu_env)->eabi) { |
bellard | 9ee1fa2 | 2007-11-11 15:11:19 +0000 | [diff] [blame] | 8043 | if (!lock_user_struct(VERIFY_READ, target_efl, arg3, 1)) |
| 8044 | goto efault; |
ths | 5813427 | 2007-03-31 18:59:32 +0000 | [diff] [blame] | 8045 | fl.l_type = tswap16(target_efl->l_type); |
| 8046 | fl.l_whence = tswap16(target_efl->l_whence); |
| 8047 | fl.l_start = tswap64(target_efl->l_start); |
| 8048 | fl.l_len = tswap64(target_efl->l_len); |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 8049 | fl.l_pid = tswap32(target_efl->l_pid); |
ths | 5813427 | 2007-03-31 18:59:32 +0000 | [diff] [blame] | 8050 | unlock_user_struct(target_efl, arg3, 0); |
| 8051 | } else |
| 8052 | #endif |
| 8053 | { |
bellard | 9ee1fa2 | 2007-11-11 15:11:19 +0000 | [diff] [blame] | 8054 | if (!lock_user_struct(VERIFY_READ, target_fl, arg3, 1)) |
| 8055 | goto efault; |
ths | 5813427 | 2007-03-31 18:59:32 +0000 | [diff] [blame] | 8056 | fl.l_type = tswap16(target_fl->l_type); |
| 8057 | fl.l_whence = tswap16(target_fl->l_whence); |
| 8058 | fl.l_start = tswap64(target_fl->l_start); |
| 8059 | fl.l_len = tswap64(target_fl->l_len); |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 8060 | fl.l_pid = tswap32(target_fl->l_pid); |
ths | 5813427 | 2007-03-31 18:59:32 +0000 | [diff] [blame] | 8061 | unlock_user_struct(target_fl, arg3, 0); |
| 8062 | } |
ths | b1e341e | 2007-03-20 21:50:52 +0000 | [diff] [blame] | 8063 | ret = get_errno(fcntl(arg1, cmd, &fl)); |
bellard | 77e4672 | 2003-04-29 20:39:06 +0000 | [diff] [blame] | 8064 | if (ret == 0) { |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 8065 | #ifdef TARGET_ARM |
| 8066 | if (((CPUARMState *)cpu_env)->eabi) { |
bellard | 9ee1fa2 | 2007-11-11 15:11:19 +0000 | [diff] [blame] | 8067 | if (!lock_user_struct(VERIFY_WRITE, target_efl, arg3, 0)) |
| 8068 | goto efault; |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 8069 | target_efl->l_type = tswap16(fl.l_type); |
| 8070 | target_efl->l_whence = tswap16(fl.l_whence); |
| 8071 | target_efl->l_start = tswap64(fl.l_start); |
| 8072 | target_efl->l_len = tswap64(fl.l_len); |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 8073 | target_efl->l_pid = tswap32(fl.l_pid); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8074 | unlock_user_struct(target_efl, arg3, 1); |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 8075 | } else |
| 8076 | #endif |
| 8077 | { |
bellard | 9ee1fa2 | 2007-11-11 15:11:19 +0000 | [diff] [blame] | 8078 | if (!lock_user_struct(VERIFY_WRITE, target_fl, arg3, 0)) |
| 8079 | goto efault; |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 8080 | target_fl->l_type = tswap16(fl.l_type); |
| 8081 | target_fl->l_whence = tswap16(fl.l_whence); |
| 8082 | target_fl->l_start = tswap64(fl.l_start); |
| 8083 | target_fl->l_len = tswap64(fl.l_len); |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 8084 | target_fl->l_pid = tswap32(fl.l_pid); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8085 | unlock_user_struct(target_fl, arg3, 1); |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 8086 | } |
bellard | 77e4672 | 2003-04-29 20:39:06 +0000 | [diff] [blame] | 8087 | } |
| 8088 | break; |
| 8089 | |
ths | b1e341e | 2007-03-20 21:50:52 +0000 | [diff] [blame] | 8090 | case TARGET_F_SETLK64: |
| 8091 | case TARGET_F_SETLKW64: |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 8092 | #ifdef TARGET_ARM |
| 8093 | if (((CPUARMState *)cpu_env)->eabi) { |
bellard | 9ee1fa2 | 2007-11-11 15:11:19 +0000 | [diff] [blame] | 8094 | if (!lock_user_struct(VERIFY_READ, target_efl, arg3, 1)) |
| 8095 | goto efault; |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 8096 | fl.l_type = tswap16(target_efl->l_type); |
| 8097 | fl.l_whence = tswap16(target_efl->l_whence); |
| 8098 | fl.l_start = tswap64(target_efl->l_start); |
| 8099 | fl.l_len = tswap64(target_efl->l_len); |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 8100 | fl.l_pid = tswap32(target_efl->l_pid); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8101 | unlock_user_struct(target_efl, arg3, 0); |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 8102 | } else |
| 8103 | #endif |
| 8104 | { |
bellard | 9ee1fa2 | 2007-11-11 15:11:19 +0000 | [diff] [blame] | 8105 | if (!lock_user_struct(VERIFY_READ, target_fl, arg3, 1)) |
| 8106 | goto efault; |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 8107 | fl.l_type = tswap16(target_fl->l_type); |
| 8108 | fl.l_whence = tswap16(target_fl->l_whence); |
| 8109 | fl.l_start = tswap64(target_fl->l_start); |
| 8110 | fl.l_len = tswap64(target_fl->l_len); |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 8111 | fl.l_pid = tswap32(target_fl->l_pid); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8112 | unlock_user_struct(target_fl, arg3, 0); |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 8113 | } |
ths | b1e341e | 2007-03-20 21:50:52 +0000 | [diff] [blame] | 8114 | ret = get_errno(fcntl(arg1, cmd, &fl)); |
bellard | 77e4672 | 2003-04-29 20:39:06 +0000 | [diff] [blame] | 8115 | break; |
bellard | 60cd49d | 2003-03-16 22:53:56 +0000 | [diff] [blame] | 8116 | default: |
Arnaud Patard (Rtp) | 5f10681 | 2009-06-03 14:35:04 +0200 | [diff] [blame] | 8117 | ret = do_fcntl(arg1, arg2, arg3); |
bellard | 60cd49d | 2003-03-16 22:53:56 +0000 | [diff] [blame] | 8118 | break; |
| 8119 | } |
bellard | 77e4672 | 2003-04-29 20:39:06 +0000 | [diff] [blame] | 8120 | break; |
| 8121 | } |
bellard | 60cd49d | 2003-03-16 22:53:56 +0000 | [diff] [blame] | 8122 | #endif |
ths | 7d600c8 | 2006-12-08 01:32:58 +0000 | [diff] [blame] | 8123 | #ifdef TARGET_NR_cacheflush |
| 8124 | case TARGET_NR_cacheflush: |
| 8125 | /* self-modifying code is handled automatically, so nothing needed */ |
| 8126 | ret = 0; |
| 8127 | break; |
| 8128 | #endif |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 8129 | #ifdef TARGET_NR_security |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8130 | case TARGET_NR_security: |
| 8131 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 8132 | #endif |
bellard | c573ff6 | 2004-01-04 15:51:36 +0000 | [diff] [blame] | 8133 | #ifdef TARGET_NR_getpagesize |
| 8134 | case TARGET_NR_getpagesize: |
| 8135 | ret = TARGET_PAGE_SIZE; |
| 8136 | break; |
| 8137 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8138 | case TARGET_NR_gettid: |
| 8139 | ret = get_errno(gettid()); |
| 8140 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 8141 | #ifdef TARGET_NR_readahead |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8142 | case TARGET_NR_readahead: |
aurel32 | 2054ac9 | 2008-10-13 21:08:07 +0000 | [diff] [blame] | 8143 | #if TARGET_ABI_BITS == 32 |
Riku Voipio | 48e515d | 2011-07-12 15:40:51 +0300 | [diff] [blame] | 8144 | if (regpairs_aligned(cpu_env)) { |
aurel32 | 2054ac9 | 2008-10-13 21:08:07 +0000 | [diff] [blame] | 8145 | arg2 = arg3; |
| 8146 | arg3 = arg4; |
| 8147 | arg4 = arg5; |
| 8148 | } |
aurel32 | 2054ac9 | 2008-10-13 21:08:07 +0000 | [diff] [blame] | 8149 | ret = get_errno(readahead(arg1, ((off64_t)arg3 << 32) | arg2, arg4)); |
| 8150 | #else |
| 8151 | ret = get_errno(readahead(arg1, arg2, arg3)); |
| 8152 | #endif |
| 8153 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 8154 | #endif |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 8155 | #ifdef CONFIG_ATTR |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 8156 | #ifdef TARGET_NR_setxattr |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8157 | case TARGET_NR_listxattr: |
| 8158 | case TARGET_NR_llistxattr: |
Peter Maydell | fb5590f | 2011-12-14 15:37:19 +0000 | [diff] [blame] | 8159 | { |
| 8160 | void *p, *b = 0; |
| 8161 | if (arg2) { |
| 8162 | b = lock_user(VERIFY_WRITE, arg2, arg3, 0); |
| 8163 | if (!b) { |
| 8164 | ret = -TARGET_EFAULT; |
| 8165 | break; |
| 8166 | } |
| 8167 | } |
| 8168 | p = lock_user_string(arg1); |
| 8169 | if (p) { |
| 8170 | if (num == TARGET_NR_listxattr) { |
| 8171 | ret = get_errno(listxattr(p, b, arg3)); |
| 8172 | } else { |
| 8173 | ret = get_errno(llistxattr(p, b, arg3)); |
| 8174 | } |
| 8175 | } else { |
| 8176 | ret = -TARGET_EFAULT; |
| 8177 | } |
| 8178 | unlock_user(p, arg1, 0); |
| 8179 | unlock_user(b, arg2, arg3); |
Arnaud Patard | 6f932f9 | 2009-04-21 21:04:18 +0300 | [diff] [blame] | 8180 | break; |
Peter Maydell | fb5590f | 2011-12-14 15:37:19 +0000 | [diff] [blame] | 8181 | } |
| 8182 | case TARGET_NR_flistxattr: |
| 8183 | { |
| 8184 | void *b = 0; |
| 8185 | if (arg2) { |
| 8186 | b = lock_user(VERIFY_WRITE, arg2, arg3, 0); |
| 8187 | if (!b) { |
| 8188 | ret = -TARGET_EFAULT; |
| 8189 | break; |
| 8190 | } |
| 8191 | } |
| 8192 | ret = get_errno(flistxattr(arg1, b, arg3)); |
| 8193 | unlock_user(b, arg2, arg3); |
| 8194 | break; |
| 8195 | } |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 8196 | case TARGET_NR_setxattr: |
Peter Maydell | 30297b5 | 2011-12-14 15:37:18 +0000 | [diff] [blame] | 8197 | case TARGET_NR_lsetxattr: |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 8198 | { |
Peter Maydell | e3c33ec | 2011-12-14 15:37:17 +0000 | [diff] [blame] | 8199 | void *p, *n, *v = 0; |
| 8200 | if (arg3) { |
| 8201 | v = lock_user(VERIFY_READ, arg3, arg4, 1); |
| 8202 | if (!v) { |
| 8203 | ret = -TARGET_EFAULT; |
| 8204 | break; |
| 8205 | } |
| 8206 | } |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 8207 | p = lock_user_string(arg1); |
| 8208 | n = lock_user_string(arg2); |
Peter Maydell | e3c33ec | 2011-12-14 15:37:17 +0000 | [diff] [blame] | 8209 | if (p && n) { |
Peter Maydell | 30297b5 | 2011-12-14 15:37:18 +0000 | [diff] [blame] | 8210 | if (num == TARGET_NR_setxattr) { |
| 8211 | ret = get_errno(setxattr(p, n, v, arg4, arg5)); |
| 8212 | } else { |
| 8213 | ret = get_errno(lsetxattr(p, n, v, arg4, arg5)); |
| 8214 | } |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 8215 | } else { |
| 8216 | ret = -TARGET_EFAULT; |
| 8217 | } |
| 8218 | unlock_user(p, arg1, 0); |
| 8219 | unlock_user(n, arg2, 0); |
| 8220 | unlock_user(v, arg3, 0); |
| 8221 | } |
| 8222 | break; |
Peter Maydell | 30297b5 | 2011-12-14 15:37:18 +0000 | [diff] [blame] | 8223 | case TARGET_NR_fsetxattr: |
| 8224 | { |
| 8225 | void *n, *v = 0; |
| 8226 | if (arg3) { |
| 8227 | v = lock_user(VERIFY_READ, arg3, arg4, 1); |
| 8228 | if (!v) { |
| 8229 | ret = -TARGET_EFAULT; |
| 8230 | break; |
| 8231 | } |
| 8232 | } |
| 8233 | n = lock_user_string(arg2); |
| 8234 | if (n) { |
| 8235 | ret = get_errno(fsetxattr(arg1, n, v, arg4, arg5)); |
| 8236 | } else { |
| 8237 | ret = -TARGET_EFAULT; |
| 8238 | } |
| 8239 | unlock_user(n, arg2, 0); |
| 8240 | unlock_user(v, arg3, 0); |
| 8241 | } |
| 8242 | break; |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 8243 | case TARGET_NR_getxattr: |
Peter Maydell | 30297b5 | 2011-12-14 15:37:18 +0000 | [diff] [blame] | 8244 | case TARGET_NR_lgetxattr: |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 8245 | { |
Peter Maydell | e3c33ec | 2011-12-14 15:37:17 +0000 | [diff] [blame] | 8246 | void *p, *n, *v = 0; |
| 8247 | if (arg3) { |
| 8248 | v = lock_user(VERIFY_WRITE, arg3, arg4, 0); |
| 8249 | if (!v) { |
| 8250 | ret = -TARGET_EFAULT; |
| 8251 | break; |
| 8252 | } |
| 8253 | } |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 8254 | p = lock_user_string(arg1); |
| 8255 | n = lock_user_string(arg2); |
Peter Maydell | e3c33ec | 2011-12-14 15:37:17 +0000 | [diff] [blame] | 8256 | if (p && n) { |
Peter Maydell | 30297b5 | 2011-12-14 15:37:18 +0000 | [diff] [blame] | 8257 | if (num == TARGET_NR_getxattr) { |
| 8258 | ret = get_errno(getxattr(p, n, v, arg4)); |
| 8259 | } else { |
| 8260 | ret = get_errno(lgetxattr(p, n, v, arg4)); |
| 8261 | } |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 8262 | } else { |
| 8263 | ret = -TARGET_EFAULT; |
| 8264 | } |
| 8265 | unlock_user(p, arg1, 0); |
| 8266 | unlock_user(n, arg2, 0); |
| 8267 | unlock_user(v, arg3, arg4); |
| 8268 | } |
| 8269 | break; |
Peter Maydell | 30297b5 | 2011-12-14 15:37:18 +0000 | [diff] [blame] | 8270 | case TARGET_NR_fgetxattr: |
| 8271 | { |
| 8272 | void *n, *v = 0; |
| 8273 | if (arg3) { |
| 8274 | v = lock_user(VERIFY_WRITE, arg3, arg4, 0); |
| 8275 | if (!v) { |
| 8276 | ret = -TARGET_EFAULT; |
| 8277 | break; |
| 8278 | } |
| 8279 | } |
| 8280 | n = lock_user_string(arg2); |
| 8281 | if (n) { |
| 8282 | ret = get_errno(fgetxattr(arg1, n, v, arg4)); |
| 8283 | } else { |
| 8284 | ret = -TARGET_EFAULT; |
| 8285 | } |
| 8286 | unlock_user(n, arg2, 0); |
| 8287 | unlock_user(v, arg3, arg4); |
| 8288 | } |
| 8289 | break; |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 8290 | case TARGET_NR_removexattr: |
Peter Maydell | 30297b5 | 2011-12-14 15:37:18 +0000 | [diff] [blame] | 8291 | case TARGET_NR_lremovexattr: |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 8292 | { |
| 8293 | void *p, *n; |
| 8294 | p = lock_user_string(arg1); |
| 8295 | n = lock_user_string(arg2); |
| 8296 | if (p && n) { |
Peter Maydell | 30297b5 | 2011-12-14 15:37:18 +0000 | [diff] [blame] | 8297 | if (num == TARGET_NR_removexattr) { |
| 8298 | ret = get_errno(removexattr(p, n)); |
| 8299 | } else { |
| 8300 | ret = get_errno(lremovexattr(p, n)); |
| 8301 | } |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 8302 | } else { |
| 8303 | ret = -TARGET_EFAULT; |
| 8304 | } |
| 8305 | unlock_user(p, arg1, 0); |
| 8306 | unlock_user(n, arg2, 0); |
| 8307 | } |
| 8308 | break; |
Peter Maydell | 30297b5 | 2011-12-14 15:37:18 +0000 | [diff] [blame] | 8309 | case TARGET_NR_fremovexattr: |
| 8310 | { |
| 8311 | void *n; |
| 8312 | n = lock_user_string(arg2); |
| 8313 | if (n) { |
| 8314 | ret = get_errno(fremovexattr(arg1, n)); |
| 8315 | } else { |
| 8316 | ret = -TARGET_EFAULT; |
| 8317 | } |
| 8318 | unlock_user(n, arg2, 0); |
| 8319 | } |
| 8320 | break; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 8321 | #endif |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 8322 | #endif /* CONFIG_ATTR */ |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 8323 | #ifdef TARGET_NR_set_thread_area |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 8324 | case TARGET_NR_set_thread_area: |
bellard | 8d18e89 | 2007-11-14 15:18:40 +0000 | [diff] [blame] | 8325 | #if defined(TARGET_MIPS) |
ths | 6f5b89a | 2007-03-02 20:48:00 +0000 | [diff] [blame] | 8326 | ((CPUMIPSState *) cpu_env)->tls_value = arg1; |
| 8327 | ret = 0; |
| 8328 | break; |
edgar_igl | ef96779 | 2009-01-07 14:19:38 +0000 | [diff] [blame] | 8329 | #elif defined(TARGET_CRIS) |
| 8330 | if (arg1 & 0xff) |
| 8331 | ret = -TARGET_EINVAL; |
| 8332 | else { |
| 8333 | ((CPUCRISState *) cpu_env)->pregs[PR_PID] = arg1; |
| 8334 | ret = 0; |
| 8335 | } |
| 8336 | break; |
bellard | 8d18e89 | 2007-11-14 15:18:40 +0000 | [diff] [blame] | 8337 | #elif defined(TARGET_I386) && defined(TARGET_ABI32) |
| 8338 | ret = do_set_thread_area(cpu_env, arg1); |
| 8339 | break; |
ths | 6f5b89a | 2007-03-02 20:48:00 +0000 | [diff] [blame] | 8340 | #else |
| 8341 | goto unimplemented_nowarn; |
| 8342 | #endif |
| 8343 | #endif |
| 8344 | #ifdef TARGET_NR_get_thread_area |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 8345 | case TARGET_NR_get_thread_area: |
bellard | 8d18e89 | 2007-11-14 15:18:40 +0000 | [diff] [blame] | 8346 | #if defined(TARGET_I386) && defined(TARGET_ABI32) |
| 8347 | ret = do_get_thread_area(cpu_env, arg1); |
| 8348 | #else |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 8349 | goto unimplemented_nowarn; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 8350 | #endif |
bellard | 8d18e89 | 2007-11-14 15:18:40 +0000 | [diff] [blame] | 8351 | #endif |
bellard | 48dc41e | 2006-06-21 18:15:50 +0000 | [diff] [blame] | 8352 | #ifdef TARGET_NR_getdomainname |
| 8353 | case TARGET_NR_getdomainname: |
| 8354 | goto unimplemented_nowarn; |
| 8355 | #endif |
ths | 6f5b89a | 2007-03-02 20:48:00 +0000 | [diff] [blame] | 8356 | |
ths | b5906f9 | 2007-03-19 13:32:45 +0000 | [diff] [blame] | 8357 | #ifdef TARGET_NR_clock_gettime |
| 8358 | case TARGET_NR_clock_gettime: |
| 8359 | { |
| 8360 | struct timespec ts; |
| 8361 | ret = get_errno(clock_gettime(arg1, &ts)); |
| 8362 | if (!is_error(ret)) { |
| 8363 | host_to_target_timespec(arg2, &ts); |
| 8364 | } |
| 8365 | break; |
| 8366 | } |
| 8367 | #endif |
| 8368 | #ifdef TARGET_NR_clock_getres |
| 8369 | case TARGET_NR_clock_getres: |
| 8370 | { |
| 8371 | struct timespec ts; |
| 8372 | ret = get_errno(clock_getres(arg1, &ts)); |
| 8373 | if (!is_error(ret)) { |
| 8374 | host_to_target_timespec(arg2, &ts); |
| 8375 | } |
| 8376 | break; |
| 8377 | } |
| 8378 | #endif |
pbrook | 63d7651 | 2008-05-29 13:43:29 +0000 | [diff] [blame] | 8379 | #ifdef TARGET_NR_clock_nanosleep |
| 8380 | case TARGET_NR_clock_nanosleep: |
| 8381 | { |
| 8382 | struct timespec ts; |
| 8383 | target_to_host_timespec(&ts, arg3); |
| 8384 | ret = get_errno(clock_nanosleep(arg1, arg2, &ts, arg4 ? &ts : NULL)); |
| 8385 | if (arg4) |
| 8386 | host_to_target_timespec(arg4, &ts); |
| 8387 | break; |
| 8388 | } |
| 8389 | #endif |
ths | b5906f9 | 2007-03-19 13:32:45 +0000 | [diff] [blame] | 8390 | |
ths | 6f5b89a | 2007-03-02 20:48:00 +0000 | [diff] [blame] | 8391 | #if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address) |
| 8392 | case TARGET_NR_set_tid_address: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 8393 | ret = get_errno(set_tid_address((int *)g2h(arg1))); |
| 8394 | break; |
ths | 6f5b89a | 2007-03-02 20:48:00 +0000 | [diff] [blame] | 8395 | #endif |
| 8396 | |
ths | 3ae4320 | 2007-09-16 21:39:48 +0000 | [diff] [blame] | 8397 | #if defined(TARGET_NR_tkill) && defined(__NR_tkill) |
ths | 4cae1d1 | 2007-07-12 11:06:53 +0000 | [diff] [blame] | 8398 | case TARGET_NR_tkill: |
pbrook | 4cb0596 | 2008-05-30 18:05:19 +0000 | [diff] [blame] | 8399 | ret = get_errno(sys_tkill((int)arg1, target_to_host_signal(arg2))); |
ths | 4cae1d1 | 2007-07-12 11:06:53 +0000 | [diff] [blame] | 8400 | break; |
| 8401 | #endif |
| 8402 | |
ths | 3ae4320 | 2007-09-16 21:39:48 +0000 | [diff] [blame] | 8403 | #if defined(TARGET_NR_tgkill) && defined(__NR_tgkill) |
ths | 7145557 | 2007-06-21 21:45:30 +0000 | [diff] [blame] | 8404 | case TARGET_NR_tgkill: |
pbrook | 4cb0596 | 2008-05-30 18:05:19 +0000 | [diff] [blame] | 8405 | ret = get_errno(sys_tgkill((int)arg1, (int)arg2, |
| 8406 | target_to_host_signal(arg3))); |
ths | 7145557 | 2007-06-21 21:45:30 +0000 | [diff] [blame] | 8407 | break; |
| 8408 | #endif |
| 8409 | |
ths | 4f2b1fe | 2007-06-21 21:57:12 +0000 | [diff] [blame] | 8410 | #ifdef TARGET_NR_set_robust_list |
| 8411 | case TARGET_NR_set_robust_list: |
| 8412 | goto unimplemented_nowarn; |
| 8413 | #endif |
| 8414 | |
ths | 9007f0e | 2007-09-25 17:50:37 +0000 | [diff] [blame] | 8415 | #if defined(TARGET_NR_utimensat) && defined(__NR_utimensat) |
| 8416 | case TARGET_NR_utimensat: |
| 8417 | { |
Riku Voipio | ebc996f | 2009-04-21 15:01:51 +0300 | [diff] [blame] | 8418 | struct timespec *tsp, ts[2]; |
| 8419 | if (!arg3) { |
| 8420 | tsp = NULL; |
| 8421 | } else { |
| 8422 | target_to_host_timespec(ts, arg3); |
| 8423 | target_to_host_timespec(ts+1, arg3+sizeof(struct target_timespec)); |
| 8424 | tsp = ts; |
| 8425 | } |
ths | 9007f0e | 2007-09-25 17:50:37 +0000 | [diff] [blame] | 8426 | if (!arg2) |
Riku Voipio | ebc996f | 2009-04-21 15:01:51 +0300 | [diff] [blame] | 8427 | ret = get_errno(sys_utimensat(arg1, NULL, tsp, arg4)); |
ths | 9007f0e | 2007-09-25 17:50:37 +0000 | [diff] [blame] | 8428 | else { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 8429 | if (!(p = lock_user_string(arg2))) { |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 8430 | ret = -TARGET_EFAULT; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 8431 | goto fail; |
| 8432 | } |
Riku Voipio | ebc996f | 2009-04-21 15:01:51 +0300 | [diff] [blame] | 8433 | ret = get_errno(sys_utimensat(arg1, path(p), tsp, arg4)); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 8434 | unlock_user(p, arg2, 0); |
ths | 9007f0e | 2007-09-25 17:50:37 +0000 | [diff] [blame] | 8435 | } |
| 8436 | } |
| 8437 | break; |
| 8438 | #endif |
Juan Quintela | 2f7bb87 | 2009-07-27 16:13:24 +0200 | [diff] [blame] | 8439 | #if defined(CONFIG_USE_NPTL) |
pbrook | bd0c566 | 2008-05-29 14:34:11 +0000 | [diff] [blame] | 8440 | case TARGET_NR_futex: |
| 8441 | ret = do_futex(arg1, arg2, arg3, arg4, arg5, arg6); |
| 8442 | break; |
| 8443 | #endif |
aurel32 | dbfe4c3 | 2009-04-08 21:29:30 +0000 | [diff] [blame] | 8444 | #if defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init) |
aurel32 | 39b5976 | 2008-10-01 21:46:50 +0000 | [diff] [blame] | 8445 | case TARGET_NR_inotify_init: |
| 8446 | ret = get_errno(sys_inotify_init()); |
| 8447 | break; |
| 8448 | #endif |
Stefan Weil | a1606b0 | 2010-03-28 11:44:41 +0200 | [diff] [blame] | 8449 | #ifdef CONFIG_INOTIFY1 |
Riku Voipio | c05c7a7 | 2010-03-26 15:25:11 +0000 | [diff] [blame] | 8450 | #if defined(TARGET_NR_inotify_init1) && defined(__NR_inotify_init1) |
| 8451 | case TARGET_NR_inotify_init1: |
| 8452 | ret = get_errno(sys_inotify_init1(arg1)); |
| 8453 | break; |
| 8454 | #endif |
Stefan Weil | a1606b0 | 2010-03-28 11:44:41 +0200 | [diff] [blame] | 8455 | #endif |
aurel32 | dbfe4c3 | 2009-04-08 21:29:30 +0000 | [diff] [blame] | 8456 | #if defined(TARGET_NR_inotify_add_watch) && defined(__NR_inotify_add_watch) |
aurel32 | 39b5976 | 2008-10-01 21:46:50 +0000 | [diff] [blame] | 8457 | case TARGET_NR_inotify_add_watch: |
| 8458 | p = lock_user_string(arg2); |
| 8459 | ret = get_errno(sys_inotify_add_watch(arg1, path(p), arg3)); |
| 8460 | unlock_user(p, arg2, 0); |
| 8461 | break; |
| 8462 | #endif |
aurel32 | dbfe4c3 | 2009-04-08 21:29:30 +0000 | [diff] [blame] | 8463 | #if defined(TARGET_NR_inotify_rm_watch) && defined(__NR_inotify_rm_watch) |
aurel32 | 39b5976 | 2008-10-01 21:46:50 +0000 | [diff] [blame] | 8464 | case TARGET_NR_inotify_rm_watch: |
| 8465 | ret = get_errno(sys_inotify_rm_watch(arg1, arg2)); |
| 8466 | break; |
| 8467 | #endif |
ths | 9007f0e | 2007-09-25 17:50:37 +0000 | [diff] [blame] | 8468 | |
Nathan Froyd | 8ec9cf8 | 2009-07-22 09:14:36 -0700 | [diff] [blame] | 8469 | #if defined(TARGET_NR_mq_open) && defined(__NR_mq_open) |
aurel32 | 24e1003 | 2009-04-15 16:11:43 +0000 | [diff] [blame] | 8470 | case TARGET_NR_mq_open: |
| 8471 | { |
| 8472 | struct mq_attr posix_mq_attr; |
| 8473 | |
| 8474 | p = lock_user_string(arg1 - 1); |
| 8475 | if (arg4 != 0) |
| 8476 | copy_from_user_mq_attr (&posix_mq_attr, arg4); |
| 8477 | ret = get_errno(mq_open(p, arg2, arg3, &posix_mq_attr)); |
| 8478 | unlock_user (p, arg1, 0); |
| 8479 | } |
| 8480 | break; |
| 8481 | |
| 8482 | case TARGET_NR_mq_unlink: |
| 8483 | p = lock_user_string(arg1 - 1); |
| 8484 | ret = get_errno(mq_unlink(p)); |
| 8485 | unlock_user (p, arg1, 0); |
| 8486 | break; |
| 8487 | |
| 8488 | case TARGET_NR_mq_timedsend: |
| 8489 | { |
| 8490 | struct timespec ts; |
| 8491 | |
| 8492 | p = lock_user (VERIFY_READ, arg2, arg3, 1); |
| 8493 | if (arg5 != 0) { |
| 8494 | target_to_host_timespec(&ts, arg5); |
| 8495 | ret = get_errno(mq_timedsend(arg1, p, arg3, arg4, &ts)); |
| 8496 | host_to_target_timespec(arg5, &ts); |
| 8497 | } |
| 8498 | else |
| 8499 | ret = get_errno(mq_send(arg1, p, arg3, arg4)); |
| 8500 | unlock_user (p, arg2, arg3); |
| 8501 | } |
| 8502 | break; |
| 8503 | |
| 8504 | case TARGET_NR_mq_timedreceive: |
| 8505 | { |
| 8506 | struct timespec ts; |
| 8507 | unsigned int prio; |
| 8508 | |
| 8509 | p = lock_user (VERIFY_READ, arg2, arg3, 1); |
| 8510 | if (arg5 != 0) { |
| 8511 | target_to_host_timespec(&ts, arg5); |
| 8512 | ret = get_errno(mq_timedreceive(arg1, p, arg3, &prio, &ts)); |
| 8513 | host_to_target_timespec(arg5, &ts); |
| 8514 | } |
| 8515 | else |
| 8516 | ret = get_errno(mq_receive(arg1, p, arg3, &prio)); |
| 8517 | unlock_user (p, arg2, arg3); |
| 8518 | if (arg4 != 0) |
| 8519 | put_user_u32(prio, arg4); |
| 8520 | } |
| 8521 | break; |
| 8522 | |
| 8523 | /* Not implemented for now... */ |
| 8524 | /* case TARGET_NR_mq_notify: */ |
| 8525 | /* break; */ |
| 8526 | |
| 8527 | case TARGET_NR_mq_getsetattr: |
| 8528 | { |
| 8529 | struct mq_attr posix_mq_attr_in, posix_mq_attr_out; |
| 8530 | ret = 0; |
| 8531 | if (arg3 != 0) { |
| 8532 | ret = mq_getattr(arg1, &posix_mq_attr_out); |
| 8533 | copy_to_user_mq_attr(arg3, &posix_mq_attr_out); |
| 8534 | } |
| 8535 | if (arg2 != 0) { |
| 8536 | copy_from_user_mq_attr(&posix_mq_attr_in, arg2); |
| 8537 | ret |= mq_setattr(arg1, &posix_mq_attr_in, &posix_mq_attr_out); |
| 8538 | } |
| 8539 | |
| 8540 | } |
| 8541 | break; |
| 8542 | #endif |
| 8543 | |
vibisreenivasan | 3ce34df | 2009-05-16 18:32:41 +0530 | [diff] [blame] | 8544 | #ifdef CONFIG_SPLICE |
| 8545 | #ifdef TARGET_NR_tee |
| 8546 | case TARGET_NR_tee: |
| 8547 | { |
| 8548 | ret = get_errno(tee(arg1,arg2,arg3,arg4)); |
| 8549 | } |
| 8550 | break; |
| 8551 | #endif |
| 8552 | #ifdef TARGET_NR_splice |
| 8553 | case TARGET_NR_splice: |
| 8554 | { |
| 8555 | loff_t loff_in, loff_out; |
| 8556 | loff_t *ploff_in = NULL, *ploff_out = NULL; |
| 8557 | if(arg2) { |
| 8558 | get_user_u64(loff_in, arg2); |
| 8559 | ploff_in = &loff_in; |
| 8560 | } |
| 8561 | if(arg4) { |
| 8562 | get_user_u64(loff_out, arg2); |
| 8563 | ploff_out = &loff_out; |
| 8564 | } |
| 8565 | ret = get_errno(splice(arg1, ploff_in, arg3, ploff_out, arg5, arg6)); |
| 8566 | } |
| 8567 | break; |
| 8568 | #endif |
| 8569 | #ifdef TARGET_NR_vmsplice |
| 8570 | case TARGET_NR_vmsplice: |
| 8571 | { |
| 8572 | int count = arg3; |
| 8573 | struct iovec *vec; |
| 8574 | |
| 8575 | vec = alloca(count * sizeof(struct iovec)); |
| 8576 | if (lock_iovec(VERIFY_READ, vec, arg2, count, 1) < 0) |
| 8577 | goto efault; |
| 8578 | ret = get_errno(vmsplice(arg1, vec, count, arg4)); |
| 8579 | unlock_iovec(vec, arg2, count, 0); |
| 8580 | } |
| 8581 | break; |
| 8582 | #endif |
| 8583 | #endif /* CONFIG_SPLICE */ |
Riku Voipio | c2882b9 | 2009-08-12 15:08:24 +0300 | [diff] [blame] | 8584 | #ifdef CONFIG_EVENTFD |
| 8585 | #if defined(TARGET_NR_eventfd) |
| 8586 | case TARGET_NR_eventfd: |
| 8587 | ret = get_errno(eventfd(arg1, 0)); |
| 8588 | break; |
| 8589 | #endif |
| 8590 | #if defined(TARGET_NR_eventfd2) |
| 8591 | case TARGET_NR_eventfd2: |
| 8592 | ret = get_errno(eventfd(arg1, arg2)); |
| 8593 | break; |
| 8594 | #endif |
| 8595 | #endif /* CONFIG_EVENTFD */ |
Ulrich Hecht | d092793 | 2009-09-17 20:22:14 +0300 | [diff] [blame] | 8596 | #if defined(CONFIG_FALLOCATE) && defined(TARGET_NR_fallocate) |
| 8597 | case TARGET_NR_fallocate: |
Alexander Graf | 20249ae | 2012-02-06 21:37:07 +0100 | [diff] [blame] | 8598 | #if TARGET_ABI_BITS == 32 |
| 8599 | ret = get_errno(fallocate(arg1, arg2, target_offset64(arg3, arg4), |
| 8600 | target_offset64(arg5, arg6))); |
| 8601 | #else |
Ulrich Hecht | d092793 | 2009-09-17 20:22:14 +0300 | [diff] [blame] | 8602 | ret = get_errno(fallocate(arg1, arg2, arg3, arg4)); |
Alexander Graf | 20249ae | 2012-02-06 21:37:07 +0100 | [diff] [blame] | 8603 | #endif |
Ulrich Hecht | d092793 | 2009-09-17 20:22:14 +0300 | [diff] [blame] | 8604 | break; |
| 8605 | #endif |
Peter Maydell | c727f47 | 2011-01-06 11:05:10 +0000 | [diff] [blame] | 8606 | #if defined(CONFIG_SYNC_FILE_RANGE) |
| 8607 | #if defined(TARGET_NR_sync_file_range) |
| 8608 | case TARGET_NR_sync_file_range: |
| 8609 | #if TARGET_ABI_BITS == 32 |
Riku Voipio | bfcedc5 | 2011-06-20 16:24:39 +0300 | [diff] [blame] | 8610 | #if defined(TARGET_MIPS) |
| 8611 | ret = get_errno(sync_file_range(arg1, target_offset64(arg3, arg4), |
| 8612 | target_offset64(arg5, arg6), arg7)); |
| 8613 | #else |
Peter Maydell | c727f47 | 2011-01-06 11:05:10 +0000 | [diff] [blame] | 8614 | ret = get_errno(sync_file_range(arg1, target_offset64(arg2, arg3), |
| 8615 | target_offset64(arg4, arg5), arg6)); |
Riku Voipio | bfcedc5 | 2011-06-20 16:24:39 +0300 | [diff] [blame] | 8616 | #endif /* !TARGET_MIPS */ |
Peter Maydell | c727f47 | 2011-01-06 11:05:10 +0000 | [diff] [blame] | 8617 | #else |
| 8618 | ret = get_errno(sync_file_range(arg1, arg2, arg3, arg4)); |
| 8619 | #endif |
| 8620 | break; |
| 8621 | #endif |
| 8622 | #if defined(TARGET_NR_sync_file_range2) |
| 8623 | case TARGET_NR_sync_file_range2: |
| 8624 | /* This is like sync_file_range but the arguments are reordered */ |
| 8625 | #if TARGET_ABI_BITS == 32 |
| 8626 | ret = get_errno(sync_file_range(arg1, target_offset64(arg3, arg4), |
| 8627 | target_offset64(arg5, arg6), arg2)); |
| 8628 | #else |
| 8629 | ret = get_errno(sync_file_range(arg1, arg3, arg4, arg2)); |
| 8630 | #endif |
| 8631 | break; |
| 8632 | #endif |
| 8633 | #endif |
Peter Maydell | 3b6edd1 | 2011-02-15 18:35:05 +0000 | [diff] [blame] | 8634 | #if defined(CONFIG_EPOLL) |
| 8635 | #if defined(TARGET_NR_epoll_create) |
| 8636 | case TARGET_NR_epoll_create: |
| 8637 | ret = get_errno(epoll_create(arg1)); |
| 8638 | break; |
| 8639 | #endif |
| 8640 | #if defined(TARGET_NR_epoll_create1) && defined(CONFIG_EPOLL_CREATE1) |
| 8641 | case TARGET_NR_epoll_create1: |
| 8642 | ret = get_errno(epoll_create1(arg1)); |
| 8643 | break; |
| 8644 | #endif |
| 8645 | #if defined(TARGET_NR_epoll_ctl) |
| 8646 | case TARGET_NR_epoll_ctl: |
| 8647 | { |
| 8648 | struct epoll_event ep; |
| 8649 | struct epoll_event *epp = 0; |
| 8650 | if (arg4) { |
| 8651 | struct target_epoll_event *target_ep; |
| 8652 | if (!lock_user_struct(VERIFY_READ, target_ep, arg4, 1)) { |
| 8653 | goto efault; |
| 8654 | } |
| 8655 | ep.events = tswap32(target_ep->events); |
| 8656 | /* The epoll_data_t union is just opaque data to the kernel, |
| 8657 | * so we transfer all 64 bits across and need not worry what |
| 8658 | * actual data type it is. |
| 8659 | */ |
| 8660 | ep.data.u64 = tswap64(target_ep->data.u64); |
| 8661 | unlock_user_struct(target_ep, arg4, 0); |
| 8662 | epp = &ep; |
| 8663 | } |
| 8664 | ret = get_errno(epoll_ctl(arg1, arg2, arg3, epp)); |
| 8665 | break; |
| 8666 | } |
| 8667 | #endif |
| 8668 | |
| 8669 | #if defined(TARGET_NR_epoll_pwait) && defined(CONFIG_EPOLL_PWAIT) |
| 8670 | #define IMPLEMENT_EPOLL_PWAIT |
| 8671 | #endif |
| 8672 | #if defined(TARGET_NR_epoll_wait) || defined(IMPLEMENT_EPOLL_PWAIT) |
| 8673 | #if defined(TARGET_NR_epoll_wait) |
| 8674 | case TARGET_NR_epoll_wait: |
| 8675 | #endif |
| 8676 | #if defined(IMPLEMENT_EPOLL_PWAIT) |
| 8677 | case TARGET_NR_epoll_pwait: |
| 8678 | #endif |
| 8679 | { |
| 8680 | struct target_epoll_event *target_ep; |
| 8681 | struct epoll_event *ep; |
| 8682 | int epfd = arg1; |
| 8683 | int maxevents = arg3; |
| 8684 | int timeout = arg4; |
| 8685 | |
| 8686 | target_ep = lock_user(VERIFY_WRITE, arg2, |
| 8687 | maxevents * sizeof(struct target_epoll_event), 1); |
| 8688 | if (!target_ep) { |
| 8689 | goto efault; |
| 8690 | } |
| 8691 | |
| 8692 | ep = alloca(maxevents * sizeof(struct epoll_event)); |
| 8693 | |
| 8694 | switch (num) { |
| 8695 | #if defined(IMPLEMENT_EPOLL_PWAIT) |
| 8696 | case TARGET_NR_epoll_pwait: |
| 8697 | { |
| 8698 | target_sigset_t *target_set; |
| 8699 | sigset_t _set, *set = &_set; |
| 8700 | |
| 8701 | if (arg5) { |
| 8702 | target_set = lock_user(VERIFY_READ, arg5, |
| 8703 | sizeof(target_sigset_t), 1); |
| 8704 | if (!target_set) { |
| 8705 | unlock_user(target_ep, arg2, 0); |
| 8706 | goto efault; |
| 8707 | } |
| 8708 | target_to_host_sigset(set, target_set); |
| 8709 | unlock_user(target_set, arg5, 0); |
| 8710 | } else { |
| 8711 | set = NULL; |
| 8712 | } |
| 8713 | |
| 8714 | ret = get_errno(epoll_pwait(epfd, ep, maxevents, timeout, set)); |
| 8715 | break; |
| 8716 | } |
| 8717 | #endif |
| 8718 | #if defined(TARGET_NR_epoll_wait) |
| 8719 | case TARGET_NR_epoll_wait: |
| 8720 | ret = get_errno(epoll_wait(epfd, ep, maxevents, timeout)); |
| 8721 | break; |
| 8722 | #endif |
| 8723 | default: |
| 8724 | ret = -TARGET_ENOSYS; |
| 8725 | } |
| 8726 | if (!is_error(ret)) { |
| 8727 | int i; |
| 8728 | for (i = 0; i < ret; i++) { |
| 8729 | target_ep[i].events = tswap32(ep[i].events); |
| 8730 | target_ep[i].data.u64 = tswap64(ep[i].data.u64); |
| 8731 | } |
| 8732 | } |
| 8733 | unlock_user(target_ep, arg2, ret * sizeof(struct target_epoll_event)); |
| 8734 | break; |
| 8735 | } |
| 8736 | #endif |
| 8737 | #endif |
Peter Maydell | 163a05a | 2011-06-27 17:44:52 +0100 | [diff] [blame] | 8738 | #ifdef TARGET_NR_prlimit64 |
| 8739 | case TARGET_NR_prlimit64: |
| 8740 | { |
| 8741 | /* args: pid, resource number, ptr to new rlimit, ptr to old rlimit */ |
| 8742 | struct target_rlimit64 *target_rnew, *target_rold; |
| 8743 | struct host_rlimit64 rnew, rold, *rnewp = 0; |
| 8744 | if (arg3) { |
| 8745 | if (!lock_user_struct(VERIFY_READ, target_rnew, arg3, 1)) { |
| 8746 | goto efault; |
| 8747 | } |
| 8748 | rnew.rlim_cur = tswap64(target_rnew->rlim_cur); |
| 8749 | rnew.rlim_max = tswap64(target_rnew->rlim_max); |
| 8750 | unlock_user_struct(target_rnew, arg3, 0); |
| 8751 | rnewp = &rnew; |
| 8752 | } |
| 8753 | |
| 8754 | ret = get_errno(sys_prlimit64(arg1, arg2, rnewp, arg4 ? &rold : 0)); |
| 8755 | if (!is_error(ret) && arg4) { |
| 8756 | if (!lock_user_struct(VERIFY_WRITE, target_rold, arg4, 1)) { |
| 8757 | goto efault; |
| 8758 | } |
| 8759 | target_rold->rlim_cur = tswap64(rold.rlim_cur); |
| 8760 | target_rold->rlim_max = tswap64(rold.rlim_max); |
| 8761 | unlock_user_struct(target_rold, arg4, 1); |
| 8762 | } |
| 8763 | break; |
| 8764 | } |
| 8765 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8766 | default: |
| 8767 | unimplemented: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 8768 | gemu_log("qemu: Unsupported syscall: %d\n", num); |
ths | 4f2b1fe | 2007-06-21 21:57:12 +0000 | [diff] [blame] | 8769 | #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] | 8770 | unimplemented_nowarn: |
bellard | 80a9d03 | 2005-01-03 23:31:27 +0000 | [diff] [blame] | 8771 | #endif |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 8772 | ret = -TARGET_ENOSYS; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8773 | break; |
| 8774 | } |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 8775 | fail: |
bellard | c573ff6 | 2004-01-04 15:51:36 +0000 | [diff] [blame] | 8776 | #ifdef DEBUG |
Blue Swirl | 0bf9e31 | 2009-07-20 17:19:25 +0000 | [diff] [blame] | 8777 | gemu_log(" = " TARGET_ABI_FMT_ld "\n", ret); |
bellard | c573ff6 | 2004-01-04 15:51:36 +0000 | [diff] [blame] | 8778 | #endif |
ths | b92c47c | 2007-11-01 00:07:38 +0000 | [diff] [blame] | 8779 | if(do_strace) |
| 8780 | print_syscall_ret(num, ret); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8781 | return ret; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 8782 | efault: |
| 8783 | ret = -TARGET_EFAULT; |
| 8784 | goto fail; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8785 | } |