Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Modules |
| 3 | * |
| 4 | * Copyright 1995 Alexandre Julliard |
| 5 | */ |
| 6 | |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 7 | #include <assert.h> |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 8 | #include <fcntl.h> |
| 9 | #include <stdlib.h> |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 10 | #include <string.h> |
| 11 | #include <sys/types.h> |
| 12 | #include <unistd.h> |
Michael Veksler | ca1bc86 | 1999-01-01 18:57:33 +0000 | [diff] [blame] | 13 | #include "wine/winuser16.h" |
Marcus Meissner | 317af32 | 1999-02-17 13:51:06 +0000 | [diff] [blame] | 14 | #include "wine/winbase16.h" |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 15 | #include "windef.h" |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 16 | #include "winerror.h" |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 17 | #include "file.h" |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 18 | #include "global.h" |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 19 | #include "heap.h" |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 20 | #include "module.h" |
Ulrich Weigand | c50a1d0 | 1999-08-15 12:45:01 +0000 | [diff] [blame] | 21 | #include "snoop.h" |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 22 | #include "neexe.h" |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 23 | #include "pe_image.h" |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 24 | #include "dosexe.h" |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 25 | #include "process.h" |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 26 | #include "thread.h" |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 27 | #include "selectors.h" |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 28 | #include "stackframe.h" |
| 29 | #include "task.h" |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 30 | #include "debugtools.h" |
Alexandre Julliard | ff8331e | 1995-09-18 11:19:54 +0000 | [diff] [blame] | 31 | #include "callback.h" |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 32 | #include "loadorder.h" |
| 33 | #include "elfdll.h" |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 34 | |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 35 | DECLARE_DEBUG_CHANNEL(module) |
| 36 | DECLARE_DEBUG_CHANNEL(win32) |
| 37 | |
Guy Albertelli | 0e65b38 | 1999-06-12 10:49:36 +0000 | [diff] [blame] | 38 | /************************************************************************* |
| 39 | * MODULE_WalkModref |
| 40 | * Walk MODREFs for input process ID |
| 41 | */ |
| 42 | void MODULE_WalkModref( DWORD id ) |
| 43 | { |
| 44 | int i; |
| 45 | WINE_MODREF *zwm, *prev = NULL; |
| 46 | PDB *pdb = PROCESS_IdToPDB( id ); |
| 47 | |
| 48 | if (!pdb) { |
| 49 | MESSAGE("Invalid process id (pid)\n"); |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | MESSAGE("Modref list for process pdb=%p\n", pdb); |
| 54 | MESSAGE("Modref next prev handle deps flags name\n"); |
| 55 | for ( zwm = pdb->modref_list; zwm; zwm = zwm->next) { |
| 56 | MESSAGE("%p %p %p %04x %5d %04x %s\n", zwm, zwm->next, zwm->prev, |
| 57 | zwm->module, zwm->nDeps, zwm->flags, zwm->modname); |
| 58 | for ( i = 0; i < zwm->nDeps; i++ ) { |
| 59 | if ( zwm->deps[i] ) |
| 60 | MESSAGE(" %d %p %s\n", i, zwm->deps[i], zwm->deps[i]->modname); |
| 61 | } |
| 62 | if (prev != zwm->prev) |
| 63 | MESSAGE(" --> modref corrupt, previous pointer wrong!!\n"); |
| 64 | prev = zwm; |
| 65 | } |
| 66 | } |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 67 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 68 | /************************************************************************* |
| 69 | * MODULE32_LookupHMODULE |
| 70 | * looks for the referenced HMODULE in the current process |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 71 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 72 | WINE_MODREF *MODULE32_LookupHMODULE( HMODULE hmod ) |
Ulrich Weigand | 1d90d69 | 1999-02-24 14:27:07 +0000 | [diff] [blame] | 73 | { |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 74 | WINE_MODREF *wm; |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 75 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 76 | if (!hmod) |
Ulrich Weigand | 1d90d69 | 1999-02-24 14:27:07 +0000 | [diff] [blame] | 77 | return PROCESS_Current()->exe_modref; |
| 78 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 79 | if (!HIWORD(hmod)) { |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 80 | ERR_(module)("tried to lookup 0x%04x in win32 module handler!\n",hmod); |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 81 | return NULL; |
| 82 | } |
Ulrich Weigand | 1d90d69 | 1999-02-24 14:27:07 +0000 | [diff] [blame] | 83 | for ( wm = PROCESS_Current()->modref_list; wm; wm=wm->next ) |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 84 | if (wm->module == hmod) |
| 85 | return wm; |
| 86 | return NULL; |
| 87 | } |
| 88 | |
Ulrich Weigand | a3527cf | 1998-10-11 19:31:10 +0000 | [diff] [blame] | 89 | /************************************************************************* |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 90 | * MODULE_InitDll |
| 91 | */ |
| 92 | static BOOL MODULE_InitDll( WINE_MODREF *wm, DWORD type, LPVOID lpReserved ) |
| 93 | { |
| 94 | BOOL retv = TRUE; |
| 95 | |
| 96 | static LPCSTR typeName[] = { "PROCESS_DETACH", "PROCESS_ATTACH", |
| 97 | "THREAD_ATTACH", "THREAD_DETACH" }; |
| 98 | assert( wm ); |
| 99 | |
| 100 | |
| 101 | /* Skip calls for modules loaded with special load flags */ |
| 102 | |
| 103 | if ( ( wm->flags & WINE_MODREF_DONT_RESOLVE_REFS ) |
| 104 | || ( wm->flags & WINE_MODREF_LOAD_AS_DATAFILE ) ) |
| 105 | return TRUE; |
| 106 | |
| 107 | |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 108 | TRACE_(module)("(%s,%s,%p) - CALL\n", |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 109 | wm->modname, typeName[type], lpReserved ); |
| 110 | |
| 111 | /* Call the initialization routine */ |
| 112 | switch ( wm->type ) |
| 113 | { |
| 114 | case MODULE32_PE: |
| 115 | retv = PE_InitDLL( wm, type, lpReserved ); |
| 116 | break; |
| 117 | |
| 118 | case MODULE32_ELF: |
| 119 | /* no need to do that, dlopen() already does */ |
| 120 | break; |
| 121 | |
| 122 | default: |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 123 | ERR_(module)("wine_modref type %d not handled.\n", wm->type ); |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 124 | retv = FALSE; |
| 125 | break; |
| 126 | } |
| 127 | |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 128 | TRACE_(module)("(%s,%s,%p) - RETURN %d\n", |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 129 | wm->modname, typeName[type], lpReserved, retv ); |
| 130 | |
| 131 | return retv; |
| 132 | } |
| 133 | |
| 134 | /************************************************************************* |
| 135 | * MODULE_DllProcessAttach |
Ulrich Weigand | a3527cf | 1998-10-11 19:31:10 +0000 | [diff] [blame] | 136 | * |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 137 | * Send the process attach notification to all DLLs the given module |
| 138 | * depends on (recursively). This is somewhat complicated due to the fact that |
Ulrich Weigand | a3527cf | 1998-10-11 19:31:10 +0000 | [diff] [blame] | 139 | * |
| 140 | * - we have to respect the module dependencies, i.e. modules implicitly |
| 141 | * referenced by another module have to be initialized before the module |
| 142 | * itself can be initialized |
| 143 | * |
| 144 | * - the initialization routine of a DLL can itself call LoadLibrary, |
| 145 | * thereby introducing a whole new set of dependencies (even involving |
| 146 | * the 'old' modules) at any time during the whole process |
| 147 | * |
| 148 | * (Note that this routine can be recursively entered not only directly |
| 149 | * from itself, but also via LoadLibrary from one of the called initialization |
| 150 | * routines.) |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 151 | * |
| 152 | * Furthermore, we need to rearrange the main WINE_MODREF list to allow |
| 153 | * the process *detach* notifications to be sent in the correct order. |
| 154 | * This must not only take into account module dependencies, but also |
| 155 | * 'hidden' dependencies created by modules calling LoadLibrary in their |
| 156 | * attach notification routine. |
| 157 | * |
| 158 | * The strategy is rather simple: we move a WINE_MODREF to the head of the |
| 159 | * list after the attach notification has returned. This implies that the |
| 160 | * detach notifications are called in the reverse of the sequence the attach |
| 161 | * notifications *returned*. |
| 162 | * |
| 163 | * NOTE: Assumes that the process critical section is held! |
| 164 | * |
Ulrich Weigand | a3527cf | 1998-10-11 19:31:10 +0000 | [diff] [blame] | 165 | */ |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 166 | BOOL MODULE_DllProcessAttach( WINE_MODREF *wm, LPVOID lpReserved ) |
Ulrich Weigand | a3527cf | 1998-10-11 19:31:10 +0000 | [diff] [blame] | 167 | { |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 168 | BOOL retv = TRUE; |
| 169 | int i; |
| 170 | assert( wm ); |
Ulrich Weigand | a3527cf | 1998-10-11 19:31:10 +0000 | [diff] [blame] | 171 | |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 172 | /* prevent infinite recursion in case of cyclical dependencies */ |
| 173 | if ( ( wm->flags & WINE_MODREF_MARKER ) |
| 174 | || ( wm->flags & WINE_MODREF_PROCESS_ATTACHED ) ) |
| 175 | return retv; |
| 176 | |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 177 | TRACE_(module)("(%s,%p) - START\n", |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 178 | wm->modname, lpReserved ); |
Ulrich Weigand | a3527cf | 1998-10-11 19:31:10 +0000 | [diff] [blame] | 179 | |
| 180 | /* Tag current MODREF to prevent recursive loop */ |
Ulrich Weigand | e469a58 | 1999-03-27 16:45:57 +0000 | [diff] [blame] | 181 | wm->flags |= WINE_MODREF_MARKER; |
Ulrich Weigand | a3527cf | 1998-10-11 19:31:10 +0000 | [diff] [blame] | 182 | |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 183 | /* Recursively attach all DLLs this one depends on */ |
| 184 | for ( i = 0; retv && i < wm->nDeps; i++ ) |
| 185 | if ( wm->deps[i] ) |
| 186 | retv = MODULE_DllProcessAttach( wm->deps[i], lpReserved ); |
| 187 | |
| 188 | /* Call DLL entry point */ |
| 189 | if ( retv ) |
Ulrich Weigand | a3527cf | 1998-10-11 19:31:10 +0000 | [diff] [blame] | 190 | { |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 191 | retv = MODULE_InitDll( wm, DLL_PROCESS_ATTACH, lpReserved ); |
| 192 | if ( retv ) |
Ulrich Weigand | e469a58 | 1999-03-27 16:45:57 +0000 | [diff] [blame] | 193 | wm->flags |= WINE_MODREF_PROCESS_ATTACHED; |
Kevin Holbrook | a8f8bef | 1999-04-18 09:33:20 +0000 | [diff] [blame] | 194 | } |
Ulrich Weigand | e469a58 | 1999-03-27 16:45:57 +0000 | [diff] [blame] | 195 | |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 196 | /* Re-insert MODREF at head of list */ |
| 197 | if ( retv && wm->prev ) |
Kevin Holbrook | a8f8bef | 1999-04-18 09:33:20 +0000 | [diff] [blame] | 198 | { |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 199 | wm->prev->next = wm->next; |
| 200 | if ( wm->next ) wm->next->prev = wm->prev; |
| 201 | |
| 202 | wm->prev = NULL; |
| 203 | wm->next = PROCESS_Current()->modref_list; |
| 204 | PROCESS_Current()->modref_list = wm->next->prev = wm; |
Kevin Holbrook | a8f8bef | 1999-04-18 09:33:20 +0000 | [diff] [blame] | 205 | } |
Ulrich Weigand | e469a58 | 1999-03-27 16:45:57 +0000 | [diff] [blame] | 206 | |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 207 | /* Remove recursion flag */ |
| 208 | wm->flags &= ~WINE_MODREF_MARKER; |
Ulrich Weigand | e469a58 | 1999-03-27 16:45:57 +0000 | [diff] [blame] | 209 | |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 210 | TRACE_(module)("(%s,%p) - END\n", |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 211 | wm->modname, lpReserved ); |
Ulrich Weigand | e469a58 | 1999-03-27 16:45:57 +0000 | [diff] [blame] | 212 | |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 213 | return retv; |
Ulrich Weigand | ebc543c | 1998-10-23 09:37:23 +0000 | [diff] [blame] | 214 | } |
Ulrich Weigand | a3527cf | 1998-10-11 19:31:10 +0000 | [diff] [blame] | 215 | |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 216 | /************************************************************************* |
| 217 | * MODULE_DllProcessDetach |
| 218 | * |
| 219 | * Send DLL process detach notifications. See the comment about calling |
| 220 | * sequence at MODULE_DllProcessAttach. Unless the bForceDetach flag |
| 221 | * is set, only DLLs with zero refcount are notified. |
| 222 | * |
| 223 | * NOTE: Assumes that the process critical section is held! |
| 224 | * |
| 225 | */ |
| 226 | void MODULE_DllProcessDetach( BOOL bForceDetach, LPVOID lpReserved ) |
Ulrich Weigand | ebc543c | 1998-10-23 09:37:23 +0000 | [diff] [blame] | 227 | { |
Ulrich Weigand | ebc543c | 1998-10-23 09:37:23 +0000 | [diff] [blame] | 228 | WINE_MODREF *wm; |
| 229 | |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 230 | do |
| 231 | { |
| 232 | for ( wm = PROCESS_Current()->modref_list; wm; wm = wm->next ) |
Ulrich Weigand | ebc543c | 1998-10-23 09:37:23 +0000 | [diff] [blame] | 233 | { |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 234 | /* Check whether to detach this DLL */ |
| 235 | if ( !(wm->flags & WINE_MODREF_PROCESS_ATTACHED) ) |
| 236 | continue; |
| 237 | if ( wm->refCount > 0 && !bForceDetach ) |
| 238 | continue; |
| 239 | |
| 240 | /* Call detach notification */ |
| 241 | wm->flags &= ~WINE_MODREF_PROCESS_ATTACHED; |
| 242 | MODULE_InitDll( wm, DLL_PROCESS_DETACH, lpReserved ); |
| 243 | |
| 244 | /* Restart at head of WINE_MODREF list, as entries might have |
| 245 | been added and/or removed while performing the call ... */ |
Ulrich Weigand | ebc543c | 1998-10-23 09:37:23 +0000 | [diff] [blame] | 246 | break; |
Ulrich Weigand | a3527cf | 1998-10-11 19:31:10 +0000 | [diff] [blame] | 247 | } |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 248 | } while ( wm ); |
| 249 | } |
Ulrich Weigand | ebc543c | 1998-10-23 09:37:23 +0000 | [diff] [blame] | 250 | |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 251 | /************************************************************************* |
| 252 | * MODULE_DllThreadAttach |
| 253 | * |
| 254 | * Send DLL thread attach notifications. These are sent in the |
| 255 | * reverse sequence of process detach notification. |
| 256 | * |
| 257 | */ |
| 258 | void MODULE_DllThreadAttach( LPVOID lpReserved ) |
| 259 | { |
| 260 | WINE_MODREF *wm; |
| 261 | |
| 262 | EnterCriticalSection( &PROCESS_Current()->crit_section ); |
| 263 | |
| 264 | for ( wm = PROCESS_Current()->modref_list; wm; wm = wm->next ) |
| 265 | if ( !wm->next ) |
| 266 | break; |
| 267 | |
| 268 | for ( ; wm; wm = wm->prev ) |
Ulrich Weigand | ebc543c | 1998-10-23 09:37:23 +0000 | [diff] [blame] | 269 | { |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 270 | if ( !(wm->flags & WINE_MODREF_PROCESS_ATTACHED) ) |
| 271 | continue; |
| 272 | if ( wm->flags & WINE_MODREF_NO_DLL_CALLS ) |
| 273 | continue; |
Ulrich Weigand | e469a58 | 1999-03-27 16:45:57 +0000 | [diff] [blame] | 274 | |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 275 | MODULE_InitDll( wm, DLL_THREAD_ATTACH, lpReserved ); |
Ulrich Weigand | ebc543c | 1998-10-23 09:37:23 +0000 | [diff] [blame] | 276 | } |
| 277 | |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 278 | LeaveCriticalSection( &PROCESS_Current()->crit_section ); |
| 279 | } |
Ulrich Weigand | ebc543c | 1998-10-23 09:37:23 +0000 | [diff] [blame] | 280 | |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 281 | /************************************************************************* |
| 282 | * MODULE_DllThreadDetach |
| 283 | * |
| 284 | * Send DLL thread detach notifications. These are sent in the |
| 285 | * same sequence as process detach notification. |
| 286 | * |
| 287 | */ |
| 288 | void MODULE_DllThreadDetach( LPVOID lpReserved ) |
| 289 | { |
| 290 | WINE_MODREF *wm; |
| 291 | |
| 292 | EnterCriticalSection( &PROCESS_Current()->crit_section ); |
| 293 | |
| 294 | for ( wm = PROCESS_Current()->modref_list; wm; wm = wm->next ) |
| 295 | { |
| 296 | if ( !(wm->flags & WINE_MODREF_PROCESS_ATTACHED) ) |
| 297 | continue; |
| 298 | if ( wm->flags & WINE_MODREF_NO_DLL_CALLS ) |
| 299 | continue; |
| 300 | |
| 301 | MODULE_InitDll( wm, DLL_THREAD_DETACH, lpReserved ); |
| 302 | } |
| 303 | |
Ulrich Weigand | 1d90d69 | 1999-02-24 14:27:07 +0000 | [diff] [blame] | 304 | LeaveCriticalSection( &PROCESS_Current()->crit_section ); |
Ulrich Weigand | a3527cf | 1998-10-11 19:31:10 +0000 | [diff] [blame] | 305 | } |
| 306 | |
Ulrich Weigand | e469a58 | 1999-03-27 16:45:57 +0000 | [diff] [blame] | 307 | /**************************************************************************** |
| 308 | * DisableThreadLibraryCalls (KERNEL32.74) |
| 309 | * |
| 310 | * Don't call DllEntryPoint for DLL_THREAD_{ATTACH,DETACH} if set. |
| 311 | */ |
| 312 | BOOL WINAPI DisableThreadLibraryCalls( HMODULE hModule ) |
| 313 | { |
Bertho Stultiens | 1b34697 | 1999-04-11 14:52:24 +0000 | [diff] [blame] | 314 | WINE_MODREF *wm; |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 315 | BOOL retval = TRUE; |
Ulrich Weigand | e469a58 | 1999-03-27 16:45:57 +0000 | [diff] [blame] | 316 | |
| 317 | EnterCriticalSection( &PROCESS_Current()->crit_section ); |
Ulrich Weigand | e469a58 | 1999-03-27 16:45:57 +0000 | [diff] [blame] | 318 | |
Bertho Stultiens | 1b34697 | 1999-04-11 14:52:24 +0000 | [diff] [blame] | 319 | wm = MODULE32_LookupHMODULE( hModule ); |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 320 | if ( !wm ) |
| 321 | retval = FALSE; |
| 322 | else |
| 323 | wm->flags |= WINE_MODREF_NO_DLL_CALLS; |
| 324 | |
Ulrich Weigand | e469a58 | 1999-03-27 16:45:57 +0000 | [diff] [blame] | 325 | LeaveCriticalSection( &PROCESS_Current()->crit_section ); |
| 326 | |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 327 | return retval; |
Ulrich Weigand | e469a58 | 1999-03-27 16:45:57 +0000 | [diff] [blame] | 328 | } |
| 329 | |
Alexandre Julliard | a2f2e01 | 1995-06-06 16:40:35 +0000 | [diff] [blame] | 330 | |
| 331 | /*********************************************************************** |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 332 | * MODULE_CreateDummyModule |
| 333 | * |
| 334 | * Create a dummy NE module for Win32 or Winelib. |
| 335 | */ |
Ulrich Weigand | e7957d6 | 1999-11-10 19:45:56 +0000 | [diff] [blame] | 336 | HMODULE MODULE_CreateDummyModule( const OFSTRUCT *ofs, LPCSTR modName, WORD version ) |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 337 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 338 | HMODULE hModule; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 339 | NE_MODULE *pModule; |
| 340 | SEGTABLEENTRY *pSegment; |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 341 | char *pStr,*s; |
Alexandre Julliard | 17216f5 | 1997-10-12 16:30:17 +0000 | [diff] [blame] | 342 | int len; |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 343 | const char* basename; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 344 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 345 | INT of_size = sizeof(OFSTRUCT) - sizeof(ofs->szPathName) |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 346 | + strlen(ofs->szPathName) + 1; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 347 | INT size = sizeof(NE_MODULE) + |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 348 | /* loaded file info */ |
| 349 | of_size + |
| 350 | /* segment table: DS,CS */ |
| 351 | 2 * sizeof(SEGTABLEENTRY) + |
| 352 | /* name table */ |
| 353 | 9 + |
| 354 | /* several empty tables */ |
| 355 | 8; |
| 356 | |
| 357 | hModule = GlobalAlloc16( GMEM_MOVEABLE | GMEM_ZEROINIT, size ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 358 | if (!hModule) return (HMODULE)11; /* invalid exe */ |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 359 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 360 | FarSetOwner16( hModule, hModule ); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 361 | pModule = (NE_MODULE *)GlobalLock16( hModule ); |
| 362 | |
| 363 | /* Set all used entries */ |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 364 | pModule->magic = IMAGE_OS2_SIGNATURE; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 365 | pModule->count = 1; |
| 366 | pModule->next = 0; |
| 367 | pModule->flags = 0; |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 368 | pModule->dgroup = 0; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 369 | pModule->ss = 1; |
| 370 | pModule->cs = 2; |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 371 | pModule->heap_size = 0; |
| 372 | pModule->stack_size = 0; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 373 | pModule->seg_count = 2; |
| 374 | pModule->modref_count = 0; |
| 375 | pModule->nrname_size = 0; |
| 376 | pModule->fileinfo = sizeof(NE_MODULE); |
| 377 | pModule->os_flags = NE_OSFLAGS_WINDOWS; |
Ulrich Weigand | e7957d6 | 1999-11-10 19:45:56 +0000 | [diff] [blame] | 378 | pModule->expected_version = version; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 379 | pModule->self = hModule; |
| 380 | |
| 381 | /* Set loaded file information */ |
| 382 | memcpy( pModule + 1, ofs, of_size ); |
| 383 | ((OFSTRUCT *)(pModule+1))->cBytes = of_size - 1; |
| 384 | |
| 385 | pSegment = (SEGTABLEENTRY*)((char*)(pModule + 1) + of_size); |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 386 | pModule->seg_table = (int)pSegment - (int)pModule; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 387 | /* Data segment */ |
| 388 | pSegment->size = 0; |
| 389 | pSegment->flags = NE_SEGFLAGS_DATA; |
| 390 | pSegment->minsize = 0x1000; |
| 391 | pSegment++; |
| 392 | /* Code segment */ |
| 393 | pSegment->flags = 0; |
| 394 | pSegment++; |
| 395 | |
| 396 | /* Module name */ |
| 397 | pStr = (char *)pSegment; |
| 398 | pModule->name_table = (int)pStr - (int)pModule; |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 399 | if ( modName ) |
| 400 | basename = modName; |
| 401 | else |
| 402 | { |
| 403 | basename = strrchr(ofs->szPathName,'\\'); |
| 404 | if (!basename) basename = ofs->szPathName; |
| 405 | else basename++; |
| 406 | } |
Alexandre Julliard | 17216f5 | 1997-10-12 16:30:17 +0000 | [diff] [blame] | 407 | len = strlen(basename); |
| 408 | if ((s = strchr(basename,'.'))) len = s - basename; |
| 409 | if (len > 8) len = 8; |
| 410 | *pStr = len; |
| 411 | strncpy( pStr+1, basename, len ); |
| 412 | if (len < 8) pStr[len+1] = 0; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 413 | pStr += 9; |
| 414 | |
| 415 | /* All tables zero terminated */ |
| 416 | pModule->res_table = pModule->import_table = pModule->entry_table = |
| 417 | (int)pStr - (int)pModule; |
| 418 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 419 | NE_RegisterModule( pModule ); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 420 | return hModule; |
| 421 | } |
| 422 | |
| 423 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 424 | /********************************************************************** |
| 425 | * MODULE_FindModule32 |
| 426 | * |
| 427 | * Find a (loaded) win32 module depending on path |
| 428 | * The handling of '.' is a bit weird, but we need it that way, |
| 429 | * for sometimes the programs use '<name>.exe' and '<name>.dll' and |
| 430 | * this is the only way to differentiate. (mainly hypertrm.exe) |
| 431 | * |
| 432 | * RETURNS |
| 433 | * the module handle if found |
| 434 | * 0 if not |
| 435 | */ |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 436 | WINE_MODREF *MODULE_FindModule( |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 437 | LPCSTR path /* [in] pathname of module/library to be found */ |
| 438 | ) { |
| 439 | LPSTR filename; |
| 440 | LPSTR dotptr; |
| 441 | WINE_MODREF *wm; |
| 442 | |
| 443 | if (!(filename = strrchr( path, '\\' ))) |
Ulrich Weigand | 1d90d69 | 1999-02-24 14:27:07 +0000 | [diff] [blame] | 444 | filename = HEAP_strdupA( GetProcessHeap(), 0, path ); |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 445 | else |
Ulrich Weigand | 1d90d69 | 1999-02-24 14:27:07 +0000 | [diff] [blame] | 446 | filename = HEAP_strdupA( GetProcessHeap(), 0, filename+1 ); |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 447 | dotptr=strrchr(filename,'.'); |
| 448 | |
Ulrich Weigand | 1d90d69 | 1999-02-24 14:27:07 +0000 | [diff] [blame] | 449 | for ( wm = PROCESS_Current()->modref_list; wm; wm=wm->next ) { |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 450 | LPSTR xmodname,xdotptr; |
| 451 | |
| 452 | assert (wm->modname); |
Ulrich Weigand | 1d90d69 | 1999-02-24 14:27:07 +0000 | [diff] [blame] | 453 | xmodname = HEAP_strdupA( GetProcessHeap(), 0, wm->modname ); |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 454 | xdotptr=strrchr(xmodname,'.'); |
| 455 | if ( (xdotptr && !dotptr) || |
| 456 | (!xdotptr && dotptr) |
| 457 | ) { |
| 458 | if (dotptr) *dotptr = '\0'; |
| 459 | if (xdotptr) *xdotptr = '\0'; |
| 460 | } |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 461 | if (!strcasecmp( filename, xmodname)) { |
Ulrich Weigand | 1d90d69 | 1999-02-24 14:27:07 +0000 | [diff] [blame] | 462 | HeapFree( GetProcessHeap(), 0, filename ); |
| 463 | HeapFree( GetProcessHeap(), 0, xmodname ); |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 464 | return wm; |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 465 | } |
| 466 | if (dotptr) *dotptr='.'; |
| 467 | /* FIXME: add paths, shortname */ |
Ulrich Weigand | 1d90d69 | 1999-02-24 14:27:07 +0000 | [diff] [blame] | 468 | HeapFree( GetProcessHeap(), 0, xmodname ); |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 469 | } |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 470 | /* if that fails, try looking for the filename... */ |
Ulrich Weigand | 1d90d69 | 1999-02-24 14:27:07 +0000 | [diff] [blame] | 471 | for ( wm = PROCESS_Current()->modref_list; wm; wm=wm->next ) { |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 472 | LPSTR xlname,xdotptr; |
| 473 | |
| 474 | assert (wm->longname); |
Alexander Larsson | d235b13 | 1998-10-11 13:59:08 +0000 | [diff] [blame] | 475 | xlname = strrchr(wm->longname,'\\'); |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 476 | if (!xlname) |
| 477 | xlname = wm->longname; |
| 478 | else |
| 479 | xlname++; |
Ulrich Weigand | 1d90d69 | 1999-02-24 14:27:07 +0000 | [diff] [blame] | 480 | xlname = HEAP_strdupA( GetProcessHeap(), 0, xlname ); |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 481 | xdotptr=strrchr(xlname,'.'); |
| 482 | if ( (xdotptr && !dotptr) || |
| 483 | (!xdotptr && dotptr) |
| 484 | ) { |
| 485 | if (dotptr) *dotptr = '\0'; |
| 486 | if (xdotptr) *xdotptr = '\0'; |
| 487 | } |
| 488 | if (!strcasecmp( filename, xlname)) { |
Ulrich Weigand | 1d90d69 | 1999-02-24 14:27:07 +0000 | [diff] [blame] | 489 | HeapFree( GetProcessHeap(), 0, filename ); |
| 490 | HeapFree( GetProcessHeap(), 0, xlname ); |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 491 | return wm; |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 492 | } |
| 493 | if (dotptr) *dotptr='.'; |
| 494 | /* FIXME: add paths, shortname */ |
Ulrich Weigand | 1d90d69 | 1999-02-24 14:27:07 +0000 | [diff] [blame] | 495 | HeapFree( GetProcessHeap(), 0, xlname ); |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 496 | } |
Ulrich Weigand | 1d90d69 | 1999-02-24 14:27:07 +0000 | [diff] [blame] | 497 | HeapFree( GetProcessHeap(), 0, filename ); |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 498 | return NULL; |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 499 | } |
| 500 | |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 501 | /*********************************************************************** |
| 502 | * MODULE_GetBinaryType |
| 503 | * |
| 504 | * The GetBinaryType function determines whether a file is executable |
| 505 | * or not and if it is it returns what type of executable it is. |
| 506 | * The type of executable is a property that determines in which |
| 507 | * subsystem an executable file runs under. |
| 508 | * |
| 509 | * Binary types returned: |
| 510 | * SCS_32BIT_BINARY: A Win32 based application |
| 511 | * SCS_DOS_BINARY: An MS-Dos based application |
| 512 | * SCS_WOW_BINARY: A Win16 based application |
| 513 | * SCS_PIF_BINARY: A PIF file that executes an MS-Dos based app |
| 514 | * SCS_POSIX_BINARY: A POSIX based application ( Not implemented ) |
Ulrich Weigand | d523e4d | 1999-06-07 17:37:43 +0000 | [diff] [blame] | 515 | * SCS_OS216_BINARY: A 16bit OS/2 based application |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 516 | * |
| 517 | * Returns TRUE if the file is an executable in which case |
| 518 | * the value pointed by lpBinaryType is set. |
| 519 | * Returns FALSE if the file is not an executable or if the function fails. |
| 520 | * |
| 521 | * To do so it opens the file and reads in the header information |
| 522 | * if the extended header information is not presend it will |
| 523 | * assume that that the file is a DOS executable. |
| 524 | * If the extended header information is present it will |
| 525 | * determine if the file is an 16 or 32 bit Windows executable |
| 526 | * by check the flags in the header. |
| 527 | * |
| 528 | * Note that .COM and .PIF files are only recognized by their |
| 529 | * file name extension; but Windows does it the same way ... |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 530 | */ |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 531 | static BOOL MODULE_GetBinaryType( HFILE hfile, OFSTRUCT *ofs, |
| 532 | LPDWORD lpBinaryType ) |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 533 | { |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 534 | IMAGE_DOS_HEADER mz_header; |
| 535 | char magic[4], *ptr; |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 536 | |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 537 | /* Seek to the start of the file and read the DOS header information. |
| 538 | */ |
| 539 | if ( _llseek( hfile, 0, SEEK_SET ) >= 0 && |
| 540 | _lread( hfile, &mz_header, sizeof(mz_header) ) == sizeof(mz_header) ) |
Ulrich Weigand | 7df1fbb | 1998-11-01 18:01:53 +0000 | [diff] [blame] | 541 | { |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 542 | /* Now that we have the header check the e_magic field |
| 543 | * to see if this is a dos image. |
| 544 | */ |
| 545 | if ( mz_header.e_magic == IMAGE_DOS_SIGNATURE ) |
| 546 | { |
| 547 | BOOL lfanewValid = FALSE; |
| 548 | /* We do have a DOS image so we will now try to seek into |
| 549 | * the file by the amount indicated by the field |
| 550 | * "Offset to extended header" and read in the |
| 551 | * "magic" field information at that location. |
| 552 | * This will tell us if there is more header information |
| 553 | * to read or not. |
| 554 | */ |
| 555 | /* But before we do we will make sure that header |
| 556 | * structure encompasses the "Offset to extended header" |
| 557 | * field. |
| 558 | */ |
| 559 | if ( (mz_header.e_cparhdr<<4) >= sizeof(IMAGE_DOS_HEADER) ) |
Alexandre Julliard | 8c81b743 | 1999-10-13 15:47:38 +0000 | [diff] [blame] | 560 | if ( ( mz_header.e_crlc == 0 ) || |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 561 | ( mz_header.e_lfarlc >= sizeof(IMAGE_DOS_HEADER) ) ) |
| 562 | if ( mz_header.e_lfanew >= sizeof(IMAGE_DOS_HEADER) && |
| 563 | _llseek( hfile, mz_header.e_lfanew, SEEK_SET ) >= 0 && |
| 564 | _lread( hfile, magic, sizeof(magic) ) == sizeof(magic) ) |
| 565 | lfanewValid = TRUE; |
| 566 | |
| 567 | if ( !lfanewValid ) |
| 568 | { |
| 569 | /* If we cannot read this "extended header" we will |
| 570 | * assume that we have a simple DOS executable. |
| 571 | */ |
| 572 | *lpBinaryType = SCS_DOS_BINARY; |
| 573 | return TRUE; |
| 574 | } |
| 575 | else |
| 576 | { |
| 577 | /* Reading the magic field succeeded so |
| 578 | * we will try to determine what type it is. |
| 579 | */ |
| 580 | if ( *(DWORD*)magic == IMAGE_NT_SIGNATURE ) |
| 581 | { |
| 582 | /* This is an NT signature. |
| 583 | */ |
| 584 | *lpBinaryType = SCS_32BIT_BINARY; |
| 585 | return TRUE; |
| 586 | } |
| 587 | else if ( *(WORD*)magic == IMAGE_OS2_SIGNATURE ) |
| 588 | { |
| 589 | /* The IMAGE_OS2_SIGNATURE indicates that the |
| 590 | * "extended header is a Windows executable (NE) |
Ulrich Weigand | d523e4d | 1999-06-07 17:37:43 +0000 | [diff] [blame] | 591 | * header." This can mean either a 16-bit OS/2 |
| 592 | * or a 16-bit Windows or even a DOS program |
| 593 | * (running under a DOS extender). To decide |
| 594 | * which, we'll have to read the NE header. |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 595 | */ |
Ulrich Weigand | d523e4d | 1999-06-07 17:37:43 +0000 | [diff] [blame] | 596 | |
| 597 | IMAGE_OS2_HEADER ne; |
| 598 | if ( _llseek( hfile, mz_header.e_lfanew, SEEK_SET ) >= 0 && |
| 599 | _lread( hfile, &ne, sizeof(ne) ) == sizeof(ne) ) |
| 600 | { |
| 601 | switch ( ne.operating_system ) |
| 602 | { |
| 603 | case 2: *lpBinaryType = SCS_WOW_BINARY; return TRUE; |
| 604 | case 5: *lpBinaryType = SCS_DOS_BINARY; return TRUE; |
| 605 | default: *lpBinaryType = SCS_OS216_BINARY; return TRUE; |
| 606 | } |
| 607 | } |
| 608 | /* Couldn't read header, so abort. */ |
| 609 | return FALSE; |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 610 | } |
| 611 | else |
| 612 | { |
| 613 | /* Unknown extended header, so abort. |
| 614 | */ |
| 615 | return FALSE; |
| 616 | } |
| 617 | } |
| 618 | } |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 619 | } |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 620 | |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 621 | /* If we get here, we don't even have a correct MZ header. |
| 622 | * Try to check the file extension for known types ... |
| 623 | */ |
| 624 | ptr = strrchr( ofs->szPathName, '.' ); |
| 625 | if ( ptr && !strchr( ptr, '\\' ) && !strchr( ptr, '/' ) ) |
| 626 | { |
| 627 | if ( !lstrcmpiA( ptr, ".COM" ) ) |
| 628 | { |
| 629 | *lpBinaryType = SCS_DOS_BINARY; |
| 630 | return TRUE; |
| 631 | } |
Alexandre Julliard | a2f2e01 | 1995-06-06 16:40:35 +0000 | [diff] [blame] | 632 | |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 633 | if ( !lstrcmpiA( ptr, ".PIF" ) ) |
| 634 | { |
| 635 | *lpBinaryType = SCS_PIF_BINARY; |
| 636 | return TRUE; |
| 637 | } |
| 638 | } |
Alexandre Julliard | 1e37a18 | 1996-08-18 16:21:52 +0000 | [diff] [blame] | 639 | |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 640 | return FALSE; |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 641 | } |
| 642 | |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 643 | /*********************************************************************** |
| 644 | * GetBinaryTypeA [KERNEL32.280] |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 645 | */ |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 646 | BOOL WINAPI GetBinaryTypeA( LPCSTR lpApplicationName, LPDWORD lpBinaryType ) |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 647 | { |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 648 | BOOL ret = FALSE; |
| 649 | HFILE hfile; |
| 650 | OFSTRUCT ofs; |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 651 | |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 652 | TRACE_(win32)("%s\n", lpApplicationName ); |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 653 | |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 654 | /* Sanity check. |
| 655 | */ |
| 656 | if ( lpApplicationName == NULL || lpBinaryType == NULL ) |
| 657 | return FALSE; |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 658 | |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 659 | /* Open the file indicated by lpApplicationName for reading. |
| 660 | */ |
| 661 | if ( (hfile = OpenFile( lpApplicationName, &ofs, OF_READ )) == HFILE_ERROR ) |
| 662 | return FALSE; |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 663 | |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 664 | /* Check binary type |
| 665 | */ |
| 666 | ret = MODULE_GetBinaryType( hfile, &ofs, lpBinaryType ); |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 667 | |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 668 | /* Close the file. |
| 669 | */ |
| 670 | CloseHandle( hfile ); |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 671 | |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 672 | return ret; |
| 673 | } |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 674 | |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 675 | /*********************************************************************** |
| 676 | * GetBinaryTypeW [KERNEL32.281] |
| 677 | */ |
| 678 | BOOL WINAPI GetBinaryTypeW( LPCWSTR lpApplicationName, LPDWORD lpBinaryType ) |
| 679 | { |
| 680 | BOOL ret = FALSE; |
| 681 | LPSTR strNew = NULL; |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 682 | |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 683 | TRACE_(win32)("%s\n", debugstr_w(lpApplicationName) ); |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 684 | |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 685 | /* Sanity check. |
| 686 | */ |
| 687 | if ( lpApplicationName == NULL || lpBinaryType == NULL ) |
| 688 | return FALSE; |
| 689 | |
| 690 | /* Convert the wide string to a ascii string. |
| 691 | */ |
| 692 | strNew = HEAP_strdupWtoA( GetProcessHeap(), 0, lpApplicationName ); |
| 693 | |
| 694 | if ( strNew != NULL ) |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 695 | { |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 696 | ret = GetBinaryTypeA( strNew, lpBinaryType ); |
| 697 | |
| 698 | /* Free the allocated string. |
| 699 | */ |
| 700 | HeapFree( GetProcessHeap(), 0, strNew ); |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 701 | } |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 702 | |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 703 | return ret; |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 704 | } |
| 705 | |
Alexandre Julliard | 491502b | 1997-11-01 19:08:16 +0000 | [diff] [blame] | 706 | /********************************************************************** |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 707 | * MODULE_CreateUnixProcess |
| 708 | */ |
| 709 | static BOOL MODULE_CreateUnixProcess( LPCSTR filename, LPCSTR lpCmdLine, |
| 710 | LPSTARTUPINFOA lpStartupInfo, |
| 711 | LPPROCESS_INFORMATION lpProcessInfo, |
| 712 | BOOL useWine ) |
| 713 | { |
| 714 | DOS_FULL_NAME full_name; |
| 715 | const char *unixfilename = filename; |
| 716 | const char *argv[256], **argptr; |
Uwe Bonnes | 20f7ef7 | 1999-09-28 13:08:36 +0000 | [diff] [blame] | 717 | char *cmdline = NULL; |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 718 | BOOL iconic = FALSE; |
| 719 | |
| 720 | /* Get Unix file name and iconic flag */ |
| 721 | |
| 722 | if ( lpStartupInfo->dwFlags & STARTF_USESHOWWINDOW ) |
| 723 | if ( lpStartupInfo->wShowWindow == SW_SHOWMINIMIZED |
| 724 | || lpStartupInfo->wShowWindow == SW_SHOWMINNOACTIVE ) |
| 725 | iconic = TRUE; |
| 726 | |
Dave Pickles | fec2329 | 1999-06-26 11:48:26 +0000 | [diff] [blame] | 727 | /* Build argument list */ |
| 728 | |
| 729 | argptr = argv; |
| 730 | if ( !useWine ) |
| 731 | { |
Uwe Bonnes | 20f7ef7 | 1999-09-28 13:08:36 +0000 | [diff] [blame] | 732 | char *p; |
| 733 | p = cmdline = strdup(lpCmdLine); |
Alexandre Julliard | 9482242 | 1999-09-22 15:18:52 +0000 | [diff] [blame] | 734 | if (strchr(filename, '/') || strchr(filename, ':') || strchr(filename, '\\')) |
| 735 | { |
| 736 | if ( DOSFS_GetFullName( filename, TRUE, &full_name ) ) |
| 737 | unixfilename = full_name.long_name; |
| 738 | } |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 739 | *argptr++ = unixfilename; |
| 740 | if (iconic) *argptr++ = "-iconic"; |
| 741 | while (1) |
| 742 | { |
| 743 | while (*p && (*p == ' ' || *p == '\t')) *p++ = '\0'; |
| 744 | if (!*p) break; |
| 745 | *argptr++ = p; |
| 746 | while (*p && *p != ' ' && *p != '\t') p++; |
| 747 | } |
| 748 | } |
| 749 | else |
| 750 | { |
| 751 | *argptr++ = "wine"; |
| 752 | if (iconic) *argptr++ = "-iconic"; |
| 753 | *argptr++ = lpCmdLine; |
| 754 | } |
| 755 | *argptr++ = 0; |
| 756 | |
| 757 | /* Fork and execute */ |
| 758 | |
| 759 | if ( !fork() ) |
| 760 | { |
| 761 | /* Note: don't use Wine routines here, as this process |
| 762 | has not been correctly initialized! */ |
| 763 | |
| 764 | execvp( argv[0], (char**)argv ); |
| 765 | |
| 766 | /* Failed ! */ |
| 767 | if ( useWine ) |
| 768 | fprintf( stderr, "CreateProcess: can't exec 'wine %s'\n", |
| 769 | lpCmdLine ); |
| 770 | exit( 1 ); |
| 771 | } |
| 772 | |
| 773 | /* Fake success return value */ |
| 774 | |
| 775 | memset( lpProcessInfo, '\0', sizeof( *lpProcessInfo ) ); |
| 776 | lpProcessInfo->hProcess = INVALID_HANDLE_VALUE; |
| 777 | lpProcessInfo->hThread = INVALID_HANDLE_VALUE; |
Uwe Bonnes | 20f7ef7 | 1999-09-28 13:08:36 +0000 | [diff] [blame] | 778 | if (cmdline) free(cmdline); |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 779 | |
| 780 | SetLastError( ERROR_SUCCESS ); |
| 781 | return TRUE; |
| 782 | } |
| 783 | |
| 784 | /*********************************************************************** |
| 785 | * WinExec16 (KERNEL.166) |
| 786 | */ |
| 787 | HINSTANCE16 WINAPI WinExec16( LPCSTR lpCmdLine, UINT16 nCmdShow ) |
| 788 | { |
Ulrich Weigand | 6ce4006 | 1999-05-03 09:22:55 +0000 | [diff] [blame] | 789 | HINSTANCE16 hInst; |
| 790 | |
| 791 | SYSLEVEL_ReleaseWin16Lock(); |
| 792 | hInst = WinExec( lpCmdLine, nCmdShow ); |
| 793 | SYSLEVEL_RestoreWin16Lock(); |
| 794 | |
| 795 | return hInst; |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | /*********************************************************************** |
| 799 | * WinExec (KERNEL32.566) |
| 800 | */ |
| 801 | HINSTANCE WINAPI WinExec( LPCSTR lpCmdLine, UINT nCmdShow ) |
| 802 | { |
| 803 | LOADPARAMS params; |
| 804 | UINT16 paramCmdShow[2]; |
| 805 | |
| 806 | if (!lpCmdLine) |
| 807 | return 2; /* File not found */ |
| 808 | |
| 809 | /* Set up LOADPARAMS buffer for LoadModule */ |
| 810 | |
| 811 | memset( ¶ms, '\0', sizeof(params) ); |
| 812 | params.lpCmdLine = (LPSTR)lpCmdLine; |
| 813 | params.lpCmdShow = paramCmdShow; |
| 814 | params.lpCmdShow[0] = 2; |
| 815 | params.lpCmdShow[1] = nCmdShow; |
| 816 | |
| 817 | /* Now load the executable file */ |
| 818 | |
| 819 | return LoadModule( NULL, ¶ms ); |
| 820 | } |
| 821 | |
| 822 | /********************************************************************** |
| 823 | * LoadModule (KERNEL32.499) |
Alexandre Julliard | 491502b | 1997-11-01 19:08:16 +0000 | [diff] [blame] | 824 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 825 | HINSTANCE WINAPI LoadModule( LPCSTR name, LPVOID paramBlock ) |
Alexandre Julliard | 491502b | 1997-11-01 19:08:16 +0000 | [diff] [blame] | 826 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 827 | LOADPARAMS *params = (LOADPARAMS *)paramBlock; |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 828 | PROCESS_INFORMATION info; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 829 | STARTUPINFOA startup; |
| 830 | HINSTANCE hInstance; |
| 831 | PDB *pdb; |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 832 | TDB *tdb; |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 833 | |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 834 | memset( &startup, '\0', sizeof(startup) ); |
| 835 | startup.cb = sizeof(startup); |
| 836 | startup.dwFlags = STARTF_USESHOWWINDOW; |
| 837 | startup.wShowWindow = params->lpCmdShow? params->lpCmdShow[1] : 0; |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 838 | |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 839 | if ( !CreateProcessA( name, params->lpCmdLine, |
| 840 | NULL, NULL, FALSE, 0, params->lpEnvAddress, |
| 841 | NULL, &startup, &info ) ) |
| 842 | { |
| 843 | hInstance = GetLastError(); |
| 844 | if ( hInstance < 32 ) return hInstance; |
| 845 | |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 846 | FIXME_(module)("Strange error set by CreateProcess: %d\n", hInstance ); |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 847 | return 11; |
| 848 | } |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 849 | |
Ulrich Weigand | 2aad33e | 1998-12-10 08:30:30 +0000 | [diff] [blame] | 850 | /* Get 16-bit hInstance/hTask from process */ |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 851 | pdb = PROCESS_IdToPDB( info.dwProcessId ); |
Ulrich Weigand | 2aad33e | 1998-12-10 08:30:30 +0000 | [diff] [blame] | 852 | tdb = pdb? (TDB *)GlobalLock16( pdb->task ) : NULL; |
| 853 | hInstance = tdb && tdb->hInstance? tdb->hInstance : pdb? pdb->task : 0; |
Alexandre Julliard | 481a8e2 | 1999-05-03 08:58:25 +0000 | [diff] [blame] | 854 | /* If there is no hInstance (32-bit process) return a dummy value |
| 855 | * that must be > 31 |
| 856 | * FIXME: should do this in all cases and fix Win16 callers */ |
| 857 | if (!hInstance) hInstance = 33; |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 858 | |
| 859 | /* Close off the handles */ |
| 860 | CloseHandle( info.hThread ); |
| 861 | CloseHandle( info.hProcess ); |
| 862 | |
| 863 | return hInstance; |
Alexandre Julliard | 491502b | 1997-11-01 19:08:16 +0000 | [diff] [blame] | 864 | } |
| 865 | |
Guy Albertelli | 4f6d7f3 | 1999-05-02 10:17:31 +0000 | [diff] [blame] | 866 | /************************************************************************* |
Guy Albertelli | 38d7da8 | 1999-06-06 09:04:29 +0000 | [diff] [blame] | 867 | * get_makename_token |
| 868 | * |
| 869 | * Get next blank delimited token from input string. If quoted then |
| 870 | * process till matching quote and then till blank. |
| 871 | * |
| 872 | * Returns number of characters in token (not including \0). On |
| 873 | * end of string (EOS), returns a 0. |
| 874 | * |
| 875 | * from (IO) address of start of input string to scan, updated to |
| 876 | * next non-processed character. |
| 877 | * to (IO) address of start of output string (previous token \0 |
| 878 | * char), updated to end of new output string (the \0 |
| 879 | * char). |
| 880 | */ |
| 881 | static int get_makename_token(LPCSTR *from, LPSTR *to ) |
| 882 | { |
| 883 | int len = 0; |
| 884 | LPCSTR to_old = *to; /* only used for tracing */ |
| 885 | |
| 886 | while ( **from == ' ') { |
| 887 | /* Copy leading blanks (separators between previous */ |
| 888 | /* token and this token). */ |
| 889 | **to = **from; |
| 890 | (*from)++; |
| 891 | (*to)++; |
| 892 | len++; |
| 893 | } |
| 894 | do { |
| 895 | while ( (**from != 0) && (**from != ' ') && (**from != '"') ) { |
| 896 | **to = **from; (*from)++; (*to)++; len++; |
| 897 | } |
| 898 | if ( **from == '"' ) { |
| 899 | /* Handle quoted string. */ |
| 900 | (*from)++; |
| 901 | if ( !strchr(*from, '"') ) { |
| 902 | /* fail - no closing quote. Return entire string */ |
| 903 | while ( **from != 0 ) { |
| 904 | **to = **from; (*from)++; (*to)++; len++; |
| 905 | } |
| 906 | break; |
| 907 | } |
| 908 | while( **from != '"') { |
| 909 | **to = **from; |
| 910 | len++; |
| 911 | (*to)++; |
| 912 | (*from)++; |
| 913 | } |
| 914 | (*from)++; |
| 915 | continue; |
| 916 | } |
| 917 | |
| 918 | /* either EOS or ' ' */ |
| 919 | break; |
| 920 | |
| 921 | } while (1); |
| 922 | |
| 923 | **to = 0; /* terminate output string */ |
| 924 | |
| 925 | TRACE_(module)("returning token len=%d, string=%s\n", |
| 926 | len, to_old); |
| 927 | |
| 928 | return len; |
| 929 | } |
| 930 | |
| 931 | /************************************************************************* |
| 932 | * make_lpCommandLine_name |
Guy Albertelli | 4f6d7f3 | 1999-05-02 10:17:31 +0000 | [diff] [blame] | 933 | * |
| 934 | * Try longer and longer strings from "line" to find an existing |
| 935 | * file name. Each attempt is delimited by a blank outside of quotes. |
| 936 | * Also will attempt to append ".exe" if requested and not already |
| 937 | * present. Returns the address of the remaining portion of the |
| 938 | * input line. |
| 939 | * |
| 940 | */ |
Andreas Mohr | e518f47 | 1999-02-28 19:28:44 +0000 | [diff] [blame] | 941 | |
Guy Albertelli | 38d7da8 | 1999-06-06 09:04:29 +0000 | [diff] [blame] | 942 | static BOOL make_lpCommandLine_name( LPCSTR line, LPSTR name, int namelen, |
| 943 | LPCSTR *after ) |
Andreas Mohr | e518f47 | 1999-02-28 19:28:44 +0000 | [diff] [blame] | 944 | { |
Guy Albertelli | 38d7da8 | 1999-06-06 09:04:29 +0000 | [diff] [blame] | 945 | BOOL found = TRUE; |
Guy Albertelli | 4f6d7f3 | 1999-05-02 10:17:31 +0000 | [diff] [blame] | 946 | LPCSTR from; |
Guy Albertelli | 38d7da8 | 1999-06-06 09:04:29 +0000 | [diff] [blame] | 947 | char buffer[260]; |
| 948 | DWORD retlen; |
| 949 | LPSTR to, lastpart; |
Guy Albertelli | 4f6d7f3 | 1999-05-02 10:17:31 +0000 | [diff] [blame] | 950 | |
Guy Albertelli | 4f6d7f3 | 1999-05-02 10:17:31 +0000 | [diff] [blame] | 951 | from = line; |
Guy Albertelli | 38d7da8 | 1999-06-06 09:04:29 +0000 | [diff] [blame] | 952 | to = name; |
| 953 | |
| 954 | /* scan over initial blanks if any */ |
| 955 | while ( *from == ' ') from++; |
| 956 | |
| 957 | /* get a token and append to previous data the check for existance */ |
Guy Albertelli | 4f6d7f3 | 1999-05-02 10:17:31 +0000 | [diff] [blame] | 958 | do { |
Guy Albertelli | 38d7da8 | 1999-06-06 09:04:29 +0000 | [diff] [blame] | 959 | if ( !get_makename_token( &from, &to ) ) { |
| 960 | /* EOS has occured and not found - exit */ |
| 961 | retlen = 0; |
| 962 | found = FALSE; |
| 963 | break; |
Jess Haas | 1ff60f3 | 1999-03-28 15:00:44 +0000 | [diff] [blame] | 964 | } |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 965 | TRACE_(module)("checking if file exists '%s'\n", name); |
Guy Albertelli | 38d7da8 | 1999-06-06 09:04:29 +0000 | [diff] [blame] | 966 | retlen = SearchPathA( NULL, name, ".exe", sizeof(buffer), buffer, &lastpart); |
| 967 | if ( retlen && (retlen < sizeof(buffer)) ) break; |
Guy Albertelli | 4f6d7f3 | 1999-05-02 10:17:31 +0000 | [diff] [blame] | 968 | } while (1); |
| 969 | |
Guy Albertelli | 38d7da8 | 1999-06-06 09:04:29 +0000 | [diff] [blame] | 970 | /* if we have a non-null full path name in buffer then move to output */ |
Marcus Meissner | 1ab8907 | 1999-06-13 08:39:04 +0000 | [diff] [blame] | 971 | if ( retlen ) { |
| 972 | if ( strlen(buffer) <= namelen ) { |
Guy Albertelli | 38d7da8 | 1999-06-06 09:04:29 +0000 | [diff] [blame] | 973 | strcpy( name, buffer ); |
Marcus Meissner | 1ab8907 | 1999-06-13 08:39:04 +0000 | [diff] [blame] | 974 | } else { |
Guy Albertelli | 38d7da8 | 1999-06-06 09:04:29 +0000 | [diff] [blame] | 975 | /* not enough space to return full path string */ |
| 976 | FIXME_(module)("internal string not long enough, need %d\n", |
| 977 | strlen(buffer) ); |
| 978 | } |
Marcus Meissner | 1ab8907 | 1999-06-13 08:39:04 +0000 | [diff] [blame] | 979 | } |
Guy Albertelli | 38d7da8 | 1999-06-06 09:04:29 +0000 | [diff] [blame] | 980 | |
| 981 | /* all done, indicate end of module name and then trace and exit */ |
| 982 | if (after) *after = from; |
| 983 | TRACE_(module)("%i, selected file name '%s'\n and cmdline as %s\n", |
| 984 | found, name, debugstr_a(from)); |
| 985 | return found; |
Andreas Mohr | e518f47 | 1999-02-28 19:28:44 +0000 | [diff] [blame] | 986 | } |
Guy Albertelli | 4f6d7f3 | 1999-05-02 10:17:31 +0000 | [diff] [blame] | 987 | |
| 988 | /************************************************************************* |
Guy Albertelli | 38d7da8 | 1999-06-06 09:04:29 +0000 | [diff] [blame] | 989 | * make_lpApplicationName_name |
Guy Albertelli | 4f6d7f3 | 1999-05-02 10:17:31 +0000 | [diff] [blame] | 990 | * |
| 991 | * Scan input string (the lpApplicationName) and remove any quotes |
Guy Albertelli | 38d7da8 | 1999-06-06 09:04:29 +0000 | [diff] [blame] | 992 | * if they are balanced. |
Guy Albertelli | 4f6d7f3 | 1999-05-02 10:17:31 +0000 | [diff] [blame] | 993 | * |
| 994 | */ |
| 995 | |
Guy Albertelli | 38d7da8 | 1999-06-06 09:04:29 +0000 | [diff] [blame] | 996 | static BOOL make_lpApplicationName_name( LPCSTR line, LPSTR name, int namelen) |
Guy Albertelli | 4f6d7f3 | 1999-05-02 10:17:31 +0000 | [diff] [blame] | 997 | { |
| 998 | LPCSTR from; |
| 999 | LPSTR to, to_end, to_old; |
Guy Albertelli | 38d7da8 | 1999-06-06 09:04:29 +0000 | [diff] [blame] | 1000 | DOS_FULL_NAME full_name; |
Guy Albertelli | 4f6d7f3 | 1999-05-02 10:17:31 +0000 | [diff] [blame] | 1001 | |
| 1002 | to = name; |
| 1003 | to_end = to + namelen - 1; |
| 1004 | to_old = to; |
| 1005 | |
| 1006 | while ( *line == ' ' ) line++; /* point to beginning of string */ |
| 1007 | from = line; |
| 1008 | do { |
Guy Albertelli | 38d7da8 | 1999-06-06 09:04:29 +0000 | [diff] [blame] | 1009 | /* Copy all input till end, or quote */ |
Guy Albertelli | 4f6d7f3 | 1999-05-02 10:17:31 +0000 | [diff] [blame] | 1010 | while((*from != 0) && (*from != '"') && (to < to_end)) |
| 1011 | *to++ = *from++; |
| 1012 | if (to >= to_end) { *to = 0; break; } |
| 1013 | |
| 1014 | if (*from == '"') |
| 1015 | { |
| 1016 | /* Handle quoted string. If there is a closing quote, copy all */ |
| 1017 | /* that is inside. */ |
| 1018 | from++; |
| 1019 | if (!strchr(from, '"')) |
| 1020 | { |
| 1021 | /* fail - no closing quote */ |
| 1022 | to = to_old; /* restore to previous attempt */ |
| 1023 | *to = 0; /* end string */ |
| 1024 | break; /* exit with previous attempt */ |
| 1025 | } |
| 1026 | while((*from != '"') && (to < to_end)) *to++ = *from++; |
| 1027 | if (to >= to_end) { *to = 0; break; } |
| 1028 | from++; |
| 1029 | continue; /* past quoted string, so restart from top */ |
| 1030 | } |
| 1031 | |
| 1032 | *to = 0; /* terminate output string */ |
| 1033 | to_old = to; /* save for possible use in unmatched quote case */ |
| 1034 | |
| 1035 | /* loop around keeping the blank as part of file name */ |
| 1036 | if (!*from) |
| 1037 | break; /* exit if out of input string */ |
Guy Albertelli | 4f6d7f3 | 1999-05-02 10:17:31 +0000 | [diff] [blame] | 1038 | } while (1); |
| 1039 | |
Guy Albertelli | 38d7da8 | 1999-06-06 09:04:29 +0000 | [diff] [blame] | 1040 | if (!DOSFS_GetFullName(name, TRUE, &full_name)) { |
| 1041 | TRACE_(module)("file not found '%s'\n", name ); |
| 1042 | return FALSE; |
Guy Albertelli | 4f6d7f3 | 1999-05-02 10:17:31 +0000 | [diff] [blame] | 1043 | } |
| 1044 | |
Guy Albertelli | 38d7da8 | 1999-06-06 09:04:29 +0000 | [diff] [blame] | 1045 | if (strlen(full_name.long_name) >= namelen ) { |
| 1046 | FIXME_(module)("name longer than buffer (len=%d), file=%s\n", |
| 1047 | namelen, full_name.long_name); |
| 1048 | return FALSE; |
| 1049 | } |
| 1050 | strcpy(name, full_name.long_name); |
| 1051 | |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1052 | TRACE_(module)("selected as file name '%s'\n", name ); |
Guy Albertelli | 38d7da8 | 1999-06-06 09:04:29 +0000 | [diff] [blame] | 1053 | return TRUE; |
Andreas Mohr | e518f47 | 1999-02-28 19:28:44 +0000 | [diff] [blame] | 1054 | } |
| 1055 | |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1056 | /********************************************************************** |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 1057 | * CreateProcessA (KERNEL32.171) |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1058 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1059 | BOOL WINAPI CreateProcessA( LPCSTR lpApplicationName, LPSTR lpCommandLine, |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 1060 | LPSECURITY_ATTRIBUTES lpProcessAttributes, |
| 1061 | LPSECURITY_ATTRIBUTES lpThreadAttributes, |
| 1062 | BOOL bInheritHandles, DWORD dwCreationFlags, |
| 1063 | LPVOID lpEnvironment, LPCSTR lpCurrentDirectory, |
| 1064 | LPSTARTUPINFOA lpStartupInfo, |
| 1065 | LPPROCESS_INFORMATION lpProcessInfo ) |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1066 | { |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 1067 | BOOL retv = FALSE; |
Guy Albertelli | 38d7da8 | 1999-06-06 09:04:29 +0000 | [diff] [blame] | 1068 | BOOL found_file = FALSE; |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 1069 | HFILE hFile; |
| 1070 | OFSTRUCT ofs; |
| 1071 | DWORD type; |
Dave Pickles | fec2329 | 1999-06-26 11:48:26 +0000 | [diff] [blame] | 1072 | char name[256], dummy[256]; |
Guy Albertelli | 4f6d7f3 | 1999-05-02 10:17:31 +0000 | [diff] [blame] | 1073 | LPCSTR cmdline = NULL; |
Dave Pickles | fec2329 | 1999-06-26 11:48:26 +0000 | [diff] [blame] | 1074 | LPSTR tidy_cmdline; |
| 1075 | int len = 0; |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1076 | |
| 1077 | /* Get name and command line */ |
| 1078 | |
| 1079 | if (!lpApplicationName && !lpCommandLine) |
| 1080 | { |
| 1081 | SetLastError( ERROR_FILE_NOT_FOUND ); |
| 1082 | return FALSE; |
| 1083 | } |
| 1084 | |
Dave Pickles | fec2329 | 1999-06-26 11:48:26 +0000 | [diff] [blame] | 1085 | /* Process the AppName and/or CmdLine to get module name and path */ |
Marcus Meissner | 1ab8907 | 1999-06-13 08:39:04 +0000 | [diff] [blame] | 1086 | |
| 1087 | name[0] = '\0'; |
| 1088 | |
| 1089 | if (lpApplicationName) { |
| 1090 | found_file = make_lpApplicationName_name( lpApplicationName, name, sizeof(name) ); |
Dave Pickles | fec2329 | 1999-06-26 11:48:26 +0000 | [diff] [blame] | 1091 | if (lpCommandLine) { |
| 1092 | make_lpCommandLine_name( lpCommandLine, dummy, sizeof ( dummy ), &cmdline ); |
Marcus Meissner | 1ab8907 | 1999-06-13 08:39:04 +0000 | [diff] [blame] | 1093 | } |
Dave Pickles | fec2329 | 1999-06-26 11:48:26 +0000 | [diff] [blame] | 1094 | else { |
| 1095 | cmdline = lpApplicationName; |
| 1096 | } |
| 1097 | len += strlen(lpApplicationName); |
| 1098 | } |
| 1099 | else { |
Marcus Meissner | 1ab8907 | 1999-06-13 08:39:04 +0000 | [diff] [blame] | 1100 | found_file = make_lpCommandLine_name( lpCommandLine, name, sizeof ( name ), &cmdline ); |
Dave Pickles | fec2329 | 1999-06-26 11:48:26 +0000 | [diff] [blame] | 1101 | if (lpCommandLine) len = strlen(lpCommandLine); |
| 1102 | } |
Marcus Meissner | 1ab8907 | 1999-06-13 08:39:04 +0000 | [diff] [blame] | 1103 | |
| 1104 | if ( !found_file ) { |
| 1105 | /* make an early exit if file not found - save second pass */ |
| 1106 | SetLastError( ERROR_FILE_NOT_FOUND ); |
| 1107 | return FALSE; |
| 1108 | } |
| 1109 | |
Dave Pickles | fec2329 | 1999-06-26 11:48:26 +0000 | [diff] [blame] | 1110 | len += strlen(name) + 2; |
| 1111 | tidy_cmdline = HeapAlloc( GetProcessHeap(), 0, len ); |
| 1112 | sprintf( tidy_cmdline, "\"%s\"%s", name, cmdline); |
| 1113 | |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1114 | /* Warn if unsupported features are used */ |
| 1115 | |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1116 | if (dwCreationFlags & DETACHED_PROCESS) |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1117 | FIXME_(module)("(%s,...): DETACHED_PROCESS ignored\n", name); |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1118 | if (dwCreationFlags & CREATE_NEW_CONSOLE) |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1119 | FIXME_(module)("(%s,...): CREATE_NEW_CONSOLE ignored\n", name); |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1120 | if (dwCreationFlags & NORMAL_PRIORITY_CLASS) |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1121 | FIXME_(module)("(%s,...): NORMAL_PRIORITY_CLASS ignored\n", name); |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1122 | if (dwCreationFlags & IDLE_PRIORITY_CLASS) |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1123 | FIXME_(module)("(%s,...): IDLE_PRIORITY_CLASS ignored\n", name); |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1124 | if (dwCreationFlags & HIGH_PRIORITY_CLASS) |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1125 | FIXME_(module)("(%s,...): HIGH_PRIORITY_CLASS ignored\n", name); |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1126 | if (dwCreationFlags & REALTIME_PRIORITY_CLASS) |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1127 | FIXME_(module)("(%s,...): REALTIME_PRIORITY_CLASS ignored\n", name); |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1128 | if (dwCreationFlags & CREATE_NEW_PROCESS_GROUP) |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1129 | FIXME_(module)("(%s,...): CREATE_NEW_PROCESS_GROUP ignored\n", name); |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1130 | if (dwCreationFlags & CREATE_UNICODE_ENVIRONMENT) |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1131 | FIXME_(module)("(%s,...): CREATE_UNICODE_ENVIRONMENT ignored\n", name); |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1132 | if (dwCreationFlags & CREATE_SEPARATE_WOW_VDM) |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1133 | FIXME_(module)("(%s,...): CREATE_SEPARATE_WOW_VDM ignored\n", name); |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1134 | if (dwCreationFlags & CREATE_SHARED_WOW_VDM) |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1135 | FIXME_(module)("(%s,...): CREATE_SHARED_WOW_VDM ignored\n", name); |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1136 | if (dwCreationFlags & CREATE_DEFAULT_ERROR_MODE) |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1137 | FIXME_(module)("(%s,...): CREATE_DEFAULT_ERROR_MODE ignored\n", name); |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1138 | if (dwCreationFlags & CREATE_NO_WINDOW) |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1139 | FIXME_(module)("(%s,...): CREATE_NO_WINDOW ignored\n", name); |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1140 | if (dwCreationFlags & PROFILE_USER) |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1141 | FIXME_(module)("(%s,...): PROFILE_USER ignored\n", name); |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1142 | if (dwCreationFlags & PROFILE_KERNEL) |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1143 | FIXME_(module)("(%s,...): PROFILE_KERNEL ignored\n", name); |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1144 | if (dwCreationFlags & PROFILE_SERVER) |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1145 | FIXME_(module)("(%s,...): PROFILE_SERVER ignored\n", name); |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1146 | if (lpCurrentDirectory) |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1147 | FIXME_(module)("(%s,...): lpCurrentDirectory %s ignored\n", |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1148 | name, lpCurrentDirectory); |
| 1149 | if (lpStartupInfo->lpDesktop) |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1150 | FIXME_(module)("(%s,...): lpStartupInfo->lpDesktop %s ignored\n", |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1151 | name, lpStartupInfo->lpDesktop); |
| 1152 | if (lpStartupInfo->lpTitle) |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1153 | FIXME_(module)("(%s,...): lpStartupInfo->lpTitle %s ignored\n", |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1154 | name, lpStartupInfo->lpTitle); |
| 1155 | if (lpStartupInfo->dwFlags & STARTF_USECOUNTCHARS) |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1156 | FIXME_(module)("(%s,...): STARTF_USECOUNTCHARS (%ld,%ld) ignored\n", |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1157 | name, lpStartupInfo->dwXCountChars, lpStartupInfo->dwYCountChars); |
| 1158 | if (lpStartupInfo->dwFlags & STARTF_USEFILLATTRIBUTE) |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1159 | FIXME_(module)("(%s,...): STARTF_USEFILLATTRIBUTE %lx ignored\n", |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1160 | name, lpStartupInfo->dwFillAttribute); |
| 1161 | if (lpStartupInfo->dwFlags & STARTF_RUNFULLSCREEN) |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1162 | FIXME_(module)("(%s,...): STARTF_RUNFULLSCREEN ignored\n", name); |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1163 | if (lpStartupInfo->dwFlags & STARTF_FORCEONFEEDBACK) |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1164 | FIXME_(module)("(%s,...): STARTF_FORCEONFEEDBACK ignored\n", name); |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1165 | if (lpStartupInfo->dwFlags & STARTF_FORCEOFFFEEDBACK) |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1166 | FIXME_(module)("(%s,...): STARTF_FORCEOFFFEEDBACK ignored\n", name); |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1167 | if (lpStartupInfo->dwFlags & STARTF_USEHOTKEY) |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1168 | FIXME_(module)("(%s,...): STARTF_USEHOTKEY ignored\n", name); |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1169 | |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 1170 | /* Check for special case: second instance of NE module */ |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1171 | |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 1172 | lstrcpynA( ofs.szPathName, name, sizeof( ofs.szPathName ) ); |
Dave Pickles | fec2329 | 1999-06-26 11:48:26 +0000 | [diff] [blame] | 1173 | retv = NE_CreateProcess( HFILE_ERROR, &ofs, tidy_cmdline, lpEnvironment, |
Ulrich Weigand | 892627b | 1999-03-16 16:29:26 +0000 | [diff] [blame] | 1174 | lpProcessAttributes, lpThreadAttributes, |
Alexandre Julliard | d131a17 | 1999-05-23 20:02:04 +0000 | [diff] [blame] | 1175 | bInheritHandles, dwCreationFlags, |
| 1176 | lpStartupInfo, lpProcessInfo ); |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 1177 | |
| 1178 | /* Load file and create process */ |
| 1179 | |
| 1180 | if ( !retv ) |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1181 | { |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 1182 | /* Open file and determine executable type */ |
| 1183 | |
| 1184 | if ( (hFile = OpenFile( name, &ofs, OF_READ )) == HFILE_ERROR ) |
| 1185 | { |
| 1186 | SetLastError( ERROR_FILE_NOT_FOUND ); |
Dave Pickles | fec2329 | 1999-06-26 11:48:26 +0000 | [diff] [blame] | 1187 | HeapFree( GetProcessHeap(), 0, tidy_cmdline ); |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 1188 | return FALSE; |
| 1189 | } |
| 1190 | |
| 1191 | if ( !MODULE_GetBinaryType( hFile, &ofs, &type ) ) |
| 1192 | { |
| 1193 | CloseHandle( hFile ); |
| 1194 | |
| 1195 | /* FIXME: Try Unix executable only when appropriate! */ |
Dave Pickles | fec2329 | 1999-06-26 11:48:26 +0000 | [diff] [blame] | 1196 | if ( MODULE_CreateUnixProcess( name, tidy_cmdline, |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 1197 | lpStartupInfo, lpProcessInfo, FALSE ) ) |
Dave Pickles | fec2329 | 1999-06-26 11:48:26 +0000 | [diff] [blame] | 1198 | { |
| 1199 | HeapFree( GetProcessHeap(), 0, tidy_cmdline ); |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 1200 | return TRUE; |
Dave Pickles | fec2329 | 1999-06-26 11:48:26 +0000 | [diff] [blame] | 1201 | } |
| 1202 | HeapFree( GetProcessHeap(), 0, tidy_cmdline ); |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 1203 | SetLastError( ERROR_BAD_FORMAT ); |
| 1204 | return FALSE; |
| 1205 | } |
| 1206 | |
| 1207 | |
| 1208 | /* Create process */ |
| 1209 | |
| 1210 | switch ( type ) |
| 1211 | { |
| 1212 | case SCS_32BIT_BINARY: |
Dave Pickles | fec2329 | 1999-06-26 11:48:26 +0000 | [diff] [blame] | 1213 | retv = PE_CreateProcess( hFile, &ofs, tidy_cmdline, lpEnvironment, |
Ulrich Weigand | 892627b | 1999-03-16 16:29:26 +0000 | [diff] [blame] | 1214 | lpProcessAttributes, lpThreadAttributes, |
Alexandre Julliard | d131a17 | 1999-05-23 20:02:04 +0000 | [diff] [blame] | 1215 | bInheritHandles, dwCreationFlags, |
| 1216 | lpStartupInfo, lpProcessInfo ); |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 1217 | break; |
| 1218 | |
| 1219 | case SCS_DOS_BINARY: |
Dave Pickles | fec2329 | 1999-06-26 11:48:26 +0000 | [diff] [blame] | 1220 | retv = MZ_CreateProcess( hFile, &ofs, tidy_cmdline, lpEnvironment, |
Ulrich Weigand | 892627b | 1999-03-16 16:29:26 +0000 | [diff] [blame] | 1221 | lpProcessAttributes, lpThreadAttributes, |
Alexandre Julliard | d131a17 | 1999-05-23 20:02:04 +0000 | [diff] [blame] | 1222 | bInheritHandles, dwCreationFlags, |
| 1223 | lpStartupInfo, lpProcessInfo ); |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 1224 | break; |
| 1225 | |
| 1226 | case SCS_WOW_BINARY: |
Dave Pickles | fec2329 | 1999-06-26 11:48:26 +0000 | [diff] [blame] | 1227 | retv = NE_CreateProcess( hFile, &ofs, tidy_cmdline, lpEnvironment, |
Ulrich Weigand | 892627b | 1999-03-16 16:29:26 +0000 | [diff] [blame] | 1228 | lpProcessAttributes, lpThreadAttributes, |
Alexandre Julliard | d131a17 | 1999-05-23 20:02:04 +0000 | [diff] [blame] | 1229 | bInheritHandles, dwCreationFlags, |
| 1230 | lpStartupInfo, lpProcessInfo ); |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 1231 | break; |
| 1232 | |
| 1233 | case SCS_PIF_BINARY: |
| 1234 | case SCS_POSIX_BINARY: |
| 1235 | case SCS_OS216_BINARY: |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1236 | FIXME_(module)("Unsupported executable type: %ld\n", type ); |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 1237 | /* fall through */ |
| 1238 | |
| 1239 | default: |
| 1240 | SetLastError( ERROR_BAD_FORMAT ); |
| 1241 | retv = FALSE; |
| 1242 | break; |
| 1243 | } |
| 1244 | |
| 1245 | CloseHandle( hFile ); |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1246 | } |
Dave Pickles | fec2329 | 1999-06-26 11:48:26 +0000 | [diff] [blame] | 1247 | HeapFree( GetProcessHeap(), 0, tidy_cmdline ); |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 1248 | return retv; |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1249 | } |
| 1250 | |
| 1251 | /********************************************************************** |
Ulrich Weigand | 6e0d386 | 1999-02-28 11:14:32 +0000 | [diff] [blame] | 1252 | * CreateProcessW (KERNEL32.172) |
Juergen Schmied | d0fc60a | 1998-11-22 15:46:05 +0000 | [diff] [blame] | 1253 | * NOTES |
| 1254 | * lpReserved is not converted |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1255 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1256 | BOOL WINAPI CreateProcessW( LPCWSTR lpApplicationName, LPWSTR lpCommandLine, |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1257 | LPSECURITY_ATTRIBUTES lpProcessAttributes, |
| 1258 | LPSECURITY_ATTRIBUTES lpThreadAttributes, |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1259 | BOOL bInheritHandles, DWORD dwCreationFlags, |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1260 | LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory, |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1261 | LPSTARTUPINFOW lpStartupInfo, |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1262 | LPPROCESS_INFORMATION lpProcessInfo ) |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1263 | { BOOL ret; |
| 1264 | STARTUPINFOA StartupInfoA; |
Juergen Schmied | d0fc60a | 1998-11-22 15:46:05 +0000 | [diff] [blame] | 1265 | |
| 1266 | LPSTR lpApplicationNameA = HEAP_strdupWtoA (GetProcessHeap(),0,lpApplicationName); |
| 1267 | LPSTR lpCommandLineA = HEAP_strdupWtoA (GetProcessHeap(),0,lpCommandLine); |
| 1268 | LPSTR lpCurrentDirectoryA = HEAP_strdupWtoA (GetProcessHeap(),0,lpCurrentDirectory); |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1269 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1270 | memcpy (&StartupInfoA, lpStartupInfo, sizeof(STARTUPINFOA)); |
Juergen Schmied | d0fc60a | 1998-11-22 15:46:05 +0000 | [diff] [blame] | 1271 | StartupInfoA.lpDesktop = HEAP_strdupWtoA (GetProcessHeap(),0,lpStartupInfo->lpDesktop); |
| 1272 | StartupInfoA.lpTitle = HEAP_strdupWtoA (GetProcessHeap(),0,lpStartupInfo->lpTitle); |
| 1273 | |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1274 | TRACE_(win32)("(%s,%s,...)\n", debugstr_w(lpApplicationName), debugstr_w(lpCommandLine)); |
Juergen Schmied | d0fc60a | 1998-11-22 15:46:05 +0000 | [diff] [blame] | 1275 | |
| 1276 | if (lpStartupInfo->lpReserved) |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1277 | FIXME_(win32)("StartupInfo.lpReserved is used, please report (%s)\n", debugstr_w(lpStartupInfo->lpReserved)); |
Juergen Schmied | d0fc60a | 1998-11-22 15:46:05 +0000 | [diff] [blame] | 1278 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1279 | ret = CreateProcessA( lpApplicationNameA, lpCommandLineA, |
Juergen Schmied | d0fc60a | 1998-11-22 15:46:05 +0000 | [diff] [blame] | 1280 | lpProcessAttributes, lpThreadAttributes, |
| 1281 | bInheritHandles, dwCreationFlags, |
| 1282 | lpEnvironment, lpCurrentDirectoryA, |
| 1283 | &StartupInfoA, lpProcessInfo ); |
| 1284 | |
| 1285 | HeapFree( GetProcessHeap(), 0, lpCurrentDirectoryA ); |
| 1286 | HeapFree( GetProcessHeap(), 0, lpCommandLineA ); |
| 1287 | HeapFree( GetProcessHeap(), 0, StartupInfoA.lpDesktop ); |
| 1288 | HeapFree( GetProcessHeap(), 0, StartupInfoA.lpTitle ); |
| 1289 | |
| 1290 | return ret; |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 1291 | } |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 1292 | |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 1293 | /*********************************************************************** |
| 1294 | * GetModuleHandle (KERNEL32.237) |
| 1295 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1296 | HMODULE WINAPI GetModuleHandleA(LPCSTR module) |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 1297 | { |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1298 | WINE_MODREF *wm; |
| 1299 | |
| 1300 | if ( module == NULL ) |
| 1301 | wm = PROCESS_Current()->exe_modref; |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1302 | else |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1303 | wm = MODULE_FindModule( module ); |
| 1304 | |
| 1305 | return wm? wm->module : 0; |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 1306 | } |
| 1307 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1308 | HMODULE WINAPI GetModuleHandleW(LPCWSTR module) |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 1309 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1310 | HMODULE hModule; |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 1311 | LPSTR modulea = HEAP_strdupWtoA( GetProcessHeap(), 0, module ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1312 | hModule = GetModuleHandleA( modulea ); |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 1313 | HeapFree( GetProcessHeap(), 0, modulea ); |
| 1314 | return hModule; |
| 1315 | } |
| 1316 | |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 1317 | |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 1318 | /*********************************************************************** |
| 1319 | * GetModuleFileName32A (KERNEL32.235) |
| 1320 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1321 | DWORD WINAPI GetModuleFileNameA( |
| 1322 | HMODULE hModule, /* [in] module handle (32bit) */ |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 1323 | LPSTR lpFileName, /* [out] filenamebuffer */ |
| 1324 | DWORD size /* [in] size of filenamebuffer */ |
| 1325 | ) { |
Ulrich Weigand | 1d90d69 | 1999-02-24 14:27:07 +0000 | [diff] [blame] | 1326 | WINE_MODREF *wm = MODULE32_LookupHMODULE( hModule ); |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 1327 | |
| 1328 | if (!wm) /* can happen on start up or the like */ |
| 1329 | return 0; |
| 1330 | |
Alexander Larsson | d235b13 | 1998-10-11 13:59:08 +0000 | [diff] [blame] | 1331 | if (PE_HEADER(wm->module)->OptionalHeader.MajorOperatingSystemVersion >= 4.0) |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1332 | lstrcpynA( lpFileName, wm->longname, size ); |
Alexander Larsson | d235b13 | 1998-10-11 13:59:08 +0000 | [diff] [blame] | 1333 | else |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1334 | lstrcpynA( lpFileName, wm->shortname, size ); |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 1335 | |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1336 | TRACE_(module)("%s\n", lpFileName ); |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 1337 | return strlen(lpFileName); |
| 1338 | } |
| 1339 | |
| 1340 | |
| 1341 | /*********************************************************************** |
| 1342 | * GetModuleFileName32W (KERNEL32.236) |
| 1343 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1344 | DWORD WINAPI GetModuleFileNameW( HMODULE hModule, LPWSTR lpFileName, |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1345 | DWORD size ) |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 1346 | { |
| 1347 | LPSTR fnA = (char*)HeapAlloc( GetProcessHeap(), 0, size ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1348 | DWORD res = GetModuleFileNameA( hModule, fnA, size ); |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 1349 | lstrcpynAtoW( lpFileName, fnA, size ); |
| 1350 | HeapFree( GetProcessHeap(), 0, fnA ); |
| 1351 | return res; |
| 1352 | } |
| 1353 | |
| 1354 | |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 1355 | /*********************************************************************** |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1356 | * LoadLibraryExA (KERNEL32) |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 1357 | */ |
Jim Aston | 031f4fa | 1999-10-23 19:00:02 +0000 | [diff] [blame] | 1358 | HMODULE WINAPI LoadLibraryExA(LPCSTR libname, HANDLE hfile, DWORD flags) |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 1359 | { |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1360 | WINE_MODREF *wm; |
Marcus Meissner | 574ef76 | 1999-04-03 16:23:47 +0000 | [diff] [blame] | 1361 | |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1362 | if(!libname) |
| 1363 | { |
| 1364 | SetLastError(ERROR_INVALID_PARAMETER); |
| 1365 | return 0; |
| 1366 | } |
Ulrich Weigand | ebc543c | 1998-10-23 09:37:23 +0000 | [diff] [blame] | 1367 | |
Bertho Stultiens | af5745f | 1999-04-19 16:32:31 +0000 | [diff] [blame] | 1368 | EnterCriticalSection(&PROCESS_Current()->crit_section); |
| 1369 | |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1370 | wm = MODULE_LoadLibraryExA( libname, hfile, flags ); |
Ulrich Weigand | ebc543c | 1998-10-23 09:37:23 +0000 | [diff] [blame] | 1371 | |
Bertho Stultiens | af5745f | 1999-04-19 16:32:31 +0000 | [diff] [blame] | 1372 | if(wm && !MODULE_DllProcessAttach(wm, NULL)) |
| 1373 | { |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1374 | WARN_(module)("Attach failed for module '%s', \n", libname); |
Bertho Stultiens | af5745f | 1999-04-19 16:32:31 +0000 | [diff] [blame] | 1375 | MODULE_FreeLibrary(wm); |
| 1376 | SetLastError(ERROR_DLL_INIT_FAILED); |
| 1377 | wm = NULL; |
| 1378 | } |
| 1379 | |
| 1380 | LeaveCriticalSection(&PROCESS_Current()->crit_section); |
| 1381 | |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1382 | return wm ? wm->module : 0; |
Marcus Meissner | 8220bc9 | 1998-10-11 11:10:27 +0000 | [diff] [blame] | 1383 | } |
| 1384 | |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1385 | /*********************************************************************** |
| 1386 | * MODULE_LoadLibraryExA (internal) |
| 1387 | * |
| 1388 | * Load a PE style module according to the load order. |
| 1389 | * |
| 1390 | * The HFILE parameter is not used and marked reserved in the SDK. I can |
| 1391 | * only guess that it should force a file to be mapped, but I rather |
| 1392 | * ignore the parameter because it would be extremely difficult to |
| 1393 | * integrate this with different types of module represenations. |
| 1394 | * |
| 1395 | */ |
| 1396 | WINE_MODREF *MODULE_LoadLibraryExA( LPCSTR libname, HFILE hfile, DWORD flags ) |
Marcus Meissner | 8220bc9 | 1998-10-11 11:10:27 +0000 | [diff] [blame] | 1397 | { |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1398 | DWORD err; |
| 1399 | WINE_MODREF *pwm; |
| 1400 | int i; |
| 1401 | module_loadorder_t *plo; |
Marcus Meissner | 8220bc9 | 1998-10-11 11:10:27 +0000 | [diff] [blame] | 1402 | |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1403 | EnterCriticalSection(&PROCESS_Current()->crit_section); |
Bertho Stultiens | 1b34697 | 1999-04-11 14:52:24 +0000 | [diff] [blame] | 1404 | |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1405 | /* Check for already loaded module */ |
| 1406 | if((pwm = MODULE_FindModule(libname))) |
| 1407 | { |
Bertho Stultiens | f4b6e82 | 1999-04-22 08:56:40 +0000 | [diff] [blame] | 1408 | if(!(pwm->flags & WINE_MODREF_MARKER)) |
| 1409 | pwm->refCount++; |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1410 | TRACE_(module)("Already loaded module '%s' at 0x%08x, count=%d, \n", libname, pwm->module, pwm->refCount); |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1411 | LeaveCriticalSection(&PROCESS_Current()->crit_section); |
| 1412 | return pwm; |
| 1413 | } |
| 1414 | |
| 1415 | plo = MODULE_GetLoadOrder(libname); |
| 1416 | |
| 1417 | for(i = 0; i < MODULE_LOADORDER_NTYPES; i++) |
| 1418 | { |
| 1419 | switch(plo->loadorder[i]) |
| 1420 | { |
| 1421 | case MODULE_LOADORDER_DLL: |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1422 | TRACE_(module)("Trying native dll '%s'\n", libname); |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1423 | pwm = PE_LoadLibraryExA(libname, flags, &err); |
| 1424 | break; |
| 1425 | |
| 1426 | case MODULE_LOADORDER_ELFDLL: |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1427 | TRACE_(module)("Trying elfdll '%s'\n", libname); |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1428 | pwm = ELFDLL_LoadLibraryExA(libname, flags, &err); |
| 1429 | break; |
| 1430 | |
| 1431 | case MODULE_LOADORDER_SO: |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1432 | TRACE_(module)("Trying so-library '%s'\n", libname); |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1433 | pwm = ELF_LoadLibraryExA(libname, flags, &err); |
| 1434 | break; |
| 1435 | |
| 1436 | case MODULE_LOADORDER_BI: |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1437 | TRACE_(module)("Trying built-in '%s'\n", libname); |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1438 | pwm = BUILTIN32_LoadLibraryExA(libname, flags, &err); |
| 1439 | break; |
| 1440 | |
| 1441 | default: |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1442 | ERR_(module)("Got invalid loadorder type %d (%s index %d)\n", plo->loadorder[i], plo->modulename, i); |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1443 | /* Fall through */ |
| 1444 | |
| 1445 | case MODULE_LOADORDER_INVALID: /* We ignore this as it is an empty entry */ |
| 1446 | pwm = NULL; |
| 1447 | break; |
| 1448 | } |
| 1449 | |
| 1450 | if(pwm) |
| 1451 | { |
| 1452 | /* Initialize DLL just loaded */ |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1453 | TRACE_(module)("Loaded module '%s' at 0x%08x, \n", libname, pwm->module); |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1454 | |
| 1455 | /* Set the refCount here so that an attach failure will */ |
| 1456 | /* decrement the dependencies through the MODULE_FreeLibrary call. */ |
| 1457 | pwm->refCount++; |
| 1458 | |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1459 | LeaveCriticalSection(&PROCESS_Current()->crit_section); |
Alexandre Julliard | d131a17 | 1999-05-23 20:02:04 +0000 | [diff] [blame] | 1460 | |
| 1461 | if (PROCESS_Current()->flags & PDB32_DEBUGGED) |
Ulrich Weigand | d024d5e | 1999-11-10 20:15:04 +0000 | [diff] [blame] | 1462 | DEBUG_SendLoadDLLEvent( -1 /*FIXME*/, pwm->module, &pwm->modname ); |
Alexandre Julliard | d131a17 | 1999-05-23 20:02:04 +0000 | [diff] [blame] | 1463 | |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1464 | return pwm; |
| 1465 | } |
| 1466 | |
| 1467 | if(err != ERROR_FILE_NOT_FOUND) |
| 1468 | break; |
| 1469 | } |
| 1470 | |
Ulrich Weigand | e7957d6 | 1999-11-10 19:45:56 +0000 | [diff] [blame] | 1471 | WARN_(module)("Failed to load module '%s'; error=0x%08lx, \n", libname, err); |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1472 | SetLastError(err); |
| 1473 | LeaveCriticalSection(&PROCESS_Current()->crit_section); |
| 1474 | return NULL; |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 1475 | } |
| 1476 | |
| 1477 | /*********************************************************************** |
| 1478 | * LoadLibraryA (KERNEL32) |
| 1479 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1480 | HMODULE WINAPI LoadLibraryA(LPCSTR libname) { |
| 1481 | return LoadLibraryExA(libname,0,0); |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 1482 | } |
| 1483 | |
| 1484 | /*********************************************************************** |
| 1485 | * LoadLibraryW (KERNEL32) |
| 1486 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1487 | HMODULE WINAPI LoadLibraryW(LPCWSTR libnameW) |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 1488 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1489 | return LoadLibraryExW(libnameW,0,0); |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 1490 | } |
| 1491 | |
| 1492 | /*********************************************************************** |
Ulrich Weigand | c3d9f28 | 1999-08-18 18:31:26 +0000 | [diff] [blame] | 1493 | * LoadLibrary32_16 (KERNEL.452) |
| 1494 | */ |
| 1495 | HMODULE WINAPI LoadLibrary32_16( LPCSTR libname ) |
| 1496 | { |
| 1497 | HMODULE hModule; |
| 1498 | |
| 1499 | SYSLEVEL_ReleaseWin16Lock(); |
| 1500 | hModule = LoadLibraryA( libname ); |
| 1501 | SYSLEVEL_RestoreWin16Lock(); |
| 1502 | |
| 1503 | return hModule; |
| 1504 | } |
| 1505 | |
| 1506 | /*********************************************************************** |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 1507 | * LoadLibraryExW (KERNEL32) |
| 1508 | */ |
Jim Aston | 031f4fa | 1999-10-23 19:00:02 +0000 | [diff] [blame] | 1509 | HMODULE WINAPI LoadLibraryExW(LPCWSTR libnameW,HANDLE hfile,DWORD flags) |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 1510 | { |
| 1511 | LPSTR libnameA = HEAP_strdupWtoA( GetProcessHeap(), 0, libnameW ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1512 | HMODULE ret = LoadLibraryExA( libnameA , hfile, flags ); |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 1513 | |
| 1514 | HeapFree( GetProcessHeap(), 0, libnameA ); |
| 1515 | return ret; |
| 1516 | } |
| 1517 | |
Bertho Stultiens | 1b34697 | 1999-04-11 14:52:24 +0000 | [diff] [blame] | 1518 | /*********************************************************************** |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1519 | * MODULE_FlushModrefs |
Bertho Stultiens | 1b34697 | 1999-04-11 14:52:24 +0000 | [diff] [blame] | 1520 | * |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1521 | * NOTE: Assumes that the process critical section is held! |
Bertho Stultiens | 1b34697 | 1999-04-11 14:52:24 +0000 | [diff] [blame] | 1522 | * |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1523 | * Remove all unused modrefs and call the internal unloading routines |
| 1524 | * for the library type. |
Bertho Stultiens | 1b34697 | 1999-04-11 14:52:24 +0000 | [diff] [blame] | 1525 | */ |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1526 | static void MODULE_FlushModrefs(void) |
Bertho Stultiens | 1b34697 | 1999-04-11 14:52:24 +0000 | [diff] [blame] | 1527 | { |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1528 | WINE_MODREF *wm, *next; |
Bertho Stultiens | 1b34697 | 1999-04-11 14:52:24 +0000 | [diff] [blame] | 1529 | |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1530 | for(wm = PROCESS_Current()->modref_list; wm; wm = next) |
| 1531 | { |
| 1532 | next = wm->next; |
Bertho Stultiens | 1b34697 | 1999-04-11 14:52:24 +0000 | [diff] [blame] | 1533 | |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1534 | if(wm->refCount) |
| 1535 | continue; |
Bertho Stultiens | 1b34697 | 1999-04-11 14:52:24 +0000 | [diff] [blame] | 1536 | |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1537 | /* Unlink this modref from the chain */ |
| 1538 | if(wm->next) |
| 1539 | wm->next->prev = wm->prev; |
| 1540 | if(wm->prev) |
| 1541 | wm->prev->next = wm->next; |
| 1542 | if(wm == PROCESS_Current()->modref_list) |
| 1543 | PROCESS_Current()->modref_list = wm->next; |
Bertho Stultiens | 1b34697 | 1999-04-11 14:52:24 +0000 | [diff] [blame] | 1544 | |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1545 | /* |
| 1546 | * The unloaders are also responsible for freeing the modref itself |
| 1547 | * because the loaders were responsible for allocating it. |
| 1548 | */ |
| 1549 | switch(wm->type) |
| 1550 | { |
| 1551 | case MODULE32_PE: PE_UnloadLibrary(wm); break; |
| 1552 | case MODULE32_ELF: ELF_UnloadLibrary(wm); break; |
| 1553 | case MODULE32_ELFDLL: ELFDLL_UnloadLibrary(wm); break; |
| 1554 | case MODULE32_BI: BUILTIN32_UnloadLibrary(wm); break; |
Bertho Stultiens | 1b34697 | 1999-04-11 14:52:24 +0000 | [diff] [blame] | 1555 | |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1556 | default: |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1557 | ERR_(module)("Invalid or unhandled MODREF type %d encountered (wm=%p)\n", wm->type, wm); |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1558 | } |
| 1559 | } |
Bertho Stultiens | 1b34697 | 1999-04-11 14:52:24 +0000 | [diff] [blame] | 1560 | } |
| 1561 | |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 1562 | /*********************************************************************** |
| 1563 | * FreeLibrary |
| 1564 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1565 | BOOL WINAPI FreeLibrary(HINSTANCE hLibModule) |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 1566 | { |
Ulrich Weigand | 6315a7f | 1999-05-22 10:44:39 +0000 | [diff] [blame] | 1567 | BOOL retv = FALSE; |
Bertho Stultiens | 1b34697 | 1999-04-11 14:52:24 +0000 | [diff] [blame] | 1568 | WINE_MODREF *wm; |
Ulrich Weigand | e469a58 | 1999-03-27 16:45:57 +0000 | [diff] [blame] | 1569 | |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1570 | EnterCriticalSection( &PROCESS_Current()->crit_section ); |
Ulrich Weigand | 6315a7f | 1999-05-22 10:44:39 +0000 | [diff] [blame] | 1571 | PROCESS_Current()->free_lib_count++; |
Bertho Stultiens | 1b34697 | 1999-04-11 14:52:24 +0000 | [diff] [blame] | 1572 | |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1573 | wm = MODULE32_LookupHMODULE( hLibModule ); |
Ulrich Weigand | 6315a7f | 1999-05-22 10:44:39 +0000 | [diff] [blame] | 1574 | if ( !wm || !hLibModule ) |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1575 | SetLastError( ERROR_INVALID_HANDLE ); |
Bertho Stultiens | 1b34697 | 1999-04-11 14:52:24 +0000 | [diff] [blame] | 1576 | else |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1577 | retv = MODULE_FreeLibrary( wm ); |
Bertho Stultiens | 1b34697 | 1999-04-11 14:52:24 +0000 | [diff] [blame] | 1578 | |
Ulrich Weigand | 6315a7f | 1999-05-22 10:44:39 +0000 | [diff] [blame] | 1579 | PROCESS_Current()->free_lib_count--; |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1580 | LeaveCriticalSection( &PROCESS_Current()->crit_section ); |
Bertho Stultiens | 1b34697 | 1999-04-11 14:52:24 +0000 | [diff] [blame] | 1581 | |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1582 | return retv; |
| 1583 | } |
| 1584 | |
| 1585 | /*********************************************************************** |
| 1586 | * MODULE_DecRefCount |
| 1587 | * |
| 1588 | * NOTE: Assumes that the process critical section is held! |
| 1589 | */ |
| 1590 | static void MODULE_DecRefCount( WINE_MODREF *wm ) |
| 1591 | { |
| 1592 | int i; |
| 1593 | |
| 1594 | if ( wm->flags & WINE_MODREF_MARKER ) |
| 1595 | return; |
| 1596 | |
| 1597 | if ( wm->refCount <= 0 ) |
| 1598 | return; |
| 1599 | |
| 1600 | --wm->refCount; |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1601 | TRACE_(module)("(%s) refCount: %d\n", wm->modname, wm->refCount ); |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1602 | |
| 1603 | if ( wm->refCount == 0 ) |
| 1604 | { |
| 1605 | wm->flags |= WINE_MODREF_MARKER; |
| 1606 | |
| 1607 | for ( i = 0; i < wm->nDeps; i++ ) |
| 1608 | if ( wm->deps[i] ) |
| 1609 | MODULE_DecRefCount( wm->deps[i] ); |
| 1610 | |
| 1611 | wm->flags &= ~WINE_MODREF_MARKER; |
| 1612 | } |
| 1613 | } |
| 1614 | |
| 1615 | /*********************************************************************** |
| 1616 | * MODULE_FreeLibrary |
| 1617 | * |
| 1618 | * NOTE: Assumes that the process critical section is held! |
| 1619 | */ |
| 1620 | BOOL MODULE_FreeLibrary( WINE_MODREF *wm ) |
| 1621 | { |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1622 | TRACE_(module)("(%s) - START\n", wm->modname ); |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1623 | |
| 1624 | /* Recursively decrement reference counts */ |
| 1625 | MODULE_DecRefCount( wm ); |
| 1626 | |
| 1627 | /* Call process detach notifications */ |
Ulrich Weigand | 6315a7f | 1999-05-22 10:44:39 +0000 | [diff] [blame] | 1628 | if ( PROCESS_Current()->free_lib_count <= 1 ) |
Alexandre Julliard | d131a17 | 1999-05-23 20:02:04 +0000 | [diff] [blame] | 1629 | { |
Ulrich Weigand | 6315a7f | 1999-05-22 10:44:39 +0000 | [diff] [blame] | 1630 | MODULE_DllProcessDetach( FALSE, NULL ); |
Alexandre Julliard | d131a17 | 1999-05-23 20:02:04 +0000 | [diff] [blame] | 1631 | if (PROCESS_Current()->flags & PDB32_DEBUGGED) |
| 1632 | DEBUG_SendUnloadDLLEvent( wm->module ); |
| 1633 | } |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1634 | |
| 1635 | MODULE_FlushModrefs(); |
| 1636 | |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1637 | TRACE_(module)("(%s) - END\n", wm->modname ); |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 1638 | |
Ulrich Weigand | 6315a7f | 1999-05-22 10:44:39 +0000 | [diff] [blame] | 1639 | return TRUE; |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 1640 | } |
| 1641 | |
Bertho Stultiens | 1b34697 | 1999-04-11 14:52:24 +0000 | [diff] [blame] | 1642 | |
Sergey Turchanov | 5ffd2df | 1999-03-22 12:35:48 +0000 | [diff] [blame] | 1643 | /*********************************************************************** |
| 1644 | * FreeLibraryAndExitThread |
| 1645 | */ |
| 1646 | VOID WINAPI FreeLibraryAndExitThread(HINSTANCE hLibModule, DWORD dwExitCode) |
| 1647 | { |
| 1648 | FreeLibrary(hLibModule); |
| 1649 | ExitThread(dwExitCode); |
| 1650 | } |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 1651 | |
| 1652 | /*********************************************************************** |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 1653 | * PrivateLoadLibrary (KERNEL32) |
| 1654 | * |
| 1655 | * FIXME: rough guesswork, don't know what "Private" means |
| 1656 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1657 | HINSTANCE WINAPI PrivateLoadLibrary(LPCSTR libname) |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 1658 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1659 | return (HINSTANCE)LoadLibrary16(libname); |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 1660 | } |
| 1661 | |
| 1662 | |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 1663 | |
| 1664 | /*********************************************************************** |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 1665 | * PrivateFreeLibrary (KERNEL32) |
| 1666 | * |
| 1667 | * FIXME: rough guesswork, don't know what "Private" means |
| 1668 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1669 | void WINAPI PrivateFreeLibrary(HINSTANCE handle) |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 1670 | { |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 1671 | FreeLibrary16((HINSTANCE16)handle); |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 1672 | } |
| 1673 | |
| 1674 | |
| 1675 | /*********************************************************************** |
Alexandre Julliard | 641ee76 | 1997-08-04 16:34:36 +0000 | [diff] [blame] | 1676 | * WIN32_GetProcAddress16 (KERNEL32.36) |
| 1677 | * Get procaddress in 16bit module from win32... (kernel32 undoc. ordinal func) |
| 1678 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1679 | FARPROC16 WINAPI WIN32_GetProcAddress16( HMODULE hModule, LPCSTR name ) |
Alexandre Julliard | 641ee76 | 1997-08-04 16:34:36 +0000 | [diff] [blame] | 1680 | { |
| 1681 | WORD ordinal; |
| 1682 | FARPROC16 ret; |
| 1683 | |
| 1684 | if (!hModule) { |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1685 | WARN_(module)("hModule may not be 0!\n"); |
Alexandre Julliard | 641ee76 | 1997-08-04 16:34:36 +0000 | [diff] [blame] | 1686 | return (FARPROC16)0; |
| 1687 | } |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 1688 | if (HIWORD(hModule)) |
| 1689 | { |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1690 | WARN_(module)("hModule is Win32 handle (%08x)\n", hModule ); |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 1691 | return (FARPROC16)0; |
| 1692 | } |
| 1693 | hModule = GetExePtr( hModule ); |
Alexandre Julliard | 641ee76 | 1997-08-04 16:34:36 +0000 | [diff] [blame] | 1694 | if (HIWORD(name)) { |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1695 | ordinal = NE_GetOrdinal( hModule, name ); |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1696 | TRACE_(module)("%04x '%s'\n", |
Alexandre Julliard | 641ee76 | 1997-08-04 16:34:36 +0000 | [diff] [blame] | 1697 | hModule, name ); |
| 1698 | } else { |
| 1699 | ordinal = LOWORD(name); |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1700 | TRACE_(module)("%04x %04x\n", |
Alexandre Julliard | 641ee76 | 1997-08-04 16:34:36 +0000 | [diff] [blame] | 1701 | hModule, ordinal ); |
| 1702 | } |
| 1703 | if (!ordinal) return (FARPROC16)0; |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1704 | ret = NE_GetEntryPoint( hModule, ordinal ); |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1705 | TRACE_(module)("returning %08x\n",(UINT)ret); |
Alexandre Julliard | 641ee76 | 1997-08-04 16:34:36 +0000 | [diff] [blame] | 1706 | return ret; |
| 1707 | } |
| 1708 | |
| 1709 | /*********************************************************************** |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 1710 | * GetProcAddress16 (KERNEL.50) |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 1711 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1712 | FARPROC16 WINAPI GetProcAddress16( HMODULE16 hModule, SEGPTR name ) |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 1713 | { |
| 1714 | WORD ordinal; |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 1715 | FARPROC16 ret; |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 1716 | |
| 1717 | if (!hModule) hModule = GetCurrentTask(); |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1718 | hModule = GetExePtr( hModule ); |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 1719 | |
| 1720 | if (HIWORD(name) != 0) |
| 1721 | { |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1722 | ordinal = NE_GetOrdinal( hModule, (LPSTR)PTR_SEG_TO_LIN(name) ); |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1723 | TRACE_(module)("%04x '%s'\n", |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 1724 | hModule, (LPSTR)PTR_SEG_TO_LIN(name) ); |
| 1725 | } |
| 1726 | else |
| 1727 | { |
| 1728 | ordinal = LOWORD(name); |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1729 | TRACE_(module)("%04x %04x\n", |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 1730 | hModule, ordinal ); |
| 1731 | } |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 1732 | if (!ordinal) return (FARPROC16)0; |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 1733 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1734 | ret = NE_GetEntryPoint( hModule, ordinal ); |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 1735 | |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1736 | TRACE_(module)("returning %08x\n", (UINT)ret ); |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 1737 | return ret; |
| 1738 | } |
| 1739 | |
| 1740 | |
| 1741 | /*********************************************************************** |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1742 | * GetProcAddress32 (KERNEL32.257) |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 1743 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1744 | FARPROC WINAPI GetProcAddress( HMODULE hModule, LPCSTR function ) |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 1745 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1746 | return MODULE_GetProcAddress( hModule, function, TRUE ); |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1747 | } |
| 1748 | |
Ulrich Weigand | a3527cf | 1998-10-11 19:31:10 +0000 | [diff] [blame] | 1749 | /*********************************************************************** |
| 1750 | * WIN16_GetProcAddress32 (KERNEL.453) |
| 1751 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1752 | FARPROC WINAPI GetProcAddress32_16( HMODULE hModule, LPCSTR function ) |
Ulrich Weigand | a3527cf | 1998-10-11 19:31:10 +0000 | [diff] [blame] | 1753 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1754 | return MODULE_GetProcAddress( hModule, function, FALSE ); |
Ulrich Weigand | a3527cf | 1998-10-11 19:31:10 +0000 | [diff] [blame] | 1755 | } |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1756 | |
| 1757 | /*********************************************************************** |
| 1758 | * MODULE_GetProcAddress32 (internal) |
| 1759 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1760 | FARPROC MODULE_GetProcAddress( |
| 1761 | HMODULE hModule, /* [in] current module handle */ |
Ulrich Weigand | a3527cf | 1998-10-11 19:31:10 +0000 | [diff] [blame] | 1762 | LPCSTR function, /* [in] function to be looked up */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1763 | BOOL snoop ) |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1764 | { |
Ulrich Weigand | 1d90d69 | 1999-02-24 14:27:07 +0000 | [diff] [blame] | 1765 | WINE_MODREF *wm = MODULE32_LookupHMODULE( hModule ); |
Marcus Meissner | 574ef76 | 1999-04-03 16:23:47 +0000 | [diff] [blame] | 1766 | FARPROC retproc; |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 1767 | |
Alexandre Julliard | 84c70f5 | 1997-05-09 08:40:27 +0000 | [diff] [blame] | 1768 | if (HIWORD(function)) |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1769 | TRACE_(win32)("(%08lx,%s)\n",(DWORD)hModule,function); |
Alexandre Julliard | 84c70f5 | 1997-05-09 08:40:27 +0000 | [diff] [blame] | 1770 | else |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1771 | TRACE_(win32)("(%08lx,%p)\n",(DWORD)hModule,function); |
Marcus Meissner | 574ef76 | 1999-04-03 16:23:47 +0000 | [diff] [blame] | 1772 | if (!wm) { |
| 1773 | SetLastError(ERROR_INVALID_HANDLE); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1774 | return (FARPROC)0; |
Marcus Meissner | 574ef76 | 1999-04-03 16:23:47 +0000 | [diff] [blame] | 1775 | } |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1776 | switch (wm->type) |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 1777 | { |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1778 | case MODULE32_PE: |
Marcus Meissner | 574ef76 | 1999-04-03 16:23:47 +0000 | [diff] [blame] | 1779 | retproc = PE_FindExportedFunction( wm, function, snoop ); |
| 1780 | if (!retproc) SetLastError(ERROR_PROC_NOT_FOUND); |
| 1781 | return retproc; |
Marcus Meissner | 8220bc9 | 1998-10-11 11:10:27 +0000 | [diff] [blame] | 1782 | case MODULE32_ELF: |
Marcus Meissner | 574ef76 | 1999-04-03 16:23:47 +0000 | [diff] [blame] | 1783 | retproc = ELF_FindExportedFunction( wm, function); |
| 1784 | if (!retproc) SetLastError(ERROR_PROC_NOT_FOUND); |
| 1785 | return retproc; |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1786 | default: |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 1787 | ERR_(module)("wine_modref type %d not handled.\n",wm->type); |
Marcus Meissner | 574ef76 | 1999-04-03 16:23:47 +0000 | [diff] [blame] | 1788 | SetLastError(ERROR_INVALID_HANDLE); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1789 | return (FARPROC)0; |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 1790 | } |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 1791 | } |
| 1792 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1793 | |
Alexandre Julliard | 84c70f5 | 1997-05-09 08:40:27 +0000 | [diff] [blame] | 1794 | /*********************************************************************** |
| 1795 | * RtlImageNtHeaders (NTDLL) |
| 1796 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1797 | PIMAGE_NT_HEADERS WINAPI RtlImageNtHeader(HMODULE hModule) |
Alexandre Julliard | 84c70f5 | 1997-05-09 08:40:27 +0000 | [diff] [blame] | 1798 | { |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 1799 | /* basically: |
| 1800 | * return hModule+(((IMAGE_DOS_HEADER*)hModule)->e_lfanew); |
| 1801 | * but we could get HMODULE16 or the like (think builtin modules) |
| 1802 | */ |
| 1803 | |
Ulrich Weigand | 1d90d69 | 1999-02-24 14:27:07 +0000 | [diff] [blame] | 1804 | WINE_MODREF *wm = MODULE32_LookupHMODULE( hModule ); |
Uwe Bonnes | 73d6c13 | 1998-10-16 09:30:33 +0000 | [diff] [blame] | 1805 | if (!wm || (wm->type != MODULE32_PE)) return (PIMAGE_NT_HEADERS)0; |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1806 | return PE_HEADER(wm->module); |
Alexandre Julliard | 84c70f5 | 1997-05-09 08:40:27 +0000 | [diff] [blame] | 1807 | } |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 1808 | |
| 1809 | |
| 1810 | /*************************************************************************** |
| 1811 | * HasGPHandler (KERNEL.338) |
| 1812 | */ |
| 1813 | |
Patrik Stridvall | c7a8dde | 1999-04-25 12:36:53 +0000 | [diff] [blame] | 1814 | #include "pshpack1.h" |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 1815 | typedef struct _GPHANDLERDEF |
| 1816 | { |
| 1817 | WORD selector; |
| 1818 | WORD rangeStart; |
| 1819 | WORD rangeEnd; |
| 1820 | WORD handler; |
| 1821 | } GPHANDLERDEF; |
Patrik Stridvall | c7a8dde | 1999-04-25 12:36:53 +0000 | [diff] [blame] | 1822 | #include "poppack.h" |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 1823 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1824 | SEGPTR WINAPI HasGPHandler16( SEGPTR address ) |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 1825 | { |
| 1826 | HMODULE16 hModule; |
Ulrich Weigand | a3527cf | 1998-10-11 19:31:10 +0000 | [diff] [blame] | 1827 | int gpOrdinal; |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 1828 | SEGPTR gpPtr; |
| 1829 | GPHANDLERDEF *gpHandler; |
| 1830 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1831 | if ( (hModule = FarGetOwner16( SELECTOROF(address) )) != 0 |
Ulrich Weigand | a3527cf | 1998-10-11 19:31:10 +0000 | [diff] [blame] | 1832 | && (gpOrdinal = NE_GetOrdinal( hModule, "__GP" )) != 0 |
| 1833 | && (gpPtr = (SEGPTR)NE_GetEntryPointEx( hModule, gpOrdinal, FALSE )) != 0 |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 1834 | && !IsBadReadPtr16( gpPtr, sizeof(GPHANDLERDEF) ) |
| 1835 | && (gpHandler = PTR_SEG_TO_LIN( gpPtr )) != NULL ) |
| 1836 | { |
| 1837 | while (gpHandler->selector) |
| 1838 | { |
| 1839 | if ( SELECTOROF(address) == gpHandler->selector |
| 1840 | && OFFSETOF(address) >= gpHandler->rangeStart |
| 1841 | && OFFSETOF(address) < gpHandler->rangeEnd ) |
| 1842 | return PTR_SEG_OFF_TO_SEGPTR( gpHandler->selector, |
| 1843 | gpHandler->handler ); |
| 1844 | gpHandler++; |
| 1845 | } |
| 1846 | } |
| 1847 | |
| 1848 | return 0; |
| 1849 | } |
| 1850 | |