[PATCH] ntdll: Use the old mmap() wrapper on 32-bit Mac OS. (try 2)

Charles Davis cdavis at mymail.mines.edu
Thu May 13 12:34:59 CDT 2010


From: Charles Davis <cdavis at mines.edu>

This patch does not break libwine compatibility at all.
---
 dlls/ntdll/virtual.c |   41 ++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 40 insertions(+), 1 deletions(-)

diff --git a/dlls/ntdll/virtual.c b/dlls/ntdll/virtual.c
index 6fedbf3..446fd00 100644
--- a/dlls/ntdll/virtual.c
+++ b/dlls/ntdll/virtual.c
@@ -61,6 +61,45 @@
 WINE_DEFAULT_DEBUG_CHANNEL(virtual);
 WINE_DECLARE_DEBUG_CHANNEL(module);
 
+/*
+ * In Mac OS 10.5, the mmap() function was changed to match UNIX '03 (as
+ * Linux does). In particular, this means that unaligned file offsets fail
+ * with EINVAL. However, that check is done at the library level, not the
+ * kernel level. This is done to maintain backwards compatibility with old
+ * programs that expect unaligned offsets to succeed.
+ * Because the syscall itself still supports unaligned file offsets, instead
+ * of calling the wrapper in libc, we define our own function to make the
+ * syscall directly on 64-bit Mac OS.
+ * For 32-bit Mac OS, the old wrapper is still exported from libc, so we
+ * just remap wine_mmap to mmap. For other platforms, we just use the default
+ * mmap.
+ */
+#if defined(__APPLE__) && !defined(__x86_64__)
+extern void *wine_mmap( void *start, size_t size, int port, int flags, int fd,
+                        off_t off ) __asm("_mmap");
+#elif defined(__APPLE__) && defined(__x86_64__)
+__ASM_GLOBAL_FUNC( wine_mmap,
+                   "movq %rcx,%r10\n\t"
+                   "movl $0x020000c5,%eax\n\t"  /* SYS_mmap (decorated) */
+                   "syscall\n\t"
+                   "jae 1f\n\t"
+                   "movq _errno at GOTPCREL(%rip),%r11\n\t"
+                   "movq %rax,(%r11)\n\t"
+                   "movq %rsp,%rdx\n\t"
+                   "andq $~16,%rsp\n\t"
+                   "subq $16,%rsp\n\t"
+                   "movq %rdx,(%rsp)\n\t"
+                   "movq %rax,%rdi\n\t"
+                   "callq _cthread_set_errno_self\n\t"
+                   "movq (%rsp),%rsp\n\t"
+                   "stc\n\t"
+                   "sbbq %rdx,%rdx\n\t"
+                   "sbbq %rax,%rax\n\t"
+                   "1:\tret\n\t" )
+#else
+#define wine_mmap mmap
+#endif
+
 #ifndef MS_SYNC
 #define MS_SYNC 0
 #endif
@@ -867,7 +906,7 @@ static NTSTATUS map_file_into_view( struct file_view *view, int fd, size_t start
     {
         int flags = MAP_FIXED | (shared_write ? MAP_SHARED : MAP_PRIVATE);
 
-        if (mmap( (char *)view->base + start, size, prot, flags, fd, offset ) != (void *)-1)
+        if (wine_mmap( (char *)view->base + start, size, prot, flags, fd, offset ) != (void *)-1)
             goto done;
 
         /* mmap() failed; if this is because the file offset is not    */
-- 
1.7.1




More information about the wine-patches mailing list