--- /Users/stranche/Documents/devel/MPlayer-1.0pre8/loader/ldt_keeper.c	2006-06-11 20:35:46.000000000 +0200
+++ ldt_keeper.c	2006-06-22 23:46:02.000000000 +0200
@@ -102,7 +102,7 @@
 #define       LDT_SEL(idx) ((idx) << 3 | 1 << 2 | 3)
 
 /* i got this value from wine sources, it's the first free LDT entry */
-#if defined(__FreeBSD__) && defined(LDT_AUTO_ALLOC)
+#if (defined(__FreeBSD__) || defined(CONFIG_DARWIN)) && defined(LDT_AUTO_ALLOC)
 #define       TEB_SEL_IDX     LDT_AUTO_ALLOC
 #endif
 
@@ -167,7 +167,7 @@
 #endif
 #endif
 
-#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
+#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(CONFIG_DARWIN) || defined(__OpenBSD__) || defined(__DragonFly__)
 static void LDT_EntryToBytes( unsigned long *buffer, const struct modify_ldt_ldt_s *content )
 {
     *buffer++ = ((content->base_addr & 0x0000ffff) << 16) |
@@ -193,7 +193,7 @@
 
     if (!ldt_fs)
 	return NULL;
-
+#ifndef CONFIG_DARWIN
     ldt_fs->fd = open("/dev/zero", O_RDWR);
     if(ldt_fs->fd<0){
         perror( "Cannot open /dev/zero for READ+WRITE. Check permissions! error: ");
@@ -202,6 +202,10 @@
     fs_seg=
     ldt_fs->fs_seg = mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE, MAP_PRIVATE,
 			  ldt_fs->fd, 0);
+#else
+    fs_seg=
+    ldt_fs->fs_seg = mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
+#endif /* CONFIG_DARWIN */
     if (ldt_fs->fs_seg == (void*)-1)
     {
 	perror("ERROR: Couldn't allocate memory for fs segment");
@@ -229,12 +233,12 @@
     }
 #endif /*linux*/
 
-#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
+#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(CONFIG_DARWIN) || defined(__OpenBSD__) || defined(__DragonFly__)
     {
         unsigned long d[2];
 
         LDT_EntryToBytes( d, &array );
-#if defined(__FreeBSD__) && defined(LDT_AUTO_ALLOC)
+#if (defined(__FreeBSD__) || defined(CONFIG_DARWIN)) && defined(LDT_AUTO_ALLOC)
         ret = i386_set_ldt(LDT_AUTO_ALLOC, (union descriptor *)d, 1);
         array.entry_number = ret;
         fs_ldt = ret;
