diff -rNbu MPlayer-1.0pre82/help/help_mp-en.h MPlayer-1.0pre8/help/help_mp-en.h
--- MPlayer-1.0pre82/help/help_mp-en.h	2006-06-11 12:35:45.000000000 -0600
+++ MPlayer-1.0pre8/help/help_mp-en.h	2006-08-01 09:58:40.000000000 -0600
@@ -1814,3 +1814,7 @@
 // libvo/vo_xv.c
 
 #define MSGTR_LIBVO_XV_DrawFrameCalled "[VO_XV] draw_frame() called!!!!!!\n"
+
+// loader/ldt_keeper.c
+
+#define MSGTR_LOADER_DYLD_Warning "WARNING: Attempting to use DLL codecs but environment variable DYLD_BIND_AT_LAUNCH not set.\nThis will likely crash.\n"
diff -rNbu MPlayer-1.0pre82/loader/Makefile MPlayer-1.0pre8/loader/Makefile
--- MPlayer-1.0pre82/loader/Makefile	2006-06-11 12:35:46.000000000 -0600
+++ MPlayer-1.0pre8/loader/Makefile	2006-08-01 09:59:01.000000000 -0600
@@ -9,7 +9,24 @@
 else
 LIB_OBJECTS= ldt_keeper.o pe_image.o module.o ext.o win32.o \
              driver.o pe_resource.o resource.o registry.o \
-             elfdll.o afl.o vfl.o wrapper.o
+             elfdll.o afl.o vfl.o mmap_anon.o
+
+# QTX emulation is not supported in Darwin
+ifneq ($(TARGET_OS),Darwin)
+LIB_OBJECTS+=wrapper.o
+endif
+
+endif
+
+# stubs_bsd.s for OpenBSD and Darwin, and stubs.s for the rest
+ifeq ($(TARGET_OS),Darwin)
+LIB_OBJECTS+=stubs_bsd.o
+else 
+ifeq ($(TARGET_OS),OpenBSD)
+LIB_OBJECTS+=stubs_bsd.o
+else
+LIB_OBJECTS+=stubs.o
+endif
 endif
 
 # gcc-3.0 produces buggy code for acmStreamOpen() with
@@ -34,12 +51,8 @@
 .c.o:
 	$(CC) $(CFLAGS) $(DEFINES) -c $<
 
-libloader.a:  $(LIB_OBJECTS) stubs.s
-	$(CC) -c ./stubs.s -o stubs.o
-ifeq ($(TARGET_OS),OpenBSD)
-	./loader_objfix.sh
-endif
-	$(AR) -r libloader.a $(LIB_OBJECTS) stubs.o
+libloader.a:  $(LIB_OBJECTS) 
+	$(AR) -r libloader.a $(LIB_OBJECTS)
 	$(RANLIB) libloader.a
 
 dep:
diff -rNbu MPlayer-1.0pre82/loader/ext.c MPlayer-1.0pre8/loader/ext.c
--- MPlayer-1.0pre82/loader/ext.c	2006-06-11 12:35:46.000000000 -0600
+++ MPlayer-1.0pre8/loader/ext.c	2006-08-01 09:58:45.000000000 -0600
@@ -26,6 +26,8 @@
 #include <stdarg.h>
 #include <ctype.h>
 
+#include <mmap_anon.h>
+
 #include "wine/windef.h"
 #include "wine/winbase.h"
 #include "wine/debugtools.h"
@@ -233,7 +235,6 @@
 
 //#define MAP_PRIVATE
 //#define MAP_SHARED
-#undef MAP_ANON
 LPVOID FILE_dommap( int unix_handle, LPVOID start,
                     DWORD size_high, DWORD size_low,
                     DWORD offset_high, DWORD offset_low,
@@ -248,36 +249,14 @@
 
     if (unix_handle == -1)
     {
-#ifdef MAP_ANON
-//	printf("Anonymous\n");
-        flags |= MAP_ANON;
-#else
-        static int fdzero = -1;
-
-        if (fdzero == -1)
-        {
-            if ((fdzero = open( "/dev/zero", O_RDONLY )) == -1)
-            {
-    		perror( "Cannot open /dev/zero for READ. Check permissions! error: " );
-                exit(1);
+        ret = mmap_anon( start, size_low, prot, flags, offset_low, &fd );
             }
+    else {
+        fd = unix_handle;
+        ret = mmap( start, size_low, prot, flags, fd, offset_low );
         }
-        fd = fdzero;
-#endif  /* MAP_ANON */
-	/* Linux EINVAL's on us if we don't pass MAP_PRIVATE to an anon mmap */
-#ifdef MAP_SHARED
-	flags &= ~MAP_SHARED;
-#endif
-#ifdef MAP_PRIVATE
-	flags |= MAP_PRIVATE;
-#endif
-    }
-    else fd = unix_handle;
-//    printf("fd %x, start %x, size %x, pos %x, prot %x\n",fd,start,size_low, offset_low, prot);
-//    if ((ret = mmap( start, size_low, prot,
-//                     flags, fd, offset_low )) != (LPVOID)-1)
-    if ((ret = mmap( start, size_low, prot,
-                     MAP_PRIVATE | MAP_FIXED, fd, offset_low )) != (LPVOID)-1)
+
+    if (ret != (LPVOID)-1)
     {
 //	    printf("address %08x\n", *(int*)ret);
 //	printf("%x\n", ret);
@@ -370,15 +349,10 @@
     LPVOID answer;
     int anon=0;
     int mmap_access=0;
+
     if(hFile<0)
-    {
 	anon=1;
-	hFile=open("/dev/zero", O_RDWR);
-	if(hFile<0){
-    	    perror( "Cannot open /dev/zero for READ+WRITE. Check permissions! error: " );
-	    return 0;
-	}
-    }
+
     if(!anon)
     {
         len=lseek(hFile, 0, SEEK_END);
@@ -391,8 +365,12 @@
     else
 	mmap_access |=PROT_READ|PROT_WRITE;
 
-    answer=mmap(NULL, len, mmap_access, MAP_PRIVATE, hFile, 0);
     if(anon)
+      answer=mmap_anon(NULL, len, mmap_access, MAP_PRIVATE, 0, &hFile);
+    else
+      answer=mmap(NULL, len, mmap_access, MAP_PRIVATE, hFile, 0);
+
+    if(anon && hFile != -1)
         close(hFile);
     if(answer!=(LPVOID)-1)
     {
@@ -418,7 +396,7 @@
 	    fm->name=NULL;
 	fm->mapping_size=len;
 
-	if(anon)
+	if(anon && hFile != -1)
 	    close(hFile);
 	return (HANDLE)answer;
     }
@@ -471,12 +449,6 @@
 
     if ((type&(MEM_RESERVE|MEM_COMMIT)) == 0) return NULL;
 
-    fd=open("/dev/zero", O_RDWR);
-    if(fd<0){
-        perror( "Cannot open /dev/zero for READ+WRITE. Check permissions! error: " );
-	return NULL;
-    }
-
     if (type&MEM_RESERVE && (unsigned)address&0xffff) {
 	size += (unsigned)address&0xffff;
 	address = (unsigned)address&~0xffff;
@@ -513,22 +485,22 @@
 		   && ((unsigned)address+size<=(unsigned)str->address+str->mapping_size)
 		   && (type & MEM_COMMIT))
 		{
-		    close(fd);
 		    return address; //returning previously reserved memory
 		}
 		//printf(" VirtualAlloc(...) does not commit or not entirely within reserved, and\n");
 	    }
 	    /*printf(" VirtualAlloc(...) (0x%08X, %u) overlaps with (0x%08X, %u, state=%d)\n",
 	           (unsigned)address, size, (unsigned)str->address, str->mapping_size, str->state);*/
-	    close(fd);
 	    return NULL;
 	}
     }
 
-    answer=mmap(address, size, PROT_READ | PROT_WRITE | PROT_EXEC,
-		MAP_PRIVATE, fd, 0);
+    answer=mmap_anon(address, size, PROT_READ | PROT_WRITE | PROT_EXEC,
+		    MAP_PRIVATE, 0, &fd);
+
 //    answer=FILE_dommap(-1, address, 0, size, 0, 0,
 //	PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE);
+    if (fd != -1)
     close(fd);
     if (answer != (void *)-1 && address && answer != address) {
 	/* It is dangerous to try mmap() with MAP_FIXED since it does not
diff -rNbu MPlayer-1.0pre82/loader/ldt_keeper.c MPlayer-1.0pre8/loader/ldt_keeper.c
--- MPlayer-1.0pre82/loader/ldt_keeper.c	2006-06-11 12:35:46.000000000 -0600
+++ MPlayer-1.0pre8/loader/ldt_keeper.c	2006-08-01 09:58:55.000000000 -0600
@@ -28,6 +28,11 @@
 #include <sys/types.h>
 #include <stdio.h>
 #include <unistd.h>
+
+#include <mmap_anon.h>
+#include <mp_msg.h>
+#include <help_mp.h>
+
 #ifdef __linux__
 #include <asm/unistd.h>
 #include <asm/ldt.h>
@@ -102,8 +107,9 @@
 #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(__APPLE__) || defined(__FreeBSD__)) && defined(LDT_AUTO_ALLOC)
 #define       TEB_SEL_IDX     LDT_AUTO_ALLOC
+#define	      USE_LDT_AA
 #endif
 
 #ifndef       TEB_SEL_IDX
@@ -167,7 +173,7 @@
 #endif
 #endif
 
-#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
+#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__APPLE__)
 static void LDT_EntryToBytes( unsigned long *buffer, const struct modify_ldt_ldt_s *content )
 {
     *buffer++ = ((content->base_addr & 0x0000ffff) << 16) |
@@ -194,14 +200,14 @@
     if (!ldt_fs)
 	return NULL;
 
-    ldt_fs->fd = open("/dev/zero", O_RDWR);
-    if(ldt_fs->fd<0){
-        perror( "Cannot open /dev/zero for READ+WRITE. Check permissions! error: ");
-	return NULL;
-    }
+#ifdef __APPLE__
+    if (getenv("DYLD_BIND_AT_LAUNCH") == NULL)
+        mp_msg(MSGT_LOADER, MSGL_WARN, MSGTR_LOADER_DYLD_Warning);
+#endif /* __APPLE__ */
+
     fs_seg=
-    ldt_fs->fs_seg = mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE, MAP_PRIVATE,
-			  ldt_fs->fd, 0);
+    ldt_fs->fs_seg = mmap_anon(NULL, getpagesize(), PROT_READ | PROT_WRITE, MAP_PRIVATE,
+			       0, &ldt_fs->fd);
     if (ldt_fs->fs_seg == (void*)-1)
     {
 	perror("ERROR: Couldn't allocate memory for fs segment");
@@ -229,12 +235,12 @@
     }
 #endif /*linux*/
 
-#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
+#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__APPLE__)
     {
         unsigned long d[2];
 
         LDT_EntryToBytes( d, &array );
-#if defined(__FreeBSD__) && defined(LDT_AUTO_ALLOC)
+#ifdef USE_LDT_AA
         ret = i386_set_ldt(LDT_AUTO_ALLOC, (union descriptor *)d, 1);
         array.entry_number = ret;
         fs_ldt = ret;
@@ -251,7 +257,7 @@
 #endif
         }
     }
-#endif  /* __NetBSD__ || __FreeBSD__ || __OpenBSD__ || __DragonFly__ */
+#endif  /* __NetBSD__ || __FreeBSD__ || __OpenBSD__ || __DragonFly__ || __APPLE__ */
 
 #if defined(__svr4__)
     {
@@ -286,6 +292,7 @@
 	free(ldt_fs->prev_struct);
     munmap((char*)ldt_fs->fs_seg, getpagesize());
     ldt_fs->fs_seg = 0;
+    if (ldt_fs->fd != -1)
     close(ldt_fs->fd);
     free(ldt_fs);
 }
diff -rNbu MPlayer-1.0pre82/loader/mmap_anon.c MPlayer-1.0pre8/loader/mmap_anon.c
--- MPlayer-1.0pre82/loader/mmap_anon.c	1969-12-31 17:00:00.000000000 -0700
+++ MPlayer-1.0pre8/loader/mmap_anon.c	2006-08-01 10:01:36.000000000 -0600
@@ -0,0 +1,48 @@
+/*
+ * mmap_anon.c: provide a compatible anonymous space mapping function
+ */
+
+#include <sys/mman.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+/*
+ * mmap() anonymous space, depending on the system's mmap() style. On systems
+ * that use the /dev/zero mapping idiom, zerofd will be set to the file descriptor
+ * of the opened /dev/zero. 
+ */
+void *mmap_anon(void *addr, size_t len, int prot, int flags, off_t offset, int *zerofd)
+{
+    int fd;
+    void *result;
+
+     /* From loader/ext.c:
+      * "Linux EINVAL's on us if we don't pass MAP_PRIVATE to an anon mmap"
+      * Therefore we preserve the same behavior on all platforms, ie. no
+      * shared mappings of anon space (if the concepts are supported). */
+#if defined(MAP_SHARED) && defined(MAP_PRIVATE)
+     flags = (flags & ~MAP_SHARED) | MAP_PRIVATE;
+#endif /* defined(MAP_SHARED) && defined(MAP_PRIVATE) */
+
+#ifdef __APPLE__
+    /* BSD-style anonymous mapping */
+    fd = -1;
+    result = mmap(addr, len, prot, flags | MAP_ANON, -1, offset);
+#else
+    /* SysV-style anonymous mapping */
+    fd = open("/dev/zero", O_RDWR);
+    if(fd < 0){
+        perror( "Cannot open /dev/zero for READ+WRITE. Check permissions! error: ");
+        return NULL;
+    }
+
+    result = mmap(addr, len, prot, flags, fd, offset);
+#endif /* __APPLE__ */
+
+    if (zerofd)
+        *zerofd = fd;
+
+    return result;
+}
+
diff -rNbu MPlayer-1.0pre82/loader/mmap_anon.h MPlayer-1.0pre8/loader/mmap_anon.h
--- MPlayer-1.0pre82/loader/mmap_anon.h	1969-12-31 17:00:00.000000000 -0700
+++ MPlayer-1.0pre8/loader/mmap_anon.h	2006-08-01 09:58:23.000000000 -0600
@@ -0,0 +1,8 @@
+#ifndef _OSDEP_MMAP_ANON_H_
+#define _OSDEP_MMAP_ANON_H_
+
+#include <sys/types.h>
+
+void *mmap_anon(void *, size_t, int, int, off_t, int *);
+
+#endif /* _OSDEP_MMAP_ANON_H_ */
diff -rNbu MPlayer-1.0pre82/loader/module.c MPlayer-1.0pre8/loader/module.c
--- MPlayer-1.0pre82/loader/module.c	2006-06-11 12:35:46.000000000 -0600
+++ MPlayer-1.0pre8/loader/module.c	2006-08-01 09:59:18.000000000 -0600
@@ -10,7 +10,10 @@
  */
 
 // define for quicktime calls debugging and/or MacOS-level emulation:
+// (not supported on OS X yet)
+#ifndef __APPLE__
 #define EMU_QTX_API
+#endif /* __APPLE__ */
 
 // define for quicktime debugging (verbose logging):
 //#define DEBUG_QTX_API
diff -rNbu MPlayer-1.0pre82/loader/stubs_bsd.s MPlayer-1.0pre8/loader/stubs_bsd.s
--- MPlayer-1.0pre82/loader/stubs_bsd.s	1969-12-31 17:00:00.000000000 -0700
+++ MPlayer-1.0pre8/loader/stubs_bsd.s	2006-08-01 10:10:23.000000000 -0600
@@ -0,0 +1,35 @@
+	.data
+.LC0:	.asciz	"Called unk_%s\n"
+       .p2align 2
+.globl _unk_exp1
+_unk_exp1:
+	pushl %ebp
+	movl %esp,%ebp
+	subl $4,%esp
+	movl $1,-4(%ebp)
+	movl -4(%ebp),%eax
+	movl %eax,%ecx
+	movl %ecx,%edx
+	sall $4,%edx
+	subl %eax,%edx
+	leal 0(,%edx,2),%eax
+	movl %eax,%edx
+	addl $_export_names,%edx
+	pushl %edx
+	pushl $.LC0
+	call _printf
+	addl $8,%esp
+	xorl %eax,%eax
+	leave
+	ret
+.globl _exp_EH_prolog
+_exp_EH_prolog:
+	pushl $0xff
+	pushl %eax
+	pushl %fs:0
+	movl  %esp, %fs:0
+	movl  12(%esp), %eax
+	movl  %ebp, 12(%esp)
+	leal  12(%esp), %ebp
+	pushl %eax
+	ret
diff -rNbu MPlayer-1.0pre82/loader/wine/poppack.h MPlayer-1.0pre8/loader/wine/poppack.h
--- MPlayer-1.0pre82/loader/wine/poppack.h	2006-06-11 12:35:46.000000000 -0600
+++ MPlayer-1.0pre8/loader/wine/poppack.h	2006-08-01 09:59:28.000000000 -0600
@@ -1,9 +1,9 @@
 #ifdef __WINE_PSHPACK_H
 #undef __WINE_PSHPACK_H
 
-#if defined(__GNUC__) || defined(__SUNPRO_C)
+#if (defined(__GNUC__) || defined(__SUNPRO_C)) && !defined(__APPLE__)
 #pragma pack()
-#elif defined(__SUNPRO_CC)
+#elif defined(__SUNPRO_CC) || defined(__APPLE__)
 #warning "Assumes default alignment is 4"
 #pragma pack(4)
 #elif !defined(RC_INVOKED)
diff -rNbu MPlayer-1.0pre82/mp_msg.h MPlayer-1.0pre8/mp_msg.h
--- MPlayer-1.0pre82/mp_msg.h	2006-06-11 12:35:47.000000000 -0600
+++ MPlayer-1.0pre8/mp_msg.h	2006-08-01 09:59:32.000000000 -0600
@@ -97,6 +97,8 @@
 
 #define MSGT_IDENTIFY 41  // -identify output
 
+#define MSGT_LOADER 42 // dll loader messages
+
 #define MSGT_MAX 64
 
 void mp_msg_init(void);
