4 * Copyright 1995 Alexandre Julliard
13 #include "wine/winbase16.h"
28 #include "builtin16.h"
29 #include "stackframe.h"
30 #include "debugtools.h"
32 #include "loadorder.h"
36 DEFAULT_DEBUG_CHANNEL(module)
38 #define hFirstModule (pThhook->hExeHead)
40 static NE_MODULE *pCachedModule = 0; /* Module cached by NE_OpenFile */
42 static BOOL16 NE_FreeModule( HMODULE16 hModule, BOOL call_wep );
44 static HINSTANCE16 MODULE_LoadModule16( LPCSTR libname, BOOL implicit, BOOL lib_only );
46 static HMODULE16 NE_GetModuleByFilename( LPCSTR name );
48 /***********************************************************************
51 NE_MODULE *NE_GetPtr( HMODULE16 hModule )
53 return (NE_MODULE *)GlobalLock16( GetExePtr(hModule) );
57 /***********************************************************************
60 void NE_DumpModule( HMODULE16 hModule )
70 if (!(pModule = NE_GetPtr( hModule )))
72 MESSAGE( "**** %04x is not a module handle\n", hModule );
76 /* Dump the module info */
78 DPRINTF( "Module %04x:\n", hModule );
79 DPRINTF( "count=%d flags=%04x heap=%d stack=%d\n",
80 pModule->count, pModule->flags,
81 pModule->heap_size, pModule->stack_size );
82 DPRINTF( "cs:ip=%04x:%04x ss:sp=%04x:%04x ds=%04x nb seg=%d modrefs=%d\n",
83 pModule->cs, pModule->ip, pModule->ss, pModule->sp, pModule->dgroup,
84 pModule->seg_count, pModule->modref_count );
85 DPRINTF( "os_flags=%d swap_area=%d version=%04x\n",
86 pModule->os_flags, pModule->min_swap_area,
87 pModule->expected_version );
88 if (pModule->flags & NE_FFLAGS_WIN32)
89 DPRINTF( "PE module=%08x\n", pModule->module32 );
91 /* Dump the file info */
93 DPRINTF( "Filename: '%s'\n", NE_MODULE_NAME(pModule) );
95 /* Dump the segment table */
97 DPRINTF( "Segment table:\n" );
98 pSeg = NE_SEG_TABLE( pModule );
99 for (i = 0; i < pModule->seg_count; i++, pSeg++)
100 DPRINTF( "%02x: pos=%d size=%d flags=%04x minsize=%d hSeg=%04x\n",
101 i + 1, pSeg->filepos, pSeg->size, pSeg->flags,
102 pSeg->minsize, pSeg->hSeg );
104 /* Dump the resource table */
106 DPRINTF( "Resource table:\n" );
107 if (pModule->res_table)
109 pword = (WORD *)((BYTE *)pModule + pModule->res_table);
110 DPRINTF( "Alignment: %d\n", *pword++ );
113 struct resource_typeinfo_s *ptr = (struct resource_typeinfo_s *)pword;
114 struct resource_nameinfo_s *pname = (struct resource_nameinfo_s *)(ptr + 1);
115 DPRINTF( "id=%04x count=%d\n", ptr->type_id, ptr->count );
116 for (i = 0; i < ptr->count; i++, pname++)
117 DPRINTF( "offset=%d len=%d id=%04x\n",
118 pname->offset, pname->length, pname->id );
119 pword = (WORD *)pname;
122 else DPRINTF( "None\n" );
124 /* Dump the resident name table */
126 DPRINTF( "Resident-name table:\n" );
127 pstr = (char *)pModule + pModule->name_table;
130 DPRINTF( "%*.*s: %d\n", *pstr, *pstr, pstr + 1,
131 *(WORD *)(pstr + *pstr + 1) );
132 pstr += *pstr + 1 + sizeof(WORD);
135 /* Dump the module reference table */
137 DPRINTF( "Module ref table:\n" );
138 if (pModule->modref_table)
140 pword = (WORD *)((BYTE *)pModule + pModule->modref_table);
141 for (i = 0; i < pModule->modref_count; i++, pword++)
144 GetModuleName16( *pword, name, sizeof(name) );
145 DPRINTF( "%d: %04x -> '%s'\n", i, *pword, name );
148 else DPRINTF( "None\n" );
150 /* Dump the entry table */
152 DPRINTF( "Entry table:\n" );
153 bundle = (ET_BUNDLE *)((BYTE *)pModule+pModule->entry_table);
155 entry = (ET_ENTRY *)((BYTE *)bundle+6);
156 DPRINTF( "Bundle %d-%d: %02x\n", bundle->first, bundle->last, entry->type);
157 ordinal = bundle->first;
158 while (ordinal < bundle->last)
160 if (entry->type == 0xff)
161 DPRINTF("%d: %02x:%04x (moveable)\n", ordinal++, entry->segnum, entry->offs);
163 DPRINTF("%d: %02x:%04x (fixed)\n", ordinal++, entry->segnum, entry->offs);
166 } while ( (bundle->next)
167 && (bundle = ((ET_BUNDLE *)((BYTE *)pModule + bundle->next))) );
169 /* Dump the non-resident names table */
171 DPRINTF( "Non-resident names table:\n" );
172 if (pModule->nrname_handle)
174 pstr = (char *)GlobalLock16( pModule->nrname_handle );
177 DPRINTF( "%*.*s: %d\n", *pstr, *pstr, pstr + 1,
178 *(WORD *)(pstr + *pstr + 1) );
179 pstr += *pstr + 1 + sizeof(WORD);
186 /***********************************************************************
189 * Walk the module list and print the modules.
191 void NE_WalkModules(void)
193 HMODULE16 hModule = hFirstModule;
194 MESSAGE( "Module Flags Name\n" );
197 NE_MODULE *pModule = NE_GetPtr( hModule );
200 MESSAGE( "Bad module %04x in list\n", hModule );
203 MESSAGE( " %04x %04x %.*s\n", hModule, pModule->flags,
204 *((char *)pModule + pModule->name_table),
205 (char *)pModule + pModule->name_table + 1 );
206 hModule = pModule->next;
211 /**********************************************************************
214 void NE_RegisterModule( NE_MODULE *pModule )
216 pModule->next = hFirstModule;
217 hFirstModule = pModule->self;
221 /***********************************************************************
224 * Lookup the ordinal for a given name.
226 WORD NE_GetOrdinal( HMODULE16 hModule, const char *name )
228 unsigned char buffer[256], *cpnt;
232 if (!(pModule = NE_GetPtr( hModule ))) return 0;
233 assert( !(pModule->flags & NE_FFLAGS_WIN32) );
235 TRACE("(%04x,'%s')\n", hModule, name );
237 /* First handle names of the form '#xxxx' */
239 if (name[0] == '#') return atoi( name + 1 );
241 /* Now copy and uppercase the string */
243 strcpy( buffer, name );
244 CharUpperA( buffer );
245 len = strlen( buffer );
247 /* First search the resident names */
249 cpnt = (char *)pModule + pModule->name_table;
251 /* Skip the first entry (module name) */
252 cpnt += *cpnt + 1 + sizeof(WORD);
255 if (((BYTE)*cpnt == len) && !memcmp( cpnt+1, buffer, len ))
257 TRACE(" Found: ordinal=%d\n",
258 *(WORD *)(cpnt + *cpnt + 1) );
259 return *(WORD *)(cpnt + *cpnt + 1);
261 cpnt += *cpnt + 1 + sizeof(WORD);
264 /* Now search the non-resident names table */
266 if (!pModule->nrname_handle) return 0; /* No non-resident table */
267 cpnt = (char *)GlobalLock16( pModule->nrname_handle );
269 /* Skip the first entry (module description string) */
270 cpnt += *cpnt + 1 + sizeof(WORD);
273 if (((BYTE)*cpnt == len) && !memcmp( cpnt+1, buffer, len ))
275 TRACE(" Found: ordinal=%d\n",
276 *(WORD *)(cpnt + *cpnt + 1) );
277 return *(WORD *)(cpnt + *cpnt + 1);
279 cpnt += *cpnt + 1 + sizeof(WORD);
285 /***********************************************************************
286 * NE_GetEntryPoint (WPROCS.27)
288 * Return the entry point for a given ordinal.
290 FARPROC16 WINAPI WIN16_NE_GetEntryPoint( HMODULE16 hModule, WORD ordinal )
292 FARPROC16 ret = NE_GetEntryPointEx( hModule, ordinal, TRUE );
293 CURRENT_STACK16->ecx = hModule; /* FIXME: might be incorrect value */
296 FARPROC16 WINAPI NE_GetEntryPoint( HMODULE16 hModule, WORD ordinal )
298 return NE_GetEntryPointEx( hModule, ordinal, TRUE );
300 FARPROC16 NE_GetEntryPointEx( HMODULE16 hModule, WORD ordinal, BOOL16 snoop )
308 if (!(pModule = NE_GetPtr( hModule ))) return 0;
309 assert( !(pModule->flags & NE_FFLAGS_WIN32) );
311 bundle = (ET_BUNDLE *)((BYTE *)pModule + pModule->entry_table);
312 while ((ordinal < bundle->first + 1) || (ordinal > bundle->last))
316 bundle = (ET_BUNDLE *)((BYTE *)pModule + bundle->next);
319 entry = (ET_ENTRY *)((BYTE *)bundle+6);
320 for (i=0; i < (ordinal - bundle->first - 1); i++)
324 offset = entry->offs;
326 if (sel == 0xfe) sel = 0xffff; /* constant entry */
327 else sel = GlobalHandleToSel16(NE_SEG_TABLE(pModule)[sel-1].hSeg);
329 return (FARPROC16)PTR_SEG_OFF_TO_SEGPTR( sel, offset );
331 return (FARPROC16)PTR_SEG_OFF_TO_SEGPTR( sel, offset );
333 return (FARPROC16)SNOOP16_GetProcAddress16(hModule,ordinal,(FARPROC16)PTR_SEG_OFF_TO_SEGPTR( sel, offset ));
337 /***********************************************************************
340 * Change the value of an entry point. Use with caution!
341 * It can only change the offset value, not the selector.
343 BOOL16 NE_SetEntryPoint( HMODULE16 hModule, WORD ordinal, WORD offset )
350 if (!(pModule = NE_GetPtr( hModule ))) return FALSE;
351 assert( !(pModule->flags & NE_FFLAGS_WIN32) );
353 bundle = (ET_BUNDLE *)((BYTE *)pModule + pModule->entry_table);
354 while ((ordinal < bundle->first + 1) || (ordinal > bundle->last))
356 bundle = (ET_BUNDLE *)((BYTE *)pModule + bundle->next);
361 entry = (ET_ENTRY *)((BYTE *)bundle+6);
362 for (i=0; i < (ordinal - bundle->first - 1); i++)
365 entry->offs = offset;
370 /***********************************************************************
373 HANDLE NE_OpenFile( NE_MODULE *pModule )
377 static HANDLE cachedfd = -1;
379 TRACE("(%p) cache: mod=%p fd=%d\n",
380 pModule, pCachedModule, cachedfd );
381 if (pCachedModule == pModule) return cachedfd;
382 CloseHandle( cachedfd );
383 pCachedModule = pModule;
384 name = NE_MODULE_NAME( pModule );
385 if ((cachedfd = CreateFileA( name, GENERIC_READ, FILE_SHARE_READ,
386 NULL, OPEN_EXISTING, 0, -1 )) == -1)
387 MESSAGE( "Can't open file '%s' for module %04x\n", name, pModule->self );
389 /* FIXME: should not be necessary */
390 cachedfd = ConvertToGlobalHandle(cachedfd);
391 TRACE("opened '%s' -> %d\n",
397 /***********************************************************************
400 static HMODULE16 NE_LoadExeHeader( HFILE16 hFile, OFSTRUCT *ofs )
402 IMAGE_DOS_HEADER mz_header;
403 IMAGE_OS2_HEADER ne_header;
407 BYTE *pData, *pTempEntryTable;
408 char *buffer, *fastload = NULL;
409 int fastload_offset = 0, fastload_length = 0;
411 ET_BUNDLE *bundle, *oldbundle;
413 /* Read a block from either the file or the fast-load area. */
414 #define READ(offset,size,buffer) \
415 ((fastload && ((offset) >= fastload_offset) && \
416 ((offset)+(size) <= fastload_offset+fastload_length)) ? \
417 (memcpy( buffer, fastload+(offset)-fastload_offset, (size) ), TRUE) : \
418 (_llseek16( hFile, (offset), SEEK_SET), \
419 _hread16( hFile, (buffer), (size) ) == (size)))
421 _llseek16( hFile, 0, SEEK_SET );
422 if ((_hread16(hFile,&mz_header,sizeof(mz_header)) != sizeof(mz_header)) ||
423 (mz_header.e_magic != IMAGE_DOS_SIGNATURE))
424 return (HMODULE16)11; /* invalid exe */
426 _llseek16( hFile, mz_header.e_lfanew, SEEK_SET );
427 if (_hread16( hFile, &ne_header, sizeof(ne_header) ) != sizeof(ne_header))
428 return (HMODULE16)11; /* invalid exe */
430 if (ne_header.ne_magic == IMAGE_NT_SIGNATURE) return (HMODULE16)21; /* win32 exe */
431 if (ne_header.ne_magic != IMAGE_OS2_SIGNATURE) return (HMODULE16)11; /* invalid exe */
433 if (ne_header.ne_magic == IMAGE_OS2_SIGNATURE_LX) {
434 MESSAGE("Sorry, this is an OS/2 linear executable (LX) file !\n");
435 return (HMODULE16)12;
438 /* We now have a valid NE header */
440 size = sizeof(NE_MODULE) +
442 ne_header.n_segment_tab * sizeof(SEGTABLEENTRY) +
444 ne_header.rname_tab_offset - ne_header.resource_tab_offset +
445 /* resident names table */
446 ne_header.moduleref_tab_offset - ne_header.rname_tab_offset +
447 /* module ref table */
448 ne_header.n_mod_ref_tab * sizeof(WORD) +
449 /* imported names table */
450 ne_header.entry_tab_offset - ne_header.iname_tab_offset +
451 /* entry table length */
452 ne_header.entry_tab_length +
453 /* entry table extra conversion space */
455 2 * (ne_header.entry_tab_length - ne_header.n_mov_entry_points*6) +
456 /* loaded file info */
457 sizeof(OFSTRUCT)-sizeof(ofs->szPathName)+strlen(ofs->szPathName)+1;
459 hModule = GlobalAlloc16( GMEM_FIXED | GMEM_ZEROINIT, size );
460 if (!hModule) return (HMODULE16)11; /* invalid exe */
461 FarSetOwner16( hModule, hModule );
462 pModule = (NE_MODULE *)GlobalLock16( hModule );
463 memcpy( pModule, &ne_header, sizeof(ne_header) );
465 /* check *programs* for default minimal stack size */
466 if ( (!(pModule->flags & NE_FFLAGS_LIBMODULE))
467 && (pModule->stack_size < 0x1400) )
468 pModule->stack_size = 0x1400;
469 pModule->module32 = 0;
470 pModule->self = hModule;
471 pModule->self_loading_sel = 0;
472 pData = (BYTE *)(pModule + 1);
474 /* Clear internal Wine flags in case they are set in the EXE file */
476 pModule->flags &= ~(NE_FFLAGS_BUILTIN | NE_FFLAGS_WIN32);
478 /* Read the fast-load area */
480 if (ne_header.additional_flags & NE_AFLAGS_FASTLOAD)
482 fastload_offset=ne_header.fastload_offset<<ne_header.align_shift_count;
483 fastload_length=ne_header.fastload_length<<ne_header.align_shift_count;
484 TRACE("Using fast-load area offset=%x len=%d\n",
485 fastload_offset, fastload_length );
486 if ((fastload = HeapAlloc( SystemHeap, 0, fastload_length )) != NULL)
488 _llseek16( hFile, fastload_offset, SEEK_SET);
489 if (_hread16(hFile, fastload, fastload_length) != fastload_length)
491 HeapFree( SystemHeap, 0, fastload );
492 WARN("Error reading fast-load area!\n");
498 /* Get the segment table */
500 pModule->seg_table = (int)pData - (int)pModule;
501 buffer = HeapAlloc( SystemHeap, 0, ne_header.n_segment_tab *
502 sizeof(struct ne_segment_table_entry_s));
506 struct ne_segment_table_entry_s *pSeg;
508 if (!READ( mz_header.e_lfanew + ne_header.segment_tab_offset,
509 ne_header.n_segment_tab * sizeof(struct ne_segment_table_entry_s),
512 HeapFree( SystemHeap, 0, buffer );
514 HeapFree( SystemHeap, 0, fastload );
515 GlobalFree16( hModule );
516 return (HMODULE16)11; /* invalid exe */
518 pSeg = (struct ne_segment_table_entry_s *)buffer;
519 for (i = ne_header.n_segment_tab; i > 0; i--, pSeg++)
521 memcpy( pData, pSeg, sizeof(*pSeg) );
522 pData += sizeof(SEGTABLEENTRY);
524 HeapFree( SystemHeap, 0, buffer );
529 HeapFree( SystemHeap, 0, fastload );
530 GlobalFree16( hModule );
531 return (HMODULE16)11; /* invalid exe */
534 /* Get the resource table */
536 if (ne_header.resource_tab_offset < ne_header.rname_tab_offset)
538 pModule->res_table = (int)pData - (int)pModule;
539 if (!READ(mz_header.e_lfanew + ne_header.resource_tab_offset,
540 ne_header.rname_tab_offset - ne_header.resource_tab_offset,
541 pData )) return (HMODULE16)11; /* invalid exe */
542 pData += ne_header.rname_tab_offset - ne_header.resource_tab_offset;
543 NE_InitResourceHandler( hModule );
545 else pModule->res_table = 0; /* No resource table */
547 /* Get the resident names table */
549 pModule->name_table = (int)pData - (int)pModule;
550 if (!READ( mz_header.e_lfanew + ne_header.rname_tab_offset,
551 ne_header.moduleref_tab_offset - ne_header.rname_tab_offset,
555 HeapFree( SystemHeap, 0, fastload );
556 GlobalFree16( hModule );
557 return (HMODULE16)11; /* invalid exe */
559 pData += ne_header.moduleref_tab_offset - ne_header.rname_tab_offset;
561 /* Get the module references table */
563 if (ne_header.n_mod_ref_tab > 0)
565 pModule->modref_table = (int)pData - (int)pModule;
566 if (!READ( mz_header.e_lfanew + ne_header.moduleref_tab_offset,
567 ne_header.n_mod_ref_tab * sizeof(WORD),
571 HeapFree( SystemHeap, 0, fastload );
572 GlobalFree16( hModule );
573 return (HMODULE16)11; /* invalid exe */
575 pData += ne_header.n_mod_ref_tab * sizeof(WORD);
577 else pModule->modref_table = 0; /* No module references */
579 /* Get the imported names table */
581 pModule->import_table = (int)pData - (int)pModule;
582 if (!READ( mz_header.e_lfanew + ne_header.iname_tab_offset,
583 ne_header.entry_tab_offset - ne_header.iname_tab_offset,
587 HeapFree( SystemHeap, 0, fastload );
588 GlobalFree16( hModule );
589 return (HMODULE16)11; /* invalid exe */
591 pData += ne_header.entry_tab_offset - ne_header.iname_tab_offset;
593 /* Load entry table, convert it to the optimized version used by Windows */
595 if ((pTempEntryTable = HeapAlloc( SystemHeap, 0, ne_header.entry_tab_length)) != NULL)
597 BYTE nr_entries, type, *s;
599 TRACE("Converting entry table.\n");
600 pModule->entry_table = (int)pData - (int)pModule;
601 if (!READ( mz_header.e_lfanew + ne_header.entry_tab_offset,
602 ne_header.entry_tab_length, pTempEntryTable ))
604 HeapFree( SystemHeap, 0, pTempEntryTable );
606 HeapFree( SystemHeap, 0, fastload );
607 GlobalFree16( hModule );
608 return (HMODULE16)11; /* invalid exe */
612 TRACE("entry table: offs %04x, len %04x, entries %d\n", ne_header.entry_tab_offset, ne_header.entry_tab_length, *s);
614 bundle = (ET_BUNDLE *)pData;
615 TRACE("first bundle: %p\n", bundle);
616 memset(bundle, 0, sizeof(ET_BUNDLE)); /* in case no entry table exists */
617 entry = (ET_ENTRY *)((BYTE *)bundle+6);
619 while ((nr_entries = *s++))
623 bundle->last += nr_entries;
630 entry->segnum = *s++;
631 entry->offs = *(WORD *)s; s += 2;
632 /*TRACE(module, "entry: %p, type: %d, flags: %d, segnum: %d, offs: %04x\n", entry, entry->type, entry->flags, entry->segnum, entry->offs);*/
640 entry->segnum = type;
641 entry->offs = *(WORD *)s; s += 2;
642 /*TRACE(module, "entry: %p, type: %d, flags: %d, segnum: %d, offs: %04x\n", entry, entry->type, entry->flags, entry->segnum, entry->offs);*/
648 if (bundle->first == bundle->last)
650 bundle->first += nr_entries;
651 bundle->last += nr_entries;
656 oldbundle->next = ((int)entry - (int)pModule);
657 bundle = (ET_BUNDLE *)entry;
658 TRACE("new bundle: %p\n", bundle);
659 bundle->first = bundle->last =
660 oldbundle->last + nr_entries;
662 (BYTE *)entry += sizeof(ET_BUNDLE);
666 HeapFree( SystemHeap, 0, pTempEntryTable );
671 HeapFree( SystemHeap, 0, fastload );
672 GlobalFree16( hModule );
673 return (HMODULE16)11; /* invalid exe */
676 pData += ne_header.entry_tab_length + sizeof(ET_BUNDLE) +
677 2 * (ne_header.entry_tab_length - ne_header.n_mov_entry_points*6);
679 if ((DWORD)entry > (DWORD)pData)
680 ERR("converted entry table bigger than reserved space !!!\nentry: %p, pData: %p. Please report !\n", entry, pData);
682 /* Store the filename information */
684 pModule->fileinfo = (int)pData - (int)pModule;
685 size = sizeof(OFSTRUCT)-sizeof(ofs->szPathName)+strlen(ofs->szPathName)+1;
686 memcpy( pData, ofs, size );
687 ((OFSTRUCT *)pData)->cBytes = size - 1;
690 /* Free the fast-load area */
694 HeapFree( SystemHeap, 0, fastload );
696 /* Get the non-resident names table */
698 if (ne_header.nrname_tab_length)
700 pModule->nrname_handle = GLOBAL_Alloc( 0, ne_header.nrname_tab_length,
701 hModule, FALSE, FALSE, FALSE );
702 if (!pModule->nrname_handle)
704 GlobalFree16( hModule );
705 return (HMODULE16)11; /* invalid exe */
707 buffer = GlobalLock16( pModule->nrname_handle );
708 _llseek16( hFile, ne_header.nrname_tab_offset, SEEK_SET );
709 if (_hread16( hFile, buffer, ne_header.nrname_tab_length )
710 != ne_header.nrname_tab_length)
712 GlobalFree16( pModule->nrname_handle );
713 GlobalFree16( hModule );
714 return (HMODULE16)11; /* invalid exe */
717 else pModule->nrname_handle = 0;
719 /* Allocate a segment for the implicitly-loaded DLLs */
721 if (pModule->modref_count)
723 pModule->dlls_to_init = GLOBAL_Alloc(GMEM_ZEROINIT,
724 (pModule->modref_count+1)*sizeof(HMODULE16),
725 hModule, FALSE, FALSE, FALSE );
726 if (!pModule->dlls_to_init)
728 if (pModule->nrname_handle) GlobalFree16( pModule->nrname_handle );
729 GlobalFree16( hModule );
730 return (HMODULE16)11; /* invalid exe */
733 else pModule->dlls_to_init = 0;
735 NE_RegisterModule( pModule );
736 SNOOP16_RegisterDLL(pModule,ofs->szPathName);
742 /***********************************************************************
745 * Load all DLLs implicitly linked to a module.
747 static BOOL NE_LoadDLLs( NE_MODULE *pModule )
750 WORD *pModRef = (WORD *)((char *)pModule + pModule->modref_table);
751 WORD *pDLLs = (WORD *)GlobalLock16( pModule->dlls_to_init );
753 for (i = 0; i < pModule->modref_count; i++, pModRef++)
756 BYTE *pstr = (BYTE *)pModule + pModule->import_table + *pModRef;
757 memcpy( buffer, pstr + 1, *pstr );
758 *(buffer + *pstr) = 0; /* terminate it */
760 TRACE("Loading '%s'\n", buffer );
761 if (!(*pModRef = GetModuleHandle16( buffer )))
763 /* If the DLL is not loaded yet, load it and store */
764 /* its handle in the list of DLLs to initialize. */
767 if ((hDLL = MODULE_LoadModule16( buffer, TRUE, TRUE )) < 32)
769 /* FIXME: cleanup what was done */
771 MESSAGE( "Could not load '%s' required by '%.*s', error=%d\n",
772 buffer, *((BYTE*)pModule + pModule->name_table),
773 (char *)pModule + pModule->name_table + 1, hDLL );
776 *pModRef = GetExePtr( hDLL );
779 else /* Increment the reference count of the DLL */
783 pOldDLL = NE_GetPtr( *pModRef );
784 if (pOldDLL) pOldDLL->count++;
791 /**********************************************************************
794 * Load first instance of NE module from file.
796 * pModule must point to a module structure prepared by NE_LoadExeHeader.
797 * This routine must never be called twice on a module.
800 static HINSTANCE16 NE_DoLoadModule( NE_MODULE *pModule )
802 /* Allocate the segments for this module */
804 if (!NE_CreateAllSegments( pModule ))
805 return 8; /* Insufficient memory */
807 /* Load the referenced DLLs */
809 if (!NE_LoadDLLs( pModule ))
812 /* Load the segments */
814 NE_LoadAllSegments( pModule );
816 /* Make sure the usage count is 1 on the first loading of */
817 /* the module, even if it contains circular DLL references */
821 return NE_GetInstance( pModule );
824 /**********************************************************************
827 * Load first instance of NE module. (Note: caller is responsible for
828 * ensuring the module isn't already loaded!)
830 * If the module turns out to be an executable module, only a
831 * handle to a module stub is returned; this needs to be initialized
832 * by calling NE_DoLoadModule later, in the context of the newly
835 * If lib_only is TRUE, however, the module is perforce treated
836 * like a DLL module, even if it is an executable module.
839 HINSTANCE16 NE_LoadModule( LPCSTR name, BOOL implicit, BOOL lib_only )
843 HINSTANCE16 hInstance;
847 if ((hFile = OpenFile16( name, &ofs, OF_READ )) == HFILE_ERROR16)
853 /* 4 == strlen(".dll") */
854 strncpy(buffer, name, sizeof(buffer) - 1 - 4);
855 strcat(buffer, ".dll");
856 if ((hFile = OpenFile16( buffer, &ofs, OF_READ )) == HFILE_ERROR16)
857 return 2; /* File not found */
861 hModule = NE_LoadExeHeader( hFile, &ofs );
864 if (hModule < 32) return hModule;
865 pModule = NE_GetPtr( hModule );
866 if ( !pModule ) return hModule;
868 if ( !lib_only && !( pModule->flags & NE_FFLAGS_LIBMODULE ) )
871 hInstance = NE_DoLoadModule( pModule );
872 if ( hInstance < 32 )
875 NE_FreeModule( hModule, 0 );
882 /**********************************************************************
883 * MODULE_LoadModule16
885 * Load a NE module in the order of the loadorder specification.
886 * The caller is responsible that the module is not loaded already.
889 static HINSTANCE16 MODULE_LoadModule16( LPCSTR libname, BOOL implicit, BOOL lib_only )
893 module_loadorder_t *plo;
895 plo = MODULE_GetLoadOrder(libname);
897 for(i = 0; i < MODULE_LOADORDER_NTYPES; i++)
899 switch(plo->loadorder[i])
901 case MODULE_LOADORDER_DLL:
902 TRACE("Trying native dll '%s'\n", libname);
903 hinst = NE_LoadModule(libname, implicit, lib_only);
906 case MODULE_LOADORDER_ELFDLL:
907 TRACE("Trying elfdll '%s'\n", libname);
908 hinst = ELFDLL_LoadModule16(libname, implicit);
911 case MODULE_LOADORDER_BI:
912 TRACE("Trying built-in '%s'\n", libname);
913 hinst = BUILTIN_LoadModule(libname, TRUE);
917 ERR("Got invalid loadorder type %d (%s index %d)\n", plo->loadorder[i], plo->modulename, i);
920 case MODULE_LOADORDER_SO: /* This is not supported for NE modules */
921 case MODULE_LOADORDER_INVALID: /* We ignore this as it is an empty entry */
933 hModule = GetModuleHandle16(libname);
936 ERR("Serious trouble. Just loaded module '%s' (hinst=0x%04x), but can't get module handle\n",
938 return 6; /* ERROR_INVALID_HANDLE seems most appropriate */
941 pModule = NE_GetPtr(hModule);
944 ERR("Serious trouble. Just loaded module '%s' (hinst=0x%04x), but can't get NE_MODULE pointer\n",
946 return 6; /* ERROR_INVALID_HANDLE seems most appropriate */
949 TRACE("Loaded module '%s' at 0x%04x, \n", libname, hinst);
952 * Call initialization routines for all loaded DLLs. Note that
953 * when we load implicitly linked DLLs this will be done by InitTask().
955 if(pModule->flags & NE_FFLAGS_LIBMODULE)
956 NE_InitializeDLLs(hModule);
963 /* We quit searching when we get another error than 'File not found' */
967 return hinst; /* The last error that occured */
971 /**********************************************************************
972 * LoadModule16 (KERNEL.45)
974 HINSTANCE16 WINAPI LoadModule16( LPCSTR name, LPVOID paramBlock )
976 BOOL lib_only = !paramBlock || (paramBlock == (LPVOID)-1);
977 LOADPARAMS16 *params;
978 LPSTR cmd_line, new_cmd_line;
980 STARTUPINFOA startup;
981 PROCESS_INFORMATION info;
988 if ( (hModule = NE_GetModuleByFilename(name) ) != 0 )
990 /* Special case: second instance of an already loaded NE module */
992 if ( !( pModule = NE_GetPtr( hModule ) ) ) return (HINSTANCE16)11;
993 if ( pModule->module32 ) return (HINSTANCE16)21;
995 /* Increment refcount */
1001 /* Main case: load first instance of NE module */
1003 if ( (hModule = MODULE_LoadModule16( name, FALSE, lib_only )) < 32 )
1006 if ( !(pModule = NE_GetPtr( hModule )) )
1007 return (HINSTANCE16)11;
1010 /* If library module, we just retrieve the instance handle */
1012 if ( ( pModule->flags & NE_FFLAGS_LIBMODULE ) || lib_only )
1013 return NE_GetInstance( pModule );
1016 * At this point, we need to create a new process.
1018 * pModule points either to an already loaded module, whose refcount
1019 * has already been incremented (to avoid having the module vanish
1020 * in the meantime), or else to a stub module which contains only header
1023 * All remaining initialization (really loading the module in the second
1024 * case, and creating the new instance in both cases) are to be done in
1025 * the context of the new process. This happens in the NE_InitProcess
1026 * routine, which will be called from the 32-bit process initialization.
1030 params = (LOADPARAMS16 *)paramBlock;
1031 cmd_line = (LPSTR)PTR_SEG_TO_LIN( params->cmdLine );
1032 if (!cmd_line) cmd_line = "";
1033 else if (*cmd_line) cmd_line++; /* skip the length byte */
1035 if (!(new_cmd_line = HeapAlloc( GetProcessHeap(), 0,
1036 strlen(cmd_line)+strlen(name)+2 )))
1038 strcpy( new_cmd_line, name );
1039 strcat( new_cmd_line, " " );
1040 strcat( new_cmd_line, cmd_line );
1042 if (params->hEnvironment) env = GlobalLock16( params->hEnvironment );
1044 memset( &info, '\0', sizeof(info) );
1045 memset( &startup, '\0', sizeof(startup) );
1046 startup.cb = sizeof(startup);
1047 if (params->showCmd)
1049 startup.dwFlags = STARTF_USESHOWWINDOW;
1050 startup.wShowWindow = ((UINT16 *)PTR_SEG_TO_LIN(params->showCmd))[1];
1053 SYSLEVEL_ReleaseWin16Lock();
1054 pdb = PROCESS_Create( pModule, new_cmd_line, env,
1055 NULL, NULL, TRUE, 0, &startup, &info );
1056 SYSLEVEL_RestoreWin16Lock();
1058 CloseHandle( info.hThread );
1059 CloseHandle( info.hProcess );
1061 if (params->hEnvironment) GlobalUnlock16( params->hEnvironment );
1062 HeapFree( GetProcessHeap(), 0, new_cmd_line );
1064 return GetProcessDword( info.dwProcessId, GPD_HINSTANCE16 );
1067 /**********************************************************************
1070 BOOL NE_CreateProcess( HFILE hFile, OFSTRUCT *ofs, LPCSTR cmd_line, LPCSTR env,
1071 LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
1072 BOOL inherit, DWORD flags, LPSTARTUPINFOA startup,
1073 LPPROCESS_INFORMATION info )
1079 SYSLEVEL_EnterWin16Lock();
1081 /* Special case: second instance of an already loaded NE module */
1083 if ( ( hModule = NE_GetModuleByFilename( ofs->szPathName ) ) != 0 )
1085 if ( !( pModule = NE_GetPtr( hModule) )
1086 || ( pModule->flags & NE_FFLAGS_LIBMODULE )
1087 || pModule->module32 )
1089 SetLastError( ERROR_BAD_FORMAT );
1096 /* Main case: load first instance of NE module */
1099 /* If we didn't get a file handle, return */
1101 if ( hFile == HFILE_ERROR )
1104 /* Allocate temporary HFILE16 for NE_LoadFileModule */
1106 if (!DuplicateHandle( GetCurrentProcess(), hFile,
1107 GetCurrentProcess(), &hFile,
1108 0, FALSE, DUPLICATE_SAME_ACCESS ))
1110 SetLastError( ERROR_INVALID_HANDLE );
1113 hFile16 = FILE_AllocDosHandle( hFile );
1117 hModule = NE_LoadExeHeader( hFile16, ofs );
1118 _lclose16( hFile16 );
1122 SetLastError( hModule );
1126 if ( !( pModule = NE_GetPtr( hModule ) )
1127 || ( pModule->flags & NE_FFLAGS_LIBMODULE) )
1129 GlobalFreeAll16( hModule );
1130 SetLastError( ERROR_BAD_FORMAT );
1135 SYSLEVEL_LeaveWin16Lock();
1137 if ( !PROCESS_Create( pModule, cmd_line, env,
1138 psa, tsa, inherit, flags, startup, info ) )
1144 SYSLEVEL_LeaveWin16Lock();
1148 /**********************************************************************
1151 BOOL NE_InitProcess( NE_MODULE *pModule )
1153 HINSTANCE16 hInstance, hPrevInstance;
1156 SEGTABLEENTRY *pSegTable = NE_SEG_TABLE( pModule );
1160 SYSLEVEL_EnterWin16Lock();
1162 if ( pModule->count > 0 )
1164 /* Second instance of an already loaded NE module */
1165 /* Note that the refcount was already incremented by the parent */
1167 hPrevInstance = NE_GetInstance( pModule );
1169 if ( pModule->dgroup )
1170 if ( NE_CreateSegment( pModule, pModule->dgroup ) )
1171 NE_LoadSegment( pModule, pModule->dgroup );
1173 hInstance = NE_GetInstance( pModule );
1177 /* Load first instance of NE module */
1179 pModule->flags |= NE_FFLAGS_GUI; /* FIXME: is this necessary? */
1181 hInstance = NE_DoLoadModule( pModule );
1185 if ( hInstance < 32 )
1187 SYSLEVEL_LeaveWin16Lock();
1189 SetLastError( hInstance );
1193 /* Enter instance handles into task struct */
1195 pTask = (TDB *)GlobalLock16( GetCurrentTask() );
1196 pTask->hInstance = hInstance;
1197 pTask->hPrevInstance = hPrevInstance;
1199 /* Use DGROUP for 16-bit stack */
1201 if (!(sp = pModule->sp))
1202 sp = pSegTable[pModule->ss-1].minsize + pModule->stack_size;
1203 sp &= ~1; sp -= sizeof(STACK16FRAME);
1204 pTask->teb->cur_stack = PTR_SEG_OFF_TO_SEGPTR( hInstance, sp );
1206 SYSLEVEL_LeaveWin16Lock();
1211 /***********************************************************************
1212 * LoadLibrary16 (KERNEL.95)
1214 HINSTANCE16 WINAPI LoadLibrary16( LPCSTR libname )
1216 return LoadModule16(libname, (LPVOID)-1 );
1220 /**********************************************************************
1223 * Call a DLL's WEP, allowing it to shut down.
1224 * FIXME: we always pass the WEP WEP_FREE_DLL, never WEP_SYSTEM_EXIT
1226 static BOOL16 MODULE_CallWEP( HMODULE16 hModule )
1228 FARPROC16 WEP = (FARPROC16)0;
1229 WORD ordinal = NE_GetOrdinal( hModule, "WEP" );
1231 if (ordinal) WEP = NE_GetEntryPoint( hModule, ordinal );
1234 WARN("module %04x doesn't have a WEP\n", hModule );
1237 return Callbacks->CallWindowsExitProc( WEP, WEP_FREE_DLL );
1241 /**********************************************************************
1244 * Implementation of FreeModule16().
1246 static BOOL16 NE_FreeModule( HMODULE16 hModule, BOOL call_wep )
1248 HMODULE16 *hPrevModule;
1253 if (!(pModule = NE_GetPtr( hModule ))) return FALSE;
1254 hModule = pModule->self;
1256 TRACE("%04x count %d\n", hModule, pModule->count );
1258 if (((INT16)(--pModule->count)) > 0 ) return TRUE;
1259 else pModule->count = 0;
1261 if (pModule->flags & NE_FFLAGS_BUILTIN)
1262 return FALSE; /* Can't free built-in module */
1264 if (call_wep && !(pModule->flags & NE_FFLAGS_WIN32))
1266 if (pModule->flags & NE_FFLAGS_LIBMODULE)
1268 MODULE_CallWEP( hModule );
1270 /* Free the objects owned by the DLL module */
1271 TASK_CallTaskSignalProc( USIG16_DLL_UNLOAD, hModule );
1272 PROCESS_CallUserSignalProc( USIG_DLL_UNLOAD_WIN16, hModule );
1275 call_wep = FALSE; /* We are freeing a task -> no more WEPs */
1279 /* Clear magic number just in case */
1281 pModule->magic = pModule->self = 0;
1283 /* Remove it from the linked list */
1285 hPrevModule = &hFirstModule;
1286 while (*hPrevModule && (*hPrevModule != hModule))
1288 hPrevModule = &(NE_GetPtr( *hPrevModule ))->next;
1290 if (*hPrevModule) *hPrevModule = pModule->next;
1292 /* Free the referenced modules */
1294 pModRef = (HMODULE16*)NE_MODULE_TABLE( pModule );
1295 for (i = 0; i < pModule->modref_count; i++, pModRef++)
1297 NE_FreeModule( *pModRef, call_wep );
1300 /* Free the module storage */
1302 GlobalFreeAll16( hModule );
1304 /* Remove module from cache */
1306 if (pCachedModule == pModule) pCachedModule = NULL;
1311 /**********************************************************************
1312 * FreeModule16 (KERNEL.46)
1314 BOOL16 WINAPI FreeModule16( HMODULE16 hModule )
1316 return NE_FreeModule( hModule, TRUE );
1320 /***********************************************************************
1321 * FreeLibrary16 (KERNEL.96)
1323 void WINAPI FreeLibrary16( HINSTANCE16 handle )
1325 TRACE("%04x\n", handle );
1326 FreeModule16( handle );
1330 /**********************************************************************
1331 * GetModuleName (KERNEL.27)
1333 BOOL16 WINAPI GetModuleName16( HINSTANCE16 hinst, LPSTR buf, INT16 count )
1338 if (!(pModule = NE_GetPtr( hinst ))) return FALSE;
1339 p = (BYTE *)pModule + pModule->name_table;
1340 if (count > *p) count = *p + 1;
1343 memcpy( buf, p + 1, count - 1 );
1344 buf[count-1] = '\0';
1350 /**********************************************************************
1351 * GetModuleUsage (KERNEL.48)
1353 INT16 WINAPI GetModuleUsage16( HINSTANCE16 hModule )
1355 NE_MODULE *pModule = NE_GetPtr( hModule );
1356 return pModule ? pModule->count : 0;
1360 /**********************************************************************
1361 * GetExpWinVer (KERNEL.167)
1363 WORD WINAPI GetExpWinVer16( HMODULE16 hModule )
1365 NE_MODULE *pModule = NE_GetPtr( hModule );
1366 if ( !pModule ) return 0;
1369 * For built-in modules, fake the expected version the module should
1370 * have according to the Windows version emulated by Wine
1372 if ( !pModule->expected_version )
1374 OSVERSIONINFOA versionInfo;
1375 versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);
1377 if ( GetVersionExA( &versionInfo ) )
1378 pModule->expected_version =
1379 (versionInfo.dwMajorVersion & 0xff) << 8
1380 | (versionInfo.dwMinorVersion & 0xff);
1383 return pModule->expected_version;
1387 /**********************************************************************
1388 * GetModuleFileName16 (KERNEL.49)
1390 INT16 WINAPI GetModuleFileName16( HINSTANCE16 hModule, LPSTR lpFileName,
1395 if (!hModule) hModule = GetCurrentTask();
1396 if (!(pModule = NE_GetPtr( hModule ))) return 0;
1397 lstrcpynA( lpFileName, NE_MODULE_NAME(pModule), nSize );
1398 TRACE("%s\n", lpFileName );
1399 return strlen(lpFileName);
1403 /**********************************************************************
1404 * GetModuleHandle16 (KERNEL.47)
1406 * Find a module from a module name.
1408 * NOTE: The current implementation works the same way the Windows 95 one
1409 * does. Do not try to 'fix' it, fix the callers.
1410 * + It does not do ANY extension handling (except that strange .EXE bit)!
1411 * + It does not care about paths, just about basenames. (same as Windows)
1415 * the win16 module handle if found
1417 * HIWORD (undocumented, see "Undocumented Windows", chapter 5):
1418 * Always hFirstModule
1420 DWORD WINAPI WIN16_GetModuleHandle( SEGPTR name )
1422 if (HIWORD(name) == 0)
1423 return MAKELONG(GetExePtr( (HINSTANCE16)name), hFirstModule );
1424 return MAKELONG(GetModuleHandle16( PTR_SEG_TO_LIN(name)), hFirstModule );
1427 HMODULE16 WINAPI GetModuleHandle16( LPCSTR name )
1429 HMODULE16 hModule = hFirstModule;
1431 BYTE len, *name_table;
1435 TRACE("(%s)\n", name);
1438 return GetExePtr(LOWORD(name));
1444 strncpy(tmpstr, name, sizeof(tmpstr));
1445 tmpstr[sizeof(tmpstr)-1] = '\0';
1447 /* If 'name' matches exactly the module name of a module:
1448 * Return its handle.
1450 for (hModule = hFirstModule; hModule ; hModule = pModule->next)
1452 pModule = NE_GetPtr( hModule );
1453 if (!pModule) break;
1454 if (pModule->flags & NE_FFLAGS_WIN32) continue;
1456 name_table = (BYTE *)pModule + pModule->name_table;
1457 if ((*name_table == len) && !strncmp(name, name_table+1, len))
1461 /* If uppercased 'name' matches exactly the module name of a module:
1464 for (s = tmpstr; *s; s++)
1467 for (hModule = hFirstModule; hModule ; hModule = pModule->next)
1469 pModule = NE_GetPtr( hModule );
1470 if (!pModule) break;
1471 if (pModule->flags & NE_FFLAGS_WIN32) continue;
1473 name_table = (BYTE *)pModule + pModule->name_table;
1474 /* FIXME: the lstrncmpiA is WRONG. It should not be case insensitive,
1475 * but case sensitive! (Unfortunately Winword 6 and subdlls have
1476 * lowercased module names, but try to load uppercase DLLs, so this
1477 * 'i' compare is just a quickfix until the loader handles that
1478 * correctly. -MM 990705
1480 if ((*name_table == len) && !lstrncmpiA(tmpstr, name_table+1, len))
1484 /* If the base filename of 'name' matches the base filename of the module
1485 * filename of some module (case-insensitive compare):
1486 * Return its handle.
1489 /* basename: search backwards in passed name to \ / or : */
1490 s = tmpstr + strlen(tmpstr);
1493 if (s[-1]=='/' || s[-1]=='\\' || s[-1]==':')
1498 /* search this in loaded filename list */
1499 for (hModule = hFirstModule; hModule ; hModule = pModule->next)
1504 pModule = NE_GetPtr( hModule );
1505 if (!pModule) break;
1506 if (!pModule->fileinfo) continue;
1507 if (pModule->flags & NE_FFLAGS_WIN32) continue;
1509 ofs = (OFSTRUCT*)((BYTE *)pModule + pModule->fileinfo);
1510 loadedfn = ((char*)ofs->szPathName) + strlen(ofs->szPathName);
1511 /* basename: search backwards in pathname to \ / or : */
1512 while (loadedfn > (char*)ofs->szPathName)
1514 if (loadedfn[-1]=='/' || loadedfn[-1]=='\\' || loadedfn[-1]==':')
1518 /* case insensitive compare ... */
1519 if (!lstrcmpiA(loadedfn, s))
1523 /* If the extension of 'name' is '.EXE' and the base filename of 'name'
1524 * matches the base filename of the module filename of some 32-bit module:
1525 * Return the corresponding 16-bit dummy module handle.
1527 if (len >= 4 && !strcasecmp(name+len-4, ".EXE"))
1529 HMODULE hModule = GetModuleHandleA( name );
1531 return MapHModuleLS( hModule );
1534 if (!strcmp(tmpstr,"MSDOS"))
1537 if (!strcmp(tmpstr,"TIMER"))
1539 FIXME("Eh... Should return caller's code segment, expect crash\n");
1546 /**********************************************************************
1547 * NE_GetModuleByFilename
1549 static HMODULE16 NE_GetModuleByFilename( LPCSTR name )
1553 BYTE len, *name_table;
1557 strncpy(tmpstr, name, sizeof(tmpstr));
1558 tmpstr[sizeof(tmpstr)-1] = '\0';
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 (!lstrcmpiA(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) && !lstrncmpiA(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 EAX_reg(context) = MapHModuleLS(EAX_reg(context));
1734 /***************************************************************************
1735 * MapHInstSL (KERNEL32.518)(KERNEL.473)
1737 void WINAPI MapHInstSL( CONTEXT86 *context )
1739 EAX_reg(context) = MapHModuleSL(EAX_reg(context));
1742 /***************************************************************************
1743 * MapHInstLS_PN (KERNEL32.517)
1745 void WINAPI MapHInstLS_PN( CONTEXT86 *context )
1747 if (EAX_reg(context))
1748 EAX_reg(context) = MapHModuleLS(EAX_reg(context));
1751 /***************************************************************************
1752 * MapHInstSL_PN (KERNEL32.519)
1754 void WINAPI MapHInstSL_PN( CONTEXT86 *context )
1756 if (EAX_reg(context))
1757 EAX_reg(context) = MapHModuleSL(EAX_reg(context));