4 * Copyright 1995 Alexandre Julliard
13 #include "wine/winbase16.h"
25 #include "builtin16.h"
26 #include "stackframe.h"
27 #include "debugtools.h"
28 #include "loadorder.h"
32 DEFAULT_DEBUG_CHANNEL(module);
34 #define hFirstModule (pThhook->hExeHead)
36 static NE_MODULE *pCachedModule = 0; /* Module cached by NE_OpenFile */
38 static HINSTANCE16 NE_LoadModule( LPCSTR name, BOOL lib_only );
39 static BOOL16 NE_FreeModule( HMODULE16 hModule, BOOL call_wep );
40 static void NE_InitProcess(void) WINE_NORETURN;
42 static HINSTANCE16 MODULE_LoadModule16( LPCSTR libname, BOOL implicit, BOOL lib_only );
44 static HMODULE16 NE_GetModuleByFilename( LPCSTR name );
46 /* ### start build ### */
47 extern WORD CALLBACK NE_CallTo16_word_w(FARPROC16,WORD);
48 /* ### stop build ### */
50 /***********************************************************************
53 NE_MODULE *NE_GetPtr( HMODULE16 hModule )
55 return (NE_MODULE *)GlobalLock16( GetExePtr(hModule) );
59 /***********************************************************************
62 void NE_DumpModule( HMODULE16 hModule )
72 if (!(pModule = NE_GetPtr( hModule )))
74 MESSAGE( "**** %04x is not a module handle\n", hModule );
78 /* Dump the module info */
80 DPRINTF( "Module %04x:\n", hModule );
81 DPRINTF( "count=%d flags=%04x heap=%d stack=%d\n",
82 pModule->count, pModule->flags,
83 pModule->heap_size, pModule->stack_size );
84 DPRINTF( "cs:ip=%04x:%04x ss:sp=%04x:%04x ds=%04x nb seg=%d modrefs=%d\n",
85 pModule->cs, pModule->ip, pModule->ss, pModule->sp, pModule->dgroup,
86 pModule->seg_count, pModule->modref_count );
87 DPRINTF( "os_flags=%d swap_area=%d version=%04x\n",
88 pModule->os_flags, pModule->min_swap_area,
89 pModule->expected_version );
90 if (pModule->flags & NE_FFLAGS_WIN32)
91 DPRINTF( "PE module=%08x\n", pModule->module32 );
93 /* Dump the file info */
95 DPRINTF( "Filename: '%s'\n", NE_MODULE_NAME(pModule) );
97 /* Dump the segment table */
99 DPRINTF( "Segment table:\n" );
100 pSeg = NE_SEG_TABLE( pModule );
101 for (i = 0; i < pModule->seg_count; i++, pSeg++)
102 DPRINTF( "%02x: pos=%d size=%d flags=%04x minsize=%d hSeg=%04x\n",
103 i + 1, pSeg->filepos, pSeg->size, pSeg->flags,
104 pSeg->minsize, pSeg->hSeg );
106 /* Dump the resource table */
108 DPRINTF( "Resource table:\n" );
109 if (pModule->res_table)
111 pword = (WORD *)((BYTE *)pModule + pModule->res_table);
112 DPRINTF( "Alignment: %d\n", *pword++ );
115 struct resource_typeinfo_s *ptr = (struct resource_typeinfo_s *)pword;
116 struct resource_nameinfo_s *pname = (struct resource_nameinfo_s *)(ptr + 1);
117 DPRINTF( "id=%04x count=%d\n", ptr->type_id, ptr->count );
118 for (i = 0; i < ptr->count; i++, pname++)
119 DPRINTF( "offset=%d len=%d id=%04x\n",
120 pname->offset, pname->length, pname->id );
121 pword = (WORD *)pname;
124 else DPRINTF( "None\n" );
126 /* Dump the resident name table */
128 DPRINTF( "Resident-name table:\n" );
129 pstr = (char *)pModule + pModule->name_table;
132 DPRINTF( "%*.*s: %d\n", *pstr, *pstr, pstr + 1,
133 *(WORD *)(pstr + *pstr + 1) );
134 pstr += *pstr + 1 + sizeof(WORD);
137 /* Dump the module reference table */
139 DPRINTF( "Module ref table:\n" );
140 if (pModule->modref_table)
142 pword = (WORD *)((BYTE *)pModule + pModule->modref_table);
143 for (i = 0; i < pModule->modref_count; i++, pword++)
146 GetModuleName16( *pword, name, sizeof(name) );
147 DPRINTF( "%d: %04x -> '%s'\n", i, *pword, name );
150 else DPRINTF( "None\n" );
152 /* Dump the entry table */
154 DPRINTF( "Entry table:\n" );
155 bundle = (ET_BUNDLE *)((BYTE *)pModule+pModule->entry_table);
157 entry = (ET_ENTRY *)((BYTE *)bundle+6);
158 DPRINTF( "Bundle %d-%d: %02x\n", bundle->first, bundle->last, entry->type);
159 ordinal = bundle->first;
160 while (ordinal < bundle->last)
162 if (entry->type == 0xff)
163 DPRINTF("%d: %02x:%04x (moveable)\n", ordinal++, entry->segnum, entry->offs);
165 DPRINTF("%d: %02x:%04x (fixed)\n", ordinal++, entry->segnum, entry->offs);
168 } while ( (bundle->next)
169 && (bundle = ((ET_BUNDLE *)((BYTE *)pModule + bundle->next))) );
171 /* Dump the non-resident names table */
173 DPRINTF( "Non-resident names table:\n" );
174 if (pModule->nrname_handle)
176 pstr = (char *)GlobalLock16( pModule->nrname_handle );
179 DPRINTF( "%*.*s: %d\n", *pstr, *pstr, pstr + 1,
180 *(WORD *)(pstr + *pstr + 1) );
181 pstr += *pstr + 1 + sizeof(WORD);
188 /***********************************************************************
191 * Walk the module list and print the modules.
193 void NE_WalkModules(void)
195 HMODULE16 hModule = hFirstModule;
196 MESSAGE( "Module Flags Name\n" );
199 NE_MODULE *pModule = NE_GetPtr( hModule );
202 MESSAGE( "Bad module %04x in list\n", hModule );
205 MESSAGE( " %04x %04x %.*s\n", hModule, pModule->flags,
206 *((char *)pModule + pModule->name_table),
207 (char *)pModule + pModule->name_table + 1 );
208 hModule = pModule->next;
213 /**********************************************************************
216 void NE_RegisterModule( NE_MODULE *pModule )
218 pModule->next = hFirstModule;
219 hFirstModule = pModule->self;
223 /***********************************************************************
226 * Lookup the ordinal for a given name.
228 WORD NE_GetOrdinal( HMODULE16 hModule, const char *name )
230 unsigned char buffer[256], *cpnt;
234 if (!(pModule = NE_GetPtr( hModule ))) return 0;
235 assert( !(pModule->flags & NE_FFLAGS_WIN32) );
237 TRACE("(%04x,'%s')\n", hModule, name );
239 /* First handle names of the form '#xxxx' */
241 if (name[0] == '#') return atoi( name + 1 );
243 /* Now copy and uppercase the string */
245 strcpy( buffer, name );
247 len = strlen( buffer );
249 /* First search the resident names */
251 cpnt = (char *)pModule + pModule->name_table;
253 /* Skip the first entry (module name) */
254 cpnt += *cpnt + 1 + sizeof(WORD);
257 if (((BYTE)*cpnt == len) && !memcmp( cpnt+1, buffer, len ))
259 TRACE(" Found: ordinal=%d\n",
260 *(WORD *)(cpnt + *cpnt + 1) );
261 return *(WORD *)(cpnt + *cpnt + 1);
263 cpnt += *cpnt + 1 + sizeof(WORD);
266 /* Now search the non-resident names table */
268 if (!pModule->nrname_handle) return 0; /* No non-resident table */
269 cpnt = (char *)GlobalLock16( pModule->nrname_handle );
271 /* Skip the first entry (module description string) */
272 cpnt += *cpnt + 1 + sizeof(WORD);
275 if (((BYTE)*cpnt == len) && !memcmp( cpnt+1, buffer, len ))
277 TRACE(" Found: ordinal=%d\n",
278 *(WORD *)(cpnt + *cpnt + 1) );
279 return *(WORD *)(cpnt + *cpnt + 1);
281 cpnt += *cpnt + 1 + sizeof(WORD);
287 /***********************************************************************
288 * NE_GetEntryPoint (WPROCS.27)
290 * Return the entry point for a given ordinal.
292 FARPROC16 WINAPI WIN16_NE_GetEntryPoint( HMODULE16 hModule, WORD ordinal )
294 FARPROC16 ret = NE_GetEntryPointEx( hModule, ordinal, TRUE );
295 CURRENT_STACK16->ecx = hModule; /* FIXME: might be incorrect value */
298 FARPROC16 WINAPI NE_GetEntryPoint( HMODULE16 hModule, WORD ordinal )
300 return NE_GetEntryPointEx( hModule, ordinal, TRUE );
302 FARPROC16 NE_GetEntryPointEx( HMODULE16 hModule, WORD ordinal, BOOL16 snoop )
310 if (!(pModule = NE_GetPtr( hModule ))) return 0;
311 assert( !(pModule->flags & NE_FFLAGS_WIN32) );
313 bundle = (ET_BUNDLE *)((BYTE *)pModule + pModule->entry_table);
314 while ((ordinal < bundle->first + 1) || (ordinal > bundle->last))
318 bundle = (ET_BUNDLE *)((BYTE *)pModule + bundle->next);
321 entry = (ET_ENTRY *)((BYTE *)bundle+6);
322 for (i=0; i < (ordinal - bundle->first - 1); i++)
326 offset = entry->offs;
328 if (sel == 0xfe) sel = 0xffff; /* constant entry */
329 else sel = GlobalHandleToSel16(NE_SEG_TABLE(pModule)[sel-1].hSeg);
331 return (FARPROC16)PTR_SEG_OFF_TO_SEGPTR( sel, offset );
333 return (FARPROC16)PTR_SEG_OFF_TO_SEGPTR( sel, offset );
335 return (FARPROC16)SNOOP16_GetProcAddress16(hModule,ordinal,(FARPROC16)PTR_SEG_OFF_TO_SEGPTR( sel, offset ));
339 /***********************************************************************
342 * Change the value of an entry point. Use with caution!
343 * It can only change the offset value, not the selector.
345 BOOL16 NE_SetEntryPoint( HMODULE16 hModule, WORD ordinal, WORD offset )
352 if (!(pModule = NE_GetPtr( hModule ))) return FALSE;
353 assert( !(pModule->flags & NE_FFLAGS_WIN32) );
355 bundle = (ET_BUNDLE *)((BYTE *)pModule + pModule->entry_table);
356 while ((ordinal < bundle->first + 1) || (ordinal > bundle->last))
358 bundle = (ET_BUNDLE *)((BYTE *)pModule + bundle->next);
363 entry = (ET_ENTRY *)((BYTE *)bundle+6);
364 for (i=0; i < (ordinal - bundle->first - 1); i++)
367 entry->offs = offset;
372 /***********************************************************************
375 HANDLE NE_OpenFile( NE_MODULE *pModule )
379 static HANDLE cachedfd = -1;
381 TRACE("(%p) cache: mod=%p fd=%d\n",
382 pModule, pCachedModule, cachedfd );
383 if (pCachedModule == pModule) return cachedfd;
384 CloseHandle( cachedfd );
385 pCachedModule = pModule;
386 name = NE_MODULE_NAME( pModule );
387 if ((cachedfd = CreateFileA( name, GENERIC_READ, FILE_SHARE_READ,
388 NULL, OPEN_EXISTING, 0, -1 )) == -1)
389 MESSAGE( "Can't open file '%s' for module %04x\n", name, pModule->self );
390 TRACE("opened '%s' -> %d\n",
396 /***********************************************************************
399 * We always have to close hFile upon exit.
400 * Otherwise we get file sharing trouble !
402 static HMODULE16 NE_LoadExeHeader( LPCSTR filename )
404 IMAGE_DOS_HEADER mz_header;
405 IMAGE_OS2_HEADER ne_header;
409 BYTE *pData, *pTempEntryTable;
410 char *buffer, *fastload = NULL;
411 int fastload_offset = 0, fastload_length = 0;
413 ET_BUNDLE *bundle, *oldbundle;
418 if ((hFile = OpenFile16( filename, &ofs, OF_READ )) == HFILE_ERROR16)
419 return (HMODULE16)2; /* File not found */
421 /* Read a block from either the file or the fast-load area. */
422 #define READ(offset,size,buffer) \
423 ((fastload && ((offset) >= fastload_offset) && \
424 ((offset)+(size) <= fastload_offset+fastload_length)) ? \
425 (memcpy( buffer, fastload+(offset)-fastload_offset, (size) ), TRUE) : \
426 (_llseek16( hFile, (offset), SEEK_SET), \
427 _hread16( hFile, (buffer), (size) ) == (size)))
429 _llseek16( hFile, 0, SEEK_SET );
430 if ((_hread16(hFile,&mz_header,sizeof(mz_header)) != sizeof(mz_header)) ||
431 (mz_header.e_magic != IMAGE_DOS_SIGNATURE))
434 return (HMODULE16)11; /* invalid exe */
437 _llseek16( hFile, mz_header.e_lfanew, SEEK_SET );
438 if (_hread16( hFile, &ne_header, sizeof(ne_header) ) != sizeof(ne_header))
441 return (HMODULE16)11; /* invalid exe */
444 if (ne_header.ne_magic == IMAGE_NT_SIGNATURE)
447 return (HMODULE16)21; /* win32 exe */
449 if (ne_header.ne_magic == IMAGE_OS2_SIGNATURE_LX) {
450 MESSAGE("Sorry, this is an OS/2 linear executable (LX) file !\n");
452 return (HMODULE16)12;
454 if (ne_header.ne_magic != IMAGE_OS2_SIGNATURE)
457 return (HMODULE16)11; /* invalid exe */
460 /* We now have a valid NE header */
462 size = sizeof(NE_MODULE) +
464 ne_header.ne_cseg * sizeof(SEGTABLEENTRY) +
466 ne_header.ne_restab - ne_header.ne_rsrctab +
467 /* resident names table */
468 ne_header.ne_modtab - ne_header.ne_restab +
469 /* module ref table */
470 ne_header.ne_cmod * sizeof(WORD) +
471 /* imported names table */
472 ne_header.ne_enttab - ne_header.ne_imptab +
473 /* entry table length */
474 ne_header.ne_cbenttab +
475 /* entry table extra conversion space */
477 2 * (ne_header.ne_cbenttab - ne_header.ne_cmovent*6) +
478 /* loaded file info */
479 sizeof(OFSTRUCT)-sizeof(ofs.szPathName)+strlen(ofs.szPathName)+1;
481 hModule = GlobalAlloc16( GMEM_FIXED | GMEM_ZEROINIT, size );
485 return (HMODULE16)11; /* invalid exe */
488 FarSetOwner16( hModule, hModule );
489 pModule = (NE_MODULE *)GlobalLock16( hModule );
490 memcpy( pModule, &ne_header, sizeof(ne_header) );
492 /* check *programs* for default minimal stack size */
493 if ( (!(pModule->flags & NE_FFLAGS_LIBMODULE))
494 && (pModule->stack_size < 0x1400) )
495 pModule->stack_size = 0x1400;
496 pModule->module32 = 0;
497 pModule->self = hModule;
498 pModule->self_loading_sel = 0;
499 pData = (BYTE *)(pModule + 1);
501 /* Clear internal Wine flags in case they are set in the EXE file */
503 pModule->flags &= ~(NE_FFLAGS_BUILTIN | NE_FFLAGS_WIN32);
505 /* Read the fast-load area */
507 if (ne_header.ne_flagsothers & NE_AFLAGS_FASTLOAD)
509 fastload_offset=ne_header.fastload_offset << ne_header.ne_align;
510 fastload_length=ne_header.fastload_length << ne_header.ne_align;
511 TRACE("Using fast-load area offset=%x len=%d\n",
512 fastload_offset, fastload_length );
513 if ((fastload = HeapAlloc( GetProcessHeap(), 0, fastload_length )) != NULL)
515 _llseek16( hFile, fastload_offset, SEEK_SET);
516 if (_hread16(hFile, fastload, fastload_length) != fastload_length)
518 HeapFree( GetProcessHeap(), 0, fastload );
519 WARN("Error reading fast-load area!\n");
525 /* Get the segment table */
527 pModule->seg_table = (int)pData - (int)pModule;
528 buffer = HeapAlloc( GetProcessHeap(), 0, ne_header.ne_cseg *
529 sizeof(struct ne_segment_table_entry_s));
533 struct ne_segment_table_entry_s *pSeg;
535 if (!READ( mz_header.e_lfanew + ne_header.ne_segtab,
536 ne_header.ne_cseg * sizeof(struct ne_segment_table_entry_s),
539 HeapFree( GetProcessHeap(), 0, buffer );
541 HeapFree( GetProcessHeap(), 0, fastload );
542 GlobalFree16( hModule );
544 return (HMODULE16)11; /* invalid exe */
546 pSeg = (struct ne_segment_table_entry_s *)buffer;
547 for (i = ne_header.ne_cseg; i > 0; i--, pSeg++)
549 memcpy( pData, pSeg, sizeof(*pSeg) );
550 pData += sizeof(SEGTABLEENTRY);
552 HeapFree( GetProcessHeap(), 0, buffer );
557 HeapFree( GetProcessHeap(), 0, fastload );
558 GlobalFree16( hModule );
560 return (HMODULE16)11; /* invalid exe */
563 /* Get the resource table */
565 if (ne_header.ne_rsrctab < ne_header.ne_restab)
567 pModule->res_table = (int)pData - (int)pModule;
568 if (!READ(mz_header.e_lfanew + ne_header.ne_rsrctab,
569 ne_header.ne_restab - ne_header.ne_rsrctab,
573 return (HMODULE16)11; /* invalid exe */
575 pData += ne_header.ne_restab - ne_header.ne_rsrctab;
576 NE_InitResourceHandler( hModule );
578 else pModule->res_table = 0; /* No resource table */
580 /* Get the resident names table */
582 pModule->name_table = (int)pData - (int)pModule;
583 if (!READ( mz_header.e_lfanew + ne_header.ne_restab,
584 ne_header.ne_modtab - ne_header.ne_restab,
588 HeapFree( GetProcessHeap(), 0, fastload );
589 GlobalFree16( hModule );
591 return (HMODULE16)11; /* invalid exe */
593 pData += ne_header.ne_modtab - ne_header.ne_restab;
595 /* Get the module references table */
597 if (ne_header.ne_cmod > 0)
599 pModule->modref_table = (int)pData - (int)pModule;
600 if (!READ( mz_header.e_lfanew + ne_header.ne_modtab,
601 ne_header.ne_cmod * sizeof(WORD),
605 HeapFree( GetProcessHeap(), 0, fastload );
606 GlobalFree16( hModule );
608 return (HMODULE16)11; /* invalid exe */
610 pData += ne_header.ne_cmod * sizeof(WORD);
612 else pModule->modref_table = 0; /* No module references */
614 /* Get the imported names table */
616 pModule->import_table = (int)pData - (int)pModule;
617 if (!READ( mz_header.e_lfanew + ne_header.ne_imptab,
618 ne_header.ne_enttab - ne_header.ne_imptab,
622 HeapFree( GetProcessHeap(), 0, fastload );
623 GlobalFree16( hModule );
625 return (HMODULE16)11; /* invalid exe */
627 pData += ne_header.ne_enttab - ne_header.ne_imptab;
629 /* Load entry table, convert it to the optimized version used by Windows */
631 if ((pTempEntryTable = HeapAlloc( GetProcessHeap(), 0, ne_header.ne_cbenttab)) != NULL)
633 BYTE nr_entries, type, *s;
635 TRACE("Converting entry table.\n");
636 pModule->entry_table = (int)pData - (int)pModule;
637 if (!READ( mz_header.e_lfanew + ne_header.ne_enttab,
638 ne_header.ne_cbenttab, pTempEntryTable ))
640 HeapFree( GetProcessHeap(), 0, pTempEntryTable );
642 HeapFree( GetProcessHeap(), 0, fastload );
643 GlobalFree16( hModule );
645 return (HMODULE16)11; /* invalid exe */
649 TRACE("entry table: offs %04x, len %04x, entries %d\n", ne_header.ne_enttab, ne_header.ne_cbenttab, *s);
651 bundle = (ET_BUNDLE *)pData;
652 TRACE("first bundle: %p\n", bundle);
653 memset(bundle, 0, sizeof(ET_BUNDLE)); /* in case no entry table exists */
654 entry = (ET_ENTRY *)((BYTE *)bundle+6);
656 while ((nr_entries = *s++))
660 bundle->last += nr_entries;
667 entry->segnum = *s++;
668 entry->offs = *(WORD *)s; s += 2;
669 /*TRACE(module, "entry: %p, type: %d, flags: %d, segnum: %d, offs: %04x\n", entry, entry->type, entry->flags, entry->segnum, entry->offs);*/
677 entry->segnum = type;
678 entry->offs = *(WORD *)s; s += 2;
679 /*TRACE(module, "entry: %p, type: %d, flags: %d, segnum: %d, offs: %04x\n", entry, entry->type, entry->flags, entry->segnum, entry->offs);*/
685 if (bundle->first == bundle->last)
687 bundle->first += nr_entries;
688 bundle->last += nr_entries;
693 oldbundle->next = ((int)entry - (int)pModule);
694 bundle = (ET_BUNDLE *)entry;
695 TRACE("new bundle: %p\n", bundle);
696 bundle->first = bundle->last =
697 oldbundle->last + nr_entries;
699 (BYTE *)entry += sizeof(ET_BUNDLE);
703 HeapFree( GetProcessHeap(), 0, pTempEntryTable );
708 HeapFree( GetProcessHeap(), 0, fastload );
709 GlobalFree16( hModule );
711 return (HMODULE16)11; /* invalid exe */
714 pData += ne_header.ne_cbenttab + sizeof(ET_BUNDLE) +
715 2 * (ne_header.ne_cbenttab - ne_header.ne_cmovent*6);
717 if ((DWORD)entry > (DWORD)pData)
718 ERR("converted entry table bigger than reserved space !!!\nentry: %p, pData: %p. Please report !\n", entry, pData);
720 /* Store the filename information */
722 pModule->fileinfo = (int)pData - (int)pModule;
723 size = sizeof(OFSTRUCT)-sizeof(ofs.szPathName)+strlen(ofs.szPathName)+1;
724 ofs.cBytes = size - 1;
725 memcpy( pData, &ofs, size );
728 /* Free the fast-load area */
732 HeapFree( GetProcessHeap(), 0, fastload );
734 /* Get the non-resident names table */
736 if (ne_header.ne_cbnrestab)
738 pModule->nrname_handle = GLOBAL_Alloc( 0, ne_header.ne_cbnrestab,
739 hModule, WINE_LDT_FLAGS_DATA );
740 if (!pModule->nrname_handle)
742 GlobalFree16( hModule );
744 return (HMODULE16)11; /* invalid exe */
746 buffer = GlobalLock16( pModule->nrname_handle );
747 _llseek16( hFile, ne_header.ne_nrestab, SEEK_SET );
748 if (_hread16( hFile, buffer, ne_header.ne_cbnrestab )
749 != ne_header.ne_cbnrestab)
751 GlobalFree16( pModule->nrname_handle );
752 GlobalFree16( hModule );
754 return (HMODULE16)11; /* invalid exe */
757 else pModule->nrname_handle = 0;
759 /* Allocate a segment for the implicitly-loaded DLLs */
761 if (pModule->modref_count)
763 pModule->dlls_to_init = GLOBAL_Alloc(GMEM_ZEROINIT,
764 (pModule->modref_count+1)*sizeof(HMODULE16),
765 hModule, WINE_LDT_FLAGS_DATA );
766 if (!pModule->dlls_to_init)
768 if (pModule->nrname_handle) GlobalFree16( pModule->nrname_handle );
769 GlobalFree16( hModule );
771 return (HMODULE16)11; /* invalid exe */
774 else pModule->dlls_to_init = 0;
776 NE_RegisterModule( pModule );
777 SNOOP16_RegisterDLL(pModule,ofs.szPathName);
784 /***********************************************************************
787 * Load all DLLs implicitly linked to a module.
789 static BOOL NE_LoadDLLs( NE_MODULE *pModule )
792 WORD *pModRef = (WORD *)((char *)pModule + pModule->modref_table);
793 WORD *pDLLs = (WORD *)GlobalLock16( pModule->dlls_to_init );
795 for (i = 0; i < pModule->modref_count; i++, pModRef++)
797 char buffer[260], *p;
798 BYTE *pstr = (BYTE *)pModule + pModule->import_table + *pModRef;
799 memcpy( buffer, pstr + 1, *pstr );
800 *(buffer + *pstr) = 0; /* terminate it */
802 TRACE("Loading '%s'\n", buffer );
803 if (!(*pModRef = GetModuleHandle16( buffer )))
805 /* If the DLL is not loaded yet, load it and store */
806 /* its handle in the list of DLLs to initialize. */
809 /* Append .DLL to name if no extension present */
810 if (!(p = strrchr( buffer, '.')) || strchr( p, '/' ) || strchr( p, '\\'))
811 strcat( buffer, ".DLL" );
813 if ((hDLL = MODULE_LoadModule16( buffer, TRUE, TRUE )) < 32)
815 /* FIXME: cleanup what was done */
817 MESSAGE( "Could not load '%s' required by '%.*s', error=%d\n",
818 buffer, *((BYTE*)pModule + pModule->name_table),
819 (char *)pModule + pModule->name_table + 1, hDLL );
822 *pModRef = GetExePtr( hDLL );
825 else /* Increment the reference count of the DLL */
829 pOldDLL = NE_GetPtr( *pModRef );
830 if (pOldDLL) pOldDLL->count++;
837 /**********************************************************************
840 * Load first instance of NE module from file.
842 * pModule must point to a module structure prepared by NE_LoadExeHeader.
843 * This routine must never be called twice on a module.
846 static HINSTANCE16 NE_DoLoadModule( NE_MODULE *pModule )
848 /* Allocate the segments for this module */
850 if (!NE_CreateAllSegments( pModule ))
851 return ERROR_NOT_ENOUGH_MEMORY; /* 8 */
853 /* Load the referenced DLLs */
855 if (!NE_LoadDLLs( pModule ))
856 return ERROR_FILE_NOT_FOUND; /* 2 */
858 /* Load the segments */
860 NE_LoadAllSegments( pModule );
862 /* Make sure the usage count is 1 on the first loading of */
863 /* the module, even if it contains circular DLL references */
867 return NE_GetInstance( pModule );
870 /**********************************************************************
873 * Load first instance of NE module. (Note: caller is responsible for
874 * ensuring the module isn't already loaded!)
876 * If the module turns out to be an executable module, only a
877 * handle to a module stub is returned; this needs to be initialized
878 * by calling NE_DoLoadModule later, in the context of the newly
881 * If lib_only is TRUE, however, the module is perforce treated
882 * like a DLL module, even if it is an executable module.
885 static HINSTANCE16 NE_LoadModule( LPCSTR name, BOOL lib_only )
889 HINSTANCE16 hInstance;
891 hModule = NE_LoadExeHeader( name );
892 if (hModule < 32) return hModule;
894 pModule = NE_GetPtr( hModule );
895 if ( !pModule ) return hModule;
897 if ( !lib_only && !( pModule->flags & NE_FFLAGS_LIBMODULE ) )
900 hInstance = NE_DoLoadModule( pModule );
901 if ( hInstance < 32 )
904 NE_FreeModule( hModule, 0 );
911 /**********************************************************************
912 * MODULE_LoadModule16
914 * Load a NE module in the order of the loadorder specification.
915 * The caller is responsible that the module is not loaded already.
918 static HINSTANCE16 MODULE_LoadModule16( LPCSTR libname, BOOL implicit, BOOL lib_only )
922 module_loadorder_t *plo;
924 plo = MODULE_GetLoadOrder(libname, FALSE);
926 for(i = 0; i < MODULE_LOADORDER_NTYPES; i++)
928 switch(plo->loadorder[i])
930 case MODULE_LOADORDER_DLL:
931 TRACE("Trying native dll '%s'\n", libname);
932 hinst = NE_LoadModule(libname, lib_only);
935 case MODULE_LOADORDER_BI:
936 TRACE("Trying built-in '%s'\n", libname);
937 hinst = BUILTIN_LoadModule(libname);
941 ERR("Got invalid loadorder type %d (%s index %d)\n", plo->loadorder[i], plo->modulename, i);
944 case MODULE_LOADORDER_SO: /* This is not supported for NE modules */
945 case MODULE_LOADORDER_ELFDLL: /* This is not supported for NE modules */
946 case MODULE_LOADORDER_INVALID: /* We ignore this as it is an empty entry */
958 hModule = GetModuleHandle16(libname);
961 ERR("Serious trouble. Just loaded module '%s' (hinst=0x%04x), but can't get module handle. Filename too long ?\n",
963 return 6; /* ERROR_INVALID_HANDLE seems most appropriate */
966 pModule = NE_GetPtr(hModule);
969 ERR("Serious trouble. Just loaded module '%s' (hinst=0x%04x), but can't get NE_MODULE pointer\n",
971 return 6; /* ERROR_INVALID_HANDLE seems most appropriate */
974 TRACE("Loaded module '%s' at 0x%04x.\n", libname, hinst);
977 * Call initialization routines for all loaded DLLs. Note that
978 * when we load implicitly linked DLLs this will be done by InitTask().
980 if(pModule->flags & NE_FFLAGS_LIBMODULE)
982 NE_InitializeDLLs(hModule);
983 NE_DllProcessAttach(hModule);
991 /* We quit searching when we get another error than 'File not found' */
995 return hinst; /* The last error that occured */
999 /**********************************************************************
1000 * LoadModule16 (KERNEL.45)
1002 HINSTANCE16 WINAPI LoadModule16( LPCSTR name, LPVOID paramBlock )
1005 BOOL lib_only = !paramBlock || (paramBlock == (LPVOID)-1);
1006 LOADPARAMS16 *params;
1007 HINSTANCE16 instance = 0;
1014 HANDLE hThread = -1;
1019 if ( (hModule = NE_GetModuleByFilename(name) ) != 0 )
1021 /* Special case: second instance of an already loaded NE module */
1023 if ( !( pModule = NE_GetPtr( hModule ) ) ) return (HINSTANCE16)11;
1024 if ( pModule->module32 ) return (HINSTANCE16)21;
1026 /* Increment refcount */
1032 /* Main case: load first instance of NE module */
1034 if ( (hModule = MODULE_LoadModule16( name, FALSE, lib_only )) < 32 )
1037 if ( !(pModule = NE_GetPtr( hModule )) )
1038 return (HINSTANCE16)11;
1041 /* If library module, we just retrieve the instance handle */
1043 if ( ( pModule->flags & NE_FFLAGS_LIBMODULE ) || lib_only )
1044 return NE_GetInstance( pModule );
1047 * At this point, we need to create a new process.
1049 * pModule points either to an already loaded module, whose refcount
1050 * has already been incremented (to avoid having the module vanish
1051 * in the meantime), or else to a stub module which contains only header
1055 /* Create the main thread */
1059 struct new_thread_request *req = server_alloc_req( sizeof(*req), 0 );
1062 if (!server_call_fd( REQ_NEW_THREAD, -1, &socket )) hThread = req->handle;
1065 if (hThread == -1) return 0;
1067 if (!(teb = THREAD_Create( socket, 0, FALSE ))) goto error;
1068 teb->startup = NE_InitProcess;
1070 /* Create a task for this process */
1072 params = (LOADPARAMS16 *)paramBlock;
1073 cmdShow = ((WORD *)PTR_SEG_TO_LIN(params->showCmd))[1];
1074 cmdline = PTR_SEG_TO_LIN( params->cmdLine );
1075 if (!TASK_Create( pModule, cmdShow, teb, cmdline + 1, *cmdline )) goto error;
1077 hTask = teb->htask16;
1079 if (SYSDEPS_SpawnThread( teb ) == -1) goto error;
1081 /* Post event to start the task */
1082 PostEvent16( hTask );
1084 /* Wait until we get the instance handle */
1087 DirectedYield16( hTask );
1088 if (!IsTask16( hTask )) /* thread has died */
1091 WaitForSingleObject( hThread, INFINITE );
1092 GetExitCodeThread( hThread, &exit_code );
1093 CloseHandle( hThread );
1096 if (!(pTask = (TDB *)GlobalLock16( hTask ))) break;
1097 instance = pTask->hInstance;
1098 GlobalUnlock16( hTask );
1099 } while (!instance);
1104 /* FIXME: free TEB and task */
1106 CloseHandle( hThread );
1107 return 0; /* FIXME */
1111 /**********************************************************************
1114 static void NE_InitProcess(void)
1116 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
1117 NE_MODULE *pModule = NE_GetPtr( pTask->hModule );
1118 HINSTANCE16 hInstance, hPrevInstance;
1119 SEGTABLEENTRY *pSegTable = NE_SEG_TABLE( pModule );
1124 if ( pModule->count > 0 )
1126 /* Second instance of an already loaded NE module */
1127 /* Note that the refcount was already incremented by the parent */
1129 hPrevInstance = NE_GetInstance( pModule );
1131 if ( pModule->dgroup )
1132 if ( NE_CreateSegment( pModule, pModule->dgroup ) )
1133 NE_LoadSegment( pModule, pModule->dgroup );
1135 hInstance = NE_GetInstance( pModule );
1136 TRACE("created second instance %04x[%d] of instance %04x.\n", hInstance, pModule->dgroup, hPrevInstance);
1141 /* Load first instance of NE module */
1143 pModule->flags |= NE_FFLAGS_GUI; /* FIXME: is this necessary? */
1145 hInstance = NE_DoLoadModule( pModule );
1149 if ( hInstance >= 32 )
1153 /* Enter instance handles into task struct */
1155 pTask->hInstance = hInstance;
1156 pTask->hPrevInstance = hPrevInstance;
1158 /* Use DGROUP for 16-bit stack */
1160 if (!(sp = pModule->sp))
1161 sp = pSegTable[pModule->ss-1].minsize + pModule->stack_size;
1163 sp -= sizeof(STACK16FRAME);
1164 pTask->teb->cur_stack = PTR_SEG_OFF_TO_SEGPTR( GlobalHandleToSel16(hInstance), sp );
1166 /* Registers at initialization must be:
1168 * bx stack size in bytes
1169 * cx heap size in bytes
1170 * si previous app instance
1171 * di current app instance
1173 * es selector to the PSP
1174 * ds dgroup of the application
1176 * sp top of the stack
1178 memset( &context, 0, sizeof(context) );
1179 context.SegCs = GlobalHandleToSel16(pSegTable[pModule->cs - 1].hSeg);
1180 context.SegDs = GlobalHandleToSel16(pTask->hInstance);
1181 context.SegEs = pTask->hPDB;
1182 context.Eip = pModule->ip;
1183 context.Ebx = pModule->stack_size;
1184 context.Ecx = pModule->heap_size;
1185 context.Edi = pTask->hInstance;
1186 context.Esi = pTask->hPrevInstance;
1188 /* Now call 16-bit entry point */
1190 TRACE("Starting main program: cs:ip=%04lx:%04lx ds=%04lx ss:sp=%04x:%04x\n",
1191 context.SegCs, context.Eip, context.SegDs,
1192 SELECTOROF(pTask->teb->cur_stack),
1193 OFFSETOF(pTask->teb->cur_stack) );
1195 CallTo16RegisterShort( &context, 0 );
1196 ExitThread( LOWORD(context.Eax) );
1200 ExitThread( hInstance );
1203 /***********************************************************************
1204 * LoadLibrary16 (KERNEL.95)
1206 HINSTANCE16 WINAPI LoadLibrary16( LPCSTR libname )
1208 return LoadModule16(libname, (LPVOID)-1 );
1212 /**********************************************************************
1215 * Call a DLL's WEP, allowing it to shut down.
1216 * FIXME: we always pass the WEP WEP_FREE_DLL, never WEP_SYSTEM_EXIT
1218 static BOOL16 MODULE_CallWEP( HMODULE16 hModule )
1220 FARPROC16 WEP = (FARPROC16)0;
1221 WORD ordinal = NE_GetOrdinal( hModule, "WEP" );
1223 if (ordinal) WEP = NE_GetEntryPoint( hModule, ordinal );
1226 WARN("module %04x doesn't have a WEP\n", hModule );
1229 return NE_CallTo16_word_w( WEP, WEP_FREE_DLL );
1233 /**********************************************************************
1236 * Implementation of FreeModule16().
1238 static BOOL16 NE_FreeModule( HMODULE16 hModule, BOOL call_wep )
1240 HMODULE16 *hPrevModule;
1245 if (!(pModule = NE_GetPtr( hModule ))) return FALSE;
1246 hModule = pModule->self;
1248 TRACE("%04x count %d\n", hModule, pModule->count );
1250 if (((INT16)(--pModule->count)) > 0 ) return TRUE;
1251 else pModule->count = 0;
1253 if (pModule->flags & NE_FFLAGS_BUILTIN)
1254 return FALSE; /* Can't free built-in module */
1256 if (call_wep && !(pModule->flags & NE_FFLAGS_WIN32))
1258 if (pModule->flags & NE_FFLAGS_LIBMODULE)
1260 MODULE_CallWEP( hModule );
1262 /* Free the objects owned by the DLL module */
1263 TASK_CallTaskSignalProc( USIG16_DLL_UNLOAD, hModule );
1264 PROCESS_CallUserSignalProc( USIG_DLL_UNLOAD_WIN16, hModule );
1267 call_wep = FALSE; /* We are freeing a task -> no more WEPs */
1271 /* Clear magic number just in case */
1273 pModule->magic = pModule->self = 0;
1275 /* Remove it from the linked list */
1277 hPrevModule = &hFirstModule;
1278 while (*hPrevModule && (*hPrevModule != hModule))
1280 hPrevModule = &(NE_GetPtr( *hPrevModule ))->next;
1282 if (*hPrevModule) *hPrevModule = pModule->next;
1284 /* Free the referenced modules */
1286 pModRef = (HMODULE16*)NE_MODULE_TABLE( pModule );
1287 for (i = 0; i < pModule->modref_count; i++, pModRef++)
1289 NE_FreeModule( *pModRef, call_wep );
1292 /* Free the module storage */
1294 GlobalFreeAll16( hModule );
1296 /* Remove module from cache */
1298 if (pCachedModule == pModule) pCachedModule = NULL;
1303 /**********************************************************************
1304 * FreeModule16 (KERNEL.46)
1306 BOOL16 WINAPI FreeModule16( HMODULE16 hModule )
1308 return NE_FreeModule( hModule, TRUE );
1312 /***********************************************************************
1313 * FreeLibrary16 (KERNEL.96)
1315 void WINAPI FreeLibrary16( HINSTANCE16 handle )
1317 TRACE("%04x\n", handle );
1318 FreeModule16( handle );
1322 /**********************************************************************
1323 * GetModuleName (KERNEL.27)
1325 BOOL16 WINAPI GetModuleName16( HINSTANCE16 hinst, LPSTR buf, INT16 count )
1330 if (!(pModule = NE_GetPtr( hinst ))) return FALSE;
1331 p = (BYTE *)pModule + pModule->name_table;
1332 if (count > *p) count = *p + 1;
1335 memcpy( buf, p + 1, count - 1 );
1336 buf[count-1] = '\0';
1342 /**********************************************************************
1343 * GetModuleUsage (KERNEL.48)
1345 INT16 WINAPI GetModuleUsage16( HINSTANCE16 hModule )
1347 NE_MODULE *pModule = NE_GetPtr( hModule );
1348 return pModule ? pModule->count : 0;
1352 /**********************************************************************
1353 * GetExpWinVer (KERNEL.167)
1355 WORD WINAPI GetExpWinVer16( HMODULE16 hModule )
1357 NE_MODULE *pModule = NE_GetPtr( hModule );
1358 if ( !pModule ) return 0;
1361 * For built-in modules, fake the expected version the module should
1362 * have according to the Windows version emulated by Wine
1364 if ( !pModule->expected_version )
1366 OSVERSIONINFOA versionInfo;
1367 versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);
1369 if ( GetVersionExA( &versionInfo ) )
1370 pModule->expected_version =
1371 (versionInfo.dwMajorVersion & 0xff) << 8
1372 | (versionInfo.dwMinorVersion & 0xff);
1375 return pModule->expected_version;
1379 /**********************************************************************
1380 * GetModuleFileName16 (KERNEL.49)
1382 * Comment: see GetModuleFileNameA
1384 * Even if invoked by second instance of a program,
1385 * it still returns path of first one.
1387 INT16 WINAPI GetModuleFileName16( HINSTANCE16 hModule, LPSTR lpFileName,
1392 /* Win95 does not query hModule if set to 0 !
1393 * Is this wrong or maybe Win3.1 only ? */
1394 if (!hModule) hModule = GetCurrentTask();
1396 if (!(pModule = NE_GetPtr( hModule ))) return 0;
1397 lstrcpynA( lpFileName, NE_MODULE_NAME(pModule), nSize );
1398 if (pModule->expected_version >= 0x400)
1399 GetLongPathNameA(NE_MODULE_NAME(pModule), lpFileName, nSize);
1400 TRACE("%04x -> '%s'\n", hModule, lpFileName );
1401 return strlen(lpFileName);
1405 /**********************************************************************
1406 * GetModuleHandle (KERNEL.47)
1408 * Find a module from a module name.
1410 * NOTE: The current implementation works the same way the Windows 95 one
1411 * does. Do not try to 'fix' it, fix the callers.
1412 * + It does not do ANY extension handling (except that strange .EXE bit)!
1413 * + It does not care about paths, just about basenames. (same as Windows)
1417 * the win16 module handle if found
1419 * HIWORD (undocumented, see "Undocumented Windows", chapter 5):
1420 * Always hFirstModule
1422 DWORD WINAPI WIN16_GetModuleHandle( SEGPTR name )
1424 if (HIWORD(name) == 0)
1425 return MAKELONG(GetExePtr( (HINSTANCE16)name), hFirstModule );
1426 return MAKELONG(GetModuleHandle16( PTR_SEG_TO_LIN(name)), hFirstModule );
1429 HMODULE16 WINAPI GetModuleHandle16( LPCSTR name )
1431 HMODULE16 hModule = hFirstModule;
1433 BYTE len, *name_table;
1434 char tmpstr[MAX_PATH];
1437 TRACE("(%s)\n", name);
1440 return GetExePtr(LOWORD(name));
1446 lstrcpynA(tmpstr, name, sizeof(tmpstr));
1448 /* If 'name' matches exactly the module name of a module:
1449 * Return its handle.
1451 for (hModule = hFirstModule; hModule ; hModule = pModule->next)
1453 pModule = NE_GetPtr( hModule );
1454 if (!pModule) break;
1455 if (pModule->flags & NE_FFLAGS_WIN32) continue;
1457 name_table = (BYTE *)pModule + pModule->name_table;
1458 if ((*name_table == len) && !strncmp(name, name_table+1, len))
1462 /* If uppercased 'name' matches exactly the module name of a module:
1465 for (s = tmpstr; *s; s++)
1468 for (hModule = hFirstModule; hModule ; hModule = pModule->next)
1470 pModule = NE_GetPtr( hModule );
1471 if (!pModule) break;
1472 if (pModule->flags & NE_FFLAGS_WIN32) continue;
1474 name_table = (BYTE *)pModule + pModule->name_table;
1475 /* FIXME: the strncasecmp is WRONG. It should not be case insensitive,
1476 * but case sensitive! (Unfortunately Winword 6 and subdlls have
1477 * lowercased module names, but try to load uppercase DLLs, so this
1478 * 'i' compare is just a quickfix until the loader handles that
1479 * correctly. -MM 990705
1481 if ((*name_table == len) && !strncasecmp(tmpstr, name_table+1, len))
1485 /* If the base filename of 'name' matches the base filename of the module
1486 * filename of some module (case-insensitive compare):
1487 * Return its handle.
1490 /* basename: search backwards in passed name to \ / or : */
1491 s = tmpstr + strlen(tmpstr);
1494 if (s[-1]=='/' || s[-1]=='\\' || s[-1]==':')
1499 /* search this in loaded filename list */
1500 for (hModule = hFirstModule; hModule ; hModule = pModule->next)
1505 pModule = NE_GetPtr( hModule );
1506 if (!pModule) break;
1507 if (!pModule->fileinfo) continue;
1508 if (pModule->flags & NE_FFLAGS_WIN32) continue;
1510 ofs = (OFSTRUCT*)((BYTE *)pModule + pModule->fileinfo);
1511 loadedfn = ((char*)ofs->szPathName) + strlen(ofs->szPathName);
1512 /* basename: search backwards in pathname to \ / or : */
1513 while (loadedfn > (char*)ofs->szPathName)
1515 if (loadedfn[-1]=='/' || loadedfn[-1]=='\\' || loadedfn[-1]==':')
1519 /* case insensitive compare ... */
1520 if (!strcasecmp(loadedfn, s))
1524 /* If the extension of 'name' is '.EXE' and the base filename of 'name'
1525 * matches the base filename of the module filename of some 32-bit module:
1526 * Return the corresponding 16-bit dummy module handle.
1528 if (len >= 4 && !strcasecmp(name+len-4, ".EXE"))
1530 HMODULE hModule = GetModuleHandleA( name );
1532 return MapHModuleLS( hModule );
1535 if (!strcmp(tmpstr,"MSDOS"))
1538 if (!strcmp(tmpstr,"TIMER"))
1540 FIXME("Eh... Should return caller's code segment, expect crash\n");
1547 /**********************************************************************
1548 * NE_GetModuleByFilename
1550 static HMODULE16 NE_GetModuleByFilename( LPCSTR name )
1554 BYTE len, *name_table;
1555 char tmpstr[MAX_PATH];
1558 lstrcpynA(tmpstr, name, sizeof(tmpstr));
1560 /* If the base filename of 'name' matches the base filename of the module
1561 * filename of some module (case-insensitive compare):
1562 * Return its handle.
1565 /* basename: search backwards in passed name to \ / or : */
1566 s = tmpstr + strlen(tmpstr);
1569 if (s[-1]=='/' || s[-1]=='\\' || s[-1]==':')
1574 /* search this in loaded filename list */
1575 for (hModule = hFirstModule; hModule ; hModule = pModule->next)
1580 pModule = NE_GetPtr( hModule );
1581 if (!pModule) break;
1582 if (!pModule->fileinfo) continue;
1583 if (pModule->flags & NE_FFLAGS_WIN32) continue;
1585 ofs = (OFSTRUCT*)((BYTE *)pModule + pModule->fileinfo);
1586 loadedfn = ((char*)ofs->szPathName) + strlen(ofs->szPathName);
1587 /* basename: search backwards in pathname to \ / or : */
1588 while (loadedfn > (char*)ofs->szPathName)
1590 if (loadedfn[-1]=='/' || loadedfn[-1]=='\\' || loadedfn[-1]==':')
1594 /* case insensitive compare ... */
1595 if (!strcasecmp(loadedfn, s))
1599 /* If basename (without ext) matches the module name of a module:
1600 * Return its handle.
1603 if ( (p = strrchr( s, '.' )) != NULL ) *p = '\0';
1606 for (hModule = hFirstModule; hModule ; hModule = pModule->next)
1608 pModule = NE_GetPtr( hModule );
1609 if (!pModule) break;
1610 if (pModule->flags & NE_FFLAGS_WIN32) continue;
1612 name_table = (BYTE *)pModule + pModule->name_table;
1613 if ((*name_table == len) && !strncasecmp(s, name_table+1, len))
1620 /**********************************************************************
1621 * ModuleFirst (TOOLHELP.59)
1623 BOOL16 WINAPI ModuleFirst16( MODULEENTRY *lpme )
1625 lpme->wNext = hFirstModule;
1626 return ModuleNext16( lpme );
1630 /**********************************************************************
1631 * ModuleNext (TOOLHELP.60)
1633 BOOL16 WINAPI ModuleNext16( MODULEENTRY *lpme )
1638 if (!lpme->wNext) return FALSE;
1639 if (!(pModule = NE_GetPtr( lpme->wNext ))) return FALSE;
1640 name = (char *)pModule + pModule->name_table;
1641 memcpy( lpme->szModule, name + 1, min(*name, MAX_MODULE_NAME) );
1642 lpme->szModule[min(*name, MAX_MODULE_NAME)] = '\0';
1643 lpme->hModule = lpme->wNext;
1644 lpme->wcUsage = pModule->count;
1645 lstrcpynA( lpme->szExePath, NE_MODULE_NAME(pModule), sizeof(lpme->szExePath) );
1646 lpme->wNext = pModule->next;
1651 /**********************************************************************
1652 * ModuleFindName (TOOLHELP.61)
1654 BOOL16 WINAPI ModuleFindName16( MODULEENTRY *lpme, LPCSTR name )
1656 lpme->wNext = GetModuleHandle16( name );
1657 return ModuleNext16( lpme );
1661 /**********************************************************************
1662 * ModuleFindHandle (TOOLHELP.62)
1664 BOOL16 WINAPI ModuleFindHandle16( MODULEENTRY *lpme, HMODULE16 hModule )
1666 hModule = GetExePtr( hModule );
1667 lpme->wNext = hModule;
1668 return ModuleNext16( lpme );
1672 /***************************************************************************
1673 * IsRomModule16 (KERNEL.323)
1675 BOOL16 WINAPI IsRomModule16( HMODULE16 unused )
1680 /***************************************************************************
1681 * IsRomFile16 (KERNEL.326)
1683 BOOL16 WINAPI IsRomFile16( HFILE16 unused )
1688 /***************************************************************************
1689 * MapHModuleLS (KERNEL32.520)
1691 HMODULE16 WINAPI MapHModuleLS(HMODULE hmod) {
1695 return ((TDB*)GlobalLock16(GetCurrentTask()))->hInstance;
1697 return hmod; /* we already have a 16 bit module handle */
1698 pModule = (NE_MODULE*)GlobalLock16(hFirstModule);
1700 if (pModule->module32 == hmod)
1701 return pModule->self;
1702 pModule = (NE_MODULE*)GlobalLock16(pModule->next);
1707 /***************************************************************************
1708 * MapHModuleSL (KERNEL32.521)
1710 HMODULE WINAPI MapHModuleSL(HMODULE16 hmod) {
1714 TDB *pTask = (TDB*)GlobalLock16(GetCurrentTask());
1716 hmod = pTask->hModule;
1718 pModule = (NE_MODULE*)GlobalLock16(hmod);
1719 if ( (pModule->magic!=IMAGE_OS2_SIGNATURE) ||
1720 !(pModule->flags & NE_FFLAGS_WIN32)
1723 return pModule->module32;
1726 /***************************************************************************
1727 * MapHInstLS (KERNEL32.516)(KERNEL.472)
1729 void WINAPI MapHInstLS( CONTEXT86 *context )
1731 context->Eax = MapHModuleLS(context->Eax);
1734 /***************************************************************************
1735 * MapHInstSL (KERNEL32.518)(KERNEL.473)
1737 void WINAPI MapHInstSL( CONTEXT86 *context )
1739 context->Eax = MapHModuleSL(context->Eax);
1742 /***************************************************************************
1743 * MapHInstLS_PN (KERNEL32.517)
1745 void WINAPI MapHInstLS_PN( CONTEXT86 *context )
1747 if (context->Eax) context->Eax = MapHModuleLS(context->Eax);
1750 /***************************************************************************
1751 * MapHInstSL_PN (KERNEL32.519)
1753 void WINAPI MapHInstSL_PN( CONTEXT86 *context )
1755 if (context->Eax) context->Eax = MapHModuleSL(context->Eax);