process.cc revision 8216:70e61aa65759
1/* 2 * Copyright (c) 2010 ARM Limited 3 * All rights reserved 4 * 5 * The license below extends only to copyright in the software and shall 6 * not be construed as granting a license to any other intellectual 7 * property including but not limited to intellectual property relating 8 * to a hardware implementation of the functionality of the software 9 * licensed hereunder. You may use the software subject to the license 10 * terms below provided that you ensure that this notice is replicated 11 * unmodified and in its entirety in all distributions of the software, 12 * modified or unmodified, in source code or in binary form. 13 * 14 * Copyright (c) 2003-2005 The Regents of The University of Michigan 15 * Copyright (c) 2007-2008 The Florida State University 16 * All rights reserved. 17 * 18 * Redistribution and use in source and binary forms, with or without 19 * modification, are permitted provided that the following conditions are 20 * met: redistributions of source code must retain the above copyright 21 * notice, this list of conditions and the following disclaimer; 22 * redistributions in binary form must reproduce the above copyright 23 * notice, this list of conditions and the following disclaimer in the 24 * documentation and/or other materials provided with the distribution; 25 * neither the name of the copyright holders nor the names of its 26 * contributors may be used to endorse or promote products derived from 27 * this software without specific prior written permission. 28 * 29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 40 * 41 * Authors: Korey Sewell 42 * Stephen Hines 43 * Ali Saidi 44 */ 45 46#include "arch/arm/linux/linux.hh" 47#include "arch/arm/linux/process.hh" 48#include "arch/arm/isa_traits.hh" 49 50#include "base/trace.hh" 51#include "cpu/thread_context.hh" 52#include "kern/linux/linux.hh" 53 54#include "sim/process.hh" 55#include "sim/syscall_emul.hh" 56#include "sim/system.hh" 57 58using namespace std; 59using namespace ArmISA; 60 61/// Target uname() handler. 62static SyscallReturn 63unameFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 64 ThreadContext *tc) 65{ 66 int index = 0; 67 TypedBufferArg<Linux::utsname> name(process->getSyscallArg(tc, index)); 68 69 strcpy(name->sysname, "Linux"); 70 strcpy(name->nodename, "m5.eecs.umich.edu"); 71 strcpy(name->release, "2.6.29"); 72 strcpy(name->version, "#1 Mon Aug 18 11:32:15 EDT 2003"); 73 strcpy(name->machine, "armv7l"); 74 75 name.copyOut(tc->getMemPort()); 76 return 0; 77} 78 79SyscallDesc ArmLinuxProcess::syscallDescs[] = { 80 /* 0 */ SyscallDesc("syscall", unimplementedFunc), 81 /* 1 */ SyscallDesc("exit", exitFunc), 82 /* 2 */ SyscallDesc("fork", unimplementedFunc), 83 /* 3 */ SyscallDesc("read", readFunc), 84 /* 4 */ SyscallDesc("write", writeFunc), 85 /* 5 */ SyscallDesc("open", openFunc<ArmLinux>), 86 /* 6 */ SyscallDesc("close", closeFunc), 87 /* 7 */ SyscallDesc("unused#7", unimplementedFunc), 88 /* 8 */ SyscallDesc("creat", unimplementedFunc), 89 /* 9 */ SyscallDesc("link", unimplementedFunc), 90 /* 10 */ SyscallDesc("unlink", unlinkFunc), 91 /* 11 */ SyscallDesc("execve", unimplementedFunc), 92 /* 12 */ SyscallDesc("chdir", unimplementedFunc), 93 /* 13 */ SyscallDesc("time", timeFunc<ArmLinux>), 94 /* 14 */ SyscallDesc("mknod", unimplementedFunc), 95 /* 15 */ SyscallDesc("chmod", chmodFunc<ArmLinux>), 96 /* 16 */ SyscallDesc("lchown", chownFunc), 97 /* 17 */ SyscallDesc("unused#17", unimplementedFunc), 98 /* 18 */ SyscallDesc("unused#18", unimplementedFunc), 99 /* 19 */ SyscallDesc("lseek", lseekFunc), 100 /* 20 */ SyscallDesc("getpid", getpidFunc), 101 /* 21 */ SyscallDesc("mount", unimplementedFunc), 102 /* 22 */ SyscallDesc("umount", unimplementedFunc), 103 /* 23 */ SyscallDesc("setuid", setuidFunc), 104 /* 24 */ SyscallDesc("getuid", getuidFunc), 105 /* 25 */ SyscallDesc("stime", unimplementedFunc), 106 /* 26 */ SyscallDesc("ptrace", unimplementedFunc), 107 /* 27 */ SyscallDesc("alarm", unimplementedFunc), 108 /* 28 */ SyscallDesc("unused#28", unimplementedFunc), 109 /* 29 */ SyscallDesc("pause", unimplementedFunc), 110 /* 30 */ SyscallDesc("utime", unimplementedFunc), 111 /* 31 */ SyscallDesc("unused#31", unimplementedFunc), 112 /* 32 */ SyscallDesc("unused#32", unimplementedFunc), 113 /* 33 */ SyscallDesc("access", unimplementedFunc), 114 /* 34 */ SyscallDesc("nice", unimplementedFunc), 115 /* 35 */ SyscallDesc("unused#35", unimplementedFunc), 116 /* 36 */ SyscallDesc("sync", unimplementedFunc), 117 /* 37 */ SyscallDesc("kill", ignoreFunc), 118 /* 38 */ SyscallDesc("rename", renameFunc), 119 /* 39 */ SyscallDesc("mkdir", mkdirFunc), 120 /* 40 */ SyscallDesc("rmdir", unimplementedFunc), 121 /* 41 */ SyscallDesc("dup", dupFunc), 122 /* 42 */ SyscallDesc("pipe", pipePseudoFunc), 123 /* 43 */ SyscallDesc("times", timesFunc<ArmLinux>), 124 /* 44 */ SyscallDesc("unused#44", unimplementedFunc), 125 /* 45 */ SyscallDesc("brk", brkFunc), 126 /* 46 */ SyscallDesc("setgid", unimplementedFunc), 127 /* 47 */ SyscallDesc("getgid", getgidFunc), 128 /* 48 */ SyscallDesc("unused#48", unimplementedFunc), 129 /* 49 */ SyscallDesc("geteuid", geteuidFunc), 130 /* 50 */ SyscallDesc("getegid", getegidFunc), 131 /* 51 */ SyscallDesc("acct", unimplementedFunc), 132 /* 52 */ SyscallDesc("umount2", unimplementedFunc), 133 /* 53 */ SyscallDesc("unused#53", unimplementedFunc), 134 /* 54 */ SyscallDesc("ioctl", ioctlFunc<ArmLinux>), 135 /* 55 */ SyscallDesc("fcntl", fcntlFunc), 136 /* 56 */ SyscallDesc("unused#56", unimplementedFunc), 137 /* 57 */ SyscallDesc("setpgid", unimplementedFunc), 138 /* 58 */ SyscallDesc("unused#58", unimplementedFunc), 139 /* 59 */ SyscallDesc("unused#59", unimplementedFunc), 140 /* 60 */ SyscallDesc("umask", unimplementedFunc), 141 /* 61 */ SyscallDesc("chroot", unimplementedFunc), 142 /* 62 */ SyscallDesc("ustat", unimplementedFunc), 143 /* 63 */ SyscallDesc("dup2", unimplementedFunc), 144 /* 64 */ SyscallDesc("getppid", getppidFunc), 145 /* 65 */ SyscallDesc("getpgrp", unimplementedFunc), 146 /* 66 */ SyscallDesc("setsid", unimplementedFunc), 147 /* 67 */ SyscallDesc("sigaction",unimplementedFunc), 148 /* 68 */ SyscallDesc("unused#68", unimplementedFunc), 149 /* 69 */ SyscallDesc("unused#69", unimplementedFunc), 150 /* 70 */ SyscallDesc("setreuid", unimplementedFunc), 151 /* 71 */ SyscallDesc("setregid", unimplementedFunc), 152 /* 72 */ SyscallDesc("sigsuspend", unimplementedFunc), 153 /* 73 */ SyscallDesc("sigpending", unimplementedFunc), 154 /* 74 */ SyscallDesc("sethostname", ignoreFunc), 155 /* 75 */ SyscallDesc("setrlimit", ignoreFunc), 156 /* 76 */ SyscallDesc("getrlimit", unimplementedFunc), 157 /* 77 */ SyscallDesc("getrusage", getrusageFunc<ArmLinux>), 158 /* 78 */ SyscallDesc("gettimeofday", gettimeofdayFunc<ArmLinux>), 159 /* 79 */ SyscallDesc("settimeofday", unimplementedFunc), 160 /* 80 */ SyscallDesc("getgroups", unimplementedFunc), 161 /* 81 */ SyscallDesc("setgroups", unimplementedFunc), 162 /* 82 */ SyscallDesc("reserved#82", unimplementedFunc), 163 /* 83 */ SyscallDesc("symlink", unimplementedFunc), 164 /* 84 */ SyscallDesc("unused#84", unimplementedFunc), 165 /* 85 */ SyscallDesc("readlink", readlinkFunc), 166 /* 86 */ SyscallDesc("uselib", unimplementedFunc), 167 /* 87 */ SyscallDesc("swapon", unimplementedFunc), 168 /* 88 */ SyscallDesc("reboot", unimplementedFunc), 169 /* 89 */ SyscallDesc("readdir", unimplementedFunc), 170 /* 90 */ SyscallDesc("mmap", mmapFunc<ArmLinux>), 171 /* 91 */ SyscallDesc("munmap", munmapFunc), 172 /* 92 */ SyscallDesc("truncate", truncateFunc), 173 /* 93 */ SyscallDesc("ftruncate", ftruncateFunc), 174 /* 94 */ SyscallDesc("fchmod", unimplementedFunc), 175 /* 95 */ SyscallDesc("fchown", unimplementedFunc), 176 /* 96 */ SyscallDesc("getpriority", unimplementedFunc), 177 /* 97 */ SyscallDesc("setpriority", unimplementedFunc), 178 /* 98 */ SyscallDesc("unused#98", unimplementedFunc), 179 /* 99 */ SyscallDesc("statfs", unimplementedFunc), 180 /* 100 */ SyscallDesc("fstatfs", unimplementedFunc), 181 /* 101 */ SyscallDesc("unused#101", unimplementedFunc), 182 /* 102 */ SyscallDesc("socketcall", unimplementedFunc), 183 /* 103 */ SyscallDesc("syslog", unimplementedFunc), 184 /* 104 */ SyscallDesc("setitimer", unimplementedFunc), 185 /* 105 */ SyscallDesc("getitimer", unimplementedFunc), 186 /* 106 */ SyscallDesc("stat", statFunc<ArmLinux>), 187 /* 107 */ SyscallDesc("lstat", unimplementedFunc), 188 /* 108 */ SyscallDesc("fstat", fstatFunc<ArmLinux>), 189 /* 109 */ SyscallDesc("unused#109", unimplementedFunc), 190 /* 110 */ SyscallDesc("unused#101", unimplementedFunc), 191 /* 111 */ SyscallDesc("vhangup", unimplementedFunc), 192 /* 112 */ SyscallDesc("unused#112", unimplementedFunc), 193 /* 113 */ SyscallDesc("syscall", unimplementedFunc), 194 /* 114 */ SyscallDesc("wait4", unimplementedFunc), 195 /* 115 */ SyscallDesc("swapoff", unimplementedFunc), 196 /* 116 */ SyscallDesc("sysinfo", sysinfoFunc<ArmLinux>), 197 /* 117 */ SyscallDesc("ipc", unimplementedFunc), 198 /* 118 */ SyscallDesc("fsync", unimplementedFunc), 199 /* 119 */ SyscallDesc("sigreturn", unimplementedFunc), 200 /* 120 */ SyscallDesc("clone", cloneFunc), 201 /* 121 */ SyscallDesc("setdomainname", unimplementedFunc), 202 /* 122 */ SyscallDesc("uname", unameFunc), 203 /* 123 */ SyscallDesc("unused#123", unimplementedFunc), 204 /* 124 */ SyscallDesc("adjtimex", unimplementedFunc), 205 /* 125 */ SyscallDesc("mprotect", ignoreFunc), 206 /* 126 */ SyscallDesc("sigprocmask", unimplementedFunc), 207 /* 127 */ SyscallDesc("unused#127", unimplementedFunc), 208 /* 128 */ SyscallDesc("init_module", unimplementedFunc), 209 /* 129 */ SyscallDesc("delete_module", unimplementedFunc), 210 /* 130 */ SyscallDesc("unused#130", unimplementedFunc), 211 /* 131 */ SyscallDesc("quotactl", unimplementedFunc), 212 /* 132 */ SyscallDesc("getpgid", unimplementedFunc), 213 /* 133 */ SyscallDesc("fchdir", unimplementedFunc), 214 /* 134 */ SyscallDesc("bdflush", unimplementedFunc), 215 /* 135 */ SyscallDesc("sysfs", unimplementedFunc), 216 /* 136 */ SyscallDesc("personality", unimplementedFunc), 217 /* 137 */ SyscallDesc("reserved#138", unimplementedFunc), 218 /* 138 */ SyscallDesc("setfsuid", unimplementedFunc), 219 /* 139 */ SyscallDesc("setfsgid", unimplementedFunc), 220 /* 140 */ SyscallDesc("llseek", _llseekFunc), 221 /* 141 */ SyscallDesc("getdents", unimplementedFunc), 222 /* 142 */ SyscallDesc("newselect", unimplementedFunc), 223 /* 143 */ SyscallDesc("flock", unimplementedFunc), 224 /* 144 */ SyscallDesc("msync", unimplementedFunc), 225 /* 145 */ SyscallDesc("readv", unimplementedFunc), 226 /* 146 */ SyscallDesc("writev", writevFunc<ArmLinux>), 227 /* 147 */ SyscallDesc("getsid", unimplementedFunc), 228 /* 148 */ SyscallDesc("fdatasync", unimplementedFunc), 229 /* 149 */ SyscallDesc("sysctl", unimplementedFunc), 230 /* 150 */ SyscallDesc("mlock", unimplementedFunc), 231 /* 151 */ SyscallDesc("munlock", unimplementedFunc), 232 /* 152 */ SyscallDesc("mlockall", unimplementedFunc), 233 /* 153 */ SyscallDesc("munlockall", unimplementedFunc), 234 /* 154 */ SyscallDesc("sched_setparam", unimplementedFunc), 235 /* 155 */ SyscallDesc("sched_getparam", unimplementedFunc), 236 /* 156 */ SyscallDesc("sched_setscheduler", unimplementedFunc), 237 /* 157 */ SyscallDesc("sched_getscheduler", unimplementedFunc), 238 /* 158 */ SyscallDesc("sched_yield", unimplementedFunc), 239 /* 159 */ SyscallDesc("sched_get_priority_max", unimplementedFunc), 240 /* 160 */ SyscallDesc("sched_get_priority_min", unimplementedFunc), 241 /* 161 */ SyscallDesc("sched_rr_get_interval", unimplementedFunc), 242 /* 162 */ SyscallDesc("nanosleep", ignoreWarnOnceFunc), 243 /* 163 */ SyscallDesc("mremap", mremapFunc<ArmLinux>), // ARM-specific 244 /* 164 */ SyscallDesc("setresuid", unimplementedFunc), 245 /* 165 */ SyscallDesc("getresuid", unimplementedFunc), 246 /* 166 */ SyscallDesc("unused#166", unimplementedFunc), 247 /* 167 */ SyscallDesc("unused#167", unimplementedFunc), 248 /* 168 */ SyscallDesc("poll", unimplementedFunc), 249 /* 169 */ SyscallDesc("nfsservctl", unimplementedFunc), 250 /* 170 */ SyscallDesc("setresgid", unimplementedFunc), 251 /* 171 */ SyscallDesc("getresgid", unimplementedFunc), 252 /* 172 */ SyscallDesc("prctl", unimplementedFunc), 253 /* 173 */ SyscallDesc("rt_sigreturn", unimplementedFunc), 254 /* 174 */ SyscallDesc("rt_sigaction", ignoreWarnOnceFunc), 255 /* 175 */ SyscallDesc("rt_sigprocmask", ignoreWarnOnceFunc), 256 /* 176 */ SyscallDesc("rt_sigpending", unimplementedFunc), 257 /* 177 */ SyscallDesc("rt_sigtimedwait", unimplementedFunc), 258 /* 178 */ SyscallDesc("rt_sigqueueinfo", ignoreFunc), 259 /* 179 */ SyscallDesc("rt_sigsuspend", unimplementedFunc), 260 /* 180 */ SyscallDesc("pread64", unimplementedFunc), 261 /* 181 */ SyscallDesc("pwrite64", unimplementedFunc), 262 /* 182 */ SyscallDesc("chown", unimplementedFunc), 263 /* 183 */ SyscallDesc("getcwd", getcwdFunc), 264 /* 184 */ SyscallDesc("capget", unimplementedFunc), 265 /* 185 */ SyscallDesc("capset", unimplementedFunc), 266 /* 186 */ SyscallDesc("sigaltstack", unimplementedFunc), 267 /* 187 */ SyscallDesc("sendfile", unimplementedFunc), 268 /* 188 */ SyscallDesc("unused#188", unimplementedFunc), 269 /* 189 */ SyscallDesc("unused#189", unimplementedFunc), 270 /* 190 */ SyscallDesc("vfork", unimplementedFunc), 271 /* 191 */ SyscallDesc("getrlimit", getrlimitFunc<ArmLinux>), 272 /* 192 */ SyscallDesc("mmap2", mmapFunc<ArmLinux>), 273 /* 193 */ SyscallDesc("truncate64", unimplementedFunc), 274 /* 194 */ SyscallDesc("ftruncate64", ftruncate64Func), 275 /* 195 */ SyscallDesc("stat64", stat64Func<ArmLinux>), 276 /* 196 */ SyscallDesc("lstat64", lstat64Func<ArmLinux>), 277 /* 197 */ SyscallDesc("fstat64", fstat64Func<ArmLinux>), 278 /* 198 */ SyscallDesc("lchown", unimplementedFunc), 279 /* 199 */ SyscallDesc("getuid", getuidFunc), 280 /* 200 */ SyscallDesc("getgid", getgidFunc), 281 /* 201 */ SyscallDesc("geteuid", geteuidFunc), 282 /* 202 */ SyscallDesc("getegid", getegidFunc), 283 /* 203 */ SyscallDesc("setreuid", unimplementedFunc), 284 /* 204 */ SyscallDesc("setregid", unimplementedFunc), 285 /* 205 */ SyscallDesc("getgroups", unimplementedFunc), 286 /* 206 */ SyscallDesc("setgroups", unimplementedFunc), 287 /* 207 */ SyscallDesc("fchown", unimplementedFunc), 288 /* 208 */ SyscallDesc("setresuid", unimplementedFunc), 289 /* 209 */ SyscallDesc("getresuid", unimplementedFunc), 290 /* 210 */ SyscallDesc("setresgid", unimplementedFunc), 291 /* 211 */ SyscallDesc("getresgid", unimplementedFunc), 292 /* 212 */ SyscallDesc("chown", unimplementedFunc), 293 /* 213 */ SyscallDesc("setuid", unimplementedFunc), 294 /* 214 */ SyscallDesc("setgid", unimplementedFunc), 295 /* 215 */ SyscallDesc("setfsuid", unimplementedFunc), 296 /* 216 */ SyscallDesc("setfsgid", unimplementedFunc), 297 /* 217 */ SyscallDesc("getdents64", unimplementedFunc), 298 /* 218 */ SyscallDesc("pivot_root", unimplementedFunc), 299 /* 219 */ SyscallDesc("mincore", unimplementedFunc), 300 /* 220 */ SyscallDesc("madvise", unimplementedFunc), 301 /* 221 */ SyscallDesc("fcntl64", fcntl64Func), 302 /* 222 */ SyscallDesc("unused#222", unimplementedFunc), 303 /* 223 */ SyscallDesc("unknown#223", unimplementedFunc), 304 /* 224 */ SyscallDesc("gettid", unimplementedFunc), 305 /* 225 */ SyscallDesc("readahead", unimplementedFunc), 306 /* 226 */ SyscallDesc("setxattr", unimplementedFunc), 307 /* 227 */ SyscallDesc("lsetxattr", unimplementedFunc), 308 /* 228 */ SyscallDesc("fsetxattr", unimplementedFunc), 309 /* 229 */ SyscallDesc("getxattr", unimplementedFunc), 310 /* 230 */ SyscallDesc("lgetxattr", unimplementedFunc), 311 /* 231 */ SyscallDesc("fgetxattr", unimplementedFunc), 312 /* 232 */ SyscallDesc("listxattr", unimplementedFunc), 313 /* 233 */ SyscallDesc("llistxattr", unimplementedFunc), 314 /* 234 */ SyscallDesc("flistxattr", unimplementedFunc), 315 /* 235 */ SyscallDesc("removexattr", unimplementedFunc), 316 /* 236 */ SyscallDesc("lremovexattr", unimplementedFunc), 317 /* 237 */ SyscallDesc("fremovexattr", unimplementedFunc), 318 /* 238 */ SyscallDesc("tkill", unimplementedFunc), 319 /* 239 */ SyscallDesc("sendfile64", unimplementedFunc), 320 /* 240 */ SyscallDesc("futex", ignoreWarnOnceFunc), 321 /* 241 */ SyscallDesc("sched_setaffinity", unimplementedFunc), 322 /* 242 */ SyscallDesc("sched_getaffinity", unimplementedFunc), 323 /* 243 */ SyscallDesc("io_setup", unimplementedFunc), 324 /* 244 */ SyscallDesc("io_destory", unimplementedFunc), 325 /* 245 */ SyscallDesc("io_getevents", unimplementedFunc), 326 /* 246 */ SyscallDesc("io_submit", unimplementedFunc), 327 /* 247 */ SyscallDesc("io_cancel", unimplementedFunc), 328 /* 248 */ SyscallDesc("exit_group", exitGroupFunc), 329 /* 249 */ SyscallDesc("lookup_dcookie", unimplementedFunc), 330 /* 250 */ SyscallDesc("epoll_create", unimplementedFunc), 331 /* 251 */ SyscallDesc("epoll_ctl", unimplementedFunc), 332 /* 252 */ SyscallDesc("epoll_wait", unimplementedFunc), 333 /* 253 */ SyscallDesc("remap_file_pages", unimplementedFunc), 334 /* 254 */ SyscallDesc("unused#254", unimplementedFunc), 335 /* 255 */ SyscallDesc("unused#255", unimplementedFunc), 336 /* 256 */ SyscallDesc("set_tid_address", unimplementedFunc), 337 /* 257 */ SyscallDesc("timer_create", unimplementedFunc), 338 /* 258 */ SyscallDesc("timer_settime", unimplementedFunc), 339 /* 259 */ SyscallDesc("timer_gettime", unimplementedFunc), 340 /* 260 */ SyscallDesc("timer_getoverrun", unimplementedFunc), 341 /* 261 */ SyscallDesc("timer_delete", unimplementedFunc), 342 /* 262 */ SyscallDesc("clock_settime", unimplementedFunc), 343 /* 263 */ SyscallDesc("clock_gettime", unimplementedFunc), 344 /* 264 */ SyscallDesc("clock_getres", unimplementedFunc), 345 /* 265 */ SyscallDesc("clock_nanosleep", unimplementedFunc), 346 /* 266 */ SyscallDesc("statfs64", unimplementedFunc), 347 /* 267 */ SyscallDesc("fstatfs64", unimplementedFunc), 348 /* 268 */ SyscallDesc("tgkill", unimplementedFunc), 349 /* 269 */ SyscallDesc("utimes", unimplementedFunc), 350 /* 270 */ SyscallDesc("arm_fadvise64_64", unimplementedFunc), 351 /* 271 */ SyscallDesc("pciconfig_iobase", unimplementedFunc), 352 /* 272 */ SyscallDesc("pciconfig_read", unimplementedFunc), 353 /* 273 */ SyscallDesc("pciconfig_write", unimplementedFunc), 354 /* 274 */ SyscallDesc("mq_open", unimplementedFunc), 355 /* 275 */ SyscallDesc("mq_unlink", unimplementedFunc), 356 /* 276 */ SyscallDesc("mq_timedsend", unimplementedFunc), 357 /* 277 */ SyscallDesc("mq_timedreceive", unimplementedFunc), 358 /* 278 */ SyscallDesc("mq_notify", unimplementedFunc), 359 /* 279 */ SyscallDesc("mq_getsetattr", unimplementedFunc), 360 /* 280 */ SyscallDesc("waitid", unimplementedFunc), 361 /* 281 */ SyscallDesc("socket", unimplementedFunc), 362 /* 282 */ SyscallDesc("bind", unimplementedFunc), 363 /* 283 */ SyscallDesc("connect", unimplementedFunc), 364 /* 284 */ SyscallDesc("listen", unimplementedFunc), 365 /* 285 */ SyscallDesc("accept", unimplementedFunc), 366 /* 286 */ SyscallDesc("getsockname", unimplementedFunc), 367 /* 287 */ SyscallDesc("getpeername", unimplementedFunc), 368 /* 288 */ SyscallDesc("socketpair", unimplementedFunc), 369 /* 289 */ SyscallDesc("send", unimplementedFunc), 370 /* 290 */ SyscallDesc("sendto", unimplementedFunc), 371 /* 291 */ SyscallDesc("recv", unimplementedFunc), 372 /* 292 */ SyscallDesc("recvfrom", unimplementedFunc), 373 /* 293 */ SyscallDesc("shutdown", unimplementedFunc), 374 /* 294 */ SyscallDesc("setsockopt", unimplementedFunc), 375 /* 295 */ SyscallDesc("getsockopt", unimplementedFunc), 376 /* 296 */ SyscallDesc("sendmsg", unimplementedFunc), 377 /* 297 */ SyscallDesc("rcvmsg", unimplementedFunc), 378 /* 298 */ SyscallDesc("semop", unimplementedFunc), 379 /* 299 */ SyscallDesc("semget", unimplementedFunc), 380 /* 300 */ SyscallDesc("semctl", unimplementedFunc), 381 /* 301 */ SyscallDesc("msgsend", unimplementedFunc), 382 /* 302 */ SyscallDesc("msgrcv", unimplementedFunc), 383 /* 303 */ SyscallDesc("msgget", unimplementedFunc), 384 /* 304 */ SyscallDesc("msgctl", unimplementedFunc), 385 /* 305 */ SyscallDesc("shmat", unimplementedFunc), 386 /* 306 */ SyscallDesc("shmdt", unimplementedFunc), 387 /* 307 */ SyscallDesc("shmget", unimplementedFunc), 388 /* 308 */ SyscallDesc("shmctl", unimplementedFunc), 389 /* 309 */ SyscallDesc("add_key", unimplementedFunc), 390 /* 310 */ SyscallDesc("request_key", unimplementedFunc), 391 /* 311 */ SyscallDesc("keyctl", unimplementedFunc), 392 /* 312 */ SyscallDesc("semtimedop", unimplementedFunc), 393 /* 313 */ SyscallDesc("unused#313", unimplementedFunc), 394 /* 314 */ SyscallDesc("ioprio_set", unimplementedFunc), 395 /* 315 */ SyscallDesc("ioprio_get", unimplementedFunc), 396 /* 316 */ SyscallDesc("inotify_init", unimplementedFunc), 397 /* 317 */ SyscallDesc("inotify_add_watch", unimplementedFunc), 398 /* 318 */ SyscallDesc("inotify_rm_watch", unimplementedFunc), 399 /* 319 */ SyscallDesc("mbind", unimplementedFunc), 400 /* 320 */ SyscallDesc("get_mempolicy", unimplementedFunc), 401 /* 321 */ SyscallDesc("set_mempolicy", unimplementedFunc), 402 /* 322 */ SyscallDesc("openat", unimplementedFunc), 403 /* 323 */ SyscallDesc("mkdirat", unimplementedFunc), 404 /* 324 */ SyscallDesc("mknodat", unimplementedFunc), 405 /* 325 */ SyscallDesc("fchownat", unimplementedFunc), 406 /* 326 */ SyscallDesc("futimesat", unimplementedFunc), 407 /* 327 */ SyscallDesc("fstatat64", unimplementedFunc), 408 /* 328 */ SyscallDesc("unlinkat", unimplementedFunc), 409 /* 329 */ SyscallDesc("renameat", unimplementedFunc), 410 /* 330 */ SyscallDesc("linkat", unimplementedFunc), 411 /* 331 */ SyscallDesc("symlinkat", unimplementedFunc), 412 /* 332 */ SyscallDesc("readlinkat", unimplementedFunc), 413 /* 333 */ SyscallDesc("fchmodat", unimplementedFunc), 414 /* 334 */ SyscallDesc("faccessat", unimplementedFunc), 415 /* 335 */ SyscallDesc("pselect6", unimplementedFunc), 416 /* 336 */ SyscallDesc("ppoll", unimplementedFunc), 417 /* 337 */ SyscallDesc("unshare", unimplementedFunc), 418 /* 338 */ SyscallDesc("set_robust_list", unimplementedFunc), 419 /* 339 */ SyscallDesc("get_robust_list", unimplementedFunc), 420 /* 340 */ SyscallDesc("splice", unimplementedFunc), 421 /* 341 */ SyscallDesc("arm_sync_file_range", unimplementedFunc), 422 /* 342 */ SyscallDesc("tee", unimplementedFunc), 423 /* 343 */ SyscallDesc("vmsplice", unimplementedFunc), 424 /* 344 */ SyscallDesc("move_pages", unimplementedFunc), 425 /* 345 */ SyscallDesc("getcpu", unimplementedFunc), 426 /* 346 */ SyscallDesc("epoll_pwait", unimplementedFunc), 427 /* 347 */ SyscallDesc("sys_kexec_load", unimplementedFunc), 428 /* 348 */ SyscallDesc("sys_utimensat", unimplementedFunc), 429 /* 349 */ SyscallDesc("sys_signalfd", unimplementedFunc), 430 /* 350 */ SyscallDesc("sys_timerfd_create", unimplementedFunc), 431 /* 351 */ SyscallDesc("sys_eventfd", unimplementedFunc), 432 /* 352 */ SyscallDesc("sys_fallocate", unimplementedFunc), 433 /* 353 */ SyscallDesc("sys_timerfd_settime", unimplementedFunc), 434 /* 354 */ SyscallDesc("sys_timerfd_gettime", unimplementedFunc), 435 /* 355 */ SyscallDesc("sys_signalfd4", unimplementedFunc), 436 /* 356 */ SyscallDesc("sys_eventfd2", unimplementedFunc), 437 /* 357 */ SyscallDesc("sys_epoll_create1", unimplementedFunc), 438 /* 358 */ SyscallDesc("sys_dup3", unimplementedFunc), 439 /* 359 */ SyscallDesc("sys_pipe2", unimplementedFunc), 440 /* 360 */ SyscallDesc("sys_inotify_init1", unimplementedFunc), 441 /* 361 */ SyscallDesc("sys_preadv", unimplementedFunc), 442 /* 362 */ SyscallDesc("sys_pwritev", unimplementedFunc), 443 /* 363 */ SyscallDesc("sys_rt_tgsigqueueinfo", unimplementedFunc), 444 /* 364 */ SyscallDesc("sys_perf_event_open", unimplementedFunc), 445 /* 365 */ SyscallDesc("sys_recvmmsg", unimplementedFunc), 446 447}; 448 449/// Target set_tls() handler. 450static SyscallReturn 451setTLSFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 452 ThreadContext *tc) 453{ 454 int index = 0; 455 uint32_t tlsPtr = process->getSyscallArg(tc, index); 456 457 tc->getMemPort()->writeBlob(ArmLinuxProcess::commPage + 0x0ff0, 458 (uint8_t *)&tlsPtr, sizeof(tlsPtr)); 459 tc->setMiscReg(MISCREG_TPIDRURO,tlsPtr); 460 return 0; 461} 462 463SyscallDesc ArmLinuxProcess::privSyscallDescs[] = { 464 /* 1 */ SyscallDesc("breakpoint", unimplementedFunc), 465 /* 2 */ SyscallDesc("cacheflush", unimplementedFunc), 466 /* 3 */ SyscallDesc("usr26", unimplementedFunc), 467 /* 4 */ SyscallDesc("usr32", unimplementedFunc), 468 /* 5 */ SyscallDesc("set_tls", setTLSFunc) 469}; 470 471ArmLinuxProcess::ArmLinuxProcess(LiveProcessParams * params, 472 ObjectFile *objFile, ObjectFile::Arch _arch) 473 : ArmLiveProcess(params, objFile, _arch), 474 Num_Syscall_Descs(sizeof(syscallDescs) / sizeof(SyscallDesc)), 475 Num_Priv_Syscall_Descs(sizeof(privSyscallDescs) / sizeof(SyscallDesc)) 476{ } 477 478const Addr ArmLinuxProcess::commPage = 0xffff0000; 479 480SyscallDesc* 481ArmLinuxProcess::getDesc(int callnum) 482{ 483 // Angel SWI syscalls are unsupported in this release 484 if (callnum == 0x123456) { 485 panic("Attempt to execute an ANGEL_SWI system call (newlib-related)"); 486 } else if ((callnum & 0x00f00000) == 0x00900000 || 487 (callnum & 0xf0000) == 0xf0000) { 488 callnum &= 0x000fffff; 489 if ((callnum & 0x0f0000) == 0xf0000) { 490 callnum -= 0x0f0001; 491 if (callnum < 0 || callnum > Num_Priv_Syscall_Descs) 492 return NULL; 493 return &privSyscallDescs[callnum]; 494 } 495 } 496 // Linux syscalls have to strip off the 0x00900000 497 498 if (callnum < 0 || callnum > Num_Syscall_Descs) 499 return NULL; 500 501 return &syscallDescs[callnum]; 502} 503 504void 505ArmLinuxProcess::initState() 506{ 507 ArmLiveProcess::initState(); 508 pTable->allocate(commPage, PageBytes); 509 ThreadContext *tc = system->getThreadContext(contextIds[0]); 510 511 uint8_t swiNeg1[] = { 512 0xff, 0xff, 0xff, 0xef // swi -1 513 }; 514 515 // Fill this page with swi -1 so we'll no if we land in it somewhere. 516 for (Addr addr = 0; addr < PageBytes; addr += sizeof(swiNeg1)) { 517 tc->getMemPort()->writeBlob(commPage + addr, 518 swiNeg1, sizeof(swiNeg1)); 519 } 520 521 uint8_t memory_barrier[] = 522 { 523 0x5f, 0xf0, 0x7f, 0xf5, // dmb 524 0x0e, 0xf0, 0xa0, 0xe1 // return 525 }; 526 tc->getMemPort()->writeBlob(commPage + 0x0fa0, memory_barrier, 527 sizeof(memory_barrier)); 528 529 uint8_t cmpxchg[] = 530 { 531 0x9f, 0x3f, 0x92, 0xe1, // ldrex r3, [r2] 532 0x00, 0x30, 0x53, 0xe0, // subs r3, r3, r0 533 0x91, 0x3f, 0x82, 0x01, // strexeq r3, r1, [r2] 534 0x01, 0x00, 0x33, 0x03, // teqeq r3, #1 535 0xfa, 0xff, 0xff, 0x0a, // beq 1b 536 0x00, 0x00, 0x73, 0xe2, // rsbs r0, r3, #0 537 0x5f, 0xf0, 0x7f, 0xf5, // dmb 538 0x0e, 0xf0, 0xa0, 0xe1 // return 539 }; 540 tc->getMemPort()->writeBlob(commPage + 0x0fc0, cmpxchg, sizeof(cmpxchg)); 541 542 uint8_t get_tls[] = 543 { 544 // read user read-only thread id register 545 0x70, 0x0f, 0x1d, 0xee, // mrc p15, 0, r0, c13, c0, 3 546 0x0e, 0xf0, 0xa0, 0xe1 // return 547 }; 548 tc->getMemPort()->writeBlob(commPage + 0x0fe0, get_tls, sizeof(get_tls)); 549} 550 551ArmISA::IntReg 552ArmLinuxProcess::getSyscallArg(ThreadContext *tc, int &i) 553{ 554 // Linux apparently allows more parameter than the ABI says it should. 555 // This limit may need to be increased even further. 556 assert(i < 6); 557 return tc->readIntReg(ArgumentReg0 + i++); 558} 559 560void 561ArmLinuxProcess::setSyscallArg(ThreadContext *tc, int i, ArmISA::IntReg val) 562{ 563 // Linux apparently allows more parameter than the ABI says it should. 564 // This limit may need to be increased even further. 565 assert(i < 6); 566 tc->setIntReg(ArgumentReg0 + i, val); 567} 568