Replace malloc and friends.
[wincetools.git] / loader / ntdll_loader.c
index 3acf297..8d6ba06 100644 (file)
@@ -26,6 +26,7 @@
 \r
 #include <assert.h>\r
 \r
+#include "dlmalloc.h"\r
 #include "wine.h"\r
 \r
 PIMAGE_NT_HEADERS MyRtlImageNtHeader(HMODULE hModule)\r
@@ -142,6 +143,7 @@ static WINE_MODREF *import_dll( HMODULE module, const IMAGE_IMPORT_DESCRIPTOR *d
   SIZE_T protect_size = 0;\r
   DWORD protect_old;\r
 #endif\r
+  int iscoredll = 0;\r
 \r
   thunk_list = get_rva( module, (DWORD)descr->FirstThunk );\r
   if (descr->OriginalFirstThunk)\r
@@ -151,8 +153,12 @@ static WINE_MODREF *import_dll( HMODULE module, const IMAGE_IMPORT_DESCRIPTOR *d
 \r
   while (len && name[len-1] == ' ') len--;  /* remove trailing spaces */\r
 \r
+  if (! _stricmp (name, "coredll.dll"))\r
+    iscoredll = 1;\r
+\r
   if (len * sizeof(WCHAR) < sizeof(buffer))\r
     {\r
+\r
       ascii_to_unicode( buffer, name, len );\r
       buffer[len] = 0;\r
       //      status = load_dll( load_path, buffer, 0, &wmImp );\r
@@ -232,7 +238,28 @@ static WINE_MODREF *import_dll( HMODULE module, const IMAGE_IMPORT_DESCRIPTOR *d
 \r
          //      thunk_list->u1.Function = (ULONG_PTR)find_ordinal_export( imp_mod, exports, exp_size,\r
          //                                                                ordinal - exports->Base, load_path );\r
-         thunk_list->u1.Function = (PDWORD)(ULONG_PTR)GetProcAddress (imp_mod, (void *) (ordinal & 0xffff));\r
+\r
+         if (iscoredll)\r
+           {\r
+#define COREDLL_MALLOC 1041\r
+#define COREDLL_CALLOC 1346\r
+#define COREDLL_FREE 1018\r
+#define COREDLL_REALLOC 1054\r
+\r
+             if (ordinal == COREDLL_MALLOC)\r
+               thunk_list->u1.Function = (PWORD) dlmalloc;\r
+             else if (ordinal == COREDLL_CALLOC)\r
+               thunk_list->u1.Function = (PWORD) dlcalloc;\r
+             else if (ordinal == COREDLL_FREE)\r
+               thunk_list->u1.Function = (PWORD) dlfree;\r
+             else if (ordinal == COREDLL_REALLOC)\r
+               thunk_list->u1.Function = (PWORD) dlrealloc;\r
+             else\r
+               thunk_list->u1.Function = (PWORD)(ULONG_PTR)GetProcAddress (imp_mod, (void *) (ordinal & 0xffff));\r
+           }\r
+         else\r
+           thunk_list->u1.Function = (PDWORD)(ULONG_PTR)GetProcAddress (imp_mod, (void *) (ordinal & 0xffff));\r
+\r
          if (!thunk_list->u1.Function)\r
             {\r
              thunk_list->u1.Function = (PDWORD) allocate_stub( name, IntToPtr(ordinal) );\r
@@ -245,11 +272,28 @@ static WINE_MODREF *import_dll( HMODULE module, const IMAGE_IMPORT_DESCRIPTOR *d
       else  /* import by name */\r
         {\r
          IMAGE_IMPORT_BY_NAME *pe_name;\r
+         const char *symname = (const char*)pe_name->Name;\r
          pe_name = get_rva( module, (DWORD)import_list->u1.AddressOfData );\r
+\r
          //      thunk_list->u1.Function = (ULONG_PTR)find_named_export( imp_mod, exports, exp_size,\r
          //                                                              (const char*)pe_name->Name,\r
          //                                                              pe_name->Hint, load_path );\r
-         thunk_list->u1.Function = (PDWORD)(ULONG_PTR)GetProcAddressA (imp_mod, (const char*)pe_name->Name);\r
+\r
+         if (iscoredll)\r
+           {\r
+             if (! strcmp (symname, "malloc"))\r
+               thunk_list->u1.Function = (PWORD) dlmalloc;\r
+             else if (! strcmp (symname, "calloc"))\r
+               thunk_list->u1.Function = (PWORD) dlcalloc;\r
+             else if (! strcmp (symname, "free"))\r
+               thunk_list->u1.Function = (PWORD) dlfree;\r
+             else if (! strcmp (symname, "realloc"))\r
+               thunk_list->u1.Function = (PWORD) dlrealloc;\r
+             else\r
+               thunk_list->u1.Function = (PDWORD)(ULONG_PTR)GetProcAddressA (imp_mod, symname);\r
+           }\r
+         else\r
+           thunk_list->u1.Function = (PDWORD)(ULONG_PTR)GetProcAddressA (imp_mod, (const char*)pe_name->Name);\r
          if (!thunk_list->u1.Function)\r
             {\r
              thunk_list->u1.Function = (PDWORD) allocate_stub( name, (const char*)pe_name->Name );\r