]>
git.proxmox.com Git - mirror_qemu.git/blob - bsd-user/bsd-proc.h
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
);
128 static inline abi_long
do_bsd_getrusage(abi_long who
, abi_ulong target_addr
)
131 struct rusage rusage
;
133 ret
= get_errno(getrusage(who
, &rusage
));
134 if (!is_error(ret
)) {
135 host_to_target_rusage(target_addr
, &rusage
);
141 static inline abi_long
do_bsd_getrlimit(abi_long arg1
, abi_ulong arg2
)
144 int resource
= target_to_host_resource(arg1
);
145 struct target_rlimit
*target_rlim
;
150 rlim
.rlim_cur
= target_dflssiz
;
151 rlim
.rlim_max
= target_maxssiz
;
156 rlim
.rlim_cur
= target_dfldsiz
;
157 rlim
.rlim_max
= target_maxdsiz
;
162 ret
= get_errno(getrlimit(resource
, &rlim
));
165 if (!is_error(ret
)) {
166 if (!lock_user_struct(VERIFY_WRITE
, target_rlim
, arg2
, 0)) {
167 return -TARGET_EFAULT
;
169 target_rlim
->rlim_cur
= host_to_target_rlim(rlim
.rlim_cur
);
170 target_rlim
->rlim_max
= host_to_target_rlim(rlim
.rlim_max
);
171 unlock_user_struct(target_rlim
, arg2
, 1);
177 static inline abi_long
do_bsd_setrlimit(abi_long arg1
, abi_ulong arg2
)
180 int resource
= target_to_host_resource(arg1
);
181 struct target_rlimit
*target_rlim
;
184 if (RLIMIT_STACK
== resource
) {
185 /* XXX We should, maybe, allow the stack size to shrink */
188 if (!lock_user_struct(VERIFY_READ
, target_rlim
, arg2
, 1)) {
189 return -TARGET_EFAULT
;
191 rlim
.rlim_cur
= target_to_host_rlim(target_rlim
->rlim_cur
);
192 rlim
.rlim_max
= target_to_host_rlim(target_rlim
->rlim_max
);
193 unlock_user_struct(target_rlim
, arg2
, 0);
194 ret
= get_errno(setrlimit(resource
, &rlim
));
200 static inline abi_long
do_bsd_getpid(void)
202 return get_errno(getpid());
206 static inline abi_long
do_bsd_getppid(void)
208 return get_errno(getppid());
212 static inline abi_long
do_bsd_getuid(void)
214 return get_errno(getuid());
218 static inline abi_long
do_bsd_geteuid(void)
220 return get_errno(geteuid());
224 static inline abi_long
do_bsd_getgid(void)
226 return get_errno(getgid());
230 static inline abi_long
do_bsd_getegid(void)
232 return get_errno(getegid());
236 static inline abi_long
do_bsd_setuid(abi_long arg1
)
238 return get_errno(setuid(arg1
));
242 static inline abi_long
do_bsd_seteuid(abi_long arg1
)
244 return get_errno(seteuid(arg1
));
248 static inline abi_long
do_bsd_setgid(abi_long arg1
)
250 return get_errno(setgid(arg1
));
254 static inline abi_long
do_bsd_setegid(abi_long arg1
)
256 return get_errno(setegid(arg1
));
260 static inline abi_long
do_bsd_getpgid(pid_t pid
)
262 return get_errno(getpgid(pid
));
266 static inline abi_long
do_bsd_setpgid(int pid
, int pgrp
)
268 return get_errno(setpgid(pid
, pgrp
));
272 static inline abi_long
do_bsd_getpgrp(void)
274 return get_errno(getpgrp());
278 static inline abi_long
do_bsd_setreuid(abi_long arg1
, abi_long arg2
)
280 return get_errno(setreuid(arg1
, arg2
));
284 static inline abi_long
do_bsd_setregid(abi_long arg1
, abi_long arg2
)
286 return get_errno(setregid(arg1
, arg2
));
290 static inline abi_long
do_bsd_setresgid(gid_t rgid
, gid_t egid
, gid_t sgid
)
292 return get_errno(setresgid(rgid
, egid
, sgid
));
296 static inline abi_long
do_bsd_setresuid(uid_t ruid
, uid_t euid
, uid_t suid
)
298 return get_errno(setresuid(ruid
, euid
, suid
));
302 static inline abi_long
do_bsd_getresuid(abi_ulong arg1
, abi_ulong arg2
,
306 uid_t ruid
, euid
, suid
;
308 ret
= get_errno(getresuid(&ruid
, &euid
, &suid
));
312 if (put_user_s32(ruid
, arg1
)) {
313 return -TARGET_EFAULT
;
315 if (put_user_s32(euid
, arg2
)) {
316 return -TARGET_EFAULT
;
318 if (put_user_s32(suid
, arg3
)) {
319 return -TARGET_EFAULT
;
325 static inline abi_long
do_bsd_getresgid(abi_ulong arg1
, abi_ulong arg2
,
329 uid_t ruid
, euid
, suid
;
331 ret
= get_errno(getresgid(&ruid
, &euid
, &suid
));
335 if (put_user_s32(ruid
, arg1
)) {
336 return -TARGET_EFAULT
;
338 if (put_user_s32(euid
, arg2
)) {
339 return -TARGET_EFAULT
;
341 if (put_user_s32(suid
, arg3
)) {
342 return -TARGET_EFAULT
;
348 static inline abi_long
do_bsd_getsid(abi_long arg1
)
350 return get_errno(getsid(arg1
));
354 static inline abi_long
do_bsd_setsid(void)
356 return get_errno(setsid());
360 static inline abi_long
do_bsd_issetugid(void)
362 return get_errno(issetugid());
366 static inline abi_long
do_bsd_profil(abi_long arg1
, abi_long arg2
,
367 abi_long arg3
, abi_long arg4
)
369 return -TARGET_ENOSYS
;
373 static inline abi_long
do_bsd_ktrace(abi_long arg1
, abi_long arg2
,
374 abi_long arg3
, abi_long arg4
)
376 return -TARGET_ENOSYS
;
380 static inline abi_long
do_bsd_utrace(abi_long arg1
, abi_long arg2
)
382 return -TARGET_ENOSYS
;
387 static inline abi_long
do_bsd_ptrace(abi_long arg1
, abi_long arg2
,
388 abi_long arg3
, abi_long arg4
)
390 return -TARGET_ENOSYS
;
394 static inline abi_long
do_bsd_getpriority(abi_long which
, abi_long who
)
398 * Note that negative values are valid for getpriority, so we must
399 * differentiate based on errno settings.
402 ret
= getpriority(which
, who
);
403 if (ret
== -1 && errno
!= 0) {
404 return -host_to_target_errno(errno
);
411 static inline abi_long
do_bsd_setpriority(abi_long which
, abi_long who
,
414 return get_errno(setpriority(which
, who
, prio
));
417 #endif /* !BSD_PROC_H_ */