]> git.proxmox.com Git - mirror_qemu.git/blob - bsd-user/freebsd/os-proc.h
04bce755e58b1d9c36b3e8888edf5a9c43949e12
[mirror_qemu.git] / bsd-user / freebsd / os-proc.h
1 /*
2 * process related system call shims and definitions
3 *
4 * Copyright (c) 2013-14 Stacey D. Son
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
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef BSD_USER_FREEBSD_OS_PROC_H
21 #define BSD_USER_FREEBSD_OS_PROC_H
22
23 #include <sys/param.h>
24 #include <sys/procctl.h>
25 #include <sys/signal.h>
26 #include <sys/types.h>
27 #include <sys/procdesc.h>
28 #include <sys/wait.h>
29 #include <unistd.h>
30
31 #include "target_arch_cpu.h"
32
33 pid_t safe_wait4(pid_t wpid, int *status, int options, struct rusage *rusage);
34 pid_t safe_wait6(idtype_t idtype, id_t id, int *status, int options,
35 struct __wrusage *wrusage, siginfo_t *infop);
36
37 /* execve(2) */
38 static inline abi_long do_freebsd_execve(abi_ulong path_or_fd, abi_ulong argp,
39 abi_ulong envp)
40 {
41
42 return freebsd_exec_common(path_or_fd, argp, envp, 0);
43 }
44
45 /* fexecve(2) */
46 static inline abi_long do_freebsd_fexecve(abi_ulong path_or_fd, abi_ulong argp,
47 abi_ulong envp)
48 {
49
50 return freebsd_exec_common(path_or_fd, argp, envp, 1);
51 }
52
53 /* wait4(2) */
54 static inline abi_long do_freebsd_wait4(abi_long arg1, abi_ulong target_status,
55 abi_long arg3, abi_ulong target_rusage)
56 {
57 abi_long ret;
58 int status;
59 struct rusage rusage, *rusage_ptr = NULL;
60
61 if (target_rusage) {
62 rusage_ptr = &rusage;
63 }
64 ret = get_errno(safe_wait4(arg1, &status, arg3, rusage_ptr));
65
66 if (ret < 0) {
67 return ret;
68 }
69 if (target_status != 0) {
70 status = host_to_target_waitstatus(status);
71 if (put_user_s32(status, target_status) != 0) {
72 return -TARGET_EFAULT;
73 }
74 }
75 if (target_rusage != 0) {
76 host_to_target_rusage(target_rusage, &rusage);
77 }
78 return ret;
79 }
80
81 /* wait6(2) */
82 static inline abi_long do_freebsd_wait6(void *cpu_env, abi_long idtype,
83 abi_long id1, abi_long id2,
84 abi_ulong target_status, abi_long options, abi_ulong target_wrusage,
85 abi_ulong target_infop, abi_ulong pad1)
86 {
87 abi_long ret;
88 int status;
89 struct __wrusage wrusage, *wrusage_ptr = NULL;
90 siginfo_t info;
91 void *p;
92
93 if (regpairs_aligned(cpu_env) != 0) {
94 /* printf("shifting args\n"); */
95 /* 64-bit id is aligned, so shift all the arguments over by one */
96 id1 = id2;
97 id2 = target_status;
98 target_status = options;
99 options = target_wrusage;
100 target_wrusage = target_infop;
101 target_infop = pad1;
102 }
103
104 if (target_wrusage) {
105 wrusage_ptr = &wrusage;
106 }
107 ret = get_errno(safe_wait6(idtype, target_arg64(id1, id2),
108 &status, options, wrusage_ptr, &info));
109
110 if (ret < 0) {
111 return ret;
112 }
113 if (target_status != 0) {
114 status = host_to_target_waitstatus(status);
115 if (put_user_s32(status, target_status) != 0) {
116 return -TARGET_EFAULT;
117 }
118 }
119 if (target_wrusage != 0) {
120 host_to_target_wrusage(target_wrusage, &wrusage);
121 }
122 if (target_infop != 0) {
123 p = lock_user(VERIFY_WRITE, target_infop, sizeof(target_siginfo_t), 0);
124 if (p == NULL) {
125 return -TARGET_EFAULT;
126 }
127 host_to_target_siginfo(p, &info);
128 unlock_user(p, target_infop, sizeof(target_siginfo_t));
129 }
130 return ret;
131 }
132
133 #endif /* BSD_USER_FREEBSD_OS_PROC_H */