2 * process related system call shims and definitions
4 * Copyright (c) 2013-2014 Stacey D. Son
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.
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.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
23 #include <sys/resource.h>
26 #include "gdbstub/syscalls.h"
27 #include "qemu/plugin.h"
29 extern int _getlogin(char*, int);
30 int bsd_get_ncpu(void);
33 static inline abi_long do_bsd_exit(void *cpu_env, abi_long arg1)
39 qemu_plugin_user_exit();
46 static inline abi_long do_bsd_getgroups(abi_long gidsetsize, abi_long arg2)
49 uint32_t *target_grouplist;
50 g_autofree gid_t *grouplist;
53 grouplist = g_try_new(gid_t, gidsetsize);
54 ret = get_errno(getgroups(gidsetsize, grouplist));
55 if (gidsetsize != 0) {
57 target_grouplist = lock_user(VERIFY_WRITE, arg2, gidsetsize * 2, 0);
58 if (!target_grouplist) {
59 return -TARGET_EFAULT;
61 for (i = 0; i < ret; i++) {
62 target_grouplist[i] = tswap32(grouplist[i]);
64 unlock_user(target_grouplist, arg2, gidsetsize * 2);
71 static inline abi_long do_bsd_setgroups(abi_long gidsetsize, abi_long arg2)
73 uint32_t *target_grouplist;
74 g_autofree gid_t *grouplist;
77 grouplist = g_try_new(gid_t, gidsetsize);
78 target_grouplist = lock_user(VERIFY_READ, arg2, gidsetsize * 2, 1);
79 if (!target_grouplist) {
80 return -TARGET_EFAULT;
82 for (i = 0; i < gidsetsize; i++) {
83 grouplist[i] = tswap32(target_grouplist[i]);
85 unlock_user(target_grouplist, arg2, 0);
86 return get_errno(setgroups(gidsetsize, grouplist));
90 static inline abi_long do_bsd_umask(abi_long arg1)
92 return get_errno(umask(arg1));
96 static inline abi_long do_bsd_setlogin(abi_long arg1)
101 p = lock_user_string(arg1);
103 return -TARGET_EFAULT;
105 ret = get_errno(setlogin(p));
106 unlock_user(p, arg1, 0);
112 static inline abi_long do_bsd_getlogin(abi_long arg1, abi_long arg2)
117 p = lock_user(VERIFY_WRITE, arg1, arg2, 0);
119 return -TARGET_EFAULT;
121 ret = get_errno(_getlogin(p, arg2));
122 unlock_user(p, arg1, arg2);
127 #endif /* !BSD_PROC_H_ */