]>
Commit | Line | Data |
---|---|---|
9554d330 WL |
1 | /* |
2 | * process related system call shims and definitions | |
3 | * | |
4 | * Copyright (c) 2013-2014 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_PROC_H_ | |
21 | #define BSD_PROC_H_ | |
22 | ||
9554d330 | 23 | #include <sys/resource.h> |
9554d330 | 24 | |
0caa3768 SS |
25 | #include "qemu-bsd.h" |
26 | #include "gdbstub/syscalls.h" | |
27 | #include "qemu/plugin.h" | |
28 | ||
82fe5f3a | 29 | extern int _getlogin(char*, int); |
b623031c KE |
30 | int bsd_get_ncpu(void); |
31 | ||
9554d330 WL |
32 | /* exit(2) */ |
33 | static inline abi_long do_bsd_exit(void *cpu_env, abi_long arg1) | |
34 | { | |
35 | #ifdef TARGET_GPROF | |
36 | _mcleanup(); | |
37 | #endif | |
38 | gdb_exit(arg1); | |
39 | qemu_plugin_user_exit(); | |
40 | _exit(arg1); | |
41 | ||
42 | return 0; | |
43 | } | |
44 | ||
a478416d SS |
45 | /* getgroups(2) */ |
46 | static inline abi_long do_bsd_getgroups(abi_long gidsetsize, abi_long arg2) | |
47 | { | |
48 | abi_long ret; | |
49 | uint32_t *target_grouplist; | |
50 | g_autofree gid_t *grouplist; | |
51 | int i; | |
52 | ||
53 | grouplist = g_try_new(gid_t, gidsetsize); | |
54 | ret = get_errno(getgroups(gidsetsize, grouplist)); | |
55 | if (gidsetsize != 0) { | |
56 | if (!is_error(ret)) { | |
57 | target_grouplist = lock_user(VERIFY_WRITE, arg2, gidsetsize * 2, 0); | |
58 | if (!target_grouplist) { | |
59 | return -TARGET_EFAULT; | |
60 | } | |
61 | for (i = 0; i < ret; i++) { | |
62 | target_grouplist[i] = tswap32(grouplist[i]); | |
63 | } | |
64 | unlock_user(target_grouplist, arg2, gidsetsize * 2); | |
65 | } | |
66 | } | |
67 | return ret; | |
68 | } | |
69 | ||
70 | /* setgroups(2) */ | |
71 | static inline abi_long do_bsd_setgroups(abi_long gidsetsize, abi_long arg2) | |
72 | { | |
73 | uint32_t *target_grouplist; | |
74 | g_autofree gid_t *grouplist; | |
75 | int i; | |
76 | ||
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; | |
81 | } | |
82 | for (i = 0; i < gidsetsize; i++) { | |
83 | grouplist[i] = tswap32(target_grouplist[i]); | |
84 | } | |
85 | unlock_user(target_grouplist, arg2, 0); | |
86 | return get_errno(setgroups(gidsetsize, grouplist)); | |
87 | } | |
88 | ||
82fe5f3a SS |
89 | /* umask(2) */ |
90 | static inline abi_long do_bsd_umask(abi_long arg1) | |
91 | { | |
92 | return get_errno(umask(arg1)); | |
93 | } | |
94 | ||
95 | /* setlogin(2) */ | |
96 | static inline abi_long do_bsd_setlogin(abi_long arg1) | |
97 | { | |
98 | abi_long ret; | |
99 | void *p; | |
100 | ||
101 | p = lock_user_string(arg1); | |
102 | if (p == NULL) { | |
103 | return -TARGET_EFAULT; | |
104 | } | |
105 | ret = get_errno(setlogin(p)); | |
106 | unlock_user(p, arg1, 0); | |
107 | ||
108 | return ret; | |
109 | } | |
110 | ||
111 | /* getlogin(2) */ | |
112 | static inline abi_long do_bsd_getlogin(abi_long arg1, abi_long arg2) | |
113 | { | |
114 | abi_long ret; | |
115 | void *p; | |
116 | ||
117 | p = lock_user(VERIFY_WRITE, arg1, arg2, 0); | |
118 | if (p == NULL) { | |
119 | return -TARGET_EFAULT; | |
120 | } | |
121 | ret = get_errno(_getlogin(p, arg2)); | |
122 | unlock_user(p, arg1, arg2); | |
123 | ||
124 | return ret; | |
125 | } | |
126 | ||
59e801ef SS |
127 | /* getrusage(2) */ |
128 | static inline abi_long do_bsd_getrusage(abi_long who, abi_ulong target_addr) | |
129 | { | |
130 | abi_long ret; | |
131 | struct rusage rusage; | |
132 | ||
133 | ret = get_errno(getrusage(who, &rusage)); | |
134 | if (!is_error(ret)) { | |
135 | host_to_target_rusage(target_addr, &rusage); | |
136 | } | |
137 | return ret; | |
138 | } | |
139 | ||
9554d330 | 140 | #endif /* !BSD_PROC_H_ */ |