os-syscall.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953
  1. /*
  2. * BSD syscalls
  3. *
  4. * Copyright (c) 2003-2008 Fabrice Bellard
  5. * Copyright (c) 2013-2014 Stacey D. Son
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include "qemu/osdep.h"
  21. #include "qemu/cutils.h"
  22. #include "qemu/path.h"
  23. #include <sys/syscall.h>
  24. #include <sys/cdefs.h>
  25. #include <sys/param.h>
  26. #include <sys/mount.h>
  27. #include <sys/sysctl.h>
  28. #include <utime.h>
  29. #include "include/gdbstub/syscalls.h"
  30. #include "qemu.h"
  31. #include "signal-common.h"
  32. #include "user/syscall-trace.h"
  33. /* BSD independent syscall shims */
  34. #include "bsd-file.h"
  35. #include "bsd-mem.h"
  36. #include "bsd-proc.h"
  37. /* BSD dependent syscall shims */
  38. #include "os-stat.h"
  39. #include "os-proc.h"
  40. #include "os-misc.h"
  41. /* I/O */
  42. safe_syscall3(int, open, const char *, path, int, flags, mode_t, mode);
  43. safe_syscall4(int, openat, int, fd, const char *, path, int, flags, mode_t,
  44. mode);
  45. safe_syscall3(ssize_t, read, int, fd, void *, buf, size_t, nbytes);
  46. safe_syscall4(ssize_t, pread, int, fd, void *, buf, size_t, nbytes, off_t,
  47. offset);
  48. safe_syscall3(ssize_t, readv, int, fd, const struct iovec *, iov, int, iovcnt);
  49. safe_syscall4(ssize_t, preadv, int, fd, const struct iovec *, iov, int, iovcnt,
  50. off_t, offset);
  51. safe_syscall3(ssize_t, write, int, fd, void *, buf, size_t, nbytes);
  52. safe_syscall4(ssize_t, pwrite, int, fd, void *, buf, size_t, nbytes, off_t,
  53. offset);
  54. safe_syscall3(ssize_t, writev, int, fd, const struct iovec *, iov, int, iovcnt);
  55. safe_syscall4(ssize_t, pwritev, int, fd, const struct iovec *, iov, int, iovcnt,
  56. off_t, offset);
  57. /* used in os-proc */
  58. safe_syscall4(pid_t, wait4, pid_t, wpid, int *, status, int, options,
  59. struct rusage *, rusage);
  60. safe_syscall6(pid_t, wait6, idtype_t, idtype, id_t, id, int *, status, int,
  61. options, struct __wrusage *, wrusage, siginfo_t *, infop);
  62. /*
  63. * errno conversion.
  64. */
  65. abi_long get_errno(abi_long ret)
  66. {
  67. if (ret == -1) {
  68. return -host_to_target_errno(errno);
  69. } else {
  70. return ret;
  71. }
  72. }
  73. int host_to_target_errno(int err)
  74. {
  75. /*
  76. * All the BSDs have the property that the error numbers are uniform across
  77. * all architectures for a given BSD, though they may vary between different
  78. * BSDs.
  79. */
  80. return err;
  81. }
  82. bool is_error(abi_long ret)
  83. {
  84. return (abi_ulong)ret >= (abi_ulong)(-4096);
  85. }
  86. /*
  87. * Unlocks a iovec. Unlike unlock_iovec, it assumes the tvec array itself is
  88. * already locked from target_addr. It will be unlocked as well as all the iovec
  89. * elements.
  90. */
  91. static void helper_unlock_iovec(struct target_iovec *target_vec,
  92. abi_ulong target_addr, struct iovec *vec,
  93. int count, int copy)
  94. {
  95. for (int i = 0; i < count; i++) {
  96. abi_ulong base = tswapal(target_vec[i].iov_base);
  97. if (vec[i].iov_base) {
  98. unlock_user(vec[i].iov_base, base, copy ? vec[i].iov_len : 0);
  99. }
  100. }
  101. unlock_user(target_vec, target_addr, 0);
  102. }
  103. struct iovec *lock_iovec(int type, abi_ulong target_addr,
  104. int count, int copy)
  105. {
  106. struct target_iovec *target_vec;
  107. struct iovec *vec;
  108. abi_ulong total_len, max_len;
  109. int i;
  110. int err = 0;
  111. if (count == 0) {
  112. errno = 0;
  113. return NULL;
  114. }
  115. if (count < 0 || count > IOV_MAX) {
  116. errno = EINVAL;
  117. return NULL;
  118. }
  119. vec = g_try_new0(struct iovec, count);
  120. if (vec == NULL) {
  121. errno = ENOMEM;
  122. return NULL;
  123. }
  124. target_vec = lock_user(VERIFY_READ, target_addr,
  125. count * sizeof(struct target_iovec), 1);
  126. if (target_vec == NULL) {
  127. err = EFAULT;
  128. goto fail2;
  129. }
  130. max_len = 0x7fffffff & MIN(TARGET_PAGE_MASK, PAGE_MASK);
  131. total_len = 0;
  132. for (i = 0; i < count; i++) {
  133. abi_ulong base = tswapal(target_vec[i].iov_base);
  134. abi_long len = tswapal(target_vec[i].iov_len);
  135. if (len < 0) {
  136. err = EINVAL;
  137. goto fail;
  138. } else if (len == 0) {
  139. /* Zero length pointer is ignored. */
  140. vec[i].iov_base = 0;
  141. } else {
  142. vec[i].iov_base = lock_user(type, base, len, copy);
  143. /*
  144. * If the first buffer pointer is bad, this is a fault. But
  145. * subsequent bad buffers will result in a partial write; this is
  146. * realized by filling the vector with null pointers and zero
  147. * lengths.
  148. */
  149. if (!vec[i].iov_base) {
  150. if (i == 0) {
  151. err = EFAULT;
  152. goto fail;
  153. } else {
  154. /*
  155. * Fail all the subsequent addresses, they are already
  156. * zero'd.
  157. */
  158. goto out;
  159. }
  160. }
  161. if (len > max_len - total_len) {
  162. len = max_len - total_len;
  163. }
  164. }
  165. vec[i].iov_len = len;
  166. total_len += len;
  167. }
  168. out:
  169. unlock_user(target_vec, target_addr, 0);
  170. return vec;
  171. fail:
  172. helper_unlock_iovec(target_vec, target_addr, vec, i, copy);
  173. fail2:
  174. g_free(vec);
  175. errno = err;
  176. return NULL;
  177. }
  178. void unlock_iovec(struct iovec *vec, abi_ulong target_addr,
  179. int count, int copy)
  180. {
  181. struct target_iovec *target_vec;
  182. target_vec = lock_user(VERIFY_READ, target_addr,
  183. count * sizeof(struct target_iovec), 1);
  184. if (target_vec) {
  185. helper_unlock_iovec(target_vec, target_addr, vec, count, copy);
  186. }
  187. g_free(vec);
  188. }
  189. /*
  190. * All errnos that freebsd_syscall() returns must be -TARGET_<errcode>.
  191. */
  192. static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
  193. abi_long arg2, abi_long arg3, abi_long arg4,
  194. abi_long arg5, abi_long arg6, abi_long arg7,
  195. abi_long arg8)
  196. {
  197. abi_long ret;
  198. switch (num) {
  199. /*
  200. * process system calls
  201. */
  202. case TARGET_FREEBSD_NR_fork: /* fork(2) */
  203. ret = do_freebsd_fork(cpu_env);
  204. break;
  205. case TARGET_FREEBSD_NR_vfork: /* vfork(2) */
  206. ret = do_freebsd_vfork(cpu_env);
  207. break;
  208. case TARGET_FREEBSD_NR_rfork: /* rfork(2) */
  209. ret = do_freebsd_rfork(cpu_env, arg1);
  210. break;
  211. case TARGET_FREEBSD_NR_pdfork: /* pdfork(2) */
  212. ret = do_freebsd_pdfork(cpu_env, arg1, arg2);
  213. break;
  214. case TARGET_FREEBSD_NR_execve: /* execve(2) */
  215. ret = do_freebsd_execve(arg1, arg2, arg3);
  216. break;
  217. case TARGET_FREEBSD_NR_fexecve: /* fexecve(2) */
  218. ret = do_freebsd_fexecve(arg1, arg2, arg3);
  219. break;
  220. case TARGET_FREEBSD_NR_wait4: /* wait4(2) */
  221. ret = do_freebsd_wait4(arg1, arg2, arg3, arg4);
  222. break;
  223. case TARGET_FREEBSD_NR_wait6: /* wait6(2) */
  224. ret = do_freebsd_wait6(cpu_env, arg1, arg2, arg3,
  225. arg4, arg5, arg6, arg7, arg8);
  226. break;
  227. case TARGET_FREEBSD_NR_exit: /* exit(2) */
  228. ret = do_bsd_exit(cpu_env, arg1);
  229. break;
  230. case TARGET_FREEBSD_NR_getgroups: /* getgroups(2) */
  231. ret = do_bsd_getgroups(arg1, arg2);
  232. break;
  233. case TARGET_FREEBSD_NR_setgroups: /* setgroups(2) */
  234. ret = do_bsd_setgroups(arg1, arg2);
  235. break;
  236. case TARGET_FREEBSD_NR_umask: /* umask(2) */
  237. ret = do_bsd_umask(arg1);
  238. break;
  239. case TARGET_FREEBSD_NR_setlogin: /* setlogin(2) */
  240. ret = do_bsd_setlogin(arg1);
  241. break;
  242. case TARGET_FREEBSD_NR_getlogin: /* getlogin(2) */
  243. ret = do_bsd_getlogin(arg1, arg2);
  244. break;
  245. case TARGET_FREEBSD_NR_getrusage: /* getrusage(2) */
  246. ret = do_bsd_getrusage(arg1, arg2);
  247. break;
  248. case TARGET_FREEBSD_NR_getrlimit: /* getrlimit(2) */
  249. ret = do_bsd_getrlimit(arg1, arg2);
  250. break;
  251. case TARGET_FREEBSD_NR_setrlimit: /* setrlimit(2) */
  252. ret = do_bsd_setrlimit(arg1, arg2);
  253. break;
  254. case TARGET_FREEBSD_NR_getpid: /* getpid(2) */
  255. ret = do_bsd_getpid();
  256. break;
  257. case TARGET_FREEBSD_NR_getppid: /* getppid(2) */
  258. ret = do_bsd_getppid();
  259. break;
  260. case TARGET_FREEBSD_NR_getuid: /* getuid(2) */
  261. ret = do_bsd_getuid();
  262. break;
  263. case TARGET_FREEBSD_NR_geteuid: /* geteuid(2) */
  264. ret = do_bsd_geteuid();
  265. break;
  266. case TARGET_FREEBSD_NR_getgid: /* getgid(2) */
  267. ret = do_bsd_getgid();
  268. break;
  269. case TARGET_FREEBSD_NR_getegid: /* getegid(2) */
  270. ret = do_bsd_getegid();
  271. break;
  272. case TARGET_FREEBSD_NR_setuid: /* setuid(2) */
  273. ret = do_bsd_setuid(arg1);
  274. break;
  275. case TARGET_FREEBSD_NR_seteuid: /* seteuid(2) */
  276. ret = do_bsd_seteuid(arg1);
  277. break;
  278. case TARGET_FREEBSD_NR_setgid: /* setgid(2) */
  279. ret = do_bsd_setgid(arg1);
  280. break;
  281. case TARGET_FREEBSD_NR_setegid: /* setegid(2) */
  282. ret = do_bsd_setegid(arg1);
  283. break;
  284. case TARGET_FREEBSD_NR_getpgrp: /* getpgrp(2) */
  285. ret = do_bsd_getpgrp();
  286. break;
  287. case TARGET_FREEBSD_NR_getpgid: /* getpgid(2) */
  288. ret = do_bsd_getpgid(arg1);
  289. break;
  290. case TARGET_FREEBSD_NR_setpgid: /* setpgid(2) */
  291. ret = do_bsd_setpgid(arg1, arg2);
  292. break;
  293. case TARGET_FREEBSD_NR_setreuid: /* setreuid(2) */
  294. ret = do_bsd_setreuid(arg1, arg2);
  295. break;
  296. case TARGET_FREEBSD_NR_setregid: /* setregid(2) */
  297. ret = do_bsd_setregid(arg1, arg2);
  298. break;
  299. case TARGET_FREEBSD_NR_getresuid: /* getresuid(2) */
  300. ret = do_bsd_getresuid(arg1, arg2, arg3);
  301. break;
  302. case TARGET_FREEBSD_NR_getresgid: /* getresgid(2) */
  303. ret = do_bsd_getresgid(arg1, arg2, arg3);
  304. break;
  305. case TARGET_FREEBSD_NR_setresuid: /* setresuid(2) */
  306. ret = do_bsd_setresuid(arg1, arg2, arg3);
  307. break;
  308. case TARGET_FREEBSD_NR_setresgid: /* setresgid(2) */
  309. ret = do_bsd_setresgid(arg1, arg2, arg3);
  310. break;
  311. case TARGET_FREEBSD_NR_getsid: /* getsid(2) */
  312. ret = do_bsd_getsid(arg1);
  313. break;
  314. case TARGET_FREEBSD_NR_setsid: /* setsid(2) */
  315. ret = do_bsd_setsid();
  316. break;
  317. case TARGET_FREEBSD_NR_issetugid: /* issetugid(2) */
  318. ret = do_bsd_issetugid();
  319. break;
  320. case TARGET_FREEBSD_NR_profil: /* profil(2) */
  321. ret = do_bsd_profil(arg1, arg2, arg3, arg4);
  322. break;
  323. case TARGET_FREEBSD_NR_ktrace: /* ktrace(2) */
  324. ret = do_bsd_ktrace(arg1, arg2, arg3, arg4);
  325. break;
  326. case TARGET_FREEBSD_NR_setloginclass: /* setloginclass(2) */
  327. ret = do_freebsd_setloginclass(arg1);
  328. break;
  329. case TARGET_FREEBSD_NR_getloginclass: /* getloginclass(2) */
  330. ret = do_freebsd_getloginclass(arg1, arg2);
  331. break;
  332. case TARGET_FREEBSD_NR_pdgetpid: /* pdgetpid(2) */
  333. ret = do_freebsd_pdgetpid(arg1, arg2);
  334. break;
  335. case TARGET_FREEBSD_NR___setugid: /* undocumented */
  336. ret = do_freebsd___setugid(arg1);
  337. break;
  338. case TARGET_FREEBSD_NR_utrace: /* utrace(2) */
  339. ret = do_bsd_utrace(arg1, arg2);
  340. break;
  341. case TARGET_FREEBSD_NR_ptrace: /* ptrace(2) */
  342. ret = do_bsd_ptrace(arg1, arg2, arg3, arg4);
  343. break;
  344. case TARGET_FREEBSD_NR_getpriority: /* getpriority(2) */
  345. ret = do_bsd_getpriority(arg1, arg2);
  346. break;
  347. case TARGET_FREEBSD_NR_setpriority: /* setpriority(2) */
  348. ret = do_bsd_setpriority(arg1, arg2, arg3);
  349. break;
  350. case TARGET_FREEBSD_NR_procctl: /* procctl(2) */
  351. ret = do_freebsd_procctl(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6);
  352. break;
  353. /*
  354. * File system calls.
  355. */
  356. case TARGET_FREEBSD_NR_read: /* read(2) */
  357. ret = do_bsd_read(arg1, arg2, arg3);
  358. break;
  359. case TARGET_FREEBSD_NR_pread: /* pread(2) */
  360. ret = do_bsd_pread(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6);
  361. break;
  362. case TARGET_FREEBSD_NR_readv: /* readv(2) */
  363. ret = do_bsd_readv(arg1, arg2, arg3);
  364. break;
  365. case TARGET_FREEBSD_NR_preadv: /* preadv(2) */
  366. ret = do_bsd_preadv(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6);
  367. break;
  368. case TARGET_FREEBSD_NR_write: /* write(2) */
  369. ret = do_bsd_write(arg1, arg2, arg3);
  370. break;
  371. case TARGET_FREEBSD_NR_pwrite: /* pwrite(2) */
  372. ret = do_bsd_pwrite(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6);
  373. break;
  374. case TARGET_FREEBSD_NR_writev: /* writev(2) */
  375. ret = do_bsd_writev(arg1, arg2, arg3);
  376. break;
  377. case TARGET_FREEBSD_NR_pwritev: /* pwritev(2) */
  378. ret = do_bsd_pwritev(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6);
  379. break;
  380. case TARGET_FREEBSD_NR_open: /* open(2) */
  381. ret = do_bsd_open(arg1, arg2, arg3);
  382. break;
  383. case TARGET_FREEBSD_NR_openat: /* openat(2) */
  384. ret = do_bsd_openat(arg1, arg2, arg3, arg4);
  385. break;
  386. case TARGET_FREEBSD_NR_close: /* close(2) */
  387. ret = do_bsd_close(arg1);
  388. break;
  389. case TARGET_FREEBSD_NR_fdatasync: /* fdatasync(2) */
  390. ret = do_bsd_fdatasync(arg1);
  391. break;
  392. case TARGET_FREEBSD_NR_fsync: /* fsync(2) */
  393. ret = do_bsd_fsync(arg1);
  394. break;
  395. case TARGET_FREEBSD_NR_freebsd12_closefrom: /* closefrom(2) */
  396. ret = do_bsd_closefrom(arg1);
  397. break;
  398. case TARGET_FREEBSD_NR_revoke: /* revoke(2) */
  399. ret = do_bsd_revoke(arg1);
  400. break;
  401. case TARGET_FREEBSD_NR_access: /* access(2) */
  402. ret = do_bsd_access(arg1, arg2);
  403. break;
  404. case TARGET_FREEBSD_NR_eaccess: /* eaccess(2) */
  405. ret = do_bsd_eaccess(arg1, arg2);
  406. break;
  407. case TARGET_FREEBSD_NR_faccessat: /* faccessat(2) */
  408. ret = do_bsd_faccessat(arg1, arg2, arg3, arg4);
  409. break;
  410. case TARGET_FREEBSD_NR_chdir: /* chdir(2) */
  411. ret = do_bsd_chdir(arg1);
  412. break;
  413. case TARGET_FREEBSD_NR_fchdir: /* fchdir(2) */
  414. ret = do_bsd_fchdir(arg1);
  415. break;
  416. case TARGET_FREEBSD_NR_rename: /* rename(2) */
  417. ret = do_bsd_rename(arg1, arg2);
  418. break;
  419. case TARGET_FREEBSD_NR_renameat: /* renameat(2) */
  420. ret = do_bsd_renameat(arg1, arg2, arg3, arg4);
  421. break;
  422. case TARGET_FREEBSD_NR_link: /* link(2) */
  423. ret = do_bsd_link(arg1, arg2);
  424. break;
  425. case TARGET_FREEBSD_NR_linkat: /* linkat(2) */
  426. ret = do_bsd_linkat(arg1, arg2, arg3, arg4, arg5);
  427. break;
  428. case TARGET_FREEBSD_NR_unlink: /* unlink(2) */
  429. ret = do_bsd_unlink(arg1);
  430. break;
  431. case TARGET_FREEBSD_NR_unlinkat: /* unlinkat(2) */
  432. ret = do_bsd_unlinkat(arg1, arg2, arg3);
  433. break;
  434. case TARGET_FREEBSD_NR_mkdir: /* mkdir(2) */
  435. ret = do_bsd_mkdir(arg1, arg2);
  436. break;
  437. case TARGET_FREEBSD_NR_mkdirat: /* mkdirat(2) */
  438. ret = do_bsd_mkdirat(arg1, arg2, arg3);
  439. break;
  440. case TARGET_FREEBSD_NR_rmdir: /* rmdir(2) (XXX no rmdirat()?) */
  441. ret = do_bsd_rmdir(arg1);
  442. break;
  443. case TARGET_FREEBSD_NR___getcwd: /* undocumented __getcwd() */
  444. ret = do_bsd___getcwd(arg1, arg2);
  445. break;
  446. case TARGET_FREEBSD_NR_dup: /* dup(2) */
  447. ret = do_bsd_dup(arg1);
  448. break;
  449. case TARGET_FREEBSD_NR_dup2: /* dup2(2) */
  450. ret = do_bsd_dup2(arg1, arg2);
  451. break;
  452. case TARGET_FREEBSD_NR_truncate: /* truncate(2) */
  453. ret = do_bsd_truncate(cpu_env, arg1, arg2, arg3, arg4);
  454. break;
  455. case TARGET_FREEBSD_NR_ftruncate: /* ftruncate(2) */
  456. ret = do_bsd_ftruncate(cpu_env, arg1, arg2, arg3, arg4);
  457. break;
  458. case TARGET_FREEBSD_NR_acct: /* acct(2) */
  459. ret = do_bsd_acct(arg1);
  460. break;
  461. case TARGET_FREEBSD_NR_sync: /* sync(2) */
  462. ret = do_bsd_sync();
  463. break;
  464. case TARGET_FREEBSD_NR_mount: /* mount(2) */
  465. ret = do_bsd_mount(arg1, arg2, arg3, arg4);
  466. break;
  467. case TARGET_FREEBSD_NR_unmount: /* unmount(2) */
  468. ret = do_bsd_unmount(arg1, arg2);
  469. break;
  470. case TARGET_FREEBSD_NR_nmount: /* nmount(2) */
  471. ret = do_bsd_nmount(arg1, arg2, arg3);
  472. break;
  473. case TARGET_FREEBSD_NR_symlink: /* symlink(2) */
  474. ret = do_bsd_symlink(arg1, arg2);
  475. break;
  476. case TARGET_FREEBSD_NR_symlinkat: /* symlinkat(2) */
  477. ret = do_bsd_symlinkat(arg1, arg2, arg3);
  478. break;
  479. case TARGET_FREEBSD_NR_readlink: /* readlink(2) */
  480. ret = do_bsd_readlink(cpu_env, arg1, arg2, arg3);
  481. break;
  482. case TARGET_FREEBSD_NR_readlinkat: /* readlinkat(2) */
  483. ret = do_bsd_readlinkat(arg1, arg2, arg3, arg4);
  484. break;
  485. case TARGET_FREEBSD_NR_chmod: /* chmod(2) */
  486. ret = do_bsd_chmod(arg1, arg2);
  487. break;
  488. case TARGET_FREEBSD_NR_fchmod: /* fchmod(2) */
  489. ret = do_bsd_fchmod(arg1, arg2);
  490. break;
  491. case TARGET_FREEBSD_NR_lchmod: /* lchmod(2) */
  492. ret = do_bsd_lchmod(arg1, arg2);
  493. break;
  494. case TARGET_FREEBSD_NR_fchmodat: /* fchmodat(2) */
  495. ret = do_bsd_fchmodat(arg1, arg2, arg3, arg4);
  496. break;
  497. case TARGET_FREEBSD_NR_freebsd11_mknod: /* mknod(2) */
  498. ret = do_bsd_freebsd11_mknod(arg1, arg2, arg3);
  499. break;
  500. case TARGET_FREEBSD_NR_freebsd11_mknodat: /* mknodat(2) */
  501. ret = do_bsd_freebsd11_mknodat(arg1, arg2, arg3, arg4);
  502. break;
  503. case TARGET_FREEBSD_NR_mknodat: /* mknodat(2) */
  504. ret = do_bsd_mknodat(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6);
  505. break;
  506. case TARGET_FREEBSD_NR_chown: /* chown(2) */
  507. ret = do_bsd_chown(arg1, arg2, arg3);
  508. break;
  509. case TARGET_FREEBSD_NR_fchown: /* fchown(2) */
  510. ret = do_bsd_fchown(arg1, arg2, arg3);
  511. break;
  512. case TARGET_FREEBSD_NR_lchown: /* lchown(2) */
  513. ret = do_bsd_lchown(arg1, arg2, arg3);
  514. break;
  515. case TARGET_FREEBSD_NR_fchownat: /* fchownat(2) */
  516. ret = do_bsd_fchownat(arg1, arg2, arg3, arg4, arg5);
  517. break;
  518. case TARGET_FREEBSD_NR_chflags: /* chflags(2) */
  519. ret = do_bsd_chflags(arg1, arg2);
  520. break;
  521. case TARGET_FREEBSD_NR_lchflags: /* lchflags(2) */
  522. ret = do_bsd_lchflags(arg1, arg2);
  523. break;
  524. case TARGET_FREEBSD_NR_fchflags: /* fchflags(2) */
  525. ret = do_bsd_fchflags(arg1, arg2);
  526. break;
  527. case TARGET_FREEBSD_NR_chroot: /* chroot(2) */
  528. ret = do_bsd_chroot(arg1);
  529. break;
  530. case TARGET_FREEBSD_NR_flock: /* flock(2) */
  531. ret = do_bsd_flock(arg1, arg2);
  532. break;
  533. case TARGET_FREEBSD_NR_mkfifo: /* mkfifo(2) */
  534. ret = do_bsd_mkfifo(arg1, arg2);
  535. break;
  536. case TARGET_FREEBSD_NR_mkfifoat: /* mkfifoat(2) */
  537. ret = do_bsd_mkfifoat(arg1, arg2, arg3);
  538. break;
  539. case TARGET_FREEBSD_NR_pathconf: /* pathconf(2) */
  540. ret = do_bsd_pathconf(arg1, arg2);
  541. break;
  542. case TARGET_FREEBSD_NR_lpathconf: /* lpathconf(2) */
  543. ret = do_bsd_lpathconf(arg1, arg2);
  544. break;
  545. case TARGET_FREEBSD_NR_fpathconf: /* fpathconf(2) */
  546. ret = do_bsd_fpathconf(arg1, arg2);
  547. break;
  548. case TARGET_FREEBSD_NR_undelete: /* undelete(2) */
  549. ret = do_bsd_undelete(arg1);
  550. break;
  551. /*
  552. * stat system calls
  553. */
  554. case TARGET_FREEBSD_NR_freebsd11_stat: /* stat(2) */
  555. ret = do_freebsd11_stat(arg1, arg2);
  556. break;
  557. case TARGET_FREEBSD_NR_freebsd11_lstat: /* lstat(2) */
  558. ret = do_freebsd11_lstat(arg1, arg2);
  559. break;
  560. case TARGET_FREEBSD_NR_freebsd11_fstat: /* fstat(2) */
  561. ret = do_freebsd11_fstat(arg1, arg2);
  562. break;
  563. case TARGET_FREEBSD_NR_fstat: /* fstat(2) */
  564. ret = do_freebsd_fstat(arg1, arg2);
  565. break;
  566. case TARGET_FREEBSD_NR_freebsd11_fstatat: /* fstatat(2) */
  567. ret = do_freebsd11_fstatat(arg1, arg2, arg3, arg4);
  568. break;
  569. case TARGET_FREEBSD_NR_fstatat: /* fstatat(2) */
  570. ret = do_freebsd_fstatat(arg1, arg2, arg3, arg4);
  571. break;
  572. case TARGET_FREEBSD_NR_freebsd11_nstat: /* undocumented */
  573. ret = do_freebsd11_nstat(arg1, arg2);
  574. break;
  575. case TARGET_FREEBSD_NR_freebsd11_nfstat: /* undocumented */
  576. ret = do_freebsd11_nfstat(arg1, arg2);
  577. break;
  578. case TARGET_FREEBSD_NR_freebsd11_nlstat: /* undocumented */
  579. ret = do_freebsd11_nlstat(arg1, arg2);
  580. break;
  581. case TARGET_FREEBSD_NR_getfh: /* getfh(2) */
  582. ret = do_freebsd_getfh(arg1, arg2);
  583. break;
  584. case TARGET_FREEBSD_NR_lgetfh: /* lgetfh(2) */
  585. ret = do_freebsd_lgetfh(arg1, arg2);
  586. break;
  587. case TARGET_FREEBSD_NR_fhopen: /* fhopen(2) */
  588. ret = do_freebsd_fhopen(arg1, arg2);
  589. break;
  590. case TARGET_FREEBSD_NR_freebsd11_fhstat: /* fhstat(2) */
  591. ret = do_freebsd11_fhstat(arg1, arg2);
  592. break;
  593. case TARGET_FREEBSD_NR_fhstat: /* fhstat(2) */
  594. ret = do_freebsd_fhstat(arg1, arg2);
  595. break;
  596. case TARGET_FREEBSD_NR_freebsd11_fhstatfs: /* fhstatfs(2) */
  597. ret = do_freebsd11_fhstatfs(arg1, arg2);
  598. break;
  599. case TARGET_FREEBSD_NR_fhstatfs: /* fhstatfs(2) */
  600. ret = do_freebsd_fhstatfs(arg1, arg2);
  601. break;
  602. case TARGET_FREEBSD_NR_freebsd11_statfs: /* statfs(2) */
  603. ret = do_freebsd11_statfs(arg1, arg2);
  604. break;
  605. case TARGET_FREEBSD_NR_statfs: /* statfs(2) */
  606. ret = do_freebsd_statfs(arg1, arg2);
  607. break;
  608. case TARGET_FREEBSD_NR_freebsd11_fstatfs: /* fstatfs(2) */
  609. ret = do_freebsd11_fstatfs(arg1, arg2);
  610. break;
  611. case TARGET_FREEBSD_NR_fstatfs: /* fstatfs(2) */
  612. ret = do_freebsd_fstatfs(arg1, arg2);
  613. break;
  614. case TARGET_FREEBSD_NR_freebsd11_getfsstat: /* getfsstat(2) */
  615. ret = do_freebsd11_getfsstat(arg1, arg2, arg3);
  616. break;
  617. case TARGET_FREEBSD_NR_getfsstat: /* getfsstat(2) */
  618. ret = do_freebsd_getfsstat(arg1, arg2, arg3);
  619. break;
  620. case TARGET_FREEBSD_NR_freebsd11_getdents: /* getdents(2) */
  621. ret = do_freebsd11_getdents(arg1, arg2, arg3);
  622. break;
  623. case TARGET_FREEBSD_NR_getdirentries: /* getdirentries(2) */
  624. ret = do_freebsd_getdirentries(arg1, arg2, arg3, arg4);
  625. break;
  626. case TARGET_FREEBSD_NR_freebsd11_getdirentries: /* getdirentries(2) */
  627. ret = do_freebsd11_getdirentries(arg1, arg2, arg3, arg4);
  628. break;
  629. case TARGET_FREEBSD_NR_fcntl: /* fcntl(2) */
  630. ret = do_freebsd_fcntl(arg1, arg2, arg3);
  631. break;
  632. /*
  633. * Memory management system calls.
  634. */
  635. case TARGET_FREEBSD_NR_mmap: /* mmap(2) */
  636. ret = do_bsd_mmap(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6, arg7,
  637. arg8);
  638. break;
  639. case TARGET_FREEBSD_NR_munmap: /* munmap(2) */
  640. ret = do_bsd_munmap(arg1, arg2);
  641. break;
  642. case TARGET_FREEBSD_NR_mprotect: /* mprotect(2) */
  643. ret = do_bsd_mprotect(arg1, arg2, arg3);
  644. break;
  645. case TARGET_FREEBSD_NR_msync: /* msync(2) */
  646. ret = do_bsd_msync(arg1, arg2, arg3);
  647. break;
  648. case TARGET_FREEBSD_NR_mlock: /* mlock(2) */
  649. ret = do_bsd_mlock(arg1, arg2);
  650. break;
  651. case TARGET_FREEBSD_NR_munlock: /* munlock(2) */
  652. ret = do_bsd_munlock(arg1, arg2);
  653. break;
  654. case TARGET_FREEBSD_NR_mlockall: /* mlockall(2) */
  655. ret = do_bsd_mlockall(arg1);
  656. break;
  657. case TARGET_FREEBSD_NR_munlockall: /* munlockall(2) */
  658. ret = do_bsd_munlockall();
  659. break;
  660. case TARGET_FREEBSD_NR_madvise: /* madvise(2) */
  661. ret = do_bsd_madvise(arg1, arg2, arg3);
  662. break;
  663. case TARGET_FREEBSD_NR_minherit: /* minherit(2) */
  664. ret = do_bsd_minherit(arg1, arg2, arg3);
  665. break;
  666. case TARGET_FREEBSD_NR_mincore: /* mincore(2) */
  667. ret = do_bsd_mincore(arg1, arg2, arg3);
  668. break;
  669. case TARGET_FREEBSD_NR_freebsd12_shm_open: /* shm_open(2) */
  670. ret = do_bsd_shm_open(arg1, arg2, arg3);
  671. break;
  672. #if defined(__FreeBSD_version) && __FreeBSD_version >= 1300048
  673. case TARGET_FREEBSD_NR_shm_open2: /* shm_open2(2) */
  674. ret = do_freebsd_shm_open2(arg1, arg2, arg3, arg4, arg5);
  675. break;
  676. #endif
  677. #if defined(__FreeBSD_version) && __FreeBSD_version >= 1300049
  678. case TARGET_FREEBSD_NR_shm_rename: /* shm_rename(2) */
  679. ret = do_freebsd_shm_rename(arg1, arg2, arg3);
  680. break;
  681. #endif
  682. case TARGET_FREEBSD_NR_shm_unlink: /* shm_unlink(2) */
  683. ret = do_bsd_shm_unlink(arg1);
  684. break;
  685. case TARGET_FREEBSD_NR_shmget: /* shmget(2) */
  686. ret = do_bsd_shmget(arg1, arg2, arg3);
  687. break;
  688. case TARGET_FREEBSD_NR_shmctl: /* shmctl(2) */
  689. ret = do_bsd_shmctl(arg1, arg2, arg3);
  690. break;
  691. case TARGET_FREEBSD_NR_shmat: /* shmat(2) */
  692. ret = do_bsd_shmat(arg1, arg2, arg3);
  693. break;
  694. case TARGET_FREEBSD_NR_shmdt: /* shmdt(2) */
  695. ret = do_bsd_shmdt(arg1);
  696. break;
  697. case TARGET_FREEBSD_NR_freebsd11_vadvise:
  698. ret = do_bsd_vadvise();
  699. break;
  700. case TARGET_FREEBSD_NR_sbrk:
  701. ret = do_bsd_sbrk();
  702. break;
  703. case TARGET_FREEBSD_NR_sstk:
  704. ret = do_bsd_sstk();
  705. break;
  706. /*
  707. * Misc
  708. */
  709. case TARGET_FREEBSD_NR_break:
  710. ret = do_obreak(arg1);
  711. break;
  712. /*
  713. * sys{ctl, arch, call}
  714. */
  715. case TARGET_FREEBSD_NR___sysctl: /* sysctl(3) */
  716. ret = do_freebsd_sysctl(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6);
  717. break;
  718. case TARGET_FREEBSD_NR___sysctlbyname: /* sysctlbyname(2) */
  719. ret = do_freebsd_sysctlbyname(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6);
  720. break;
  721. case TARGET_FREEBSD_NR_sysarch: /* sysarch(2) */
  722. ret = do_freebsd_sysarch(cpu_env, arg1, arg2);
  723. break;
  724. default:
  725. qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num);
  726. ret = -TARGET_ENOSYS;
  727. break;
  728. }
  729. return ret;
  730. }
  731. /*
  732. * do_freebsd_syscall() should always have a single exit point at the end so
  733. * that actions, such as logging of syscall results, can be performed. This
  734. * as a wrapper around freebsd_syscall() so that actually happens. Since
  735. * that is a singleton, modern compilers will inline it anyway...
  736. */
  737. abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,
  738. abi_long arg2, abi_long arg3, abi_long arg4,
  739. abi_long arg5, abi_long arg6, abi_long arg7,
  740. abi_long arg8)
  741. {
  742. abi_long ret;
  743. if (do_strace) {
  744. print_freebsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
  745. }
  746. ret = freebsd_syscall(cpu_env, num, arg1, arg2, arg3, arg4, arg5, arg6,
  747. arg7, arg8);
  748. if (do_strace) {
  749. print_freebsd_syscall_ret(num, ret);
  750. }
  751. return ret;
  752. }
  753. void syscall_init(void)
  754. {
  755. }