4 * Copyright 1995 Alexandre Julliard
11 #include <sys/types.h>
26 #include "selectors.h"
27 #include "stackframe.h"
32 extern BOOL32 THREAD_InitDone
;
35 /*************************************************************************
36 * MODULE32_LookupHMODULE
37 * looks for the referenced HMODULE in the current process
40 MODULE32_LookupHMODULE(PDB32
*process
,HMODULE32 hmod
) {
44 return process
->exe_modref
;
46 ERR(module
,"tried to lookup 0x%04x in win32 module handler!\n",hmod
);
49 for (wm
= process
->modref_list
;wm
;wm
=wm
->next
)
50 if (wm
->module
== hmod
)
55 /*************************************************************************
56 * MODULE_InitializeDLLs
58 * Call the initialization routines of all DLLs belonging to the
59 * current process. This is somewhat complicated due to the fact that
61 * - we have to respect the module dependencies, i.e. modules implicitly
62 * referenced by another module have to be initialized before the module
63 * itself can be initialized
65 * - the initialization routine of a DLL can itself call LoadLibrary,
66 * thereby introducing a whole new set of dependencies (even involving
67 * the 'old' modules) at any time during the whole process
69 * (Note that this routine can be recursively entered not only directly
70 * from itself, but also via LoadLibrary from one of the called initialization
73 static void MODULE_DoInitializeDLLs( PDB32
*process
, WINE_MODREF
*wm
,
74 DWORD type
, LPVOID lpReserved
)
78 assert( wm
&& !wm
->initDone
);
79 TRACE( module
, "(%p,%08x,%ld,%p) - START\n",
80 process
, wm
->module
, type
, lpReserved
);
82 /* Tag current MODREF to prevent recursive loop */
85 /* Recursively initialize all child DLLs */
86 for ( i
= 0; i
< wm
->nDeps
; i
++ )
87 if ( wm
->deps
[i
] && !wm
->deps
[i
]->initDone
)
88 MODULE_DoInitializeDLLs( process
,
89 wm
->deps
[i
], type
, lpReserved
);
91 /* Now we can call the initialization routine */
95 PE_InitDLL( wm
, type
, lpReserved
);
99 ERR(module
, "wine_modref type %d not handled.\n", wm
->type
);
103 TRACE( module
, "(%p,%08x,%ld,%p) - END\n",
104 process
, wm
->module
, type
, lpReserved
);
107 void MODULE_InitializeDLLs( PDB32
*process
, HMODULE32 root
,
108 DWORD type
, LPVOID lpReserved
)
110 BOOL32 inProgress
= FALSE
;
113 /* Grab the process critical section to protect the recursion flags */
114 /* FIXME: This is probably overkill! */
115 EnterCriticalSection( &process
->crit_section
);
117 TRACE( module
, "(%p,%08x,%ld,%p) - START\n", process
, root
, type
, lpReserved
);
119 /* First, check whether initialization is currently in progress */
120 for ( wm
= process
->modref_list
; wm
; wm
= wm
->next
)
130 * If this a LoadLibrary call from within an initialization routine,
131 * treat it analogously to an implicitly referenced DLL.
132 * Anything else may not happen at this point!
136 wm
= MODULE32_LookupHMODULE( process
, root
);
137 if ( wm
&& !wm
->initDone
)
138 MODULE_DoInitializeDLLs( process
, wm
, type
, lpReserved
);
141 FIXME(module
, "Invalid recursion!\n");
145 /* If we arrive here, this is the start of an initialization run */
148 /* If called for main EXE, initialize all DLLs */
149 for ( wm
= process
->modref_list
; wm
; wm
= wm
->next
)
151 MODULE_DoInitializeDLLs( process
, wm
, type
, lpReserved
);
155 /* If called for a specific DLL, initialize only it and its children */
156 wm
= MODULE32_LookupHMODULE( process
, root
);
157 if (wm
) MODULE_DoInitializeDLLs( process
, wm
, type
, lpReserved
);
160 /* We're finished, so we reset all recursion flags */
161 for ( wm
= process
->modref_list
; wm
; wm
= wm
->next
)
162 wm
->initDone
= FALSE
;
165 TRACE( module
, "(%p,%08x,%ld,%p) - END\n", process
, root
, type
, lpReserved
);
167 /* Release critical section */
168 LeaveCriticalSection( &process
->crit_section
);
172 /***********************************************************************
173 * MODULE_CreateDummyModule
175 * Create a dummy NE module for Win32 or Winelib.
177 HMODULE32
MODULE_CreateDummyModule( const OFSTRUCT
*ofs
)
181 SEGTABLEENTRY
*pSegment
;
184 const char* basename
;
186 INT32 of_size
= sizeof(OFSTRUCT
) - sizeof(ofs
->szPathName
)
187 + strlen(ofs
->szPathName
) + 1;
188 INT32 size
= sizeof(NE_MODULE
) +
189 /* loaded file info */
191 /* segment table: DS,CS */
192 2 * sizeof(SEGTABLEENTRY
) +
195 /* several empty tables */
198 hModule
= GlobalAlloc16( GMEM_MOVEABLE
| GMEM_ZEROINIT
, size
);
199 if (!hModule
) return (HMODULE32
)11; /* invalid exe */
201 FarSetOwner( hModule
, hModule
);
202 pModule
= (NE_MODULE
*)GlobalLock16( hModule
);
204 /* Set all used entries */
205 pModule
->magic
= IMAGE_OS2_SIGNATURE
;
212 pModule
->heap_size
= 0xe000;
213 pModule
->stack_size
= 0x1000;
214 pModule
->seg_count
= 2;
215 pModule
->modref_count
= 0;
216 pModule
->nrname_size
= 0;
217 pModule
->fileinfo
= sizeof(NE_MODULE
);
218 pModule
->os_flags
= NE_OSFLAGS_WINDOWS
;
219 pModule
->expected_version
= 0x030a;
220 pModule
->self
= hModule
;
222 /* Set loaded file information */
223 memcpy( pModule
+ 1, ofs
, of_size
);
224 ((OFSTRUCT
*)(pModule
+1))->cBytes
= of_size
- 1;
226 pSegment
= (SEGTABLEENTRY
*)((char*)(pModule
+ 1) + of_size
);
227 pModule
->seg_table
= pModule
->dgroup_entry
= (int)pSegment
- (int)pModule
;
230 pSegment
->flags
= NE_SEGFLAGS_DATA
;
231 pSegment
->minsize
= 0x1000;
238 pStr
= (char *)pSegment
;
239 pModule
->name_table
= (int)pStr
- (int)pModule
;
240 basename
= strrchr(ofs
->szPathName
,'\\');
241 if (!basename
) basename
= ofs
->szPathName
;
243 len
= strlen(basename
);
244 if ((s
= strchr(basename
,'.'))) len
= s
- basename
;
245 if (len
> 8) len
= 8;
247 strncpy( pStr
+1, basename
, len
);
248 if (len
< 8) pStr
[len
+1] = 0;
251 /* All tables zero terminated */
252 pModule
->res_table
= pModule
->import_table
= pModule
->entry_table
=
253 (int)pStr
- (int)pModule
;
255 NE_RegisterModule( pModule
);
260 /***********************************************************************
261 * MODULE_GetWndProcEntry16 (not a Windows API function)
263 * Return an entry point from the WPROCS dll.
265 FARPROC16
MODULE_GetWndProcEntry16( LPCSTR name
)
267 FARPROC16 ret
= NULL
;
271 /* FIXME: hack for Winelib */
272 extern LRESULT
ColorDlgProc(HWND16
,UINT16
,WPARAM16
,LPARAM
);
273 extern LRESULT
FileOpenDlgProc(HWND16
,UINT16
,WPARAM16
,LPARAM
);
274 extern LRESULT
FileSaveDlgProc(HWND16
,UINT16
,WPARAM16
,LPARAM
);
275 extern LRESULT
FindTextDlgProc16(HWND16
,UINT16
,WPARAM16
,LPARAM
);
276 extern LRESULT
PrintDlgProc(HWND16
,UINT16
,WPARAM16
,LPARAM
);
277 extern LRESULT
PrintSetupDlgProc(HWND16
,UINT16
,WPARAM16
,LPARAM
);
278 extern LRESULT
ReplaceTextDlgProc16(HWND16
,UINT16
,WPARAM16
,LPARAM
);
280 if (!strcmp(name
,"ColorDlgProc"))
281 return (FARPROC16
)ColorDlgProc
;
282 if (!strcmp(name
,"FileOpenDlgProc"))
283 return (FARPROC16
)FileOpenDlgProc
;
284 if (!strcmp(name
,"FileSaveDlgProc"))
285 return (FARPROC16
)FileSaveDlgProc
;
286 if (!strcmp(name
,"FindTextDlgProc"))
287 return (FARPROC16
)FindTextDlgProc16
;
288 if (!strcmp(name
,"PrintDlgProc"))
289 return (FARPROC16
)PrintDlgProc
;
290 if (!strcmp(name
,"PrintSetupDlgProc"))
291 return (FARPROC16
)PrintSetupDlgProc
;
292 if (!strcmp(name
,"ReplaceTextDlgProc"))
293 return (FARPROC16
)ReplaceTextDlgProc16
;
294 if (!strcmp(name
,"DefResourceHandler"))
295 return (FARPROC16
)NE_DefResourceHandler
;
296 if (!strcmp(name
,"LoadDIBIconHandler"))
297 return (FARPROC16
)LoadDIBIconHandler
;
298 if (!strcmp(name
,"LoadDIBCursorHandler"))
299 return (FARPROC16
)LoadDIBCursorHandler
;
300 FIXME(module
,"No mapping for %s(), add one in library/miscstubs.c\n",name
);
307 static HMODULE32 hModule
= 0;
309 if (!hModule
) hModule
= GetModuleHandle16( "WPROCS" );
310 ordinal
= NE_GetOrdinal( hModule
, name
);
311 if (!(ret
= NE_GetEntryPoint( hModule
, ordinal
)))
313 WARN( module
, "%s not found\n", name
);
321 /**********************************************************************
322 * MODULE_FindModule32
324 * Find a (loaded) win32 module depending on path
325 * The handling of '.' is a bit weird, but we need it that way,
326 * for sometimes the programs use '<name>.exe' and '<name>.dll' and
327 * this is the only way to differentiate. (mainly hypertrm.exe)
330 * the module handle if found
333 HMODULE32
MODULE_FindModule32(
334 PDB32
* process
, /* [in] process in which to find the library */
335 LPCSTR path
/* [in] pathname of module/library to be found */
343 if (!(filename
= strrchr( path
, '\\' )))
344 filename
= HEAP_strdupA(process
->heap
,0,path
);
346 filename
= HEAP_strdupA(process
->heap
,0,filename
+1);
347 dotptr
=strrchr(filename
,'.');
349 for (wm
=process
->modref_list
;wm
;wm
=wm
->next
) {
350 LPSTR xmodname
,xdotptr
;
352 assert (wm
->modname
);
353 xmodname
= HEAP_strdupA(process
->heap
,0,wm
->modname
);
354 xdotptr
=strrchr(xmodname
,'.');
355 if ( (xdotptr
&& !dotptr
) ||
358 if (dotptr
) *dotptr
= '\0';
359 if (xdotptr
) *xdotptr
= '\0';
361 if (!strcasecmp( filename
, xmodname
)) {
362 HeapFree(process
->heap
,0,filename
);
363 HeapFree(process
->heap
,0,xmodname
);
366 if (dotptr
) *dotptr
='.';
367 /* FIXME: add paths, shortname */
368 HeapFree(process
->heap
,0,xmodname
);
370 /* if that fails, try looking for the filename... */
371 for (wm
=process
->modref_list
;wm
;wm
=wm
->next
) {
372 LPSTR xlname
,xdotptr
;
374 assert (wm
->longname
);
375 xlname
= strrchr(wm
->longname
,'\\');
377 xlname
= wm
->longname
;
380 xlname
= HEAP_strdupA(process
->heap
,0,xlname
);
381 xdotptr
=strrchr(xlname
,'.');
382 if ( (xdotptr
&& !dotptr
) ||
385 if (dotptr
) *dotptr
= '\0';
386 if (xdotptr
) *xdotptr
= '\0';
388 if (!strcasecmp( filename
, xlname
)) {
389 HeapFree(process
->heap
,0,filename
);
390 HeapFree(process
->heap
,0,xlname
);
393 if (dotptr
) *dotptr
='.';
394 /* FIXME: add paths, shortname */
395 HeapFree(process
->heap
,0,xlname
);
397 HeapFree(process
->heap
,0,filename
);
403 /**********************************************************************
406 static HINSTANCE16
NE_CreateProcess( LPCSTR name
, LPCSTR cmd_line
, LPCSTR env
,
407 LPSTARTUPINFO32A startup
,
408 LPPROCESS_INFORMATION info
)
410 HINSTANCE16 hInstance
, hPrevInstance
;
415 hInstance
= NE_LoadModule( name
, &hPrevInstance
, TRUE
, FALSE
);
416 if (hInstance
< 32) return hInstance
;
418 if ( !(pModule
= NE_GetPtr(hInstance
))
419 || (pModule
->flags
& NE_FFLAGS_LIBMODULE
))
425 /* Create a task for this instance */
427 pModule
->flags
|= NE_FFLAGS_GUI
; /* FIXME: is this necessary? */
429 PROCESS_Create( pModule
, cmd_line
, env
, hInstance
,
430 hPrevInstance
, startup
, info
);
436 /**********************************************************************
437 * LoadModule16 (KERNEL.45)
439 HINSTANCE16 WINAPI
LoadModule16( LPCSTR name
, LPVOID paramBlock
)
442 LPSTR cmd_line
, new_cmd_line
;
444 STARTUPINFO32A startup
;
445 PROCESS_INFORMATION info
;
446 HINSTANCE16 hInstance
, hPrevInstance
;
452 if (!paramBlock
|| (paramBlock
== (LPVOID
)-1))
453 return LoadLibrary16( name
);
455 hInstance
= NE_LoadModule( name
, &hPrevInstance
, FALSE
, FALSE
);
456 if ( hInstance
< 32 || !(pModule
= NE_GetPtr(hInstance
))
457 || (pModule
->flags
& NE_FFLAGS_LIBMODULE
))
460 /* Create a task for this instance */
462 pModule
->flags
|= NE_FFLAGS_GUI
; /* FIXME: is this necessary? */
464 params
= (LOADPARAMS
*)paramBlock
;
465 cmd_line
= (LPSTR
)PTR_SEG_TO_LIN( params
->cmdLine
);
466 if (!cmd_line
) cmd_line
= "";
467 else if (*cmd_line
) cmd_line
++; /* skip the length byte */
469 if (!(new_cmd_line
= HeapAlloc( GetProcessHeap(), 0,
470 strlen(cmd_line
)+strlen(name
)+2 )))
472 strcpy( new_cmd_line
, name
);
473 strcat( new_cmd_line
, " " );
474 strcat( new_cmd_line
, cmd_line
);
476 if (params
->hEnvironment
) env
= GlobalLock16( params
->hEnvironment
);
478 memset( &info
, '\0', sizeof(info
) );
479 memset( &startup
, '\0', sizeof(startup
) );
480 startup
.cb
= sizeof(startup
);
483 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
484 startup
.wShowWindow
= ((UINT16
*)PTR_SEG_TO_LIN(params
->showCmd
))[1];
487 pdb
= PROCESS_Create( pModule
, new_cmd_line
, env
,
488 hInstance
, hPrevInstance
, &startup
, &info
);
490 CloseHandle( info
.hThread
);
491 CloseHandle( info
.hProcess
);
493 if (params
->hEnvironment
) GlobalUnlock16( params
->hEnvironment
);
494 HeapFree( GetProcessHeap(), 0, new_cmd_line
);
498 if (pdb
) TASK_StartTask( pdb
->task
);
503 /**********************************************************************
504 * LoadModule32 (KERNEL32.499)
506 HINSTANCE32 WINAPI
LoadModule32( LPCSTR name
, LPVOID paramBlock
)
508 LOADPARAMS32
*params
= (LOADPARAMS32
*)paramBlock
;
509 PROCESS_INFORMATION info
;
510 STARTUPINFO32A startup
;
511 HINSTANCE32 hInstance
;
515 memset( &startup
, '\0', sizeof(startup
) );
516 startup
.cb
= sizeof(startup
);
517 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
518 startup
.wShowWindow
= params
->lpCmdShow
? params
->lpCmdShow
[1] : 0;
520 if (!CreateProcess32A( name
, params
->lpCmdLine
,
521 NULL
, NULL
, FALSE
, 0, params
->lpEnvAddress
,
522 NULL
, &startup
, &info
))
523 return GetLastError(); /* guaranteed to be < 32 */
525 /* Get hInstance from process */
526 pdb
= PROCESS_IdToPDB( info
.dwProcessId
);
527 if ( pdb
->exe_modref
)
528 hInstance
= pdb
->exe_modref
->module
;
531 tdb
= pdb
? (TDB
*)GlobalLock16( pdb
->task
) : NULL
;
532 hInstance
= tdb
? tdb
->hInstance
: 0;
535 /* Close off the handles */
536 CloseHandle( info
.hThread
);
537 CloseHandle( info
.hProcess
);
542 /**********************************************************************
543 * CreateProcess32A (KERNEL32.171)
545 BOOL32 WINAPI
CreateProcess32A( LPCSTR lpApplicationName
, LPSTR lpCommandLine
,
546 LPSECURITY_ATTRIBUTES lpProcessAttributes
,
547 LPSECURITY_ATTRIBUTES lpThreadAttributes
,
548 BOOL32 bInheritHandles
, DWORD dwCreationFlags
,
549 LPVOID lpEnvironment
, LPCSTR lpCurrentDirectory
,
550 LPSTARTUPINFO32A lpStartupInfo
,
551 LPPROCESS_INFORMATION lpProcessInfo
)
553 HINSTANCE16 hInstance
;
558 /* Get name and command line */
560 if (!lpApplicationName
&& !lpCommandLine
)
562 SetLastError( ERROR_FILE_NOT_FOUND
);
566 cmdline
= lpCommandLine
? lpCommandLine
: lpApplicationName
;
568 if (lpApplicationName
)
569 lstrcpyn32A(name
, lpApplicationName
, sizeof(name
) - 4);
574 /* Take care off .exes with spaces in their names */
575 ptr
= strchr(lpCommandLine
, ' ');
577 len
= (ptr
? ptr
-lpCommandLine
: strlen(lpCommandLine
)) + 1;
578 if (len
> sizeof(name
) - 4) len
= sizeof(name
) - 4;
579 lstrcpyn32A(name
, lpCommandLine
, len
);
580 if (!strchr(name
, '\\') && !strchr(name
, '.'))
581 strcat(name
, ".exe");
582 fprintf(stderr
,"looking for: %s\n",name
);
583 if (GetFileAttributes32A(name
)!=-1)
585 /* if there is a space and no file found yet, include the word
586 * up to the next space too. If there is no next space, just
587 * use the first word.
590 ptr
= strchr(ptr
+1, ' ');
592 ptr
= strchr(lpCommandLine
, ' ');
593 len
= (ptr
? ptr
-lpCommandLine
: strlen(lpCommandLine
)) + 1;
594 if (len
> sizeof(name
) - 4) len
= sizeof(name
) - 4;
595 lstrcpyn32A(name
, lpCommandLine
, len
);
601 if (!strchr(name
, '\\') && !strchr(name
, '.'))
602 strcat(name
, ".exe");
605 /* Warn if unsupported features are used */
607 if (lpProcessAttributes
)
608 FIXME(module
, "(%s,...): lpProcessAttributes ignored\n", name
);
609 if (lpThreadAttributes
)
610 FIXME(module
, "(%s,...): lpThreadAttributes ignored\n", name
);
612 FIXME(module
, "(%s,...): bInheritHandles ignored\n", name
);
613 if (dwCreationFlags
& DEBUG_PROCESS
)
614 FIXME(module
, "(%s,...): DEBUG_PROCESS ignored\n", name
);
615 if (dwCreationFlags
& DEBUG_ONLY_THIS_PROCESS
)
616 FIXME(module
, "(%s,...): DEBUG_ONLY_THIS_PROCESS ignored\n", name
);
617 if (dwCreationFlags
& CREATE_SUSPENDED
)
618 FIXME(module
, "(%s,...): CREATE_SUSPENDED ignored\n", name
);
619 if (dwCreationFlags
& DETACHED_PROCESS
)
620 FIXME(module
, "(%s,...): DETACHED_PROCESS ignored\n", name
);
621 if (dwCreationFlags
& CREATE_NEW_CONSOLE
)
622 FIXME(module
, "(%s,...): CREATE_NEW_CONSOLE ignored\n", name
);
623 if (dwCreationFlags
& NORMAL_PRIORITY_CLASS
)
624 FIXME(module
, "(%s,...): NORMAL_PRIORITY_CLASS ignored\n", name
);
625 if (dwCreationFlags
& IDLE_PRIORITY_CLASS
)
626 FIXME(module
, "(%s,...): IDLE_PRIORITY_CLASS ignored\n", name
);
627 if (dwCreationFlags
& HIGH_PRIORITY_CLASS
)
628 FIXME(module
, "(%s,...): HIGH_PRIORITY_CLASS ignored\n", name
);
629 if (dwCreationFlags
& REALTIME_PRIORITY_CLASS
)
630 FIXME(module
, "(%s,...): REALTIME_PRIORITY_CLASS ignored\n", name
);
631 if (dwCreationFlags
& CREATE_NEW_PROCESS_GROUP
)
632 FIXME(module
, "(%s,...): CREATE_NEW_PROCESS_GROUP ignored\n", name
);
633 if (dwCreationFlags
& CREATE_UNICODE_ENVIRONMENT
)
634 FIXME(module
, "(%s,...): CREATE_UNICODE_ENVIRONMENT ignored\n", name
);
635 if (dwCreationFlags
& CREATE_SEPARATE_WOW_VDM
)
636 FIXME(module
, "(%s,...): CREATE_SEPARATE_WOW_VDM ignored\n", name
);
637 if (dwCreationFlags
& CREATE_SHARED_WOW_VDM
)
638 FIXME(module
, "(%s,...): CREATE_SHARED_WOW_VDM ignored\n", name
);
639 if (dwCreationFlags
& CREATE_DEFAULT_ERROR_MODE
)
640 FIXME(module
, "(%s,...): CREATE_DEFAULT_ERROR_MODE ignored\n", name
);
641 if (dwCreationFlags
& CREATE_NO_WINDOW
)
642 FIXME(module
, "(%s,...): CREATE_NO_WINDOW ignored\n", name
);
643 if (dwCreationFlags
& PROFILE_USER
)
644 FIXME(module
, "(%s,...): PROFILE_USER ignored\n", name
);
645 if (dwCreationFlags
& PROFILE_KERNEL
)
646 FIXME(module
, "(%s,...): PROFILE_KERNEL ignored\n", name
);
647 if (dwCreationFlags
& PROFILE_SERVER
)
648 FIXME(module
, "(%s,...): PROFILE_SERVER ignored\n", name
);
649 if (lpCurrentDirectory
)
650 FIXME(module
, "(%s,...): lpCurrentDirectory %s ignored\n",
651 name
, lpCurrentDirectory
);
652 if (lpStartupInfo
->lpDesktop
)
653 FIXME(module
, "(%s,...): lpStartupInfo->lpDesktop %s ignored\n",
654 name
, lpStartupInfo
->lpDesktop
);
655 if (lpStartupInfo
->lpTitle
)
656 FIXME(module
, "(%s,...): lpStartupInfo->lpTitle %s ignored\n",
657 name
, lpStartupInfo
->lpTitle
);
658 if (lpStartupInfo
->dwFlags
& STARTF_USECOUNTCHARS
)
659 FIXME(module
, "(%s,...): STARTF_USECOUNTCHARS (%ld,%ld) ignored\n",
660 name
, lpStartupInfo
->dwXCountChars
, lpStartupInfo
->dwYCountChars
);
661 if (lpStartupInfo
->dwFlags
& STARTF_USEFILLATTRIBUTE
)
662 FIXME(module
, "(%s,...): STARTF_USEFILLATTRIBUTE %lx ignored\n",
663 name
, lpStartupInfo
->dwFillAttribute
);
664 if (lpStartupInfo
->dwFlags
& STARTF_RUNFULLSCREEN
)
665 FIXME(module
, "(%s,...): STARTF_RUNFULLSCREEN ignored\n", name
);
666 if (lpStartupInfo
->dwFlags
& STARTF_FORCEONFEEDBACK
)
667 FIXME(module
, "(%s,...): STARTF_FORCEONFEEDBACK ignored\n", name
);
668 if (lpStartupInfo
->dwFlags
& STARTF_FORCEOFFFEEDBACK
)
669 FIXME(module
, "(%s,...): STARTF_FORCEOFFFEEDBACK ignored\n", name
);
670 if (lpStartupInfo
->dwFlags
& STARTF_USEHOTKEY
)
671 FIXME(module
, "(%s,...): STARTF_USEHOTKEY ignored\n", name
);
675 hInstance
= NE_CreateProcess( name
, cmdline
, lpEnvironment
,
676 lpStartupInfo
, lpProcessInfo
);
680 hInstance
= PE_CreateProcess( name
, cmdline
, lpEnvironment
,
681 lpStartupInfo
, lpProcessInfo
);
685 hInstance
= MZ_CreateProcess( name
, cmdline
, lpEnvironment
,
686 lpStartupInfo
, lpProcessInfo
);
690 SetLastError( hInstance
);
694 /* Get hTask from process and start the task */
695 pdb
= PROCESS_IdToPDB( lpProcessInfo
->dwProcessId
);
696 if (pdb
) TASK_StartTask( pdb
->task
);
701 /**********************************************************************
702 * CreateProcess32W (KERNEL32.172)
704 * lpReserved is not converted
706 BOOL32 WINAPI
CreateProcess32W( LPCWSTR lpApplicationName
, LPWSTR lpCommandLine
,
707 LPSECURITY_ATTRIBUTES lpProcessAttributes
,
708 LPSECURITY_ATTRIBUTES lpThreadAttributes
,
709 BOOL32 bInheritHandles
, DWORD dwCreationFlags
,
710 LPVOID lpEnvironment
, LPCWSTR lpCurrentDirectory
,
711 LPSTARTUPINFO32W lpStartupInfo
,
712 LPPROCESS_INFORMATION lpProcessInfo
)
714 STARTUPINFO32A StartupInfoA
;
716 LPSTR lpApplicationNameA
= HEAP_strdupWtoA (GetProcessHeap(),0,lpApplicationName
);
717 LPSTR lpCommandLineA
= HEAP_strdupWtoA (GetProcessHeap(),0,lpCommandLine
);
718 LPSTR lpCurrentDirectoryA
= HEAP_strdupWtoA (GetProcessHeap(),0,lpCurrentDirectory
);
720 memcpy (&StartupInfoA
, lpStartupInfo
, sizeof(STARTUPINFO32A
));
721 StartupInfoA
.lpDesktop
= HEAP_strdupWtoA (GetProcessHeap(),0,lpStartupInfo
->lpDesktop
);
722 StartupInfoA
.lpTitle
= HEAP_strdupWtoA (GetProcessHeap(),0,lpStartupInfo
->lpTitle
);
724 TRACE(win32
, "(%s,%s,...)\n", debugstr_w(lpApplicationName
), debugstr_w(lpCommandLine
));
726 if (lpStartupInfo
->lpReserved
)
727 FIXME(win32
,"StartupInfo.lpReserved is used, please report (%s)\n", debugstr_w(lpStartupInfo
->lpReserved
));
729 ret
= CreateProcess32A( lpApplicationNameA
, lpCommandLineA
,
730 lpProcessAttributes
, lpThreadAttributes
,
731 bInheritHandles
, dwCreationFlags
,
732 lpEnvironment
, lpCurrentDirectoryA
,
733 &StartupInfoA
, lpProcessInfo
);
735 HeapFree( GetProcessHeap(), 0, lpCurrentDirectoryA
);
736 HeapFree( GetProcessHeap(), 0, lpCommandLineA
);
737 HeapFree( GetProcessHeap(), 0, StartupInfoA
.lpDesktop
);
738 HeapFree( GetProcessHeap(), 0, StartupInfoA
.lpTitle
);
743 /***********************************************************************
744 * GetModuleHandle (KERNEL32.237)
746 HMODULE32 WINAPI
GetModuleHandle32A(LPCSTR module
)
749 return PROCESS_Current()->exe_modref
->module
;
751 return MODULE_FindModule32(PROCESS_Current(),module
);
754 HMODULE32 WINAPI
GetModuleHandle32W(LPCWSTR module
)
757 LPSTR modulea
= HEAP_strdupWtoA( GetProcessHeap(), 0, module
);
758 hModule
= GetModuleHandle32A( modulea
);
759 HeapFree( GetProcessHeap(), 0, modulea
);
764 /***********************************************************************
765 * GetModuleFileName32A (KERNEL32.235)
767 DWORD WINAPI
GetModuleFileName32A(
768 HMODULE32 hModule
, /* [in] module handle (32bit) */
769 LPSTR lpFileName
, /* [out] filenamebuffer */
770 DWORD size
/* [in] size of filenamebuffer */
772 WINE_MODREF
*wm
= MODULE32_LookupHMODULE(PROCESS_Current(),hModule
);
774 if (!wm
) /* can happen on start up or the like */
777 if (PE_HEADER(wm
->module
)->OptionalHeader
.MajorOperatingSystemVersion
>= 4.0)
778 lstrcpyn32A( lpFileName
, wm
->longname
, size
);
780 lstrcpyn32A( lpFileName
, wm
->shortname
, size
);
782 TRACE(module
, "%s\n", lpFileName
);
783 return strlen(lpFileName
);
787 /***********************************************************************
788 * GetModuleFileName32W (KERNEL32.236)
790 DWORD WINAPI
GetModuleFileName32W( HMODULE32 hModule
, LPWSTR lpFileName
,
793 LPSTR fnA
= (char*)HeapAlloc( GetProcessHeap(), 0, size
);
794 DWORD res
= GetModuleFileName32A( hModule
, fnA
, size
);
795 lstrcpynAtoW( lpFileName
, fnA
, size
);
796 HeapFree( GetProcessHeap(), 0, fnA
);
801 /***********************************************************************
802 * LoadLibraryEx32W (KERNEL.513)
805 HMODULE32 WINAPI
LoadLibraryEx32W16( LPCSTR libname
, HANDLE16 hf
,
808 TRACE(module
,"(%s,%d,%08lx)\n",libname
,hf
,flags
);
809 return LoadLibraryEx32A(libname
, hf
,flags
);
812 /***********************************************************************
813 * LoadLibraryEx32A (KERNEL32)
815 HMODULE32 WINAPI
LoadLibraryEx32A(LPCSTR libname
,HFILE32 hfile
,DWORD flags
)
818 hmod
= MODULE_LoadLibraryEx32A(libname
,PROCESS_Current(),hfile
,flags
);
820 /* at least call not the dllmain...*/
821 if ( DONT_RESOLVE_DLL_REFERENCES
==flags
|| LOAD_LIBRARY_AS_DATAFILE
==flags
)
822 { FIXME(module
,"flag not properly supported %lx\n", flags
);
826 /* initialize DLL just loaded */
828 MODULE_InitializeDLLs( PROCESS_Current(), hmod
,
829 DLL_PROCESS_ATTACH
, (LPVOID
)-1 );
834 HMODULE32
MODULE_LoadLibraryEx32A(LPCSTR libname
,PDB32
*process
,HFILE32 hfile
,DWORD flags
)
838 hmod
= ELF_LoadLibraryEx32A(libname
,process
,hfile
,flags
);
840 return hmod
; /* already initialized for ELF */
842 hmod
= PE_LoadLibraryEx32A(libname
,process
,hfile
,flags
);
846 strcpy( buffer
, libname
);
847 strcat( buffer
, ".dll" );
848 hmod
= PE_LoadLibraryEx32A(buffer
,process
,hfile
,flags
);
853 /***********************************************************************
854 * LoadLibraryA (KERNEL32)
856 HMODULE32 WINAPI
LoadLibrary32A(LPCSTR libname
) {
857 return LoadLibraryEx32A(libname
,0,0);
860 /***********************************************************************
861 * LoadLibraryW (KERNEL32)
863 HMODULE32 WINAPI
LoadLibrary32W(LPCWSTR libnameW
)
865 return LoadLibraryEx32W(libnameW
,0,0);
868 /***********************************************************************
869 * LoadLibraryExW (KERNEL32)
871 HMODULE32 WINAPI
LoadLibraryEx32W(LPCWSTR libnameW
,HFILE32 hfile
,DWORD flags
)
873 LPSTR libnameA
= HEAP_strdupWtoA( GetProcessHeap(), 0, libnameW
);
874 HMODULE32 ret
= LoadLibraryEx32A( libnameA
, hfile
, flags
);
876 HeapFree( GetProcessHeap(), 0, libnameA
);
880 /***********************************************************************
883 BOOL32 WINAPI
FreeLibrary32(HINSTANCE32 hLibModule
)
885 FIXME(module
,"(0x%08x): stub\n", hLibModule
);
886 return TRUE
; /* FIXME */
890 /***********************************************************************
891 * PrivateLoadLibrary (KERNEL32)
893 * FIXME: rough guesswork, don't know what "Private" means
895 HINSTANCE32 WINAPI
PrivateLoadLibrary(LPCSTR libname
)
897 return (HINSTANCE32
)LoadLibrary16(libname
);
902 /***********************************************************************
903 * PrivateFreeLibrary (KERNEL32)
905 * FIXME: rough guesswork, don't know what "Private" means
907 void WINAPI
PrivateFreeLibrary(HINSTANCE32 handle
)
909 FreeLibrary16((HINSTANCE16
)handle
);
913 /***********************************************************************
914 * WinExec16 (KERNEL.166)
916 HINSTANCE16 WINAPI
WinExec16( LPCSTR lpCmdLine
, UINT16 nCmdShow
)
918 return WinExec32( lpCmdLine
, nCmdShow
);
922 /***********************************************************************
923 * WinExec32 (KERNEL32.566)
925 HINSTANCE32 WINAPI
WinExec32( LPCSTR lpCmdLine
, UINT32 nCmdShow
)
927 HINSTANCE32 handle
= 2;
928 char *p
, filename
[256];
929 int spacelimit
= 0, exhausted
= 0;
931 UINT16 paramCmdShow
[2];
934 return 2; /* File not found */
936 /* Set up LOADPARAMS32 buffer for LoadModule32 */
938 memset( ¶ms
, '\0', sizeof(params
) );
939 params
.lpCmdLine
= (LPSTR
)lpCmdLine
;
940 params
.lpCmdShow
= paramCmdShow
;
941 params
.lpCmdShow
[0] = 2;
942 params
.lpCmdShow
[1] = nCmdShow
;
945 /* Keep trying to load a file by trying different filenames; e.g.,
946 for the cmdline "abcd efg hij", try "abcd" with args "efg hij",
947 then "abcd efg" with arg "hij", and finally "abcd efg hij" with
950 while(!exhausted
&& handle
== 2) {
953 /* Build the filename and command-line */
955 lstrcpyn32A(filename
, lpCmdLine
,
956 sizeof(filename
) - 4 /* for extension */);
958 /* Keep grabbing characters until end-of-string, tab, or until the
959 number of spaces is greater than the spacelimit */
961 for (p
= filename
; ; p
++) {
964 if(spacecount
> spacelimit
) {
970 if(*p
== '\0' || *p
== '\t') {
978 /* Now load the executable file */
982 handle
= LoadModule32( filename
, ¶ms
);
983 if (handle
== 2) /* file not found */
985 /* Check that the original file name did not have a suffix */
986 p
= strrchr(filename
, '.');
987 /* if there is a '.', check if either \ OR / follow */
988 if (!p
|| strchr(p
, '/') || strchr(p
, '\\'))
990 p
= filename
+ strlen(filename
);
992 handle
= LoadModule32( filename
, ¶ms
);
993 *p
= '\0'; /* Remove extension */
998 handle
= 2; /* file not found */
1002 /* Try to start it as a unix program */
1006 DOS_FULL_NAME full_name
;
1007 const char *unixfilename
= NULL
;
1008 const char *argv
[256], **argptr
;
1009 int iconic
= (nCmdShow
== SW_SHOWMINIMIZED
||
1010 nCmdShow
== SW_SHOWMINNOACTIVE
);
1012 THREAD_InitDone
= FALSE
; /* we didn't init this process */
1013 /* get unixfilename */
1014 if (strchr(filename
, '/') ||
1015 strchr(filename
, ':') ||
1016 strchr(filename
, '\\'))
1018 if (DOSFS_GetFullName( filename
, TRUE
, &full_name
))
1019 unixfilename
= full_name
.long_name
;
1021 else unixfilename
= filename
;
1027 if (iconic
) *argptr
++ = "-iconic";
1028 *argptr
++ = unixfilename
;
1029 p
= strdup(lpCmdLine
);
1032 while (*p
&& (*p
== ' ' || *p
== '\t')) *p
++ = '\0';
1035 while (*p
&& *p
!= ' ' && *p
!= '\t') p
++;
1040 execvp(argv
[0], (char**)argv
);
1050 if (iconic
) *argptr
++ = "-iconic";
1051 *argptr
++ = lpCmdLine
;
1055 execvp(argv
[0] , (char**)argv
);
1058 MSG("WinExec: can't exec 'wine %s'\n",
1064 } /* while (!exhausted && handle < 32) */
1070 /***********************************************************************
1071 * WIN32_GetProcAddress16 (KERNEL32.36)
1072 * Get procaddress in 16bit module from win32... (kernel32 undoc. ordinal func)
1074 FARPROC16 WINAPI
WIN32_GetProcAddress16( HMODULE32 hModule
, LPCSTR name
)
1080 WARN(module
,"hModule may not be 0!\n");
1081 return (FARPROC16
)0;
1083 if (HIWORD(hModule
))
1085 WARN( module
, "hModule is Win32 handle (%08x)\n", hModule
);
1086 return (FARPROC16
)0;
1088 hModule
= GetExePtr( hModule
);
1090 ordinal
= NE_GetOrdinal( hModule
, name
);
1091 TRACE(module
, "%04x '%s'\n",
1094 ordinal
= LOWORD(name
);
1095 TRACE(module
, "%04x %04x\n",
1098 if (!ordinal
) return (FARPROC16
)0;
1099 ret
= NE_GetEntryPoint( hModule
, ordinal
);
1100 TRACE(module
,"returning %08x\n",(UINT32
)ret
);
1104 /***********************************************************************
1105 * GetProcAddress16 (KERNEL.50)
1107 FARPROC16 WINAPI
GetProcAddress16( HMODULE16 hModule
, SEGPTR name
)
1112 if (!hModule
) hModule
= GetCurrentTask();
1113 hModule
= GetExePtr( hModule
);
1115 if (HIWORD(name
) != 0)
1117 ordinal
= NE_GetOrdinal( hModule
, (LPSTR
)PTR_SEG_TO_LIN(name
) );
1118 TRACE(module
, "%04x '%s'\n",
1119 hModule
, (LPSTR
)PTR_SEG_TO_LIN(name
) );
1123 ordinal
= LOWORD(name
);
1124 TRACE(module
, "%04x %04x\n",
1127 if (!ordinal
) return (FARPROC16
)0;
1129 ret
= NE_GetEntryPoint( hModule
, ordinal
);
1131 TRACE(module
, "returning %08x\n", (UINT32
)ret
);
1136 /***********************************************************************
1137 * GetProcAddress32 (KERNEL32.257)
1139 FARPROC32 WINAPI
GetProcAddress32( HMODULE32 hModule
, LPCSTR function
)
1141 return MODULE_GetProcAddress32( PROCESS_Current(), hModule
, function
, TRUE
);
1144 /***********************************************************************
1145 * WIN16_GetProcAddress32 (KERNEL.453)
1147 FARPROC32 WINAPI
WIN16_GetProcAddress32( HMODULE32 hModule
, LPCSTR function
)
1149 return MODULE_GetProcAddress32( PROCESS_Current(), hModule
, function
, FALSE
);
1152 /***********************************************************************
1153 * MODULE_GetProcAddress32 (internal)
1155 FARPROC32
MODULE_GetProcAddress32(
1156 PDB32
*process
, /* [in] process context */
1157 HMODULE32 hModule
, /* [in] current module handle */
1158 LPCSTR function
, /* [in] function to be looked up */
1161 WINE_MODREF
*wm
= MODULE32_LookupHMODULE(process
,hModule
);
1163 if (HIWORD(function
))
1164 TRACE(win32
,"(%08lx,%s)\n",(DWORD
)hModule
,function
);
1166 TRACE(win32
,"(%08lx,%p)\n",(DWORD
)hModule
,function
);
1168 return (FARPROC32
)0;
1172 return PE_FindExportedFunction( process
, wm
, function
, snoop
);
1174 return ELF_FindExportedFunction( process
, wm
, function
);
1176 ERR(module
,"wine_modref type %d not handled.\n",wm
->type
);
1177 return (FARPROC32
)0;
1182 /***********************************************************************
1183 * RtlImageNtHeaders (NTDLL)
1185 PIMAGE_NT_HEADERS WINAPI
RtlImageNtHeader(HMODULE32 hModule
)
1188 * return hModule+(((IMAGE_DOS_HEADER*)hModule)->e_lfanew);
1189 * but we could get HMODULE16 or the like (think builtin modules)
1192 WINE_MODREF
*wm
= MODULE32_LookupHMODULE( PROCESS_Current(), hModule
);
1193 if (!wm
|| (wm
->type
!= MODULE32_PE
)) return (PIMAGE_NT_HEADERS
)0;
1194 return PE_HEADER(wm
->module
);
1198 /***************************************************************************
1199 * HasGPHandler (KERNEL.338)
1203 typedef struct _GPHANDLERDEF
1212 SEGPTR WINAPI
HasGPHandler( SEGPTR address
)
1217 GPHANDLERDEF
*gpHandler
;
1219 if ( (hModule
= FarGetOwner( SELECTOROF(address
) )) != 0
1220 && (gpOrdinal
= NE_GetOrdinal( hModule
, "__GP" )) != 0
1221 && (gpPtr
= (SEGPTR
)NE_GetEntryPointEx( hModule
, gpOrdinal
, FALSE
)) != 0
1222 && !IsBadReadPtr16( gpPtr
, sizeof(GPHANDLERDEF
) )
1223 && (gpHandler
= PTR_SEG_TO_LIN( gpPtr
)) != NULL
)
1225 while (gpHandler
->selector
)
1227 if ( SELECTOROF(address
) == gpHandler
->selector
1228 && OFFSETOF(address
) >= gpHandler
->rangeStart
1229 && OFFSETOF(address
) < gpHandler
->rangeEnd
)
1230 return PTR_SEG_OFF_TO_SEGPTR( gpHandler
->selector
,
1231 gpHandler
->handler
);