1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
|
diff --git a/bsd-user/arm/target_vmparam.h b/bsd-user/arm/target_vmparam.h
index 0427244..24dca00 100644
--- a/bsd-user/arm/target_vmparam.h
+++ b/bsd-user/arm/target_vmparam.h
@@ -20,6 +20,10 @@ struct target_ps_strings {
#define TARGET_SZSIGCODE 0
+/* Make stack size large enough to hold everything. */
+#define TARGET_STACK_SIZE ((x86_stack_size < MAX_ARG_PAGES*TARGET_PAGE_SIZE) ? \
+ MAX_ARG_PAGES*TARGET_PAGE_SIZE : x86_stack_size)
+
#else
#define TARGET_USRSTACK 0
diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c
index 0c48f5a..f5f652f 100644
--- a/bsd-user/elfload.c
+++ b/bsd-user/elfload.c
@@ -715,9 +715,13 @@ static abi_ulong setup_arg_pages(abi_ulong p, struct bsd_binprm *bprm,
/* Create enough stack to hold everything. If we don't use
* it for args, we'll use it for something else...
*/
+#ifdef TARGET_STACK_SIZE
+ size = TARGET_STACK_SIZE;
+#else
size = x86_stack_size;
if (size < MAX_ARG_PAGES*TARGET_PAGE_SIZE)
size = MAX_ARG_PAGES*TARGET_PAGE_SIZE;
+#endif
#ifdef TARGET_USRSTACK
stack_base = TARGET_USRSTACK - size;
@@ -738,7 +742,7 @@ static abi_ulong setup_arg_pages(abi_ulong p, struct bsd_binprm *bprm,
#if defined(__FreeBSD__)
/*
- * The inital FreeBSD stack looks like follows:
+ * The inital FreeBSD stack is as follows:
* (see kern/kern_exec.c exec_copyout_strings() )
*
* Hi Address -> char **ps_argvstr (struct ps_strings for ps, w, etc.)
diff --git a/bsd-user/freebsd/strace.list b/bsd-user/freebsd/strace.list
index bcdd931..c66dcfa 100644
--- a/bsd-user/freebsd/strace.list
+++ b/bsd-user/freebsd/strace.list
@@ -118,6 +118,7 @@
{ TARGET_FREEBSD_NR_revoke, "revoke", NULL, NULL, NULL },
{ TARGET_FREEBSD_NR_rfork, "rfork", NULL, NULL, NULL },
{ TARGET_FREEBSD_NR_rmdir, "rmdir", NULL, NULL, NULL },
+{ TARGET_FREEBSD_NR_rtprio_thread, "rtprio_thread", "%s(%d, %d, %p)", NULL, NULL },
{ TARGET_FREEBSD_NR_sbrk, "sbrk", NULL, NULL, NULL },
{ TARGET_FREEBSD_NR_sched_yield, "sched_yield", NULL, NULL, NULL },
{ TARGET_FREEBSD_NR_select, "select", NULL, NULL, NULL },
diff --git a/bsd-user/i386/target_vmparam.h b/bsd-user/i386/target_vmparam.h
index 8fc98d5..ea7546c 100644
--- a/bsd-user/i386/target_vmparam.h
+++ b/bsd-user/i386/target_vmparam.h
@@ -19,6 +19,10 @@ struct target_ps_strings {
#define TARGET_SZSIGCODE 0
+/* Make stack size large enough to hold everything. */
+#define TARGET_STACK_SIZE ((x86_stack_size < MAX_ARG_PAGES*TARGET_PAGE_SIZE) ? \
+ MAX_ARG_PAGES*TARGET_PAGE_SIZE : x86_stack_size)
+
#else
#define TARGET_USRSTACK 0
diff --git a/bsd-user/main.c b/bsd-user/main.c
index 7cc77aa..32bd3e5 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -855,7 +855,9 @@ void cpu_loop(CPUARMState *env)
goto do_segv;
}
break;
+#if 0
error:
+#endif
default:
fprintf(stderr, "qemu: unhandled CPU exception 0x%x - aborting\n",
trapnr);
diff --git a/bsd-user/mips/target_vmparam.h b/bsd-user/mips/target_vmparam.h
index 9fca7f3..8abc26c 100644
--- a/bsd-user/mips/target_vmparam.h
+++ b/bsd-user/mips/target_vmparam.h
@@ -21,6 +21,10 @@ struct target_ps_strings {
#define TARGET_SZSIGCODE 0
+/* Make stack size large enough to hold everything. */
+#define TARGET_STACK_SIZE ((x86_stack_size < MAX_ARG_PAGES*TARGET_PAGE_SIZE) ? \
+ MAX_ARG_PAGES*TARGET_PAGE_SIZE : x86_stack_size)
+
#else
#define TARGET_USRSTACK 0
diff --git a/bsd-user/mips64/target_vmparam.h b/bsd-user/mips64/target_vmparam.h
index 47c2267..55ed254 100644
--- a/bsd-user/mips64/target_vmparam.h
+++ b/bsd-user/mips64/target_vmparam.h
@@ -20,6 +20,10 @@ struct target_ps_strings {
#define TARGET_PS_STRINGS (TARGET_USRSTACK - sizeof(struct target_ps_strings))
+/* Make stack size large enough to hold everything. */
+#define TARGET_STACK_SIZE ((x86_stack_size < MAX_ARG_PAGES*TARGET_PAGE_SIZE) ? \
+ MAX_ARG_PAGES*TARGET_PAGE_SIZE : x86_stack_size)
+
#else
#define TARGET_USRSTACK 0
diff --git a/bsd-user/sparc/target_vmparam.h b/bsd-user/sparc/target_vmparam.h
index 9494c46..82c29ed 100644
--- a/bsd-user/sparc/target_vmparam.h
+++ b/bsd-user/sparc/target_vmparam.h
@@ -1,8 +1,6 @@
#ifndef _TARGET_VMPARAM_H_
#define _TARGET_VMPARAM_H_
-#define TARGET_USRSTACK 0
-
#ifdef __FreeBSD__
struct target_ps_strings {
abi_ulong ps_argvstr;
@@ -14,9 +12,22 @@ struct target_ps_strings {
#define TARGET_SPACE_USRSPACE 4096
#define TARGET_ARG_MAX 262144
+/* XXX */
+#define TARGET_VM_MAXUSER_ADDRESS (0xc0000000 - (512 * 1024 * 1024))
+#define TARGET_USRSTACK TARGET_VM_MAXUSER_ADDRESS
+
#define TARGET_PS_STRINGS (TARGET_USRSTACK - sizeof(struct target_ps_strings))
#define TARGET_SZSIGCODE 0
+
+/* Make stack size large enough to hold everything. */
+#define TARGET_STACK_SIZE ((x86_stack_size < MAX_ARG_PAGES*TARGET_PAGE_SIZE) ? \
+ MAX_ARG_PAGES*TARGET_PAGE_SIZE : x86_stack_size)
+
+#else
+
+#define TARGET_USRSTACK 0
+
#endif /* __FreeBSD__ */
#endif /* _TARGET_VMPARAM_H_ */
diff --git a/bsd-user/sparc64/target_vmparam.h b/bsd-user/sparc64/target_vmparam.h
index 12af063..7f2b464 100644
--- a/bsd-user/sparc64/target_vmparam.h
+++ b/bsd-user/sparc64/target_vmparam.h
@@ -21,6 +21,10 @@ struct target_ps_strings {
#define TARGET_SZSIGCODE 0
+/* Make stack size large enough to hold everything. */
+#define TARGET_STACK_SIZE ((x86_stack_size < MAX_ARG_PAGES*TARGET_PAGE_SIZE) ? \
+ MAX_ARG_PAGES*TARGET_PAGE_SIZE : x86_stack_size)
+
#else
#define TARGET_USRSTACK 0
diff --git a/bsd-user/syscall.c b/bsd-user/syscall.c
index a40d7ce..8565ae8 100644
--- a/bsd-user/syscall.c
+++ b/bsd-user/syscall.c
@@ -409,19 +409,44 @@ static abi_long do_freebsd_sysctl(abi_ulong namep, int32_t namelen, abi_ulong ol
for (p = hnamep, q = snamep, i = 0; i < namelen; p++, i++)
*q++ = tswap32(*p);
oidfmt(snamep, namelen, NULL, &kind);
- /* XXX swap hnewp */
-#if HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 32
- /* XXX there may be more sysctls that differ */
- if (namelen == 2 &&
- snamep[0] == CTL_KERN && snamep[1] == KERN_USRSTACK &&
- holdlen && holdlen == 4 && hnewp == NULL) {
- (*(uint32_t *)holdp) = 0xfffff000U;
- ret = 0;
- } else
+
+ /* Handle some arch/emulator dependent sysctl()'s here. */
+ if (CTL_KERN == snamep[0]) {
+ switch(snamep[1]) {
+ case KERN_USRSTACK:
+#if defined(TARGET_ARM) && HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 32
+ (*(uint32_t *)holdp) = 0xfffff000U;
+ holdlen = sizeof(uint32_t);
+ ret = 0;
+#elif TARGET_USRSTACK != 0
+ (*(abi_ulong *)holdp) = tswapal(TARGET_USRSTACK);
+ holdlen = sizeof(abi_ulong);
+ ret = 0;
+#else
+ ret = -TARGET_ENOENT;
+#endif
+ goto out;
+
+ case KERN_PS_STRINGS:
+#if defined(TARGET_PS_STRINGS)
+ (*(abi_ulong *)holdp) = tswapal(TARGET_PS_STRINGS);
+ holdlen = sizeof(abi_ulong);
+ ret = 0;
+#else
+ ret = -TARGET_ENOENT;
#endif
+ goto out;
+
+ default:
+ break;
+ }
+ }
+
ret = get_errno(sysctl(snamep, namelen, holdp, &holdlen, hnewp, newlen));
if (!ret)
sysctl_oldcvt(holdp, holdlen, kind);
+
+out:
put_user_ual(holdlen, oldlenp);
unlock_user(hnamep, namep, 0);
unlock_user(holdp, oldp, holdlen);
@@ -3293,6 +3318,47 @@ host_to_target_fhandle(abi_ulong target_addr, fhandle_t *host_fh)
}
static inline abi_long
+target_to_host_rtprio(struct rtprio *host_rtp, abi_ulong target_addr)
+{
+ struct target_rtprio *target_rtp;
+
+ if (!lock_user_struct(VERIFY_READ, target_rtp, target_addr, 1))
+ return (-TARGET_EFAULT);
+ __get_user(host_rtp->type, &target_rtp->type);
+ __get_user(host_rtp->prio, &target_rtp->prio);
+ unlock_user_struct(target_rtp, target_addr, 0);
+ return (0);
+}
+
+static inline abi_long
+host_to_target_rtprio(abi_ulong target_addr, struct rtprio *host_rtp)
+{
+ struct target_rtprio *target_rtp;
+
+ if (!lock_user_struct(VERIFY_WRITE, target_rtp, target_addr, 0))
+ return (-TARGET_EFAULT);
+ __put_user(host_rtp->type, &target_rtp->type);
+ __put_user(host_rtp->prio, &target_rtp->prio);
+ unlock_user_struct(target_rtp, target_addr, 1);
+ return (0);
+}
+
+static inline abi_long
+do_rtprio_thread(int function, lwpid_t lwpid, abi_ulong target_addr)
+{
+ int ret;
+ struct rtprio rtp;
+
+ ret = target_to_host_rtprio(&rtp, target_addr);
+ if (0 == ret)
+ ret = get_errno(rtprio_thread(function, lwpid, &rtp));
+ if (0 == ret)
+ ret = host_to_target_rtprio(target_addr, &rtp);
+
+ return (ret);
+}
+
+static inline abi_long
target_to_host_sched_param(struct sched_param *host_sp, abi_ulong target_addr)
{
struct target_sched_param *target_sp;
@@ -4617,12 +4683,17 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,
struct target_rlimit *target_rlim;
struct rlimit rlim;
- if (!lock_user_struct(VERIFY_READ, target_rlim, arg2, 1))
- goto efault;
- rlim.rlim_cur = target_to_host_rlim(target_rlim->rlim_cur);
- rlim.rlim_max = target_to_host_rlim(target_rlim->rlim_max);
- unlock_user_struct(target_rlim, arg2, 0);
- ret = get_errno(setrlimit(resource, &rlim));
+ if (RLIMIT_STACK == resource) {
+ /* XXX We should, maybe, allow the stack size to shrink */
+ ret = -TARGET_EPERM;
+ } else {
+ if (!lock_user_struct(VERIFY_READ, target_rlim, arg2, 1))
+ goto efault;
+ rlim.rlim_cur = target_to_host_rlim(target_rlim->rlim_cur);
+ rlim.rlim_max = target_to_host_rlim(target_rlim->rlim_max);
+ unlock_user_struct(target_rlim, arg2, 0);
+ ret = get_errno(setrlimit(resource, &rlim));
+ }
}
break;
@@ -4633,7 +4704,12 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,
struct target_rlimit *target_rlim;
struct rlimit rlim;
- ret = get_errno(getrlimit(resource, &rlim));
+ /* Return the target stack size */
+ if (RLIMIT_STACK == resource) {
+ rlim.rlim_cur = rlim.rlim_max = TARGET_STACK_SIZE;
+ ret = 0;
+ } else
+ ret = get_errno(getrlimit(resource, &rlim));
if (!is_error(ret)) {
if (!lock_user_struct(VERIFY_WRITE, target_rlim, arg2,
0))
@@ -6148,7 +6224,7 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,
break;
case TARGET_FREEBSD_NR_rtprio_thread:
- ret = 0;
+ ret = do_rtprio_thread(arg1, arg2, arg3);
break;
case TARGET_FREEBSD_NR_getcontext:
diff --git a/bsd-user/x86_64/target_vmparam.h b/bsd-user/x86_64/target_vmparam.h
index aa5e0e0..ff9f534 100644
--- a/bsd-user/x86_64/target_vmparam.h
+++ b/bsd-user/x86_64/target_vmparam.h
@@ -20,6 +20,10 @@ struct target_ps_strings {
#define TARGET_SZSIGCODE 0
+/* Make stack size large enough to hold everything. */
+#define TARGET_STACK_SIZE ((x86_stack_size < MAX_ARG_PAGES*TARGET_PAGE_SIZE) ? \
+ MAX_ARG_PAGES*TARGET_PAGE_SIZE : x86_stack_size)
+
#else
#define TARGET_USRSTACK 0
|