| Newsgroups |
gmane.comp.emulators.winex.cvs |
| Message-ID |
<[email protected]> |
Subject: winex/library ldt.c,1.8,1.9Update of /var/lib/cvsd/cvsroot/winex/library
In directory agravaine:/tmp/cvs-serv4784/library
Modified Files:
ldt.c
Log Message:
Work around MacOS X kernel issue - avoid doing multiple calls to ldt
setting kernel API from simultaneous threads.
Index: ldt.c
===================================================================
RCS file: /var/lib/cvsd/cvsroot/winex/library/ldt.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- ldt.c 27 Mar 2007 22:23:15 -0000 1.8
+++ ldt.c 30 Mar 2007 18:34:06 -0000 1.9
@@ -21,6 +21,13 @@
#ifdef HAVE_SYS_SYSCALL_H
# include <sys/syscall.h>
#endif
+
+#ifdef __APPLE__
+/* MacOS X requires a pthread mutex around ldt calls to prevent kernel panics (?) */
+#include <pthread.h>
+pthread_mutex_t LDT_pthread_mutex;
+#endif
+
struct modify_ldt_s
{
unsigned int entry_number;
@@ -213,8 +220,11 @@
if ((ret = sysi86(SI86DSCR, &ldt_mod)) == -1) perror("sysi86");
}
#elif defined(__APPLE__)
+ /* First, lock the critsec to prevent kernel panics */
{
LDT_ENTRY entry_copy = *entry;
+ pthread_mutex_lock(&LDT_pthread_mutex);
+
/* The kernel will only let us set LDTs with user priority level (true on darwin??) */
if (entry_copy.HighWord.Bits.Pres
&& entry_copy.HighWord.Bits.Dpl != 3)
@@ -225,6 +235,7 @@
perror("i386_set_ldt");
fprintf( stderr, "Problem with MacOS i386_set_ldt function!\n" );
}
+ pthread_mutex_unlock(&LDT_pthread_mutex);
}
#else