Mach-O Support for imageSize in NtHeader

Pierre d'Herbemont stegefin at free.fr
Mon Nov 24 12:49:59 CST 2003


Hi!

Here is my second try for a replacement of the _end symbol. I think 
that since there is no support of it we need a kind of emulation 
function, which I thought should be located in the wine_port lib. So I 
add a mach-o.c port file, with the needed function. But should it be 
done this way?
Also I use the printf positional argument support (%n$x). Hope it is 
ok, since it might print warning on some compiler.

Thanks,

Pierre.

ChangeLog:
Add Mach-O Support for ImageSize in WineLib App's NtHeader.

-------------- next part --------------
Index: tools/winebuild/spec32.c
===================================================================
RCS file: /home/wine/wine/tools/winebuild/spec32.c,v
retrieving revision 1.72
diff -u -r1.72 spec32.c
--- tools/winebuild/spec32.c	3 Nov 2003 22:19:44 -0000	1.72
+++ tools/winebuild/spec32.c	22 Nov 2003 21:14:33 -0000
@@ -529,7 +529,12 @@
     fprintf( outfile, "}\n" );
     fprintf( outfile, "#endif\n" );
 
+#ifdef __APPLE__
+    fprintf( outfile, "static char _end[4];\n" );
+#else
     fprintf( outfile, "extern char _end[];\n" );
+#endif
+    
     fprintf( outfile, "extern int __wine_spec_data_start[], __wine_spec_exports[];\n\n" );
 
 #ifdef __i386__
@@ -826,7 +831,11 @@
              "{\n"
              "    extern void __wine_dll_register( const struct image_nt_headers *, const char * );\n"
              "    extern void *__wine_dbg_register( char * const *, int );\n"
-             "    __wine_dll_register( &nt_header, \"%s\" );\n"
+#ifdef __APPLE__
+             "    extern unsigned long wine_dyld_dll_image_size(const char *);\n"
+             "    *((unsigned long *)_end) = dyld_dll_image_size(\"%2$s\");\n"
+#endif
+             "    __wine_dll_register( &nt_header, \"%2$s\" );\n"
              "}\n",
              constructor, dll_file_name );
 }
--- /dev/null	Sat Nov 22 22:20:41 2003
+++ libs/port/mach-o.c	Sat Nov 22 22:22:35 2003
@@ -0,0 +1,56 @@
+/*
+ * Mach-O compatibility functions
+ *
+ * Copyright 2003 Pierre d'Herbemont
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+ 
+#include "config.h"
+#include "wine/port.h"
+
+#ifdef __APPLE__
+
+#include <strings.h>
+#include <mach-o/loader.h>
+#include <mach-o/dyld.h> 
+
+/***********************************************************************
+ *           dyld_dll_image_size
+ *
+ * Return the size of the image given its name.
+ * (Called from the generated spec.c files)
+ */
+unsigned long dyld_dll_image_size(const char * dllname)
+{
+    struct mach_header * header;
+    struct load_command * cmd;
+    unsigned long i, size = 0;
+    
+    for( i=0; i<_dyld_image_count(); i++)
+        if(strstr(_dyld_get_image_name(i), dllname)) break;
+    
+    header = _dyld_get_image_header(i);
+    cmd = (struct load_command *)((char *)header + sizeof(struct mach_header));
+    
+    for (i = 0; i < header->ncmds; i++) {
+        size += cmd->cmdsize;
+        cmd = (struct load_command *)((char *)cmd + cmd->cmdsize);
+    }
+    
+    return size;
+}
+
+#endif /* __APPLE__ */
Index: libs/port/Makefile.in
===================================================================
RCS file: /home/wine/wine/libs/port/Makefile.in,v
retrieving revision 1.8
diff -u -r1.8 Makefile.in
--- libs/port/Makefile.in	12 Nov 2003 03:16:00 -0000	1.8
+++ libs/port/Makefile.in	22 Nov 2003 21:23:25 -0000
@@ -13,6 +13,7 @@
 	gettid.c \
 	interlocked.c \
 	lstat.c \
+	mach-o.c \
 	memcpy_unaligned.c \
 	memmove.c \
 	mkstemps.c \


More information about the wine-patches mailing list