4 * Copyright 1995 Alexandre Julliard
13 #include "wine/winbase16.h"
27 #include "builtin16.h"
28 #include "stackframe.h"
29 #include "debugtools.h"
30 #include "loadorder.h"
33 DEFAULT_DEBUG_CHANNEL(module)
35 #define hFirstModule (pThhook->hExeHead)
37 static NE_MODULE *pCachedModule = 0; /* Module cached by NE_OpenFile */
39 static BOOL16 NE_FreeModule( HMODULE16 hModule, BOOL call_wep );
41 static HINSTANCE16 MODULE_LoadModule16( LPCSTR libname, BOOL implicit, BOOL lib_only );
43 static HMODULE16 NE_GetModuleByFilename( LPCSTR name );
45 /***********************************************************************
48 NE_MODULE *NE_GetPtr( HMODULE16 hModule )
50 return (NE_MODULE *)GlobalLock16( GetExePtr(hModule) );
54 /***********************************************************************
57 void NE_DumpModule( HMODULE16 hModule )
67 if (!(pModule = NE_GetPtr( hModule )))
69 MESSAGE( "**** %04x is not a module handle\n", hModule );
73 /* Dump the module info */
75 DPRINTF( "Module %04x:\n", hModule );
76 DPRINTF( "count=%d flags=%04x heap=%d stack=%d\n",
77 pModule->count, pModule->flags,
78 pModule->heap_size, pModule->stack_size );
79 DPRINTF( "cs:ip=%04x:%04x ss:sp=%04x:%04x ds=%04x nb seg=%d modrefs=%d\n",
80 pModule->cs, pModule->ip, pModule->ss, pModule->sp, pModule->dgroup,
81 pModule->seg_count, pModule->modref_count );
82 DPRINTF( "os_flags=%d swap_area=%d version=%04x\n",
83 pModule->os_flags, pModule->min_swap_area,
84 pModule->expected_version );
85 if (pModule->flags & NE_FFLAGS_WIN32)
86 DPRINTF( "PE module=%08x\n", pModule->module32 );
88 /* Dump the file info */
90 DPRINTF( "Filename: '%s'\n", NE_MODULE_NAME(pModule) );
92 /* Dump the segment table */
94 DPRINTF( "Segment table:\n" );
95 pSeg = NE_SEG_TABLE( pModule );
96 for (i = 0; i < pModule->seg_count; i++, pSeg++)
97 DPRINTF( "%02x: pos=%d size=%d flags=%04x minsize=%d hSeg=%04x\n",
98 i + 1, pSeg->filepos, pSeg->size, pSeg->flags,
99 pSeg->minsize, pSeg->hSeg );
101 /* Dump the resource table */
103 DPRINTF( "Resource table:\n" );
104 if (pModule->res_table)
106 pword = (WORD *)((BYTE *)pModule + pModule->res_table);
107 DPRINTF( "Alignment: %d\n", *pword++ );
110 struct resource_typeinfo_s *ptr = (struct resource_typeinfo_s *)pword;
111 struct resource_nameinfo_s *pname = (struct resource_nameinfo_s *)(ptr + 1);
112 DPRINTF( "id=%04x count=%d\n", ptr->type_id, ptr->count );
113 for (i = 0; i < ptr->count; i++, pname++)
114 DPRINTF( "offset=%d len=%d id=%04x\n",
115 pname->offset, pname->length, pname->id );
116 pword = (WORD *)pname;
119 else DPRINTF( "None\n" );
121 /* Dump the resident name table */
123 DPRINTF( "Resident-name table:\n" );
124 pstr = (char *)pModule + pModule->name_table;
127 DPRINTF( "%*.*s: %d\n", *pstr, *pstr, pstr + 1,
128 *(WORD *)(pstr + *pstr + 1) );
129 pstr += *pstr + 1 + sizeof(WORD);
132 /* Dump the module reference table */
134 DPRINTF( "Module ref table:\n" );
135 if (pModule->modref_table)
137 pword = (WORD *)((BYTE *)pModule + pModule->modref_table);
138 for (i = 0; i < pModule->modref_count; i++, pword++)
141 GetModuleName16( *pword, name, sizeof(name) );
142 DPRINTF( "%d: %04x -> '%s'\n", i, *pword, name );
145 else DPRINTF( "None\n" );
147 /* Dump the entry table */
149 DPRINTF( "Entry table:\n" );
150 bundle = (ET_BUNDLE *)((BYTE *)pModule+pModule->entry_table);
152 entry = (ET_ENTRY *)((BYTE *)bundle+6);
153 DPRINTF( "Bundle %d-%d: %02x\n", bundle->first, bundle->last, entry->type);
154 ordinal = bundle->first;
155 while (ordinal < bundle->last)
157 if (entry->type == 0xff)
158 DPRINTF("%d: %02x:%04x (moveable)\n", ordinal++, entry->segnum, entry->offs);
160 DPRINTF("%d: %02x:%04x (fixed)\n", ordinal++, entry->segnum, entry->offs);
163 } while ( (bundle->next)
164 && (bundle = ((ET_BUNDLE *)((BYTE *)pModule + bundle->next))) );
166 /* Dump the non-resident names table */
168 DPRINTF( "Non-resident names table:\n" );
169 if (pModule->nrname_handle)
171 pstr = (char *)GlobalLock16( pModule->nrname_handle );
174 DPRINTF( "%*.*s: %d\n", *pstr, *pstr, pstr + 1,
175 *(WORD *)(pstr + *pstr + 1) );
176 pstr += *pstr + 1 + sizeof(WORD);
183 /***********************************************************************
186 * Walk the module list and print the modules.
188 void NE_WalkModules(void)
190 HMODULE16 hModule = hFirstModule;
191 MESSAGE( "Module Flags Name\n" );
194 NE_MODULE *pModule = NE_GetPtr( hModule );
197 MESSAGE( "Bad module %04x in list\n", hModule );
200 MESSAGE( " %04x %04x %.*s\n", hModule, pModule->flags,
201 *((char *)pModule + pModule->name_table),
202 (char *)pModule + pModule->name_table + 1 );
203 hModule = pModule->next;
208 /**********************************************************************
211 void NE_RegisterModule( NE_MODULE *pModule )
213 pModule->next = hFirstModule;
214 hFirstModule = pModule->self;
218 /***********************************************************************
221 * Lookup the ordinal for a given name.
223 WORD NE_GetOrdinal( HMODULE16 hModule, const char *name )
225 unsigned char buffer[256], *cpnt;
229 if (!(pModule = NE_GetPtr( hModule ))) return 0;
230 assert( !(pModule->flags & NE_FFLAGS_WIN32) );
232 TRACE("(%04x,'%s')\n", hModule, name );
234 /* First handle names of the form '#xxxx' */
236 if (name[0] == '#') return atoi( name + 1 );
238 /* Now copy and uppercase the string */
240 strcpy( buffer, name );
241 CharUpperA( buffer );
242 len = strlen( buffer );
244 /* First search the resident names */
246 cpnt = (char *)pModule + pModule->name_table;
248 /* Skip the first entry (module name) */
249 cpnt += *cpnt + 1 + sizeof(WORD);
252 if (((BYTE)*cpnt == len) && !memcmp( cpnt+1, buffer, len ))
254 TRACE(" Found: ordinal=%d\n",
255 *(WORD *)(cpnt + *cpnt + 1) );
256 return *(WORD *)(cpnt + *cpnt + 1);
258 cpnt += *cpnt + 1 + sizeof(WORD);
261 /* Now search the non-resident names table */
263 if (!pModule->nrname_handle) return 0; /* No non-resident table */
264 cpnt = (char *)GlobalLock16( pModule->nrname_handle );
266 /* Skip the first entry (module description string) */
267 cpnt += *cpnt + 1 + sizeof(WORD);
270 if (((BYTE)*cpnt == len) && !memcmp( cpnt+1, buffer, len ))
272 TRACE(" Found: ordinal=%d\n",
273 *(WORD *)(cpnt + *cpnt + 1) );
274 return *(WORD *)(cpnt + *cpnt + 1);
276 cpnt += *cpnt + 1 + sizeof(WORD);
282 /***********************************************************************
283 * NE_GetEntryPoint (WPROCS.27)
285 * Return the entry point for a given ordinal.
287 FARPROC16 WINAPI WIN16_NE_GetEntryPoint( HMODULE16 hModule, WORD ordinal )
289 FARPROC16 ret = NE_GetEntryPointEx( hModule, ordinal, TRUE );
290 CURRENT_STACK16->ecx = hModule; /* FIXME: might be incorrect value */
293 FARPROC16 WINAPI NE_GetEntryPoint( HMODULE16 hModule, WORD ordinal )
295 return NE_GetEntryPointEx( hModule, ordinal, TRUE );
297 FARPROC16 NE_GetEntryPointEx( HMODULE16 hModule, WORD ordinal, BOOL16 snoop )
305 if (!(pModule = NE_GetPtr( hModule ))) return 0;
306 assert( !(pModule->flags & NE_FFLAGS_WIN32) );
308 bundle = (ET_BUNDLE *)((BYTE *)pModule + pModule->entry_table);
309 while ((ordinal < bundle->first + 1) || (ordinal > bundle->last))
313 bundle = (ET_BUNDLE *)((BYTE *)pModule + bundle->next);
316 entry = (ET_ENTRY *)((BYTE *)bundle+6);
317 for (i=0; i < (ordinal - bundle->first - 1); i++)
321 offset = entry->offs;
323 if (sel == 0xfe) sel = 0xffff; /* constant entry */
324 else sel = GlobalHandleToSel16(NE_SEG_TABLE(pModule)[sel-1].hSeg);
326 return (FARPROC16)PTR_SEG_OFF_TO_SEGPTR( sel, offset );
328 return (FARPROC16)PTR_SEG_OFF_TO_SEGPTR( sel, offset );
330 return (FARPROC16)SNOOP16_GetProcAddress16(hModule,ordinal,(FARPROC16)PTR_SEG_OFF_TO_SEGPTR( sel, offset ));
334 /***********************************************************************
337 * Change the value of an entry point. Use with caution!
338 * It can only change the offset value, not the selector.
340 BOOL16 NE_SetEntryPoint( HMODULE16 hModule, WORD ordinal, WORD offset )
347 if (!(pModule = NE_GetPtr( hModule ))) return FALSE;
348 assert( !(pModule->flags & NE_FFLAGS_WIN32) );
350 bundle = (ET_BUNDLE *)((BYTE *)pModule + pModule->entry_table);
351 while ((ordinal < bundle->first + 1) || (ordinal > bundle->last))
353 bundle = (ET_BUNDLE *)((BYTE *)pModule + bundle->next);
358 entry = (ET_ENTRY *)((BYTE *)bundle+6);
359 for (i=0; i < (ordinal - bundle->first - 1); i++)
362 entry->offs = offset;
367 /***********************************************************************
370 HANDLE NE_OpenFile( NE_MODULE *pModule )
374 static HANDLE cachedfd = -1;
376 TRACE("(%p) cache: mod=%p fd=%d\n",
377 pModule, pCachedModule, cachedfd );
378 if (pCachedModule == pModule) return cachedfd;
379 CloseHandle( cachedfd );
380 pCachedModule = pModule;
381 name = NE_MODULE_NAME( pModule );
382 if ((cachedfd = CreateFileA( name, GENERIC_READ, FILE_SHARE_READ,
383 NULL, OPEN_EXISTING, 0, -1 )) == -1)
384 MESSAGE( "Can't open file '%s' for module %04x\n", name, pModule->self );
386 /* FIXME: should not be necessary */
387 cachedfd = ConvertToGlobalHandle(cachedfd);
388 TRACE("opened '%s' -> %d\n",
394 /***********************************************************************
397 static HMODULE16 NE_LoadExeHeader( HFILE16 hFile, OFSTRUCT *ofs )
399 IMAGE_DOS_HEADER mz_header;
400 IMAGE_OS2_HEADER ne_header;
404 BYTE *pData, *pTempEntryTable;
405 char *buffer, *fastload = NULL;
406 int fastload_offset = 0, fastload_length = 0;
408 ET_BUNDLE *bundle, *oldbundle;
410 /* Read a block from either the file or the fast-load area. */
411 #define READ(offset,size,buffer) \
412 ((fastload && ((offset) >= fastload_offset) && \
413 ((offset)+(size) <= fastload_offset+fastload_length)) ? \
414 (memcpy( buffer, fastload+(offset)-fastload_offset, (size) ), TRUE) : \
415 (_llseek16( hFile, (offset), SEEK_SET), \
416 _hread16( hFile, (buffer), (size) ) == (size)))
418 _llseek16( hFile, 0, SEEK_SET );
419 if ((_hread16(hFile,&mz_header,sizeof(mz_header)) != sizeof(mz_header)) ||
420 (mz_header.e_magic != IMAGE_DOS_SIGNATURE))
421 return (HMODULE16)11; /* invalid exe */
423 _llseek16( hFile, mz_header.e_lfanew, SEEK_SET );
424 if (_hread16( hFile, &ne_header, sizeof(ne_header) ) != sizeof(ne_header))
425 return (HMODULE16)11; /* invalid exe */
427 if (ne_header.ne_magic == IMAGE_NT_SIGNATURE) return (HMODULE16)21; /* win32 exe */
428 if (ne_header.ne_magic != IMAGE_OS2_SIGNATURE) return (HMODULE16)11; /* invalid exe */
430 if (ne_header.ne_magic == IMAGE_OS2_SIGNATURE_LX) {
431 MESSAGE("Sorry, this is an OS/2 linear executable (LX) file !\n");
432 return (HMODULE16)12;
435 /* We now have a valid NE header */
437 size = sizeof(NE_MODULE) +
439 ne_header.n_segment_tab * sizeof(SEGTABLEENTRY) +
441 ne_header.rname_tab_offset - ne_header.resource_tab_offset +
442 /* resident names table */
443 ne_header.moduleref_tab_offset - ne_header.rname_tab_offset +
444 /* module ref table */
445 ne_header.n_mod_ref_tab * sizeof(WORD) +
446 /* imported names table */
447 ne_header.entry_tab_offset - ne_header.iname_tab_offset +
448 /* entry table length */
449 ne_header.entry_tab_length +
450 /* entry table extra conversion space */
452 2 * (ne_header.entry_tab_length - ne_header.n_mov_entry_points*6) +
453 /* loaded file info */
454 sizeof(OFSTRUCT)-sizeof(ofs->szPathName)+strlen(ofs->szPathName)+1;
456 hModule = GlobalAlloc16( GMEM_FIXED | GMEM_ZEROINIT, size );
457 if (!hModule) return (HMODULE16)11; /* invalid exe */
458 FarSetOwner16( hModule, hModule );
459 pModule = (NE_MODULE *)GlobalLock16( hModule );
460 memcpy( pModule, &ne_header, sizeof(ne_header) );
462 /* check *programs* for default minimal stack size */
463 if ( (!(pModule->flags & NE_FFLAGS_LIBMODULE))
464 && (pModule->stack_size < 0x1400) )
465 pModule->stack_size = 0x1400;
466 pModule->module32 = 0;
467 pModule->self = hModule;
468 pModule->self_loading_sel = 0;
469 pData = (BYTE *)(pModule + 1);
471 /* Clear internal Wine flags in case they are set in the EXE file */
473 pModule->flags &= ~(NE_FFLAGS_BUILTIN | NE_FFLAGS_WIN32);
475 /* Read the fast-load area */
477 if (ne_header.additional_flags & NE_AFLAGS_FASTLOAD)
479 fastload_offset=ne_header.fastload_offset<<ne_header.align_shift_count;
480 fastload_length=ne_header.fastload_length<<ne_header.align_shift_count;
481 TRACE("Using fast-load area offset=%x len=%d\n",
482 fastload_offset, fastload_length );
483 if ((fastload = HeapAlloc( SystemHeap, 0, fastload_length )) != NULL)
485 _llseek16( hFile, fastload_offset, SEEK_SET);
486 if (_hread16(hFile, fastload, fastload_length) != fastload_length)
488 HeapFree( SystemHeap, 0, fastload );
489 WARN("Error reading fast-load area!\n");
495 /* Get the segment table */
497 pModule->seg_table = (int)pData - (int)pModule;
498 buffer = HeapAlloc( SystemHeap, 0, ne_header.n_segment_tab *
499 sizeof(struct ne_segment_table_entry_s));
503 struct ne_segment_table_entry_s *pSeg;
505 if (!READ( mz_header.e_lfanew + ne_header.segment_tab_offset,
506 ne_header.n_segment_tab * sizeof(struct ne_segment_table_entry_s),
509 HeapFree( SystemHeap, 0, buffer );
511 HeapFree( SystemHeap, 0, fastload );
512 GlobalFree16( hModule );
513 return (HMODULE16)11; /* invalid exe */
515 pSeg = (struct ne_segment_table_entry_s *)buffer;
516 for (i = ne_header.n_segment_tab; i > 0; i--, pSeg++)
518 memcpy( pData, pSeg, sizeof(*pSeg) );
519 pData += sizeof(SEGTABLEENTRY);
521 HeapFree( SystemHeap, 0, buffer );
526 HeapFree( SystemHeap, 0, fastload );
527 GlobalFree16( hModule );
528 return (HMODULE16)11; /* invalid exe */
531 /* Get the resource table */
533 if (ne_header.resource_tab_offset < ne_header.rname_tab_offset)
535 pModule->res_table = (int)pData - (int)pModule;
536 if (!READ(mz_header.e_lfanew + ne_header.resource_tab_offset,
537 ne_header.rname_tab_offset - ne_header.resource_tab_offset,
538 pData )) return (HMODULE16)11; /* invalid exe */
539 pData += ne_header.rname_tab_offset - ne_header.resource_tab_offset;
540 NE_InitResourceHandler( hModule );
542 else pModule->res_table = 0; /* No resource table */
544 /* Get the resident names table */
546 pModule->name_table = (int)pData - (int)pModule;
547 if (!READ( mz_header.e_lfanew + ne_header.rname_tab_offset,
548 ne_header.moduleref_tab_offset - ne_header.rname_tab_offset,
552 HeapFree( SystemHeap, 0, fastload );
553 GlobalFree16( hModule );
554 return (HMODULE16)11; /* invalid exe */
556 pData += ne_header.moduleref_tab_offset - ne_header.rname_tab_offset;
558 /* Get the module references table */
560 if (ne_header.n_mod_ref_tab > 0)
562 pModule->modref_table = (int)pData - (int)pModule;
563 if (!READ( mz_header.e_lfanew + ne_header.moduleref_tab_offset,
564 ne_header.n_mod_ref_tab * sizeof(WORD),
568 HeapFree( SystemHeap, 0, fastload );
569 GlobalFree16( hModule );
570 return (HMODULE16)11; /* invalid exe */
572 pData += ne_header.n_mod_ref_tab * sizeof(WORD);
574 else pModule->modref_table = 0; /* No module references */
576 /* Get the imported names table */
578 pModule->import_table = (int)pData - (int)pModule;
579 if (!READ( mz_header.e_lfanew + ne_header.iname_tab_offset,
580 ne_header.entry_tab_offset - ne_header.iname_tab_offset,
584 HeapFree( SystemHeap, 0, fastload );
585 GlobalFree16( hModule );
586 return (HMODULE16)11; /* invalid exe */
588 pData += ne_header.entry_tab_offset - ne_header.iname_tab_offset;
590 /* Load entry table, convert it to the optimized version used by Windows */
592 if ((pTempEntryTable = HeapAlloc( SystemHeap, 0, ne_header.entry_tab_length)) != NULL)
594 BYTE nr_entries, type, *s;
596 TRACE("Converting entry table.\n");
597 pModule->entry_table = (int)pData - (int)pModule;
598 if (!READ( mz_header.e_lfanew + ne_header.entry_tab_offset,
599 ne_header.entry_tab_length, pTempEntryTable ))
601 HeapFree( SystemHeap, 0, pTempEntryTable );
603 HeapFree( SystemHeap, 0, fastload );
604 GlobalFree16( hModule );
605 return (HMODULE16)11; /* invalid exe */
609 TRACE("entry table: offs %04x, len %04x, entries %d\n", ne_header.entry_tab_offset, ne_header.entry_tab_length, *s);
611 bundle = (ET_BUNDLE *)pData;
612 TRACE("first bundle: %p\n", bundle);
613 memset(bundle, 0, sizeof(ET_BUNDLE)); /* in case no entry table exists */
614 entry = (ET_ENTRY *)((BYTE *)bundle+6);
616 while ((nr_entries = *s++))
620 bundle->last += nr_entries;
627 entry->segnum = *s++;
628 entry->offs = *(WORD *)s; s += 2;
629 /*TRACE(module, "entry: %p, type: %d, flags: %d, segnum: %d, offs: %04x\n", entry, entry->type, entry->flags, entry->segnum, entry->offs);*/
637 entry->segnum = type;
638 entry->offs = *(WORD *)s; s += 2;
639 /*TRACE(module, "entry: %p, type: %d, flags: %d, segnum: %d, offs: %04x\n", entry, entry->type, entry->flags, entry->segnum, entry->offs);*/
645 if (bundle->first == bundle->last)
647 bundle->first += nr_entries;
648 bundle->last += nr_entries;
653 oldbundle->next = ((int)entry - (int)pModule);
654 bundle = (ET_BUNDLE *)entry;
655 TRACE("new bundle: %p\n", bundle);
656 bundle->first = bundle->last =
657 oldbundle->last + nr_entries;
659 (BYTE *)entry += sizeof(ET_BUNDLE);
663 HeapFree( SystemHeap, 0, pTempEntryTable );
668 HeapFree( SystemHeap, 0, fastload );
669 GlobalFree16( hModule );
670 return (HMODULE16)11; /* invalid exe */
673 pData += ne_header.entry_tab_length + sizeof(ET_BUNDLE) +
674 2 * (ne_header.entry_tab_length - ne_header.n_mov_entry_points*6);
676 if ((DWORD)entry > (DWORD)pData)
677 ERR("converted entry table bigger than reserved space !!!\nentry: %p, pData: %p. Please report !\n", entry, pData);
679 /* Store the filename information */
681 pModule->fileinfo = (int)pData - (int)pModule;
682 size = sizeof(OFSTRUCT)-sizeof(ofs->szPathName)+strlen(ofs->szPathName)+1;
683 memcpy( pData, ofs, size );
684 ((OFSTRUCT *)pData)->cBytes = size - 1;
687 /* Free the fast-load area */
691 HeapFree( SystemHeap, 0, fastload );
693 /* Get the non-resident names table */
695 if (ne_header.nrname_tab_length)
697 pModule->nrname_handle = GLOBAL_Alloc( 0, ne_header.nrname_tab_length,
698 hModule, FALSE, FALSE, FALSE );
699 if (!pModule->nrname_handle)
701 GlobalFree16( hModule );
702 return (HMODULE16)11; /* invalid exe */
704 buffer = GlobalLock16( pModule->nrname_handle );
705 _llseek16( hFile, ne_header.nrname_tab_offset, SEEK_SET );
706 if (_hread16( hFile, buffer, ne_header.nrname_tab_length )
707 != ne_header.nrname_tab_length)
709 GlobalFree16( pModule->nrname_handle );
710 GlobalFree16( hModule );
711 return (HMODULE16)11; /* invalid exe */
714 else pModule->nrname_handle = 0;
716 /* Allocate a segment for the implicitly-loaded DLLs */
718 if (pModule->modref_count)
720 pModule->dlls_to_init = GLOBAL_Alloc(GMEM_ZEROINIT,
721 (pModule->modref_count+1)*sizeof(HMODULE16),
722 hModule, FALSE, FALSE, FALSE );
723 if (!pModule->dlls_to_init)
725 if (pModule->nrname_handle) GlobalFree16( pModule->nrname_handle );
726 GlobalFree16( hModule );
727 return (HMODULE16)11; /* invalid exe */
730 else pModule->dlls_to_init = 0;
732 NE_RegisterModule( pModule );
733 SNOOP16_RegisterDLL(pModule,ofs->szPathName);
739 /***********************************************************************
742 * Load all DLLs implicitly linked to a module.
744 static BOOL NE_LoadDLLs( NE_MODULE *pModule )
747 WORD *pModRef = (WORD *)((char *)pModule + pModule->modref_table);
748 WORD *pDLLs = (WORD *)GlobalLock16( pModule->dlls_to_init );
750 for (i = 0; i < pModule->modref_count; i++, pModRef++)
753 BYTE *pstr = (BYTE *)pModule + pModule->import_table + *pModRef;
754 memcpy( buffer, pstr + 1, *pstr );
755 *(buffer + *pstr) = 0; /* terminate it */
757 TRACE("Loading '%s'\n", buffer );
758 if (!(*pModRef = GetModuleHandle16( buffer )))
760 /* If the DLL is not loaded yet, load it and store */
761 /* its handle in the list of DLLs to initialize. */
764 if ((hDLL = MODULE_LoadModule16( buffer, TRUE, TRUE )) < 32)
766 /* FIXME: cleanup what was done */
768 MESSAGE( "Could not load '%s' required by '%.*s', error=%d\n",
769 buffer, *((BYTE*)pModule + pModule->name_table),
770 (char *)pModule + pModule->name_table + 1, hDLL );
773 *pModRef = GetExePtr( hDLL );
776 else /* Increment the reference count of the DLL */
780 pOldDLL = NE_GetPtr( *pModRef );
781 if (pOldDLL) pOldDLL->count++;
788 /**********************************************************************
791 * Load first instance of NE module from file.
793 * pModule must point to a module structure prepared by NE_LoadExeHeader.
794 * This routine must never be called twice on a module.
797 static HINSTANCE16 NE_DoLoadModule( NE_MODULE *pModule )
799 /* Allocate the segments for this module */
801 if (!NE_CreateAllSegments( pModule ))
802 return 8; /* Insufficient memory */
804 /* Load the referenced DLLs */
806 if (!NE_LoadDLLs( pModule ))
809 /* Load the segments */
811 NE_LoadAllSegments( pModule );
813 /* Make sure the usage count is 1 on the first loading of */
814 /* the module, even if it contains circular DLL references */
818 return NE_GetInstance( pModule );
821 /**********************************************************************
824 * Load first instance of NE module. (Note: caller is responsible for
825 * ensuring the module isn't already loaded!)
827 * If the module turns out to be an executable module, only a
828 * handle to a module stub is returned; this needs to be initialized
829 * by calling NE_DoLoadModule later, in the context of the newly
832 * If lib_only is TRUE, however, the module is perforce treated
833 * like a DLL module, even if it is an executable module.
836 HINSTANCE16 NE_LoadModule( LPCSTR name, BOOL implicit, BOOL lib_only )
840 HINSTANCE16 hInstance;
844 if ((hFile = OpenFile16( name, &ofs, OF_READ )) == HFILE_ERROR16)
850 /* 4 == strlen(".dll") */
851 strncpy(buffer, name, sizeof(buffer) - 1 - 4);
852 strcat(buffer, ".dll");
853 if ((hFile = OpenFile16( buffer, &ofs, OF_READ )) == HFILE_ERROR16)
854 return 2; /* File not found */
858 hModule = NE_LoadExeHeader( hFile, &ofs );
861 if (hModule < 32) return hModule;
862 pModule = NE_GetPtr( hModule );
863 if ( !pModule ) return hModule;
865 if ( !lib_only && !( pModule->flags & NE_FFLAGS_LIBMODULE ) )
868 hInstance = NE_DoLoadModule( pModule );
869 if ( hInstance < 32 )
872 NE_FreeModule( hModule, 0 );
879 /**********************************************************************
880 * MODULE_LoadModule16
882 * Load a NE module in the order of the loadorder specification.
883 * The caller is responsible that the module is not loaded already.
886 static HINSTANCE16 MODULE_LoadModule16( LPCSTR libname, BOOL implicit, BOOL lib_only )
890 module_loadorder_t *plo;
892 plo = MODULE_GetLoadOrder(libname);
894 for(i = 0; i < MODULE_LOADORDER_NTYPES; i++)
896 switch(plo->loadorder[i])
898 case MODULE_LOADORDER_DLL:
899 TRACE("Trying native dll '%s'\n", libname);
900 hinst = NE_LoadModule(libname, implicit, lib_only);
903 case MODULE_LOADORDER_ELFDLL:
904 TRACE("Trying elfdll '%s'\n", libname);
905 hinst = ELFDLL_LoadModule16(libname, implicit);
908 case MODULE_LOADORDER_BI:
909 TRACE("Trying built-in '%s'\n", libname);
910 hinst = BUILTIN_LoadModule(libname, TRUE);
914 ERR("Got invalid loadorder type %d (%s index %d)\n", plo->loadorder[i], plo->modulename, i);
917 case MODULE_LOADORDER_SO: /* This is not supported for NE modules */
918 case MODULE_LOADORDER_INVALID: /* We ignore this as it is an empty entry */
930 hModule = GetModuleHandle16(libname);
933 ERR("Serious trouble. Just loaded module '%s' (hinst=0x%04x), but can't get module handle\n",
935 return 6; /* ERROR_INVALID_HANDLE seems most appropriate */
938 pModule = NE_GetPtr(hModule);
941 ERR("Serious trouble. Just loaded module '%s' (hinst=0x%04x), but can't get NE_MODULE pointer\n",
943 return 6; /* ERROR_INVALID_HANDLE seems most appropriate */
946 TRACE("Loaded module '%s' at 0x%04x, \n", libname, hinst);
949 * Call initialization routines for all loaded DLLs. Note that
950 * when we load implicitly linked DLLs this will be done by InitTask().
952 if(pModule->flags & NE_FFLAGS_LIBMODULE)
953 NE_InitializeDLLs(hModule);
960 /* We quit searching when we get another error than 'File not found' */
964 return hinst; /* The last error that occured */
968 /**********************************************************************
969 * LoadModule16 (KERNEL.45)
971 HINSTANCE16 WINAPI LoadModule16( LPCSTR name, LPVOID paramBlock )
973 BOOL lib_only = !paramBlock || (paramBlock == (LPVOID)-1);
974 LOADPARAMS16 *params;
975 LPSTR cmd_line, new_cmd_line;
977 STARTUPINFOA startup;
978 PROCESS_INFORMATION info;
985 if ( (hModule = NE_GetModuleByFilename(name) ) != 0 )
987 /* Special case: second instance of an already loaded NE module */
989 if ( !( pModule = NE_GetPtr( hModule ) ) ) return (HINSTANCE16)11;
990 if ( pModule->module32 ) return (HINSTANCE16)21;
992 /* Increment refcount */
998 /* Main case: load first instance of NE module */
1000 if ( (hModule = MODULE_LoadModule16( name, FALSE, lib_only )) < 32 )
1003 if ( !(pModule = NE_GetPtr( hModule )) )
1004 return (HINSTANCE16)11;
1007 /* If library module, we just retrieve the instance handle */
1009 if ( ( pModule->flags & NE_FFLAGS_LIBMODULE ) || lib_only )
1010 return NE_GetInstance( pModule );
1013 * At this point, we need to create a new process.
1015 * pModule points either to an already loaded module, whose refcount
1016 * has already been incremented (to avoid having the module vanish
1017 * in the meantime), or else to a stub module which contains only header
1020 * All remaining initialization (really loading the module in the second
1021 * case, and creating the new instance in both cases) are to be done in
1022 * the context of the new process. This happens in the NE_InitProcess
1023 * routine, which will be called from the 32-bit process initialization.
1027 params = (LOADPARAMS16 *)paramBlock;
1028 cmd_line = (LPSTR)PTR_SEG_TO_LIN( params->cmdLine );
1029 if (!cmd_line) cmd_line = "";
1030 else if (*cmd_line) cmd_line++; /* skip the length byte */
1032 if (!(new_cmd_line = HeapAlloc( GetProcessHeap(), 0,
1033 strlen(cmd_line)+strlen(name)+2 )))
1035 strcpy( new_cmd_line, name );
1036 strcat( new_cmd_line, " " );
1037 strcat( new_cmd_line, cmd_line );
1039 if (params->hEnvironment) env = GlobalLock16( params->hEnvironment );
1041 memset( &info, '\0', sizeof(info) );
1042 memset( &startup, '\0', sizeof(startup) );
1043 startup.cb = sizeof(startup);
1044 if (params->showCmd)
1046 startup.dwFlags = STARTF_USESHOWWINDOW;
1047 startup.wShowWindow = ((UINT16 *)PTR_SEG_TO_LIN(params->showCmd))[1];
1050 SYSLEVEL_ReleaseWin16Lock();
1051 pdb = PROCESS_Create( pModule, new_cmd_line, env,
1052 NULL, NULL, TRUE, 0, &startup, &info );
1053 SYSLEVEL_RestoreWin16Lock();
1055 CloseHandle( info.hThread );
1056 CloseHandle( info.hProcess );
1058 if (params->hEnvironment) GlobalUnlock16( params->hEnvironment );
1059 HeapFree( GetProcessHeap(), 0, new_cmd_line );
1061 return GetProcessDword( info.dwProcessId, GPD_HINSTANCE16 );
1064 /**********************************************************************
1067 BOOL NE_CreateProcess( HFILE hFile, OFSTRUCT *ofs, LPCSTR cmd_line, LPCSTR env,
1068 LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
1069 BOOL inherit, DWORD flags, LPSTARTUPINFOA startup,
1070 LPPROCESS_INFORMATION info )
1076 SYSLEVEL_EnterWin16Lock();
1078 /* Special case: second instance of an already loaded NE module */
1080 if ( ( hModule = NE_GetModuleByFilename( ofs->szPathName ) ) != 0 )
1082 if ( !( pModule = NE_GetPtr( hModule) )
1083 || ( pModule->flags & NE_FFLAGS_LIBMODULE )
1084 || pModule->module32 )
1086 SetLastError( ERROR_BAD_FORMAT );
1093 /* Main case: load first instance of NE module */
1096 /* If we didn't get a file handle, return */
1098 if ( hFile == HFILE_ERROR )
1101 /* Allocate temporary HFILE16 for NE_LoadFileModule */
1103 if (!DuplicateHandle( GetCurrentProcess(), hFile,
1104 GetCurrentProcess(), &hFile,
1105 0, FALSE, DUPLICATE_SAME_ACCESS ))
1107 SetLastError( ERROR_INVALID_HANDLE );
1110 hFile16 = FILE_AllocDosHandle( hFile );
1114 hModule = NE_LoadExeHeader( hFile16, ofs );
1115 _lclose16( hFile16 );
1119 SetLastError( hModule );
1123 if ( !( pModule = NE_GetPtr( hModule ) )
1124 || ( pModule->flags & NE_FFLAGS_LIBMODULE) )
1126 GlobalFreeAll16( hModule );
1127 SetLastError( ERROR_BAD_FORMAT );
1132 SYSLEVEL_LeaveWin16Lock();
1134 if ( !PROCESS_Create( pModule, cmd_line, env,
1135 psa, tsa, inherit, flags, startup, info ) )
1141 SYSLEVEL_LeaveWin16Lock();
1145 /**********************************************************************
1148 BOOL NE_InitProcess( NE_MODULE *pModule )
1150 HINSTANCE16 hInstance, hPrevInstance;
1153 SEGTABLEENTRY *pSegTable = NE_SEG_TABLE( pModule );
1157 SYSLEVEL_EnterWin16Lock();
1159 if ( pModule->count > 0 )
1161 /* Second instance of an already loaded NE module */
1162 /* Note that the refcount was already incremented by the parent */
1164 hPrevInstance = NE_GetInstance( pModule );
1166 if ( pModule->dgroup )
1167 if ( NE_CreateSegment( pModule, pModule->dgroup ) )
1168 NE_LoadSegment( pModule, pModule->dgroup );
1170 hInstance = NE_GetInstance( pModule );
1174 /* Load first instance of NE module */
1176 pModule->flags |= NE_FFLAGS_GUI; /* FIXME: is this necessary? */
1178 hInstance = NE_DoLoadModule( pModule );
1182 if ( hInstance < 32 )
1184 SYSLEVEL_LeaveWin16Lock();
1186 SetLastError( hInstance );
1190 /* Enter instance handles into task struct */
1192 pTask = (TDB *)GlobalLock16( GetCurrentTask() );
1193 pTask->hInstance = hInstance;
1194 pTask->hPrevInstance = hPrevInstance;
1196 /* Use DGROUP for 16-bit stack */
1198 if (!(sp = pModule->sp))
1199 sp = pSegTable[pModule->ss-1].minsize + pModule->stack_size;
1200 sp &= ~1; sp -= sizeof(STACK16FRAME);
1201 pTask->teb->cur_stack = PTR_SEG_OFF_TO_SEGPTR( hInstance, sp );
1203 SYSLEVEL_LeaveWin16Lock();
1208 /***********************************************************************
1209 * LoadLibrary16 (KERNEL.95)
1211 HINSTANCE16 WINAPI LoadLibrary16( LPCSTR libname )
1213 return LoadModule16(libname, (LPVOID)-1 );
1217 /**********************************************************************
1220 * Call a DLL's WEP, allowing it to shut down.
1221 * FIXME: we always pass the WEP WEP_FREE_DLL, never WEP_SYSTEM_EXIT
1223 static BOOL16 MODULE_CallWEP( HMODULE16 hModule )
1225 FARPROC16 WEP = (FARPROC16)0;
1226 WORD ordinal = NE_GetOrdinal( hModule, "WEP" );
1228 if (ordinal) WEP = NE_GetEntryPoint( hModule, ordinal );
1231 WARN("module %04x doesn't have a WEP\n", hModule );
1234 return Callbacks->CallWindowsExitProc( WEP, WEP_FREE_DLL );
1238 /**********************************************************************
1241 * Implementation of FreeModule16().
1243 static BOOL16 NE_FreeModule( HMODULE16 hModule, BOOL call_wep )
1245 HMODULE16 *hPrevModule;
1250 if (!(pModule = NE_GetPtr( hModule ))) return FALSE;
1251 hModule = pModule->self;
1253 TRACE("%04x count %d\n", hModule, pModule->count );
1255 if (((INT16)(--pModule->count)) > 0 ) return TRUE;
1256 else pModule->count = 0;
1258 if (pModule->flags & NE_FFLAGS_BUILTIN)
1259 return FALSE; /* Can't free built-in module */
1261 if (call_wep && !(pModule->flags & NE_FFLAGS_WIN32))
1263 if (pModule->flags & NE_FFLAGS_LIBMODULE)
1265 MODULE_CallWEP( hModule );
1267 /* Free the objects owned by the DLL module */
1268 TASK_CallTaskSignalProc( USIG16_DLL_UNLOAD, hModule );
1269 PROCESS_CallUserSignalProc( USIG_DLL_UNLOAD_WIN16, hModule );
1272 call_wep = FALSE; /* We are freeing a task -> no more WEPs */
1276 /* Clear magic number just in case */
1278 pModule->magic = pModule->self = 0;
1280 /* Remove it from the linked list */
1282 hPrevModule = &hFirstModule;
1283 while (*hPrevModule && (*hPrevModule != hModule))
1285 hPrevModule = &(NE_GetPtr( *hPrevModule ))->next;
1287 if (*hPrevModule) *hPrevModule = pModule->next;
1289 /* Free the referenced modules */
1291 pModRef = (HMODULE16*)NE_MODULE_TABLE( pModule );
1292 for (i = 0; i < pModule->modref_count; i++, pModRef++)
1294 NE_FreeModule( *pModRef, call_wep );
1297 /* Free the module storage */
1299 GlobalFreeAll16( hModule );
1301 /* Remove module from cache */
1303 if (pCachedModule == pModule) pCachedModule = NULL;
1308 /**********************************************************************
1309 * FreeModule16 (KERNEL.46)
1311 BOOL16 WINAPI FreeModule16( HMODULE16 hModule )
1313 return NE_FreeModule( hModule, TRUE );
1317 /***********************************************************************
1318 * FreeLibrary16 (KERNEL.96)
1320 void WINAPI FreeLibrary16( HINSTANCE16 handle )
1322 TRACE("%04x\n", handle );
1323 FreeModule16( handle );
1327 /**********************************************************************
1328 * GetModuleName (KERNEL.27)
1330 BOOL16 WINAPI GetModuleName16( HINSTANCE16 hinst, LPSTR buf, INT16 count )
1335 if (!(pModule = NE_GetPtr( hinst ))) return FALSE;
1336 p = (BYTE *)pModule + pModule->name_table;
1337 if (count > *p) count = *p + 1;
1340 memcpy( buf, p + 1, count - 1 );
1341 buf[count-1] = '\0';
1347 /**********************************************************************
1348 * GetModuleUsage (KERNEL.48)
1350 INT16 WINAPI GetModuleUsage16( HINSTANCE16 hModule )
1352 NE_MODULE *pModule = NE_GetPtr( hModule );
1353 return pModule ? pModule->count : 0;
1357 /**********************************************************************
1358 * GetExpWinVer (KERNEL.167)
1360 WORD WINAPI GetExpWinVer16( HMODULE16 hModule )
1362 NE_MODULE *pModule = NE_GetPtr( hModule );
1363 if ( !pModule ) return 0;
1366 * For built-in modules, fake the expected version the module should
1367 * have according to the Windows version emulated by Wine
1369 if ( !pModule->expected_version )
1371 OSVERSIONINFOA versionInfo;
1372 versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);
1374 if ( GetVersionExA( &versionInfo ) )
1375 pModule->expected_version =
1376 (versionInfo.dwMajorVersion & 0xff) << 8
1377 | (versionInfo.dwMinorVersion & 0xff);
1380 return pModule->expected_version;
1384 /**********************************************************************
1385 * GetModuleFileName16 (KERNEL.49)
1387 INT16 WINAPI GetModuleFileName16( HINSTANCE16 hModule, LPSTR lpFileName,
1392 if (!hModule) hModule = GetCurrentTask();
1393 if (!(pModule = NE_GetPtr( hModule ))) return 0;
1394 lstrcpynA( lpFileName, NE_MODULE_NAME(pModule), nSize );
1395 TRACE("%s\n", lpFileName );
1396 return strlen(lpFileName);
1400 /**********************************************************************
1401 * GetModuleHandle16 (KERNEL.47)
1403 * Find a module from a module name.
1405 * NOTE: The current implementation works the same way the Windows 95 one
1406 * does. Do not try to 'fix' it, fix the callers.
1407 * + It does not do ANY extension handling (except that strange .EXE bit)!
1408 * + It does not care about paths, just about basenames. (same as Windows)
1412 * the win16 module handle if found
1414 * HIWORD (undocumented, see "Undocumented Windows", chapter 5):
1415 * Always hFirstModule
1417 DWORD WINAPI WIN16_GetModuleHandle( SEGPTR name )
1419 if (HIWORD(name) == 0)
1420 return MAKELONG(GetExePtr( (HINSTANCE16)name), hFirstModule );
1421 return MAKELONG(GetModuleHandle16( PTR_SEG_TO_LIN(name)), hFirstModule );
1424 HMODULE16 WINAPI GetModuleHandle16( LPCSTR name )
1426 HMODULE16 hModule = hFirstModule;
1428 BYTE len, *name_table;
1432 TRACE("(%s)\n", name);
1435 return GetExePtr(LOWORD(name));
1441 strncpy(tmpstr, name, sizeof(tmpstr));
1442 tmpstr[sizeof(tmpstr)-1] = '\0';
1444 /* If 'name' matches exactly the module name of a module:
1445 * Return its handle.
1447 for (hModule = hFirstModule; hModule ; hModule = pModule->next)
1449 pModule = NE_GetPtr( hModule );
1450 if (!pModule) break;
1451 if (pModule->flags & NE_FFLAGS_WIN32) continue;
1453 name_table = (BYTE *)pModule + pModule->name_table;
1454 if ((*name_table == len) && !strncmp(name, name_table+1, len))
1458 /* If uppercased 'name' matches exactly the module name of a module:
1461 for (s = tmpstr; *s; s++)
1464 for (hModule = hFirstModule; hModule ; hModule = pModule->next)
1466 pModule = NE_GetPtr( hModule );
1467 if (!pModule) break;
1468 if (pModule->flags & NE_FFLAGS_WIN32) continue;
1470 name_table = (BYTE *)pModule + pModule->name_table;
1471 /* FIXME: the lstrncmpiA is WRONG. It should not be case insensitive,
1472 * but case sensitive! (Unfortunately Winword 6 and subdlls have
1473 * lowercased module names, but try to load uppercase DLLs, so this
1474 * 'i' compare is just a quickfix until the loader handles that
1475 * correctly. -MM 990705
1477 if ((*name_table == len) && !lstrncmpiA(tmpstr, name_table+1, len))
1481 /* If the base filename of 'name' matches the base filename of the module
1482 * filename of some module (case-insensitive compare):
1483 * Return its handle.
1486 /* basename: search backwards in passed name to \ / or : */
1487 s = tmpstr + strlen(tmpstr);
1490 if (s[-1]=='/' || s[-1]=='\\' || s[-1]==':')
1495 /* search this in loaded filename list */
1496 for (hModule = hFirstModule; hModule ; hModule = pModule->next)
1501 pModule = NE_GetPtr( hModule );
1502 if (!pModule) break;
1503 if (!pModule->fileinfo) continue;
1504 if (pModule->flags & NE_FFLAGS_WIN32) continue;
1506 ofs = (OFSTRUCT*)((BYTE *)pModule + pModule->fileinfo);
1507 loadedfn = ((char*)ofs->szPathName) + strlen(ofs->szPathName);
1508 /* basename: search backwards in pathname to \ / or : */
1509 while (loadedfn > (char*)ofs->szPathName)
1511 if (loadedfn[-1]=='/' || loadedfn[-1]=='\\' || loadedfn[-1]==':')
1515 /* case insensitive compare ... */
1516 if (!lstrcmpiA(loadedfn, s))
1520 /* If the extension of 'name' is '.EXE' and the base filename of 'name'
1521 * matches the base filename of the module filename of some 32-bit module:
1522 * Return the corresponding 16-bit dummy module handle.
1524 if (len >= 4 && !strcasecmp(name+len-4, ".EXE"))
1526 HMODULE hModule = GetModuleHandleA( name );
1528 return MapHModuleLS( hModule );
1531 if (!strcmp(tmpstr,"MSDOS"))
1534 if (!strcmp(tmpstr,"TIMER"))
1536 FIXME("Eh... Should return caller's code segment, expect crash\n");
1543 /**********************************************************************
1544 * NE_GetModuleByFilename
1546 static HMODULE16 NE_GetModuleByFilename( LPCSTR name )
1550 BYTE len, *name_table;
1554 strncpy(tmpstr, name, sizeof(tmpstr));
1555 tmpstr[sizeof(tmpstr)-1] = '\0';
1557 /* If the base filename of 'name' matches the base filename of the module
1558 * filename of some module (case-insensitive compare):
1559 * Return its handle.
1562 /* basename: search backwards in passed name to \ / or : */
1563 s = tmpstr + strlen(tmpstr);
1566 if (s[-1]=='/' || s[-1]=='\\' || s[-1]==':')
1571 /* search this in loaded filename list */
1572 for (hModule = hFirstModule; hModule ; hModule = pModule->next)
1577 pModule = NE_GetPtr( hModule );
1578 if (!pModule) break;
1579 if (!pModule->fileinfo) continue;
1580 if (pModule->flags & NE_FFLAGS_WIN32) continue;
1582 ofs = (OFSTRUCT*)((BYTE *)pModule + pModule->fileinfo);
1583 loadedfn = ((char*)ofs->szPathName) + strlen(ofs->szPathName);
1584 /* basename: search backwards in pathname to \ / or : */
1585 while (loadedfn > (char*)ofs->szPathName)
1587 if (loadedfn[-1]=='/' || loadedfn[-1]=='\\' || loadedfn[-1]==':')
1591 /* case insensitive compare ... */
1592 if (!lstrcmpiA(loadedfn, s))
1596 /* If basename (without ext) matches the module name of a module:
1597 * Return its handle.
1600 if ( (p = strrchr( s, '.' )) != NULL ) *p = '\0';
1603 for (hModule = hFirstModule; hModule ; hModule = pModule->next)
1605 pModule = NE_GetPtr( hModule );
1606 if (!pModule) break;
1607 if (pModule->flags & NE_FFLAGS_WIN32) continue;
1609 name_table = (BYTE *)pModule + pModule->name_table;
1610 if ((*name_table == len) && !lstrncmpiA(s, name_table+1, len))
1617 /**********************************************************************
1618 * ModuleFirst (TOOLHELP.59)
1620 BOOL16 WINAPI ModuleFirst16( MODULEENTRY *lpme )
1622 lpme->wNext = hFirstModule;
1623 return ModuleNext16( lpme );
1627 /**********************************************************************
1628 * ModuleNext (TOOLHELP.60)
1630 BOOL16 WINAPI ModuleNext16( MODULEENTRY *lpme )
1635 if (!lpme->wNext) return FALSE;
1636 if (!(pModule = NE_GetPtr( lpme->wNext ))) return FALSE;
1637 name = (char *)pModule + pModule->name_table;
1638 memcpy( lpme->szModule, name + 1, min(*name, MAX_MODULE_NAME) );
1639 lpme->szModule[min(*name, MAX_MODULE_NAME)] = '\0';
1640 lpme->hModule = lpme->wNext;
1641 lpme->wcUsage = pModule->count;
1642 lstrcpynA( lpme->szExePath, NE_MODULE_NAME(pModule), sizeof(lpme->szExePath) );
1643 lpme->wNext = pModule->next;
1648 /**********************************************************************
1649 * ModuleFindName (TOOLHELP.61)
1651 BOOL16 WINAPI ModuleFindName16( MODULEENTRY *lpme, LPCSTR name )
1653 lpme->wNext = GetModuleHandle16( name );
1654 return ModuleNext16( lpme );
1658 /**********************************************************************
1659 * ModuleFindHandle (TOOLHELP.62)
1661 BOOL16 WINAPI ModuleFindHandle16( MODULEENTRY *lpme, HMODULE16 hModule )
1663 hModule = GetExePtr( hModule );
1664 lpme->wNext = hModule;
1665 return ModuleNext16( lpme );
1669 /***************************************************************************
1670 * IsRomModule16 (KERNEL.323)
1672 BOOL16 WINAPI IsRomModule16( HMODULE16 unused )
1677 /***************************************************************************
1678 * IsRomFile16 (KERNEL.326)
1680 BOOL16 WINAPI IsRomFile16( HFILE16 unused )
1685 /***************************************************************************
1686 * MapHModuleLS (KERNEL32.520)
1688 HMODULE16 WINAPI MapHModuleLS(HMODULE hmod) {
1692 return ((TDB*)GlobalLock16(GetCurrentTask()))->hInstance;
1694 return hmod; /* we already have a 16 bit module handle */
1695 pModule = (NE_MODULE*)GlobalLock16(hFirstModule);
1697 if (pModule->module32 == hmod)
1698 return pModule->self;
1699 pModule = (NE_MODULE*)GlobalLock16(pModule->next);
1704 /***************************************************************************
1705 * MapHModuleSL (KERNEL32.521)
1707 HMODULE WINAPI MapHModuleSL(HMODULE16 hmod) {
1711 TDB *pTask = (TDB*)GlobalLock16(GetCurrentTask());
1713 hmod = pTask->hModule;
1715 pModule = (NE_MODULE*)GlobalLock16(hmod);
1716 if ( (pModule->magic!=IMAGE_OS2_SIGNATURE) ||
1717 !(pModule->flags & NE_FFLAGS_WIN32)
1720 return pModule->module32;
1723 /***************************************************************************
1724 * MapHInstLS (KERNEL32.516)(KERNEL.472)
1726 void WINAPI MapHInstLS( CONTEXT86 *context )
1728 EAX_reg(context) = MapHModuleLS(EAX_reg(context));
1731 /***************************************************************************
1732 * MapHInstSL (KERNEL32.518)(KERNEL.473)
1734 void WINAPI MapHInstSL( CONTEXT86 *context )
1736 EAX_reg(context) = MapHModuleSL(EAX_reg(context));
1739 /***************************************************************************
1740 * MapHInstLS_PN (KERNEL32.517)
1742 void WINAPI MapHInstLS_PN( CONTEXT86 *context )
1744 if (EAX_reg(context))
1745 EAX_reg(context) = MapHModuleLS(EAX_reg(context));
1748 /***************************************************************************
1749 * MapHInstSL_PN (KERNEL32.519)
1751 void WINAPI MapHInstSL_PN( CONTEXT86 *context )
1753 if (EAX_reg(context))
1754 EAX_reg(context) = MapHModuleSL(EAX_reg(context));