Commit d8ecc0b9131a229ff6e8fbe5d3a0b284b1620452

Authored by bellard
1 parent 19c80e50

Make cpu_signal_handler work on Mac OS X/Darwin x86


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2400 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 15 additions and 3 deletions
cpu-exec.c
@@ -1176,6 +1176,18 @@ static inline int handle_cpu_signal(unsigned long pc, unsigned long address, @@ -1176,6 +1176,18 @@ static inline int handle_cpu_signal(unsigned long pc, unsigned long address,
1176 1176
1177 #if defined(__i386__) 1177 #if defined(__i386__)
1178 1178
  1179 +#if defined(__APPLE__)
  1180 +# include <sys/ucontext.h>
  1181 +
  1182 +# define EIP_sig(context) (*((unsigned long*)&(context)->uc_mcontext->ss.eip))
  1183 +# define TRAP_sig(context) ((context)->uc_mcontext->es.trapno)
  1184 +# define ERROR_sig(context) ((context)->uc_mcontext->es.err)
  1185 +#else
  1186 +# define EIP_sig(context) ((context)->uc_mcontext.gregs[REG_EIP])
  1187 +# define TRAP_sig(context) ((context)->uc_mcontext.gregs[REG_TRAPNO])
  1188 +# define ERROR_sig(context) ((context)->uc_mcontext.gregs[REG_ERR])
  1189 +#endif
  1190 +
1179 #if defined(USE_CODE_COPY) 1191 #if defined(USE_CODE_COPY)
1180 static void cpu_send_trap(unsigned long pc, int trap, 1192 static void cpu_send_trap(unsigned long pc, int trap,
1181 struct ucontext *uc) 1193 struct ucontext *uc)
@@ -1210,8 +1222,8 @@ int cpu_signal_handler(int host_signum, void *pinfo, @@ -1210,8 +1222,8 @@ int cpu_signal_handler(int host_signum, void *pinfo,
1210 #define REG_ERR ERR 1222 #define REG_ERR ERR
1211 #define REG_TRAPNO TRAPNO 1223 #define REG_TRAPNO TRAPNO
1212 #endif 1224 #endif
1213 - pc = uc->uc_mcontext.gregs[REG_EIP];  
1214 - trapno = uc->uc_mcontext.gregs[REG_TRAPNO]; 1225 + pc = EIP_sig(uc);
  1226 + trapno = TRAP_sig(uc);
1215 #if defined(TARGET_I386) && defined(USE_CODE_COPY) 1227 #if defined(TARGET_I386) && defined(USE_CODE_COPY)
1216 if (trapno == 0x00 || trapno == 0x05) { 1228 if (trapno == 0x00 || trapno == 0x05) {
1217 /* send division by zero or bound exception */ 1229 /* send division by zero or bound exception */
@@ -1221,7 +1233,7 @@ int cpu_signal_handler(int host_signum, void *pinfo, @@ -1221,7 +1233,7 @@ int cpu_signal_handler(int host_signum, void *pinfo,
1221 #endif 1233 #endif
1222 return handle_cpu_signal(pc, (unsigned long)info->si_addr, 1234 return handle_cpu_signal(pc, (unsigned long)info->si_addr,
1223 trapno == 0xe ? 1235 trapno == 0xe ?
1224 - (uc->uc_mcontext.gregs[REG_ERR] >> 1) & 1 : 0, 1236 + (ERROR_sig(uc) >> 1) & 1 : 0,
1225 &uc->uc_sigmask, puc); 1237 &uc->uc_sigmask, puc);
1226 } 1238 }
1227 1239