Skip to content

Commit 49833bd

Browse files
committed
in progress commit (in syscall at do_fork)
1 parent b999760 commit 49833bd

18 files changed

+2738
-5976
lines changed

Makefile.target

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,9 @@ endif #CONFIG_BSD_USER
134134

135135
ifdef CONFIG_DARWIN_USER
136136

137-
QEMU_CFLAGS+=-I$(SRC_PATH)/darwin-user -I$(SRC_PATH)/darwin-user/$(TARGET_ABI_DIR) \
138-
-I$(SRC_PATH)/darwin-user/$(HOST_VARIANT_DIR)
137+
QEMU_CFLAGS+=-I$(SRC_PATH)/darwin-user/$(TARGET_ABI_DIR) \
138+
-I$(SRC_PATH)/darwin-user/host/$(ARCH) \
139+
-I$(SRC_PATH)/darwin-user
139140

140141
obj-y += darwin-user/
141142
obj-y += gdbstub.o

accel/tcg/translate-all.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,8 @@ static void page_init(void)
430430
#else
431431
FILE *f;
432432

433-
last_brk = (unsigned long)sbrk(0);
433+
// depreciated in osx, but value is not used?
434+
//last_brk = (unsigned long)sbrk(0);
434435

435436
f = fopen("/compat/linux/proc/self/maps", "r");
436437
if (f) {

accel/tcg/user-exec.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,11 @@ int cpu_signal_handler(int host_signum, void *pinfo,
244244
#define TRAP_sig(context) ((context)->sc_trapno)
245245
#define ERROR_sig(context) ((context)->sc_err)
246246
#define MASK_sig(context) ((context)->sc_mask)
247+
#elif defined(__APPLE__)
248+
#define PC_sig(context) ((context)->uc_mcontext->__ss.__rip)
249+
#define TRAP_sig(context) ((context)->uc_mcontext->__es.__trapno)
250+
#define ERROR_sig(context) ((context)->uc_mcontext->__es.__err)
251+
#define MASK_sig(context) ((context)->uc_sigmask)
247252
#elif defined(__FreeBSD__) || defined(__DragonFly__)
248253
#include <ucontext.h>
249254

darwin-user/errno_defs.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#define TARGET_ENOENT 2 /* No such file or directory */
1010
#define TARGET_ESRCH 3 /* No such process */
1111
#define TARGET_EINTR 4 /* Interrupted function call */
12-
#define TARGET_EIO 5 /* I/O error */
12+
#define TARGET_EIO 5 /* I/O error */
1313
#define TARGET_ENXIO 6 /* No such device or address */
1414
#define TARGET_E2BIG 7 /* Arg list too long */
1515
#define TARGET_ENOEXEC 8 /* Exec format error */
@@ -37,7 +37,7 @@
3737
#define TARGET_EROFS 30 /* Read only file system */
3838
#define TARGET_EMLINK 31 /* Too many links */
3939
#define TARGET_EPIPE 32 /* Broken pipe */
40-
#define TARGET_EDOM 33 /* Domain error */
40+
#define TARGET_EDOM 33 /* Domain error */
4141
#define TARGET_ERANGE 34 /* Result too large */
4242
#define TARGET_ENOMSG 35 /* No message of desired type */
4343
#define TARGET_EIDRM 36 /* Identifier removed */
@@ -46,7 +46,7 @@
4646
#define TARGET_EL3HLT 39 /* Level 3 halted */
4747
#define TARGET_EL3RST 40 /* Level 3 reset */
4848
#define TARGET_ELNRNG 41 /* Link number out of range */
49-
#define TARGET_EUNATCH 42 /* Protocol driver not attached */
49+
#define TARGET_EUNATCH 42 /* Protocol driver not attached */
5050
#define TARGET_ENOCSI 43 /* No CSI structure available */
5151
#define TARGET_EL2HLT 44 /* Level 2 halted */
5252
#define TARGET_EDEADLK 45 /* Resource deadlock avoided */
@@ -74,7 +74,7 @@
7474
#define TARGET_ENOPKG 65 /* Package not installed */
7575
#define TARGET_EREMOTE 66 /* The object is remote */
7676
#define TARGET_ENOLINK 67 /* the link has been severed */
77-
#define TARGET_EADV 68 /* advertise error */
77+
#define TARGET_EADV 68 /* advertise error */
7878
#define TARGET_ESRMNT 69 /* srmount error */
7979

8080
#define TARGET_ECOMM 70 /* Communication error on send */
@@ -155,7 +155,7 @@
155155
#define TARGET_EREMDEV 142 /* Error 142 */
156156
#define TARGET_ECANCELED 158 /* AIO operation canceled */
157157

158-
#else
158+
#else /* !(defined TARGET_ABI_IRIX || defined TARGET_ABI_SOLARIS) */
159159
#define TARGET_EPERM 1 /* Operation not permitted */
160160
#define TARGET_ENOENT 2 /* No such file or directory */
161161
#define TARGET_ESRCH 3 /* No such process */
@@ -294,7 +294,7 @@
294294

295295
#define TARGET_ERFKILL 132 /* Operation not possible due to RF-kill */
296296
#define TARGET_EHWPOISON 133 /* Memory page has hardware error */
297-
#endif
297+
#endif /* defined TARGET_ABI_IRIX || defined TARGET_ABI_SOLARIS */
298298

299299
/* QEMU internal, not visible to the guest. This is returned when a
300300
* system call should be restarted, to tell the main loop that it

darwin-user/host/x86_64/hostdep.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* hostdep.h : things which are dependent on the host architecture
3+
*
4+
* * Written by Peter Maydell <[email protected]>
5+
*
6+
* Copyright (C) 2016 Linaro Limited
7+
*
8+
* This work is licensed under the terms of the GNU GPL, version 2 or later.
9+
* See the COPYING file in the top-level directory.
10+
*/
11+
12+
#ifndef X86_64_HOSTDEP_H
13+
#define X86_64_HOSTDEP_H
14+
15+
/* Turn off safe-syscall for now ... */
16+
17+
// /* We have a safe-syscall.inc.S */
18+
// #define HAVE_SAFE_SYSCALL
19+
//
20+
// #ifndef __ASSEMBLER__
21+
//
22+
// /* These are defined by the safe-syscall.inc.S file */
23+
// extern char safe_syscall_start[];
24+
// extern char safe_syscall_end[];
25+
//
26+
// /* Adjust the signal context to rewind out of safe-syscall if we're in it */
27+
// static inline void rewind_if_in_safe_syscall(void *puc)
28+
// {
29+
// ucontext_t *uc = puc;
30+
// greg_t *pcreg = &uc->uc_mcontext.gregs[REG_RIP];
31+
//
32+
// if (*pcreg > (uintptr_t)safe_syscall_start
33+
// && *pcreg < (uintptr_t)safe_syscall_end) {
34+
// *pcreg = (uintptr_t)safe_syscall_start;
35+
// }
36+
// }
37+
//
38+
// #endif /* __ASSEMBLER__ */
39+
40+
#endif
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* safe-syscall.inc.S : host-specific assembly fragment
3+
* to handle signals occurring at the same time as system calls.
4+
* This is intended to be included by linux-user/safe-syscall.S
5+
*
6+
* Copyright (C) 2015 Timothy Edward Baldwin <[email protected]>
7+
*
8+
* This work is licensed under the terms of the GNU GPL, version 2 or later.
9+
* See the COPYING file in the top-level directory.
10+
*/
11+
12+
.global safe_syscall_base
13+
.global safe_syscall_start
14+
.global safe_syscall_end
15+
.type safe_syscall_base, @function
16+
17+
/* This is the entry point for making a system call. The calling
18+
* convention here is that of a C varargs function with the
19+
* first argument an 'int *' to the signal_pending flag, the
20+
* second one the system call number (as a 'long'), and all further
21+
* arguments being syscall arguments (also 'long').
22+
* We return a long which is the syscall's return value, which
23+
* may be negative-errno on failure. Conversion to the
24+
* -1-and-errno-set convention is done by the calling wrapper.
25+
*/
26+
safe_syscall_base:
27+
.cfi_startproc
28+
/* This saves a frame pointer and aligns the stack for the syscall.
29+
* (It's unclear if the syscall ABI has the same stack alignment
30+
* requirements as the userspace function call ABI, but better safe than
31+
* sorry. Appendix A2 of http://www.x86-64.org/documentation/abi.pdf
32+
* does not list any ABI differences regarding stack alignment.)
33+
*/
34+
push %rbp
35+
.cfi_adjust_cfa_offset 8
36+
.cfi_rel_offset rbp, 0
37+
38+
/* The syscall calling convention isn't the same as the
39+
* C one:
40+
* we enter with rdi == *signal_pending
41+
* rsi == syscall number
42+
* rdx, rcx, r8, r9, (stack), (stack) == syscall arguments
43+
* and return the result in rax
44+
* and the syscall instruction needs
45+
* rax == syscall number
46+
* rdi, rsi, rdx, r10, r8, r9 == syscall arguments
47+
* and returns the result in rax
48+
* Shuffle everything around appropriately.
49+
* Note that syscall will trash rcx and r11.
50+
*/
51+
mov %rsi, %rax /* syscall number */
52+
mov %rdi, %rbp /* signal_pending pointer */
53+
/* and the syscall arguments */
54+
mov %rdx, %rdi
55+
mov %rcx, %rsi
56+
mov %r8, %rdx
57+
mov %r9, %r10
58+
mov 16(%rsp), %r8
59+
mov 24(%rsp), %r9
60+
61+
/* This next sequence of code works in conjunction with the
62+
* rewind_if_safe_syscall_function(). If a signal is taken
63+
* and the interrupted PC is anywhere between 'safe_syscall_start'
64+
* and 'safe_syscall_end' then we rewind it to 'safe_syscall_start'.
65+
* The code sequence must therefore be able to cope with this, and
66+
* the syscall instruction must be the final one in the sequence.
67+
*/
68+
safe_syscall_start:
69+
/* if signal_pending is non-zero, don't do the call */
70+
cmpl $0, (%rbp)
71+
jnz 1f
72+
syscall
73+
safe_syscall_end:
74+
/* code path for having successfully executed the syscall */
75+
pop %rbp
76+
.cfi_remember_state
77+
.cfi_def_cfa_offset 8
78+
.cfi_restore rbp
79+
ret
80+
81+
1:
82+
/* code path when we didn't execute the syscall */
83+
.cfi_restore_state
84+
mov $-TARGET_ERESTARTSYS, %rax
85+
pop %rbp
86+
.cfi_def_cfa_offset 8
87+
.cfi_restore rbp
88+
ret
89+
.cfi_endproc
90+
91+
.size safe_syscall_base, .-safe_syscall_base

0 commit comments

Comments
 (0)