xref: /openbmc/qemu/bsd-user/bsd-proc.h (revision 800af0aae1cfa456701c5fa1ef273ce47585179c)
19554d330SWarner Losh /*
29554d330SWarner Losh  *  process related system call shims and definitions
39554d330SWarner Losh  *
49554d330SWarner Losh  *  Copyright (c) 2013-2014 Stacey D. Son
59554d330SWarner Losh  *
69554d330SWarner Losh  *  This program is free software; you can redistribute it and/or modify
79554d330SWarner Losh  *  it under the terms of the GNU General Public License as published by
89554d330SWarner Losh  *  the Free Software Foundation; either version 2 of the License, or
99554d330SWarner Losh  *  (at your option) any later version.
109554d330SWarner Losh  *
119554d330SWarner Losh  *  This program is distributed in the hope that it will be useful,
129554d330SWarner Losh  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
139554d330SWarner Losh  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
149554d330SWarner Losh  *  GNU General Public License for more details.
159554d330SWarner Losh  *
169554d330SWarner Losh  *  You should have received a copy of the GNU General Public License
179554d330SWarner Losh  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
189554d330SWarner Losh  */
199554d330SWarner Losh 
209554d330SWarner Losh #ifndef BSD_PROC_H_
219554d330SWarner Losh #define BSD_PROC_H_
229554d330SWarner Losh 
239554d330SWarner Losh #include <sys/resource.h>
249554d330SWarner Losh 
250caa3768SStacey Son #include "qemu-bsd.h"
260caa3768SStacey Son #include "gdbstub/syscalls.h"
270caa3768SStacey Son #include "qemu/plugin.h"
280caa3768SStacey Son 
2982fe5f3aSStacey Son extern int _getlogin(char*, int);
30b623031cSKyle Evans int bsd_get_ncpu(void);
31b623031cSKyle Evans 
329554d330SWarner Losh /* exit(2) */
do_bsd_exit(void * cpu_env,abi_long arg1)339554d330SWarner Losh static inline abi_long do_bsd_exit(void *cpu_env, abi_long arg1)
349554d330SWarner Losh {
359554d330SWarner Losh     gdb_exit(arg1);
369554d330SWarner Losh     qemu_plugin_user_exit();
379554d330SWarner Losh     _exit(arg1);
389554d330SWarner Losh 
399554d330SWarner Losh     return 0;
409554d330SWarner Losh }
419554d330SWarner Losh 
42a478416dSStacey Son /* getgroups(2) */
do_bsd_getgroups(abi_long gidsetsize,abi_long arg2)43a478416dSStacey Son static inline abi_long do_bsd_getgroups(abi_long gidsetsize, abi_long arg2)
44a478416dSStacey Son {
45a478416dSStacey Son     abi_long ret;
46a478416dSStacey Son     uint32_t *target_grouplist;
47a478416dSStacey Son     g_autofree gid_t *grouplist;
48a478416dSStacey Son     int i;
49a478416dSStacey Son 
50a478416dSStacey Son     grouplist = g_try_new(gid_t, gidsetsize);
51a478416dSStacey Son     ret = get_errno(getgroups(gidsetsize, grouplist));
52a478416dSStacey Son     if (gidsetsize != 0) {
53a478416dSStacey Son         if (!is_error(ret)) {
54a478416dSStacey Son             target_grouplist = lock_user(VERIFY_WRITE, arg2, gidsetsize * 2, 0);
55a478416dSStacey Son             if (!target_grouplist) {
56a478416dSStacey Son                 return -TARGET_EFAULT;
57a478416dSStacey Son             }
58a478416dSStacey Son             for (i = 0; i < ret; i++) {
59a478416dSStacey Son                 target_grouplist[i] = tswap32(grouplist[i]);
60a478416dSStacey Son             }
61a478416dSStacey Son             unlock_user(target_grouplist, arg2, gidsetsize * 2);
62a478416dSStacey Son         }
63a478416dSStacey Son     }
64a478416dSStacey Son     return ret;
65a478416dSStacey Son }
66a478416dSStacey Son 
67a478416dSStacey Son /* setgroups(2) */
do_bsd_setgroups(abi_long gidsetsize,abi_long arg2)68a478416dSStacey Son static inline abi_long do_bsd_setgroups(abi_long gidsetsize, abi_long arg2)
69a478416dSStacey Son {
70a478416dSStacey Son     uint32_t *target_grouplist;
71a478416dSStacey Son     g_autofree gid_t *grouplist;
72a478416dSStacey Son     int i;
73a478416dSStacey Son 
74a478416dSStacey Son     grouplist = g_try_new(gid_t, gidsetsize);
75a478416dSStacey Son     target_grouplist = lock_user(VERIFY_READ, arg2, gidsetsize * 2, 1);
76a478416dSStacey Son     if (!target_grouplist) {
77a478416dSStacey Son         return -TARGET_EFAULT;
78a478416dSStacey Son     }
79a478416dSStacey Son     for (i = 0; i < gidsetsize; i++) {
80a478416dSStacey Son         grouplist[i] = tswap32(target_grouplist[i]);
81a478416dSStacey Son     }
82a478416dSStacey Son     unlock_user(target_grouplist, arg2, 0);
83a478416dSStacey Son     return get_errno(setgroups(gidsetsize, grouplist));
84a478416dSStacey Son }
85a478416dSStacey Son 
8682fe5f3aSStacey Son /* umask(2) */
do_bsd_umask(abi_long arg1)8782fe5f3aSStacey Son static inline abi_long do_bsd_umask(abi_long arg1)
8882fe5f3aSStacey Son {
8982fe5f3aSStacey Son     return get_errno(umask(arg1));
9082fe5f3aSStacey Son }
9182fe5f3aSStacey Son 
9282fe5f3aSStacey Son /* setlogin(2) */
do_bsd_setlogin(abi_long arg1)9382fe5f3aSStacey Son static inline abi_long do_bsd_setlogin(abi_long arg1)
9482fe5f3aSStacey Son {
9582fe5f3aSStacey Son     abi_long ret;
9682fe5f3aSStacey Son     void *p;
9782fe5f3aSStacey Son 
9882fe5f3aSStacey Son     p = lock_user_string(arg1);
9982fe5f3aSStacey Son     if (p == NULL) {
10082fe5f3aSStacey Son         return -TARGET_EFAULT;
10182fe5f3aSStacey Son     }
10282fe5f3aSStacey Son     ret = get_errno(setlogin(p));
10382fe5f3aSStacey Son     unlock_user(p, arg1, 0);
10482fe5f3aSStacey Son 
10582fe5f3aSStacey Son     return ret;
10682fe5f3aSStacey Son }
10782fe5f3aSStacey Son 
10882fe5f3aSStacey Son /* getlogin(2) */
do_bsd_getlogin(abi_long arg1,abi_long arg2)10982fe5f3aSStacey Son static inline abi_long do_bsd_getlogin(abi_long arg1, abi_long arg2)
11082fe5f3aSStacey Son {
11182fe5f3aSStacey Son     abi_long ret;
11282fe5f3aSStacey Son     void *p;
11382fe5f3aSStacey Son 
11482fe5f3aSStacey Son     p = lock_user(VERIFY_WRITE, arg1, arg2, 0);
11582fe5f3aSStacey Son     if (p == NULL) {
11682fe5f3aSStacey Son         return -TARGET_EFAULT;
11782fe5f3aSStacey Son     }
11882fe5f3aSStacey Son     ret = get_errno(_getlogin(p, arg2));
11982fe5f3aSStacey Son     unlock_user(p, arg1, arg2);
12082fe5f3aSStacey Son 
12182fe5f3aSStacey Son     return ret;
12282fe5f3aSStacey Son }
12382fe5f3aSStacey Son 
12459e801efSStacey Son /* getrusage(2) */
do_bsd_getrusage(abi_long who,abi_ulong target_addr)12559e801efSStacey Son static inline abi_long do_bsd_getrusage(abi_long who, abi_ulong target_addr)
12659e801efSStacey Son {
12759e801efSStacey Son     abi_long ret;
12859e801efSStacey Son     struct rusage rusage;
12959e801efSStacey Son 
13059e801efSStacey Son     ret = get_errno(getrusage(who, &rusage));
13159e801efSStacey Son     if (!is_error(ret)) {
13259e801efSStacey Son         host_to_target_rusage(target_addr, &rusage);
13359e801efSStacey Son     }
13459e801efSStacey Son     return ret;
13559e801efSStacey Son }
13659e801efSStacey Son 
137faba8e12SStacey Son /* getrlimit(2) */
do_bsd_getrlimit(abi_long arg1,abi_ulong arg2)138faba8e12SStacey Son static inline abi_long do_bsd_getrlimit(abi_long arg1, abi_ulong arg2)
139faba8e12SStacey Son {
140faba8e12SStacey Son     abi_long ret;
141faba8e12SStacey Son     int resource = target_to_host_resource(arg1);
142faba8e12SStacey Son     struct target_rlimit *target_rlim;
143faba8e12SStacey Son     struct rlimit rlim;
144faba8e12SStacey Son 
145faba8e12SStacey Son     switch (resource) {
146faba8e12SStacey Son     case RLIMIT_STACK:
147faba8e12SStacey Son         rlim.rlim_cur = target_dflssiz;
148faba8e12SStacey Son         rlim.rlim_max = target_maxssiz;
149faba8e12SStacey Son         ret = 0;
150faba8e12SStacey Son         break;
151faba8e12SStacey Son 
152faba8e12SStacey Son     case RLIMIT_DATA:
153faba8e12SStacey Son         rlim.rlim_cur = target_dfldsiz;
154faba8e12SStacey Son         rlim.rlim_max = target_maxdsiz;
155faba8e12SStacey Son         ret = 0;
156faba8e12SStacey Son         break;
157faba8e12SStacey Son 
158faba8e12SStacey Son     default:
159faba8e12SStacey Son         ret = get_errno(getrlimit(resource, &rlim));
160faba8e12SStacey Son         break;
161faba8e12SStacey Son     }
162faba8e12SStacey Son     if (!is_error(ret)) {
163faba8e12SStacey Son         if (!lock_user_struct(VERIFY_WRITE, target_rlim, arg2, 0)) {
164faba8e12SStacey Son             return -TARGET_EFAULT;
165faba8e12SStacey Son         }
166faba8e12SStacey Son         target_rlim->rlim_cur = host_to_target_rlim(rlim.rlim_cur);
167faba8e12SStacey Son         target_rlim->rlim_max = host_to_target_rlim(rlim.rlim_max);
168faba8e12SStacey Son         unlock_user_struct(target_rlim, arg2, 1);
169faba8e12SStacey Son     }
170faba8e12SStacey Son     return ret;
171faba8e12SStacey Son }
172faba8e12SStacey Son 
173faba8e12SStacey Son /* setrlimit(2) */
do_bsd_setrlimit(abi_long arg1,abi_ulong arg2)174faba8e12SStacey Son static inline abi_long do_bsd_setrlimit(abi_long arg1, abi_ulong arg2)
175faba8e12SStacey Son {
176faba8e12SStacey Son     abi_long ret;
177faba8e12SStacey Son     int resource = target_to_host_resource(arg1);
178faba8e12SStacey Son     struct target_rlimit *target_rlim;
179faba8e12SStacey Son     struct rlimit rlim;
180faba8e12SStacey Son 
181faba8e12SStacey Son     if (RLIMIT_STACK == resource) {
182faba8e12SStacey Son         /* XXX We should, maybe, allow the stack size to shrink */
183faba8e12SStacey Son         ret = -TARGET_EPERM;
184faba8e12SStacey Son     } else {
185faba8e12SStacey Son         if (!lock_user_struct(VERIFY_READ, target_rlim, arg2, 1)) {
186faba8e12SStacey Son             return -TARGET_EFAULT;
187faba8e12SStacey Son         }
188faba8e12SStacey Son         rlim.rlim_cur = target_to_host_rlim(target_rlim->rlim_cur);
189faba8e12SStacey Son         rlim.rlim_max = target_to_host_rlim(target_rlim->rlim_max);
190faba8e12SStacey Son         unlock_user_struct(target_rlim, arg2, 0);
191faba8e12SStacey Son         ret = get_errno(setrlimit(resource, &rlim));
192faba8e12SStacey Son     }
193faba8e12SStacey Son     return ret;
194faba8e12SStacey Son }
195faba8e12SStacey Son 
196e4446e0aSStacey Son /* getpid(2) */
do_bsd_getpid(void)197e4446e0aSStacey Son static inline abi_long do_bsd_getpid(void)
198e4446e0aSStacey Son {
199e4446e0aSStacey Son     return get_errno(getpid());
200e4446e0aSStacey Son }
201e4446e0aSStacey Son 
202e4446e0aSStacey Son /* getppid(2) */
do_bsd_getppid(void)203e4446e0aSStacey Son static inline abi_long do_bsd_getppid(void)
204e4446e0aSStacey Son {
205e4446e0aSStacey Son     return get_errno(getppid());
206e4446e0aSStacey Son }
207e4446e0aSStacey Son 
208e4446e0aSStacey Son /* getuid(2) */
do_bsd_getuid(void)209e4446e0aSStacey Son static inline abi_long do_bsd_getuid(void)
210e4446e0aSStacey Son {
211e4446e0aSStacey Son     return get_errno(getuid());
212e4446e0aSStacey Son }
213e4446e0aSStacey Son 
214e4446e0aSStacey Son /* geteuid(2) */
do_bsd_geteuid(void)215e4446e0aSStacey Son static inline abi_long do_bsd_geteuid(void)
216e4446e0aSStacey Son {
217e4446e0aSStacey Son     return get_errno(geteuid());
218e4446e0aSStacey Son }
219e4446e0aSStacey Son 
220e4446e0aSStacey Son /* getgid(2) */
do_bsd_getgid(void)221e4446e0aSStacey Son static inline abi_long do_bsd_getgid(void)
222e4446e0aSStacey Son {
223e4446e0aSStacey Son     return get_errno(getgid());
224e4446e0aSStacey Son }
225e4446e0aSStacey Son 
226e4446e0aSStacey Son /* getegid(2) */
do_bsd_getegid(void)227e4446e0aSStacey Son static inline abi_long do_bsd_getegid(void)
228e4446e0aSStacey Son {
229e4446e0aSStacey Son     return get_errno(getegid());
230e4446e0aSStacey Son }
231e4446e0aSStacey Son 
232e4446e0aSStacey Son /* setuid(2) */
do_bsd_setuid(abi_long arg1)233e4446e0aSStacey Son static inline abi_long do_bsd_setuid(abi_long arg1)
234e4446e0aSStacey Son {
235e4446e0aSStacey Son     return get_errno(setuid(arg1));
236e4446e0aSStacey Son }
237e4446e0aSStacey Son 
238e4446e0aSStacey Son /* seteuid(2) */
do_bsd_seteuid(abi_long arg1)239e4446e0aSStacey Son static inline abi_long do_bsd_seteuid(abi_long arg1)
240e4446e0aSStacey Son {
241e4446e0aSStacey Son     return get_errno(seteuid(arg1));
242e4446e0aSStacey Son }
243e4446e0aSStacey Son 
244e4446e0aSStacey Son /* setgid(2) */
do_bsd_setgid(abi_long arg1)245e4446e0aSStacey Son static inline abi_long do_bsd_setgid(abi_long arg1)
246e4446e0aSStacey Son {
247e4446e0aSStacey Son     return get_errno(setgid(arg1));
248e4446e0aSStacey Son }
249e4446e0aSStacey Son 
250e4446e0aSStacey Son /* setegid(2) */
do_bsd_setegid(abi_long arg1)251e4446e0aSStacey Son static inline abi_long do_bsd_setegid(abi_long arg1)
252e4446e0aSStacey Son {
253e4446e0aSStacey Son     return get_errno(setegid(arg1));
254e4446e0aSStacey Son }
255e4446e0aSStacey Son 
256e4446e0aSStacey Son /* getpgid(2) */
do_bsd_getpgid(pid_t pid)257e4446e0aSStacey Son static inline abi_long do_bsd_getpgid(pid_t pid)
258e4446e0aSStacey Son {
259e4446e0aSStacey Son     return get_errno(getpgid(pid));
260e4446e0aSStacey Son }
261e4446e0aSStacey Son 
262e4446e0aSStacey Son /* setpgid(2) */
do_bsd_setpgid(int pid,int pgrp)263e4446e0aSStacey Son static inline abi_long do_bsd_setpgid(int pid, int pgrp)
264e4446e0aSStacey Son {
265e4446e0aSStacey Son     return get_errno(setpgid(pid, pgrp));
266e4446e0aSStacey Son }
267e4446e0aSStacey Son 
268e4446e0aSStacey Son /* getpgrp(2) */
do_bsd_getpgrp(void)269e4446e0aSStacey Son static inline abi_long do_bsd_getpgrp(void)
270e4446e0aSStacey Son {
271e4446e0aSStacey Son     return get_errno(getpgrp());
272e4446e0aSStacey Son }
273e4446e0aSStacey Son 
274e4446e0aSStacey Son /* setreuid(2) */
do_bsd_setreuid(abi_long arg1,abi_long arg2)275e4446e0aSStacey Son static inline abi_long do_bsd_setreuid(abi_long arg1, abi_long arg2)
276e4446e0aSStacey Son {
277e4446e0aSStacey Son     return get_errno(setreuid(arg1, arg2));
278e4446e0aSStacey Son }
279e4446e0aSStacey Son 
280e4446e0aSStacey Son /* setregid(2) */
do_bsd_setregid(abi_long arg1,abi_long arg2)281e4446e0aSStacey Son static inline abi_long do_bsd_setregid(abi_long arg1, abi_long arg2)
282e4446e0aSStacey Son {
283e4446e0aSStacey Son     return get_errno(setregid(arg1, arg2));
284e4446e0aSStacey Son }
285e4446e0aSStacey Son 
286932683c3SStacey Son /* setresgid(2) */
do_bsd_setresgid(gid_t rgid,gid_t egid,gid_t sgid)287932683c3SStacey Son static inline abi_long do_bsd_setresgid(gid_t rgid, gid_t egid, gid_t sgid)
288932683c3SStacey Son {
289932683c3SStacey Son     return get_errno(setresgid(rgid, egid, sgid));
290932683c3SStacey Son }
291932683c3SStacey Son 
292932683c3SStacey Son /* setresuid(2) */
do_bsd_setresuid(uid_t ruid,uid_t euid,uid_t suid)293932683c3SStacey Son static inline abi_long do_bsd_setresuid(uid_t ruid, uid_t euid, uid_t suid)
294932683c3SStacey Son {
295932683c3SStacey Son     return get_errno(setresuid(ruid, euid, suid));
296932683c3SStacey Son }
297932683c3SStacey Son 
298932683c3SStacey Son /* getresuid(2) */
do_bsd_getresuid(abi_ulong arg1,abi_ulong arg2,abi_ulong arg3)299932683c3SStacey Son static inline abi_long do_bsd_getresuid(abi_ulong arg1, abi_ulong arg2,
300932683c3SStacey Son         abi_ulong arg3)
301932683c3SStacey Son {
302932683c3SStacey Son     abi_long ret;
303932683c3SStacey Son     uid_t ruid, euid, suid;
304932683c3SStacey Son 
305932683c3SStacey Son     ret = get_errno(getresuid(&ruid, &euid, &suid));
306932683c3SStacey Son     if (is_error(ret)) {
307932683c3SStacey Son             return ret;
308932683c3SStacey Son     }
309932683c3SStacey Son     if (put_user_s32(ruid, arg1)) {
310932683c3SStacey Son         return -TARGET_EFAULT;
311932683c3SStacey Son     }
312932683c3SStacey Son     if (put_user_s32(euid, arg2)) {
313932683c3SStacey Son         return -TARGET_EFAULT;
314932683c3SStacey Son     }
315932683c3SStacey Son     if (put_user_s32(suid, arg3)) {
316932683c3SStacey Son         return -TARGET_EFAULT;
317932683c3SStacey Son     }
318932683c3SStacey Son     return ret;
319932683c3SStacey Son }
320932683c3SStacey Son 
321932683c3SStacey Son /* getresgid(2) */
do_bsd_getresgid(abi_ulong arg1,abi_ulong arg2,abi_ulong arg3)322932683c3SStacey Son static inline abi_long do_bsd_getresgid(abi_ulong arg1, abi_ulong arg2,
323932683c3SStacey Son                                         abi_ulong arg3)
324932683c3SStacey Son {
325932683c3SStacey Son     abi_long ret;
326932683c3SStacey Son     uid_t ruid, euid, suid;
327932683c3SStacey Son 
328932683c3SStacey Son     ret = get_errno(getresgid(&ruid, &euid, &suid));
329932683c3SStacey Son     if (is_error(ret)) {
330932683c3SStacey Son             return ret;
331932683c3SStacey Son     }
332932683c3SStacey Son     if (put_user_s32(ruid, arg1)) {
333932683c3SStacey Son         return -TARGET_EFAULT;
334932683c3SStacey Son     }
335932683c3SStacey Son     if (put_user_s32(euid, arg2)) {
336932683c3SStacey Son         return -TARGET_EFAULT;
337932683c3SStacey Son     }
338932683c3SStacey Son     if (put_user_s32(suid, arg3)) {
339932683c3SStacey Son         return -TARGET_EFAULT;
340932683c3SStacey Son     }
341932683c3SStacey Son     return ret;
342932683c3SStacey Son }
343932683c3SStacey Son 
344932683c3SStacey Son /* getsid(2) */
do_bsd_getsid(abi_long arg1)345932683c3SStacey Son static inline abi_long do_bsd_getsid(abi_long arg1)
346932683c3SStacey Son {
347932683c3SStacey Son     return get_errno(getsid(arg1));
348932683c3SStacey Son }
349932683c3SStacey Son 
350932683c3SStacey Son /* setsid(2) */
do_bsd_setsid(void)351932683c3SStacey Son static inline abi_long do_bsd_setsid(void)
352932683c3SStacey Son {
353932683c3SStacey Son     return get_errno(setsid());
354932683c3SStacey Son }
355932683c3SStacey Son 
356932683c3SStacey Son /* issetugid(2) */
do_bsd_issetugid(void)357932683c3SStacey Son static inline abi_long do_bsd_issetugid(void)
358932683c3SStacey Son {
359932683c3SStacey Son     return get_errno(issetugid());
360932683c3SStacey Son }
361932683c3SStacey Son 
362615ad41cSStacey Son /* profil(2) */
do_bsd_profil(abi_long arg1,abi_long arg2,abi_long arg3,abi_long arg4)363615ad41cSStacey Son static inline abi_long do_bsd_profil(abi_long arg1, abi_long arg2,
364615ad41cSStacey Son                                      abi_long arg3, abi_long arg4)
365615ad41cSStacey Son {
366615ad41cSStacey Son     return -TARGET_ENOSYS;
367615ad41cSStacey Son }
368615ad41cSStacey Son 
369615ad41cSStacey Son /* ktrace(2) */
do_bsd_ktrace(abi_long arg1,abi_long arg2,abi_long arg3,abi_long arg4)370615ad41cSStacey Son static inline abi_long do_bsd_ktrace(abi_long arg1, abi_long arg2,
371615ad41cSStacey Son                                      abi_long arg3, abi_long arg4)
372615ad41cSStacey Son {
373615ad41cSStacey Son     return -TARGET_ENOSYS;
374615ad41cSStacey Son }
375615ad41cSStacey Son 
376615ad41cSStacey Son /* utrace(2) */
do_bsd_utrace(abi_long arg1,abi_long arg2)377615ad41cSStacey Son static inline abi_long do_bsd_utrace(abi_long arg1, abi_long arg2)
378615ad41cSStacey Son {
379615ad41cSStacey Son     return -TARGET_ENOSYS;
380615ad41cSStacey Son }
381615ad41cSStacey Son 
382615ad41cSStacey Son 
383615ad41cSStacey Son /* ptrace(2) */
do_bsd_ptrace(abi_long arg1,abi_long arg2,abi_long arg3,abi_long arg4)384615ad41cSStacey Son static inline abi_long do_bsd_ptrace(abi_long arg1, abi_long arg2,
385615ad41cSStacey Son         abi_long arg3, abi_long arg4)
386615ad41cSStacey Son {
387615ad41cSStacey Son     return -TARGET_ENOSYS;
388615ad41cSStacey Son }
389615ad41cSStacey Son 
390*ff266372SStacey Son /* getpriority(2) */
do_bsd_getpriority(abi_long which,abi_long who)391*ff266372SStacey Son static inline abi_long do_bsd_getpriority(abi_long which, abi_long who)
392*ff266372SStacey Son {
393*ff266372SStacey Son     abi_long ret;
394*ff266372SStacey Son     /*
395*ff266372SStacey Son      * Note that negative values are valid for getpriority, so we must
396*ff266372SStacey Son      * differentiate based on errno settings.
397*ff266372SStacey Son      */
398*ff266372SStacey Son     errno = 0;
399*ff266372SStacey Son     ret = getpriority(which, who);
400*ff266372SStacey Son     if (ret == -1 && errno != 0) {
401*ff266372SStacey Son         return -host_to_target_errno(errno);
402*ff266372SStacey Son     }
403*ff266372SStacey Son 
404*ff266372SStacey Son     return ret;
405*ff266372SStacey Son }
406*ff266372SStacey Son 
407*ff266372SStacey Son /* setpriority(2) */
do_bsd_setpriority(abi_long which,abi_long who,abi_long prio)408*ff266372SStacey Son static inline abi_long do_bsd_setpriority(abi_long which, abi_long who,
409*ff266372SStacey Son                                           abi_long prio)
410*ff266372SStacey Son {
411*ff266372SStacey Son     return get_errno(setpriority(which, who, prio));
412*ff266372SStacey Son }
413*ff266372SStacey Son 
4149554d330SWarner Losh #endif /* !BSD_PROC_H_ */
415