d3d10core: Implement d3d10_device_OMGetRenderTargets().
[wine.git] / dlls / krnl386.exe16 / ne_module.c
blobc0e1a9882d2c85f503d3dcf269481bfcc9f5ff10
1 /*
2 * NE modules
4 * Copyright 1995 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #include "wine/port.h"
24 #include <assert.h>
25 #include <fcntl.h>
26 #include <stdarg.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #ifdef HAVE_UNISTD_H
31 # include <unistd.h>
32 #endif
33 #include <ctype.h>
35 #include "windef.h"
36 #include "wine/winbase16.h"
37 #include "wownt32.h"
38 #include "winternl.h"
39 #include "kernel16_private.h"
40 #include "wine/exception.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(module);
44 WINE_DECLARE_DEBUG_CHANNEL(loaddll);
45 WINE_DECLARE_DEBUG_CHANNEL(relay);
46 WINE_DECLARE_DEBUG_CHANNEL(winediag);
48 #include "pshpack1.h"
49 typedef struct _GPHANDLERDEF
51 WORD selector;
52 WORD rangeStart;
53 WORD rangeEnd;
54 WORD handler;
55 } GPHANDLERDEF;
56 #include "poppack.h"
59 * Segment table entry
61 struct ne_segment_table_entry_s
63 WORD seg_data_offset; /* Sector offset of segment data */
64 WORD seg_data_length; /* Length of segment data */
65 WORD seg_flags; /* Flags associated with this segment */
66 WORD min_alloc; /* Minimum allocation size for this */
69 #define hFirstModule (pThhook->hExeHead)
71 static HINSTANCE16 NE_LoadModule( LPCSTR name, BOOL lib_only );
72 static BOOL16 NE_FreeModule( HMODULE16 hModule, BOOL call_wep );
74 static HINSTANCE16 MODULE_LoadModule16( LPCSTR libname, BOOL implicit, BOOL lib_only );
76 static HMODULE16 NE_GetModuleByFilename( LPCSTR name );
79 /* patch all the flat cs references of the code segment if necessary */
80 static inline void patch_code_segment( NE_MODULE *pModule )
82 int i;
83 CALLFROM16 *call;
84 SEGTABLEENTRY *pSeg = NE_SEG_TABLE( pModule );
86 for (i = 0; i < pModule->ne_cseg; i++, pSeg++)
87 if (!(pSeg->flags & NE_SEGFLAGS_DATA)) break; /* found the code segment */
89 call = GlobalLock16( pSeg->hSeg );
91 /* patch glue code address and code selector */
92 for (i = 0; call[i].pushl == 0x68; i++)
94 if (call[i].ret[0] == 0xca66 || call[i].ret[0] == 0xcb66) /* register entry point? */
95 call[i].glue = __wine_call_from_16_regs;
96 else
97 call[i].glue = __wine_call_from_16;
98 call[i].flatcs = wine_get_cs();
101 if (TRACE_ON(relay)) /* patch relay functions to all point to relay_call_from_16 */
102 for (i = 0; call[i].pushl == 0x68; i++) call[i].relay = relay_call_from_16;
106 /***********************************************************************
107 * contains_path
109 static inline BOOL contains_path( LPCSTR name )
111 return ((*name && (name[1] == ':')) || strchr(name, '/') || strchr(name, '\\'));
115 /***********************************************************************
116 * NE_strcasecmp
118 * locale-independent case conversion for module lookups
120 static int NE_strcasecmp( const char *str1, const char *str2 )
122 int ret = 0;
123 for ( ; ; str1++, str2++)
124 if ((ret = RtlUpperChar(*str1) - RtlUpperChar(*str2)) || !*str1) break;
125 return ret;
129 /***********************************************************************
130 * NE_strncasecmp
132 * locale-independent case conversion for module lookups
134 static int NE_strncasecmp( const char *str1, const char *str2, int len )
136 int ret = 0;
137 for ( ; len > 0; len--, str1++, str2++)
138 if ((ret = RtlUpperChar(*str1) - RtlUpperChar(*str2)) || !*str1) break;
139 return ret;
143 /***********************************************************************
144 * NE_GetPtr
146 NE_MODULE *NE_GetPtr( HMODULE16 hModule )
148 return GlobalLock16( GetExePtr(hModule) );
152 /**********************************************************************
153 * NE_RegisterModule
155 static void NE_RegisterModule( NE_MODULE *pModule )
157 pModule->next = hFirstModule;
158 hFirstModule = pModule->self;
162 /***********************************************************************
163 * NE_DumpModule
165 void NE_DumpModule( HMODULE16 hModule )
167 int i, ordinal;
168 SEGTABLEENTRY *pSeg;
169 BYTE *pstr;
170 WORD *pword;
171 NE_MODULE *pModule;
172 ET_BUNDLE *bundle;
173 ET_ENTRY *entry;
175 if (!(pModule = NE_GetPtr( hModule )))
177 ERR( "**** %04x is not a module handle\n", hModule );
178 return;
181 /* Dump the module info */
182 TRACE( "---\n" );
183 TRACE( "Module %04x:\n", hModule );
184 TRACE( "count=%d flags=%04x heap=%d stack=%d\n",
185 pModule->count, pModule->ne_flags,
186 pModule->ne_heap, pModule->ne_stack );
187 TRACE( "cs:ip=%04x:%04x ss:sp=%04x:%04x ds=%04x nb seg=%d modrefs=%d\n",
188 SELECTOROF(pModule->ne_csip), OFFSETOF(pModule->ne_csip),
189 SELECTOROF(pModule->ne_sssp), OFFSETOF(pModule->ne_sssp),
190 pModule->ne_autodata, pModule->ne_cseg, pModule->ne_cmod );
191 TRACE( "os_flags=%d swap_area=%d version=%04x\n",
192 pModule->ne_exetyp, pModule->ne_swaparea, pModule->ne_expver );
193 if (pModule->ne_flags & NE_FFLAGS_WIN32)
194 TRACE( "PE module=%p\n", pModule->module32 );
196 /* Dump the file info */
197 TRACE( "---\n" );
198 TRACE( "Filename: '%s'\n", NE_MODULE_NAME(pModule) );
200 /* Dump the segment table */
201 TRACE( "---\n" );
202 TRACE( "Segment table:\n" );
203 pSeg = NE_SEG_TABLE( pModule );
204 for (i = 0; i < pModule->ne_cseg; i++, pSeg++)
205 TRACE( "%02x: pos=%d size=%d flags=%04x minsize=%d hSeg=%04x\n",
206 i + 1, pSeg->filepos, pSeg->size, pSeg->flags,
207 pSeg->minsize, pSeg->hSeg );
209 /* Dump the resource table */
210 TRACE( "---\n" );
211 TRACE( "Resource table:\n" );
212 if (pModule->ne_rsrctab)
214 pword = (WORD *)((BYTE *)pModule + pModule->ne_rsrctab);
215 TRACE( "Alignment: %d\n", *pword++ );
216 while (*pword)
218 NE_TYPEINFO *ptr = (NE_TYPEINFO *)pword;
219 NE_NAMEINFO *pname = (NE_NAMEINFO *)(ptr + 1);
220 TRACE( "id=%04x count=%d\n", ptr->type_id, ptr->count );
221 for (i = 0; i < ptr->count; i++, pname++)
222 TRACE( "offset=%d len=%d id=%04x\n",
223 pname->offset, pname->length, pname->id );
224 pword = (WORD *)pname;
227 else TRACE( "None\n" );
229 /* Dump the resident name table */
230 TRACE( "---\n" );
231 TRACE( "Resident-name table:\n" );
232 pstr = (BYTE*) pModule + pModule->ne_restab;
233 while (*pstr)
235 TRACE( "%*.*s: %d\n", *pstr, *pstr, pstr + 1,
236 *(WORD *)(pstr + *pstr + 1) );
237 pstr += *pstr + 1 + sizeof(WORD);
240 /* Dump the module reference table */
241 TRACE( "---\n" );
242 TRACE( "Module ref table:\n" );
243 if (pModule->ne_modtab)
245 pword = (WORD *)((BYTE *)pModule + pModule->ne_modtab);
246 for (i = 0; i < pModule->ne_cmod; i++, pword++)
248 char name[10];
249 GetModuleName16( *pword, name, sizeof(name) );
250 TRACE( "%d: %04x -> '%s'\n", i, *pword, name );
253 else TRACE( "None\n" );
255 /* Dump the entry table */
256 TRACE( "---\n" );
257 TRACE( "Entry table:\n" );
258 bundle = (ET_BUNDLE *)((BYTE *)pModule+pModule->ne_enttab);
259 do {
260 entry = (ET_ENTRY *)((BYTE *)bundle+6);
261 TRACE( "Bundle %d-%d: %02x\n", bundle->first, bundle->last, entry->type);
262 ordinal = bundle->first;
263 while (ordinal < bundle->last)
265 if (entry->type == 0xff)
266 TRACE("%d: %02x:%04x (moveable)\n", ordinal++, entry->segnum, entry->offs);
267 else
268 TRACE("%d: %02x:%04x (fixed)\n", ordinal++, entry->segnum, entry->offs);
269 entry++;
271 } while ( (bundle->next) && (bundle = ((ET_BUNDLE *)((BYTE *)pModule + bundle->next))) );
273 /* Dump the non-resident names table */
274 TRACE( "---\n" );
275 TRACE( "Non-resident names table:\n" );
276 if (pModule->nrname_handle)
278 pstr = GlobalLock16( pModule->nrname_handle );
279 while (*pstr)
281 TRACE( "%*.*s: %d\n", *pstr, *pstr, pstr + 1,
282 *(WORD *)(pstr + *pstr + 1) );
283 pstr += *pstr + 1 + sizeof(WORD);
286 TRACE( "\n" );
290 /***********************************************************************
291 * NE_WalkModules
293 * Walk the module list and print the modules.
295 void NE_WalkModules(void)
297 HMODULE16 hModule = hFirstModule;
298 MESSAGE( "Module Flags Name\n" );
299 while (hModule)
301 NE_MODULE *pModule = NE_GetPtr( hModule );
302 if (!pModule)
304 MESSAGE( "Bad module %04x in list\n", hModule );
305 return;
307 MESSAGE( " %04x %04x %.*s\n", hModule, pModule->ne_flags,
308 *((char *)pModule + pModule->ne_restab),
309 (char *)pModule + pModule->ne_restab + 1 );
310 hModule = pModule->next;
315 /***********************************************************************
316 * NE_InitResourceHandler
318 * Fill in 'resloader' fields in the resource table.
320 static void NE_InitResourceHandler( HMODULE16 hModule )
322 static FARPROC16 proc;
324 NE_TYPEINFO *pTypeInfo;
325 NE_MODULE *pModule;
327 if (!(pModule = NE_GetPtr( hModule )) || !pModule->ne_rsrctab) return;
329 TRACE("InitResourceHandler[%04x]\n", hModule );
331 if (!proc) proc = GetProcAddress16( GetModuleHandle16("KERNEL"), "DefResourceHandler" );
333 pTypeInfo = (NE_TYPEINFO *)((char *)pModule + pModule->ne_rsrctab + 2);
334 while(pTypeInfo->type_id)
336 memcpy_unaligned( &pTypeInfo->resloader, &proc, sizeof(FARPROC16) );
337 pTypeInfo = (NE_TYPEINFO *)((char*)(pTypeInfo + 1) + pTypeInfo->count * sizeof(NE_NAMEINFO));
342 /***********************************************************************
343 * NE_GetOrdinal
345 * Lookup the ordinal for a given name.
347 WORD NE_GetOrdinal( HMODULE16 hModule, const char *name )
349 char buffer[256], *p;
350 BYTE *cpnt;
351 BYTE len;
352 NE_MODULE *pModule;
354 if (!(pModule = NE_GetPtr( hModule ))) return 0;
355 if (pModule->ne_flags & NE_FFLAGS_WIN32) return 0;
357 TRACE("(%04x,'%s')\n", hModule, name );
359 /* First handle names of the form '#xxxx' */
361 if (name[0] == '#') return atoi( name + 1 );
363 /* Now copy and uppercase the string */
365 strcpy( buffer, name );
366 for (p = buffer; *p; p++) *p = RtlUpperChar(*p);
367 len = p - buffer;
369 /* First search the resident names */
371 cpnt = (BYTE *)pModule + pModule->ne_restab;
373 /* Skip the first entry (module name) */
374 cpnt += *cpnt + 1 + sizeof(WORD);
375 while (*cpnt)
377 if ((*cpnt == len) && !memcmp( cpnt+1, buffer, len ))
379 WORD ordinal;
380 memcpy( &ordinal, cpnt + *cpnt + 1, sizeof(ordinal) );
381 TRACE(" Found: ordinal=%d\n", ordinal );
382 return ordinal;
384 cpnt += *cpnt + 1 + sizeof(WORD);
387 /* Now search the non-resident names table */
389 if (!pModule->nrname_handle) return 0; /* No non-resident table */
390 cpnt = GlobalLock16( pModule->nrname_handle );
392 /* Skip the first entry (module description string) */
393 cpnt += *cpnt + 1 + sizeof(WORD);
394 while (*cpnt)
396 if ((*cpnt == len) && !memcmp( cpnt+1, buffer, len ))
398 WORD ordinal;
399 memcpy( &ordinal, cpnt + *cpnt + 1, sizeof(ordinal) );
400 TRACE(" Found: ordinal=%d\n", ordinal );
401 return ordinal;
403 cpnt += *cpnt + 1 + sizeof(WORD);
405 return 0;
409 /***********************************************************************
410 * NE_GetEntryPoint
412 FARPROC16 WINAPI NE_GetEntryPoint( HMODULE16 hModule, WORD ordinal )
414 return NE_GetEntryPointEx( hModule, ordinal, TRUE );
417 /***********************************************************************
418 * NE_GetEntryPointEx
420 FARPROC16 NE_GetEntryPointEx( HMODULE16 hModule, WORD ordinal, BOOL16 snoop )
422 NE_MODULE *pModule;
423 WORD sel, offset, i;
425 ET_ENTRY *entry;
426 ET_BUNDLE *bundle;
428 if (!(pModule = NE_GetPtr( hModule ))) return 0;
429 assert( !(pModule->ne_flags & NE_FFLAGS_WIN32) );
431 bundle = (ET_BUNDLE *)((BYTE *)pModule + pModule->ne_enttab);
432 while ((ordinal < bundle->first + 1) || (ordinal > bundle->last))
434 if (!(bundle->next))
435 return 0;
436 bundle = (ET_BUNDLE *)((BYTE *)pModule + bundle->next);
439 entry = (ET_ENTRY *)((BYTE *)bundle+6);
440 for (i=0; i < (ordinal - bundle->first - 1); i++)
441 entry++;
443 sel = entry->segnum;
444 memcpy( &offset, &entry->offs, sizeof(WORD) );
446 if (sel == 0xfe) sel = 0xffff; /* constant entry */
447 else sel = GlobalHandleToSel16(NE_SEG_TABLE(pModule)[sel-1].hSeg);
448 if (sel==0xffff)
449 return (FARPROC16)MAKESEGPTR( sel, offset );
450 if (!snoop)
451 return (FARPROC16)MAKESEGPTR( sel, offset );
452 else
453 return SNOOP16_GetProcAddress16(hModule,ordinal,(FARPROC16)MAKESEGPTR( sel, offset ));
457 /***********************************************************************
458 * EntryAddrProc (KERNEL.667) Wine-specific export
460 * Return the entry point for a given ordinal.
462 FARPROC16 WINAPI EntryAddrProc16( HMODULE16 hModule, WORD ordinal )
464 FARPROC16 ret = NE_GetEntryPointEx( hModule, ordinal, TRUE );
465 CURRENT_STACK16->ecx = hModule; /* FIXME: might be incorrect value */
466 return ret;
469 /***********************************************************************
470 * NE_SetEntryPoint
472 * Change the value of an entry point. Use with caution!
473 * It can only change the offset value, not the selector.
475 BOOL16 NE_SetEntryPoint( HMODULE16 hModule, WORD ordinal, WORD offset )
477 NE_MODULE *pModule;
478 ET_ENTRY *entry;
479 ET_BUNDLE *bundle;
480 int i;
482 if (!(pModule = NE_GetPtr( hModule ))) return FALSE;
483 assert( !(pModule->ne_flags & NE_FFLAGS_WIN32) );
485 bundle = (ET_BUNDLE *)((BYTE *)pModule + pModule->ne_enttab);
486 while ((ordinal < bundle->first + 1) || (ordinal > bundle->last))
488 bundle = (ET_BUNDLE *)((BYTE *)pModule + bundle->next);
489 if (!bundle->next) return FALSE;
492 entry = (ET_ENTRY *)((BYTE *)bundle+6);
493 for (i=0; i < (ordinal - bundle->first - 1); i++)
494 entry++;
496 memcpy( &entry->offs, &offset, sizeof(WORD) );
497 return TRUE;
501 /***********************************************************************
502 * build_bundle_data
504 * Build the entry table bundle data from the on-disk format. Helper for build_module.
506 static void *build_bundle_data( NE_MODULE *pModule, void *dest, const BYTE *table )
508 ET_BUNDLE *oldbundle, *bundle = dest;
509 ET_ENTRY *entry;
510 BYTE nr_entries, type;
512 memset(bundle, 0, sizeof(ET_BUNDLE)); /* in case no entry table exists */
513 entry = (ET_ENTRY *)((BYTE *)bundle+6);
515 while ((nr_entries = *table++))
517 if ((type = *table++))
519 bundle->last += nr_entries;
520 if (type == 0xff)
522 while (nr_entries--)
524 entry->type = type;
525 entry->flags = *table++;
526 table += sizeof(WORD);
527 entry->segnum = *table++;
528 entry->offs = *(const WORD *)table;
529 table += sizeof(WORD);
530 entry++;
533 else
535 while (nr_entries--)
537 entry->type = type;
538 entry->flags = *table++;
539 entry->segnum = type;
540 entry->offs = *(const WORD *)table;
541 table += sizeof(WORD);
542 entry++;
546 else
548 if (bundle->first == bundle->last)
550 bundle->first += nr_entries;
551 bundle->last += nr_entries;
553 else
555 oldbundle = bundle;
556 oldbundle->next = (char *)entry - (char *)pModule;
557 bundle = (ET_BUNDLE *)entry;
558 bundle->first = bundle->last = oldbundle->last + nr_entries;
559 bundle->next = 0;
560 entry = (ET_ENTRY*)(((BYTE*)entry)+sizeof(ET_BUNDLE));
564 return entry;
568 /***********************************************************************
569 * build_module
571 * Build the in-memory module from the on-disk data.
573 static HMODULE16 build_module( const void *mapping, SIZE_T mapping_size, LPCSTR path )
575 const IMAGE_DOS_HEADER *mz_header = mapping;
576 const IMAGE_OS2_HEADER *ne_header;
577 const struct ne_segment_table_entry_s *pSeg;
578 const void *ptr;
579 int i;
580 size_t size;
581 HMODULE16 hModule;
582 NE_MODULE *pModule;
583 BYTE *buffer, *pData, *end;
584 OFSTRUCT *ofs;
586 if (mapping_size < sizeof(*mz_header)) return ERROR_BAD_FORMAT;
587 if (mz_header->e_magic != IMAGE_DOS_SIGNATURE) return ERROR_BAD_FORMAT;
588 ne_header = (const IMAGE_OS2_HEADER *)((const char *)mapping + mz_header->e_lfanew);
589 if (mz_header->e_lfanew + sizeof(*ne_header) > mapping_size) return ERROR_BAD_FORMAT;
590 if (ne_header->ne_magic == IMAGE_NT_SIGNATURE) return 21; /* win32 exe */
591 if (ne_header->ne_magic == IMAGE_OS2_SIGNATURE_LX)
593 MESSAGE("Sorry, %s is an OS/2 linear executable (LX) file!\n", path);
594 return 12;
596 if (ne_header->ne_magic != IMAGE_OS2_SIGNATURE) return ERROR_BAD_FORMAT;
598 /* We now have a valid NE header */
600 /* check to be able to fall back to loading OS/2 programs as DOS
601 * FIXME: should this check be reversed in order to be less strict?
602 * (only fail for OS/2 ne_exetyp 0x01 here?) */
603 if ((ne_header->ne_exetyp != 0x02 /* Windows */)
604 && (ne_header->ne_exetyp != 0x04) /* Windows 386 */)
605 return ERROR_BAD_FORMAT;
607 size = sizeof(NE_MODULE) +
608 /* segment table */
609 ne_header->ne_cseg * sizeof(SEGTABLEENTRY) +
610 /* resource table */
611 ne_header->ne_restab - ne_header->ne_rsrctab +
612 /* resident names table */
613 ne_header->ne_modtab - ne_header->ne_restab +
614 /* module ref table */
615 ne_header->ne_cmod * sizeof(WORD) +
616 /* imported names table */
617 ne_header->ne_enttab - ne_header->ne_imptab +
618 /* entry table length */
619 ne_header->ne_cbenttab +
620 /* entry table extra conversion space */
621 sizeof(ET_BUNDLE) +
622 2 * (ne_header->ne_cbenttab - ne_header->ne_cmovent*6) +
623 /* loaded file info */
624 sizeof(OFSTRUCT) - sizeof(ofs->szPathName) + strlen(path) + 1;
626 hModule = GlobalAlloc16( GMEM_FIXED | GMEM_ZEROINIT, size );
627 if (!hModule)
629 ERR_(winediag)( "Failed to create module for %s, 16-bit LDT support may be missing.\n",
630 debugstr_a(path) );
631 return ERROR_BAD_FORMAT;
634 FarSetOwner16( hModule, hModule );
635 pModule = GlobalLock16( hModule );
636 memcpy( pModule, ne_header, sizeof(*ne_header) );
637 pModule->count = 0;
638 /* check programs for default minimal stack size */
639 if (!(pModule->ne_flags & NE_FFLAGS_LIBMODULE) && (pModule->ne_stack < 0x1400))
640 pModule->ne_stack = 0x1400;
642 pModule->self = hModule;
643 pModule->mapping = mapping;
644 pModule->mapping_size = mapping_size;
646 pData = (BYTE *)(pModule + 1);
648 /* Clear internal Wine flags in case they are set in the EXE file */
650 pModule->ne_flags &= ~(NE_FFLAGS_BUILTIN | NE_FFLAGS_WIN32);
652 /* Get the segment table */
654 pModule->ne_segtab = pData - (BYTE *)pModule;
655 if (!(pSeg = NE_GET_DATA( pModule, mz_header->e_lfanew + ne_header->ne_segtab,
656 ne_header->ne_cseg * sizeof(struct ne_segment_table_entry_s) )))
657 goto failed;
658 for (i = ne_header->ne_cseg; i > 0; i--, pSeg++)
660 memcpy( pData, pSeg, sizeof(*pSeg) );
661 pData += sizeof(SEGTABLEENTRY);
664 /* Get the resource table */
666 if (ne_header->ne_rsrctab < ne_header->ne_restab)
668 pModule->ne_rsrctab = pData - (BYTE *)pModule;
669 if (!NE_READ_DATA( pModule, pData, mz_header->e_lfanew + ne_header->ne_rsrctab,
670 ne_header->ne_restab - ne_header->ne_rsrctab )) goto failed;
671 pData += ne_header->ne_restab - ne_header->ne_rsrctab;
673 else pModule->ne_rsrctab = 0; /* No resource table */
675 /* Get the resident names table */
677 pModule->ne_restab = pData - (BYTE *)pModule;
678 if (!NE_READ_DATA( pModule, pData, mz_header->e_lfanew + ne_header->ne_restab,
679 ne_header->ne_modtab - ne_header->ne_restab )) goto failed;
680 pData += ne_header->ne_modtab - ne_header->ne_restab;
682 /* Get the module references table */
684 if (ne_header->ne_cmod > 0)
686 pModule->ne_modtab = pData - (BYTE *)pModule;
687 if (!NE_READ_DATA( pModule, pData, mz_header->e_lfanew + ne_header->ne_modtab,
688 ne_header->ne_cmod * sizeof(WORD) )) goto failed;
689 pData += ne_header->ne_cmod * sizeof(WORD);
691 else pModule->ne_modtab = 0; /* No module references */
693 /* Get the imported names table */
695 pModule->ne_imptab = pData - (BYTE *)pModule;
696 if (!NE_READ_DATA( pModule, pData, mz_header->e_lfanew + ne_header->ne_imptab,
697 ne_header->ne_enttab - ne_header->ne_imptab )) goto failed;
698 pData += ne_header->ne_enttab - ne_header->ne_imptab;
700 /* Load entry table, convert it to the optimized version used by Windows */
702 pModule->ne_enttab = pData - (BYTE *)pModule;
703 if (!(ptr = NE_GET_DATA( pModule, mz_header->e_lfanew + ne_header->ne_enttab,
704 ne_header->ne_cbenttab ))) goto failed;
705 end = build_bundle_data( pModule, pData, ptr );
707 pData += ne_header->ne_cbenttab + sizeof(ET_BUNDLE) +
708 2 * (ne_header->ne_cbenttab - ne_header->ne_cmovent*6);
710 if (end > pData)
712 FIXME( "not enough space for entry table for %s\n", debugstr_a(path) );
713 goto failed;
716 /* Store the filename information */
718 pModule->fileinfo = pData - (BYTE *)pModule;
719 ofs = (OFSTRUCT *)pData;
720 ofs->cBytes = sizeof(OFSTRUCT) - sizeof(ofs->szPathName) + strlen(path);
721 ofs->fFixedDisk = 1;
722 strcpy( ofs->szPathName, path );
723 pData += ofs->cBytes + 1;
724 assert( (BYTE *)pModule + size <= pData );
726 /* Get the non-resident names table */
728 if (ne_header->ne_cbnrestab)
730 pModule->nrname_handle = GlobalAlloc16( 0, ne_header->ne_cbnrestab );
731 if (!pModule->nrname_handle) goto failed;
732 FarSetOwner16( pModule->nrname_handle, hModule );
733 buffer = GlobalLock16( pModule->nrname_handle );
734 if (!NE_READ_DATA( pModule, buffer, ne_header->ne_nrestab, ne_header->ne_cbnrestab ))
736 GlobalFree16( pModule->nrname_handle );
737 pModule->nrname_handle = 0;
740 else pModule->nrname_handle = 0;
742 /* Allocate a segment for the implicitly-loaded DLLs */
744 if (pModule->ne_cmod)
746 pModule->dlls_to_init = GlobalAlloc16( GMEM_ZEROINIT,
747 (pModule->ne_cmod+1)*sizeof(HMODULE16) );
748 if (!pModule->dlls_to_init)
750 if (pModule->nrname_handle) GlobalFree16( pModule->nrname_handle );
751 goto failed;
753 FarSetOwner16( pModule->dlls_to_init, hModule );
755 else pModule->dlls_to_init = 0;
757 NE_RegisterModule( pModule );
758 return hModule;
760 failed:
761 GlobalFree16( hModule );
762 return ERROR_BAD_FORMAT;
766 /***********************************************************************
767 * NE_LoadDLLs
769 * Load all DLLs implicitly linked to a module.
771 static BOOL NE_LoadDLLs( NE_MODULE *pModule )
773 int i;
774 WORD *pModRef = (WORD *)((char *)pModule + pModule->ne_modtab);
775 WORD *pDLLs = GlobalLock16( pModule->dlls_to_init );
777 for (i = 0; i < pModule->ne_cmod; i++, pModRef++)
779 char buffer[260], *p;
780 BYTE *pstr = (BYTE *)pModule + pModule->ne_imptab + *pModRef;
781 memcpy( buffer, pstr + 1, *pstr );
782 *(buffer + *pstr) = 0; /* terminate it */
784 TRACE("Loading '%s'\n", buffer );
785 if (!(*pModRef = GetModuleHandle16( buffer )))
787 /* If the DLL is not loaded yet, load it and store */
788 /* its handle in the list of DLLs to initialize. */
789 HMODULE16 hDLL;
791 /* Append .DLL to name if no extension present */
792 if (!(p = strrchr( buffer, '.')) || strchr( p, '/' ) || strchr( p, '\\'))
793 strcat( buffer, ".DLL" );
795 if ((hDLL = MODULE_LoadModule16( buffer, TRUE, TRUE )) < 32)
797 /* FIXME: cleanup what was done */
799 MESSAGE( "Could not load '%s' required by '%.*s', error=%d\n",
800 buffer, *((BYTE*)pModule + pModule->ne_restab),
801 (char *)pModule + pModule->ne_restab + 1, hDLL );
802 return FALSE;
804 *pModRef = GetExePtr( hDLL );
805 *pDLLs++ = *pModRef;
807 else /* Increment the reference count of the DLL */
809 NE_MODULE *pOldDLL = NE_GetPtr( *pModRef );
810 if (pOldDLL) pOldDLL->count++;
813 return TRUE;
817 /**********************************************************************
818 * NE_DoLoadModule
820 * Load first instance of NE module from file.
822 * pModule must point to a module structure prepared by build_module.
823 * This routine must never be called twice on a module.
825 static HINSTANCE16 NE_DoLoadModule( NE_MODULE *pModule )
827 /* Allocate the segments for this module */
829 if (!NE_CreateAllSegments( pModule ))
830 return ERROR_NOT_ENOUGH_MEMORY; /* 8 */
832 /* Load the referenced DLLs */
834 if (!NE_LoadDLLs( pModule ))
835 return ERROR_FILE_NOT_FOUND; /* 2 */
837 /* Load the segments */
839 NE_LoadAllSegments( pModule );
841 /* Make sure the usage count is 1 on the first loading of */
842 /* the module, even if it contains circular DLL references */
844 pModule->count = 1;
846 return NE_GetInstance( pModule );
849 /**********************************************************************
850 * NE_LoadModule
852 * Load first instance of NE module. (Note: caller is responsible for
853 * ensuring the module isn't already loaded!)
855 * If the module turns out to be an executable module, only a
856 * handle to a module stub is returned; this needs to be initialized
857 * by calling NE_DoLoadModule later, in the context of the newly
858 * created process.
860 * If lib_only is TRUE, however, the module is perforce treated
861 * like a DLL module, even if it is an executable module.
864 static HINSTANCE16 NE_LoadModule( LPCSTR name, BOOL lib_only )
866 NE_MODULE *pModule;
867 HMODULE16 hModule;
868 HINSTANCE16 hInstance;
869 HFILE16 hFile;
870 OFSTRUCT ofs;
871 HANDLE mapping;
872 void *ptr;
873 MEMORY_BASIC_INFORMATION info;
875 /* Open file */
876 if ((hFile = OpenFile16( name, &ofs, OF_READ|OF_SHARE_DENY_WRITE )) == HFILE_ERROR16)
877 return ERROR_FILE_NOT_FOUND;
879 mapping = CreateFileMappingW( DosFileHandleToWin32Handle(hFile), NULL, PAGE_WRITECOPY, 0, 0, NULL );
880 _lclose16( hFile );
881 if (!mapping) return ERROR_BAD_FORMAT;
883 ptr = MapViewOfFile( mapping, FILE_MAP_COPY, 0, 0, 0 );
884 CloseHandle( mapping );
885 if (!ptr) return ERROR_BAD_FORMAT;
887 VirtualQuery( ptr, &info, sizeof(info) );
888 hModule = build_module( ptr, info.RegionSize, ofs.szPathName );
890 if (hModule < 32)
892 UnmapViewOfFile( ptr );
893 return hModule;
896 SNOOP16_RegisterDLL( hModule, ofs.szPathName );
897 NE_InitResourceHandler( hModule );
899 pModule = NE_GetPtr( hModule );
901 if ( !lib_only && !( pModule->ne_flags & NE_FFLAGS_LIBMODULE ) )
902 return hModule;
904 hInstance = NE_DoLoadModule( pModule );
905 if ( hInstance < 32 )
907 /* cleanup ... */
908 NE_FreeModule( hModule, 0 );
911 return hInstance;
915 /***********************************************************************
916 * NE_DoLoadBuiltinModule
918 * Load a built-in Win16 module. Helper function for NE_LoadBuiltinModule.
920 static HMODULE16 NE_DoLoadBuiltinModule( const IMAGE_DOS_HEADER *mz_header, const char *file_name,
921 HMODULE owner32 )
923 NE_MODULE *pModule;
924 HMODULE16 hModule;
925 HINSTANCE16 hInstance;
926 SIZE_T mapping_size = ~0UL; /* assume builtins don't contain invalid offsets... */
928 hModule = build_module( mz_header, mapping_size, file_name );
929 if (hModule < 32) return hModule;
930 pModule = GlobalLock16( hModule );
931 pModule->ne_flags |= NE_FFLAGS_BUILTIN;
932 pModule->owner32 = owner32;
934 /* fake the expected version the module should have according to the current Windows version */
935 pModule->ne_expver = MAKEWORD( NtCurrentTeb()->Peb->OSMajorVersion,
936 NtCurrentTeb()->Peb->OSMinorVersion );
938 hInstance = NE_DoLoadModule( pModule );
939 if (hInstance < 32) NE_FreeModule( hModule, 0 );
941 NE_InitResourceHandler( hModule );
943 if (pModule->ne_heap)
945 SEGTABLEENTRY *pSeg = NE_SEG_TABLE( pModule ) + pModule->ne_autodata - 1;
946 unsigned int size = pSeg->minsize + pModule->ne_heap;
947 if (size > 0xfffe) size = 0xfffe;
948 LocalInit16( GlobalHandleToSel16(pSeg->hSeg), pSeg->minsize, size );
951 patch_code_segment( pModule );
953 return hInstance;
957 /**********************************************************************
958 * MODULE_LoadModule16
960 * Load a NE module in the order of the loadorder specification.
961 * The caller is responsible that the module is not loaded already.
964 static HINSTANCE16 MODULE_LoadModule16( LPCSTR libname, BOOL implicit, BOOL lib_only )
966 HINSTANCE16 hinst = 2;
967 HMODULE16 hModule;
968 HMODULE mod32 = 0;
969 NE_MODULE *pModule;
970 const IMAGE_DOS_HEADER *descr = NULL;
971 const char *file_name = NULL;
972 char dllname[32];
973 const char *basename, *main_module, *p;
975 /* strip path information */
977 basename = libname;
978 if (basename[0] && basename[1] == ':') basename += 2; /* strip drive specification */
979 if ((p = strrchr( basename, '\\' ))) basename = p + 1;
980 if ((p = strrchr( basename, '/' ))) basename = p + 1;
982 if (strlen(basename) < sizeof(dllname)-6)
984 char *q;
986 strcpy( dllname, basename );
987 q = strrchr( dllname, '.' );
988 if (!q) strcat( dllname, ".dll" );
989 for (q = dllname; *q; q++) if (*q >= 'A' && *q <= 'Z') *q += 32;
991 strcpy( q, "16" );
992 if ((mod32 = LoadLibraryA( dllname )))
994 if (!(descr = (void *)GetProcAddress( mod32, "__wine_spec_dos_header" )))
996 WARN( "loaded %s but does not contain a 16-bit module\n", debugstr_a(dllname) );
997 FreeLibrary( mod32 );
999 else
1001 TRACE( "found %s with embedded 16-bit module\n", debugstr_a(dllname) );
1002 file_name = basename;
1004 /* if module has a 32-bit owner, match the load order of the owner */
1005 if ((main_module = (void *)GetProcAddress( mod32, "__wine_spec_main_module" )))
1007 LDR_MODULE *ldr;
1008 HMODULE main_owner = LoadLibraryA( main_module );
1010 if (!main_owner)
1012 WARN( "couldn't load owner %s for 16-bit dll %s\n", main_module, dllname );
1013 FreeLibrary( mod32 );
1014 return ERROR_FILE_NOT_FOUND;
1016 /* check if module was loaded native */
1017 if (LdrFindEntryForAddress( main_owner, &ldr ) || !(ldr->Flags & LDR_WINE_INTERNAL))
1019 FreeLibrary( mod32 );
1020 descr = NULL;
1022 FreeLibrary( main_owner );
1027 /* loading the 32-bit library can have the side effect of loading the module */
1028 /* if so, simply incr the ref count and return the module */
1029 if (descr && (hModule = GetModuleHandle16( libname )))
1031 TRACE( "module %s already loaded by owner\n", libname );
1032 pModule = NE_GetPtr( hModule );
1033 if (pModule) pModule->count++;
1034 FreeLibrary( mod32 );
1035 return hModule;
1039 if (descr)
1041 TRACE("Trying built-in '%s'\n", libname);
1042 hinst = NE_DoLoadBuiltinModule( descr, file_name, mod32 );
1043 if (hinst > 32) TRACE_(loaddll)("Loaded module %s : builtin\n", debugstr_a(file_name));
1044 else FreeLibrary( mod32 );
1046 else
1048 TRACE("Trying native dll '%s'\n", libname);
1049 hinst = NE_LoadModule(libname, lib_only);
1050 if (hinst > 32) TRACE_(loaddll)("Loaded module %s : native\n", debugstr_a(libname));
1053 if (hinst > 32 && !implicit)
1055 hModule = GetModuleHandle16(libname);
1056 if(!hModule)
1058 ERR("Serious trouble. Just loaded module '%s' (hinst=0x%04x), but can't get module handle. Filename too long ?\n",
1059 libname, hinst);
1060 return ERROR_INVALID_HANDLE;
1063 pModule = NE_GetPtr(hModule);
1064 if(!pModule)
1066 ERR("Serious trouble. Just loaded module '%s' (hinst=0x%04x), but can't get NE_MODULE pointer\n",
1067 libname, hinst);
1068 return ERROR_INVALID_HANDLE;
1071 TRACE("Loaded module '%s' at 0x%04x.\n", libname, hinst);
1074 * Call initialization routines for all loaded DLLs. Note that
1075 * when we load implicitly linked DLLs this will be done by InitTask().
1077 if(pModule->ne_flags & NE_FFLAGS_LIBMODULE)
1079 NE_InitializeDLLs(hModule);
1080 NE_DllProcessAttach(hModule);
1082 else DOSMEM_InitDosMemory(); /* we will be running a 16-bit task, setup DOS memory */
1084 return hinst; /* The last error that occurred */
1088 /**********************************************************************
1089 * NE_CreateThread
1091 * Create the thread for a 16-bit module.
1093 static HINSTANCE16 NE_CreateThread( NE_MODULE *pModule, WORD cmdShow, LPCSTR cmdline )
1095 HANDLE hThread;
1096 TDB *pTask;
1097 HTASK16 hTask;
1098 HINSTANCE16 instance = 0;
1100 if (!(hTask = TASK_SpawnTask( pModule, cmdShow, cmdline + 1, *cmdline, &hThread )))
1101 return 0;
1103 /* Post event to start the task */
1104 PostEvent16( hTask );
1106 /* Wait until we get the instance handle */
1109 DirectedYield16( hTask );
1110 if (!IsTask16( hTask )) /* thread has died */
1112 DWORD exit_code;
1113 WaitForSingleObject( hThread, INFINITE );
1114 GetExitCodeThread( hThread, &exit_code );
1115 CloseHandle( hThread );
1116 return exit_code;
1118 if (!(pTask = GlobalLock16( hTask ))) break;
1119 instance = pTask->hInstance;
1120 GlobalUnlock16( hTask );
1121 } while (!instance);
1123 CloseHandle( hThread );
1124 return instance;
1128 /**********************************************************************
1129 * LoadModule (KERNEL.45)
1131 HINSTANCE16 WINAPI LoadModule16( LPCSTR name, LPVOID paramBlock )
1133 BOOL lib_only = !paramBlock || (paramBlock == (LPVOID)-1);
1134 LOADPARAMS16 *params;
1135 HMODULE16 hModule;
1136 NE_MODULE *pModule;
1137 LPSTR cmdline;
1138 WORD cmdShow = 1; /* SW_SHOWNORMAL but we don't want to include winuser.h here */
1140 if (name == NULL) return 0;
1142 TRACE("name %s, paramBlock %p\n", name, paramBlock);
1144 /* Load module */
1146 if ( (hModule = NE_GetModuleByFilename(name) ) != 0 )
1148 /* Special case: second instance of an already loaded NE module */
1150 if ( !( pModule = NE_GetPtr( hModule ) ) ) return ERROR_BAD_FORMAT;
1151 if ( pModule->module32 ) return (HINSTANCE16)21;
1153 /* Increment refcount */
1155 pModule->count++;
1157 else
1159 /* Main case: load first instance of NE module */
1161 if ( (hModule = MODULE_LoadModule16( name, FALSE, lib_only )) < 32 )
1162 return hModule;
1164 if ( !(pModule = NE_GetPtr( hModule )) )
1165 return ERROR_BAD_FORMAT;
1168 /* If library module, we just retrieve the instance handle */
1170 if ( ( pModule->ne_flags & NE_FFLAGS_LIBMODULE ) || lib_only )
1171 return NE_GetInstance( pModule );
1174 * At this point, we need to create a new process.
1176 * pModule points either to an already loaded module, whose refcount
1177 * has already been incremented (to avoid having the module vanish
1178 * in the meantime), or else to a stub module which contains only header
1179 * information.
1181 params = paramBlock;
1182 if (params->showCmd)
1183 cmdShow = ((WORD *)MapSL( params->showCmd ))[1];
1184 cmdline = MapSL( params->cmdLine );
1185 return NE_CreateThread( pModule, cmdShow, cmdline );
1189 /**********************************************************************
1190 * NE_StartTask
1192 * Startup code for a new 16-bit task.
1194 DWORD NE_StartTask(void)
1196 TDB *pTask = TASK_GetCurrent();
1197 NE_MODULE *pModule = NE_GetPtr( pTask->hModule );
1198 HINSTANCE16 hInstance, hPrevInstance;
1199 SEGTABLEENTRY *pSegTable = NE_SEG_TABLE( pModule );
1200 WORD sp;
1202 if ( pModule->count > 0 )
1204 /* Second instance of an already loaded NE module */
1205 /* Note that the refcount was already incremented by the parent */
1207 hPrevInstance = NE_GetInstance( pModule );
1209 if ( pModule->ne_autodata )
1210 if ( NE_CreateSegment( pModule, pModule->ne_autodata ) )
1211 NE_LoadSegment( pModule, pModule->ne_autodata );
1213 hInstance = NE_GetInstance( pModule );
1214 TRACE("created second instance %04x[%d] of instance %04x.\n", hInstance, pModule->ne_autodata, hPrevInstance);
1217 else
1219 /* Load first instance of NE module */
1221 pModule->ne_flags |= NE_FFLAGS_GUI; /* FIXME: is this necessary? */
1223 hInstance = NE_DoLoadModule( pModule );
1224 hPrevInstance = 0;
1227 if ( hInstance >= 32 )
1229 CONTEXT context;
1231 /* Enter instance handles into task struct */
1233 pTask->hInstance = hInstance;
1234 pTask->hPrevInstance = hPrevInstance;
1236 /* Use DGROUP for 16-bit stack */
1238 if (!(sp = OFFSETOF(pModule->ne_sssp)))
1239 sp = pSegTable[SELECTOROF(pModule->ne_sssp)-1].minsize + pModule->ne_stack;
1240 sp &= ~1;
1241 sp -= sizeof(STACK16FRAME);
1242 NtCurrentTeb()->WOW32Reserved = (void *)MAKESEGPTR( GlobalHandleToSel16(hInstance), sp );
1244 /* Registers at initialization must be:
1245 * ax zero
1246 * bx stack size in bytes
1247 * cx heap size in bytes
1248 * si previous app instance
1249 * di current app instance
1250 * bp zero
1251 * es selector to the PSP
1252 * ds dgroup of the application
1253 * ss stack selector
1254 * sp top of the stack
1256 memset( &context, 0, sizeof(context) );
1257 context.SegCs = GlobalHandleToSel16(pSegTable[SELECTOROF(pModule->ne_csip) - 1].hSeg);
1258 context.SegDs = GlobalHandleToSel16(pTask->hInstance);
1259 context.SegEs = pTask->hPDB;
1260 context.SegFs = wine_get_fs();
1261 context.SegGs = wine_get_gs();
1262 context.Eip = OFFSETOF(pModule->ne_csip);
1263 context.Ebx = pModule->ne_stack;
1264 context.Ecx = pModule->ne_heap;
1265 context.Edi = pTask->hInstance;
1266 context.Esi = pTask->hPrevInstance;
1268 /* Now call 16-bit entry point */
1270 TRACE("Starting main program: cs:ip=%04x:%04x ds=%04x ss:sp=%04x:%04x\n",
1271 context.SegCs, context.Eip, context.SegDs,
1272 SELECTOROF(NtCurrentTeb()->WOW32Reserved),
1273 OFFSETOF(NtCurrentTeb()->WOW32Reserved) );
1275 WOWCallback16Ex( 0, WCB16_REGS, 0, NULL, (DWORD *)&context );
1276 ExitThread( LOWORD(context.Eax) );
1278 return hInstance; /* error code */
1281 /***********************************************************************
1282 * LoadLibrary (KERNEL.95)
1283 * LoadLibrary16 (KERNEL32.35)
1285 HINSTANCE16 WINAPI LoadLibrary16( LPCSTR libname )
1287 return LoadModule16(libname, (LPVOID)-1 );
1291 /**********************************************************************
1292 * MODULE_CallWEP
1294 * Call a DLL's WEP, allowing it to shut down.
1295 * FIXME: we always pass the WEP WEP_FREE_DLL, never WEP_SYSTEM_EXIT
1297 static BOOL16 MODULE_CallWEP( HMODULE16 hModule )
1299 BOOL16 ret;
1300 FARPROC16 WEP = GetProcAddress16( hModule, "WEP" );
1301 if (!WEP) return FALSE;
1303 __TRY
1305 WORD args[1];
1306 DWORD dwRet;
1308 args[0] = WEP_FREE_DLL;
1309 WOWCallback16Ex( (DWORD)WEP, WCB16_PASCAL, sizeof(args), args, &dwRet );
1310 ret = LOWORD(dwRet);
1312 __EXCEPT_PAGE_FAULT
1314 WARN("Page fault\n");
1315 ret = 0;
1317 __ENDTRY
1319 return ret;
1323 /**********************************************************************
1324 * NE_FreeModule
1326 * Implementation of FreeModule16().
1328 static BOOL16 NE_FreeModule( HMODULE16 hModule, BOOL call_wep )
1330 HMODULE16 *hPrevModule;
1331 NE_MODULE *pModule;
1332 HMODULE16 *pModRef;
1333 int i;
1335 if (!(pModule = NE_GetPtr( hModule ))) return FALSE;
1336 hModule = pModule->self;
1338 TRACE("%04x count %d\n", hModule, pModule->count );
1340 if (((INT16)(--pModule->count)) > 0 ) return TRUE;
1341 else pModule->count = 0;
1343 if (call_wep && !(pModule->ne_flags & NE_FFLAGS_WIN32))
1345 /* Free the objects owned by the DLL module */
1346 NE_CallUserSignalProc( hModule, USIG16_DLL_UNLOAD );
1348 if (pModule->ne_flags & NE_FFLAGS_LIBMODULE)
1349 MODULE_CallWEP( hModule );
1350 else
1351 call_wep = FALSE; /* We are freeing a task -> no more WEPs */
1354 TRACE_(loaddll)("Unloaded module %s : %s\n", debugstr_a(NE_MODULE_NAME(pModule)),
1355 (pModule->ne_flags & NE_FFLAGS_BUILTIN) ? "builtin" : "native");
1357 /* Clear magic number just in case */
1359 pModule->ne_magic = pModule->self = 0;
1360 if (pModule->owner32) FreeLibrary( pModule->owner32 );
1361 else if (pModule->mapping) UnmapViewOfFile( pModule->mapping );
1363 /* Remove it from the linked list */
1365 hPrevModule = &hFirstModule;
1366 while (*hPrevModule && (*hPrevModule != hModule))
1368 hPrevModule = &(NE_GetPtr( *hPrevModule ))->next;
1370 if (*hPrevModule) *hPrevModule = pModule->next;
1372 /* Free the referenced modules */
1374 pModRef = (HMODULE16*)((char *)pModule + pModule->ne_modtab);
1375 for (i = 0; i < pModule->ne_cmod; i++, pModRef++)
1377 NE_FreeModule( *pModRef, call_wep );
1380 /* Free the module storage */
1382 GlobalFreeAll16( hModule );
1383 return TRUE;
1387 /**********************************************************************
1388 * FreeModule (KERNEL.46)
1390 BOOL16 WINAPI FreeModule16( HMODULE16 hModule )
1392 return NE_FreeModule( hModule, TRUE );
1396 /***********************************************************************
1397 * FreeLibrary (KERNEL.96)
1398 * FreeLibrary16 (KERNEL32.36)
1400 void WINAPI FreeLibrary16( HINSTANCE16 handle )
1402 TRACE("%04x\n", handle );
1403 FreeModule16( handle );
1407 /***********************************************************************
1408 * GetModuleHandle16 (KERNEL32.@)
1410 HMODULE16 WINAPI GetModuleHandle16( LPCSTR name )
1412 HMODULE16 hModule;
1413 LPSTR s;
1414 BYTE len, *name_table;
1415 char tmpstr[MAX_PATH];
1416 NE_MODULE *pModule;
1418 TRACE("(%s)\n", name);
1420 if (!HIWORD(name)) return GetExePtr(LOWORD(name));
1422 len = strlen(name);
1423 if (!len) return 0;
1425 lstrcpynA(tmpstr, name, sizeof(tmpstr));
1427 /* If 'name' matches exactly the module name of a module:
1428 * Return its handle.
1430 for (hModule = hFirstModule; hModule ; hModule = pModule->next)
1432 pModule = NE_GetPtr( hModule );
1433 if (!pModule) break;
1434 if (pModule->ne_flags & NE_FFLAGS_WIN32) continue;
1436 name_table = (BYTE *)pModule + pModule->ne_restab;
1437 if ((*name_table == len) && !strncmp(name, (char*) name_table+1, len))
1438 return hModule;
1441 /* If uppercased 'name' matches exactly the module name of a module:
1442 * Return its handle
1444 for (s = tmpstr; *s; s++) *s = RtlUpperChar(*s);
1446 for (hModule = hFirstModule; hModule ; hModule = pModule->next)
1448 pModule = NE_GetPtr( hModule );
1449 if (!pModule) break;
1450 if (pModule->ne_flags & NE_FFLAGS_WIN32) continue;
1452 name_table = (BYTE *)pModule + pModule->ne_restab;
1453 /* FIXME: the strncasecmp is WRONG. It should not be case insensitive,
1454 * but case sensitive! (Unfortunately Winword 6 and subdlls have
1455 * lowercased module names, but try to load uppercase DLLs, so this
1456 * 'i' compare is just a quickfix until the loader handles that
1457 * correctly. -MM 990705
1459 if ((*name_table == len) && !NE_strncasecmp(tmpstr, (const char*)name_table+1, len))
1460 return hModule;
1463 /* If the base filename of 'name' matches the base filename of the module
1464 * filename of some module (case-insensitive compare):
1465 * Return its handle.
1468 /* basename: search backwards in passed name to \ / or : */
1469 s = tmpstr + strlen(tmpstr);
1470 while (s > tmpstr)
1472 if (s[-1]=='/' || s[-1]=='\\' || s[-1]==':')
1473 break;
1474 s--;
1477 /* search this in loaded filename list */
1478 for (hModule = hFirstModule; hModule ; hModule = pModule->next)
1480 char *loadedfn;
1481 OFSTRUCT *ofs;
1483 pModule = NE_GetPtr( hModule );
1484 if (!pModule) break;
1485 if (!pModule->fileinfo) continue;
1486 if (pModule->ne_flags & NE_FFLAGS_WIN32) continue;
1488 ofs = (OFSTRUCT*)((BYTE *)pModule + pModule->fileinfo);
1489 loadedfn = ((char*)ofs->szPathName) + strlen(ofs->szPathName);
1490 /* basename: search backwards in pathname to \ / or : */
1491 while (loadedfn > (char*)ofs->szPathName)
1493 if (loadedfn[-1]=='/' || loadedfn[-1]=='\\' || loadedfn[-1]==':')
1494 break;
1495 loadedfn--;
1497 /* case insensitive compare ... */
1498 if (!NE_strcasecmp(loadedfn, s))
1499 return hModule;
1501 return 0;
1505 /**********************************************************************
1506 * GetModuleName (KERNEL.27)
1508 BOOL16 WINAPI GetModuleName16( HINSTANCE16 hinst, LPSTR buf, INT16 count )
1510 NE_MODULE *pModule;
1511 BYTE *p;
1513 if (!(pModule = NE_GetPtr( hinst ))) return FALSE;
1514 p = (BYTE *)pModule + pModule->ne_restab;
1515 if (count > *p) count = *p + 1;
1516 if (count > 0)
1518 memcpy( buf, p + 1, count - 1 );
1519 buf[count-1] = '\0';
1521 return TRUE;
1525 /**********************************************************************
1526 * GetModuleFileName (KERNEL.49)
1528 * See also: GetModuleFileNameA
1530 * This function returns short paths when the modules version field is < 4.0).
1532 * Even if invoked by second instance of a program,
1533 * it still returns path of first one.
1535 INT16 WINAPI GetModuleFileName16( HINSTANCE16 hModule, LPSTR lpFileName,
1536 INT16 nSize )
1538 NE_MODULE *pModule;
1540 /* Win95 does not query hModule if set to 0 !
1541 * Is this wrong or maybe Win3.1 only ? */
1542 if (!hModule) hModule = GetCurrentTask();
1544 if (!(pModule = NE_GetPtr( hModule ))) return 0;
1545 lstrcpynA( lpFileName, NE_MODULE_NAME(pModule), nSize );
1546 if (pModule->ne_expver < 0x400)
1547 GetShortPathNameA(NE_MODULE_NAME(pModule), lpFileName, nSize);
1548 TRACE("%04x -> '%s'\n", hModule, lpFileName );
1549 return strlen(lpFileName);
1553 /**********************************************************************
1554 * GetModuleUsage (KERNEL.48)
1556 INT16 WINAPI GetModuleUsage16( HINSTANCE16 hModule )
1558 NE_MODULE *pModule = NE_GetPtr( hModule );
1559 return pModule ? pModule->count : 0;
1563 /**********************************************************************
1564 * GetExpWinVer (KERNEL.167)
1566 WORD WINAPI GetExpWinVer16( HMODULE16 hModule )
1568 NE_MODULE *pModule = NE_GetPtr( hModule );
1569 if ( !pModule ) return 0;
1570 return pModule->ne_expver;
1574 /***********************************************************************
1575 * WinExec (KERNEL.166)
1577 HINSTANCE16 WINAPI WinExec16( LPCSTR lpCmdLine, UINT16 nCmdShow )
1579 LPCSTR p, args = NULL;
1580 LPCSTR name_beg, name_end;
1581 LPSTR name, cmdline;
1582 int arglen;
1583 HINSTANCE16 ret;
1584 char buffer[MAX_PATH];
1585 LOADPARAMS16 params;
1586 WORD showCmd[2];
1588 if (*lpCmdLine == '"') /* has to be only one and only at beginning ! */
1590 name_beg = lpCmdLine+1;
1591 p = strchr ( lpCmdLine+1, '"' );
1592 if (p)
1594 name_end = p;
1595 args = strchr ( p, ' ' );
1597 else /* yes, even valid with trailing '"' missing */
1598 name_end = lpCmdLine+strlen(lpCmdLine);
1600 else
1602 name_beg = lpCmdLine;
1603 args = strchr( lpCmdLine, ' ' );
1604 name_end = args ? args : lpCmdLine+strlen(lpCmdLine);
1607 if ((name_beg == lpCmdLine) && (!args))
1608 { /* just use the original cmdline string as file name */
1609 name = (LPSTR)lpCmdLine;
1611 else
1613 if (!(name = HeapAlloc( GetProcessHeap(), 0, name_end - name_beg + 1 )))
1614 return ERROR_NOT_ENOUGH_MEMORY;
1615 memcpy( name, name_beg, name_end - name_beg );
1616 name[name_end - name_beg] = '\0';
1619 if (args)
1621 args++;
1622 arglen = strlen(args);
1623 cmdline = HeapAlloc( GetProcessHeap(), 0, 2 + arglen );
1624 cmdline[0] = (BYTE)arglen;
1625 strcpy( cmdline + 1, args );
1627 else
1629 cmdline = HeapAlloc( GetProcessHeap(), 0, 2 );
1630 cmdline[0] = cmdline[1] = 0;
1633 TRACE("name: '%s', cmdline: '%.*s'\n", name, cmdline[0], &cmdline[1]);
1635 showCmd[0] = 2;
1636 showCmd[1] = nCmdShow;
1638 params.hEnvironment = 0;
1639 params.cmdLine = MapLS( cmdline );
1640 params.showCmd = MapLS( showCmd );
1641 params.reserved = 0;
1643 if (SearchPathA( NULL, name, ".exe", sizeof(buffer), buffer, NULL ))
1645 ret = LoadModule16( buffer, &params );
1647 else if (!contains_path( name )) /* try 16-bit builtin */
1649 lstrcpynA( buffer, name, sizeof(buffer) );
1650 if (strlen( buffer ) < sizeof(buffer) - 4 && !strchr( buffer, '.' )) strcat( buffer, ".exe" );
1651 ret = LoadModule16( buffer, &params );
1652 if (ret == ERROR_FILE_NOT_FOUND) ret = 21; /* it might be a 32-bit builtin too */
1654 else ret = ERROR_FILE_NOT_FOUND;
1656 UnMapLS( params.cmdLine );
1657 UnMapLS( params.showCmd );
1659 HeapFree( GetProcessHeap(), 0, cmdline );
1660 if (name != lpCmdLine) HeapFree( GetProcessHeap(), 0, name );
1662 if (ret == 21 || ret == ERROR_BAD_FORMAT) /* 32-bit module or unknown executable*/
1664 LOADPARAMS16 params;
1665 WORD showCmd[2];
1666 showCmd[0] = 2;
1667 showCmd[1] = nCmdShow;
1669 arglen = strlen( lpCmdLine );
1670 cmdline = HeapAlloc( GetProcessHeap(), 0, arglen + 1 );
1671 cmdline[0] = (BYTE)arglen;
1672 memcpy( cmdline + 1, lpCmdLine, arglen );
1674 params.hEnvironment = 0;
1675 params.cmdLine = MapLS( cmdline );
1676 params.showCmd = MapLS( showCmd );
1677 params.reserved = 0;
1679 ret = LoadModule16( "winoldap.mod", &params );
1680 UnMapLS( params.cmdLine );
1681 UnMapLS( params.showCmd );
1683 return ret;
1686 /***********************************************************************
1687 * GetProcAddress (KERNEL.50)
1689 FARPROC16 WINAPI GetProcAddress16( HMODULE16 hModule, LPCSTR name )
1691 WORD ordinal;
1692 FARPROC16 ret;
1694 if (!hModule) hModule = GetCurrentTask();
1695 hModule = GetExePtr( hModule );
1697 if (HIWORD(name) != 0)
1699 ordinal = NE_GetOrdinal( hModule, name );
1700 TRACE("%04x '%s'\n", hModule, name );
1702 else
1704 ordinal = LOWORD(name);
1705 TRACE("%04x %04x\n", hModule, ordinal );
1707 if (!ordinal) return NULL;
1709 ret = NE_GetEntryPoint( hModule, ordinal );
1711 TRACE("returning %p\n", ret );
1712 return ret;
1716 /***************************************************************************
1717 * HasGPHandler (KERNEL.338)
1719 SEGPTR WINAPI HasGPHandler16( SEGPTR address )
1721 HMODULE16 hModule;
1722 int gpOrdinal;
1723 SEGPTR gpPtr;
1724 GPHANDLERDEF *gpHandler;
1726 if ( (hModule = FarGetOwner16( SELECTOROF(address) )) != 0
1727 && (gpOrdinal = NE_GetOrdinal( hModule, "__GP" )) != 0
1728 && (gpPtr = (SEGPTR)NE_GetEntryPointEx( hModule, gpOrdinal, FALSE )) != 0
1729 && !IsBadReadPtr16( gpPtr, sizeof(GPHANDLERDEF) )
1730 && (gpHandler = MapSL( gpPtr )) != NULL )
1732 while (gpHandler->selector)
1734 if ( SELECTOROF(address) == gpHandler->selector
1735 && OFFSETOF(address) >= gpHandler->rangeStart
1736 && OFFSETOF(address) < gpHandler->rangeEnd )
1737 return MAKESEGPTR( gpHandler->selector, gpHandler->handler );
1738 gpHandler++;
1742 return 0;
1746 /**********************************************************************
1747 * GetModuleHandle (KERNEL.47)
1749 * Find a module from a module name.
1751 * NOTE: The current implementation works the same way the Windows 95 one
1752 * does. Do not try to 'fix' it, fix the callers.
1753 * + It does not do ANY extension handling (except that strange .EXE bit)!
1754 * + It does not care about paths, just about basenames. (same as Windows)
1756 * RETURNS
1757 * LOWORD:
1758 * the win16 module handle if found
1759 * 0 if not
1760 * HIWORD (undocumented, see "Undocumented Windows", chapter 5):
1761 * Always hFirstModule
1763 DWORD WINAPI WIN16_GetModuleHandle( SEGPTR name )
1765 if (HIWORD(name) == 0)
1766 return MAKELONG(GetExePtr( (HINSTANCE16)name), hFirstModule );
1767 return MAKELONG(GetModuleHandle16( MapSL(name)), hFirstModule );
1770 /**********************************************************************
1771 * NE_GetModuleByFilename
1773 static HMODULE16 NE_GetModuleByFilename( LPCSTR name )
1775 HMODULE16 hModule;
1776 LPSTR s, p;
1777 BYTE len, *name_table;
1778 char tmpstr[MAX_PATH];
1779 NE_MODULE *pModule;
1781 lstrcpynA(tmpstr, name, sizeof(tmpstr));
1783 /* If the base filename of 'name' matches the base filename of the module
1784 * filename of some module (case-insensitive compare):
1785 * Return its handle.
1788 /* basename: search backwards in passed name to \ / or : */
1789 s = tmpstr + strlen(tmpstr);
1790 while (s > tmpstr)
1792 if (s[-1]=='/' || s[-1]=='\\' || s[-1]==':')
1793 break;
1794 s--;
1797 /* search this in loaded filename list */
1798 for (hModule = hFirstModule; hModule ; hModule = pModule->next)
1800 char *loadedfn;
1801 OFSTRUCT *ofs;
1803 pModule = NE_GetPtr( hModule );
1804 if (!pModule) break;
1805 if (!pModule->fileinfo) continue;
1806 if (pModule->ne_flags & NE_FFLAGS_WIN32) continue;
1808 ofs = (OFSTRUCT*)((BYTE *)pModule + pModule->fileinfo);
1809 loadedfn = ((char*)ofs->szPathName) + strlen(ofs->szPathName);
1810 /* basename: search backwards in pathname to \ / or : */
1811 while (loadedfn > (char*)ofs->szPathName)
1813 if (loadedfn[-1]=='/' || loadedfn[-1]=='\\' || loadedfn[-1]==':')
1814 break;
1815 loadedfn--;
1817 /* case insensitive compare ... */
1818 if (!NE_strcasecmp(loadedfn, s))
1819 return hModule;
1821 /* If basename (without ext) matches the module name of a module:
1822 * Return its handle.
1825 if ( (p = strrchr( s, '.' )) != NULL ) *p = '\0';
1826 len = strlen(s);
1828 for (hModule = hFirstModule; hModule ; hModule = pModule->next)
1830 pModule = NE_GetPtr( hModule );
1831 if (!pModule) break;
1832 if (pModule->ne_flags & NE_FFLAGS_WIN32) continue;
1834 name_table = (BYTE *)pModule + pModule->ne_restab;
1835 if ((*name_table == len) && !NE_strncasecmp(s, (const char*)name_table+1, len))
1836 return hModule;
1839 return 0;
1842 /***********************************************************************
1843 * GetProcAddress16 (KERNEL32.37)
1844 * Get procaddress in 16bit module from win32... (kernel32 undoc. ordinal func)
1846 FARPROC16 WINAPI WIN32_GetProcAddress16( HMODULE hModule, LPCSTR name )
1848 if (!hModule) return 0;
1849 if (HIWORD(hModule))
1851 WARN("hModule is Win32 handle (%p)\n", hModule );
1852 return 0;
1854 return GetProcAddress16( LOWORD(hModule), name );
1857 /***************************************************************************
1858 * IsRomModule (KERNEL.323)
1860 BOOL16 WINAPI IsRomModule16( HMODULE16 unused )
1862 return FALSE;
1865 /***************************************************************************
1866 * IsRomFile (KERNEL.326)
1868 BOOL16 WINAPI IsRomFile16( HFILE16 unused )
1870 return FALSE;
1873 /***********************************************************************
1874 * create_dummy_module
1876 * Create a dummy NE module for Win32 or Winelib.
1878 static HMODULE16 create_dummy_module( HMODULE module32 )
1880 HMODULE16 hModule;
1881 NE_MODULE *pModule;
1882 SEGTABLEENTRY *pSegment;
1883 char *pStr;
1884 unsigned int len;
1885 const char *basename, *s;
1886 OFSTRUCT *ofs;
1887 int of_size, size;
1888 char filename[MAX_PATH];
1889 IMAGE_NT_HEADERS *nt = RtlImageNtHeader( module32 );
1891 if (!nt) return ERROR_BAD_FORMAT;
1893 /* Extract base filename */
1894 len = GetModuleFileNameA( module32, filename, sizeof(filename) );
1895 if (!len || len >= sizeof(filename)) return ERROR_BAD_FORMAT;
1896 basename = strrchr(filename, '\\');
1897 if (!basename) basename = filename;
1898 else basename++;
1899 len = strlen(basename);
1900 if ((s = strchr(basename, '.'))) len = s - basename;
1902 /* Allocate module */
1903 of_size = sizeof(OFSTRUCT) - sizeof(ofs->szPathName)
1904 + strlen(filename) + 1;
1905 size = sizeof(NE_MODULE) +
1906 /* loaded file info */
1907 ((of_size + 3) & ~3) +
1908 /* segment table: DS,CS */
1909 2 * sizeof(SEGTABLEENTRY) +
1910 /* name table */
1911 len + 2 +
1912 /* several empty tables */
1915 hModule = GlobalAlloc16( GMEM_MOVEABLE | GMEM_ZEROINIT, size );
1916 if (!hModule) return ERROR_BAD_FORMAT;
1918 FarSetOwner16( hModule, hModule );
1919 pModule = GlobalLock16( hModule );
1921 /* Set all used entries */
1922 pModule->ne_magic = IMAGE_OS2_SIGNATURE;
1923 pModule->count = 1;
1924 pModule->next = 0;
1925 pModule->ne_flags = NE_FFLAGS_WIN32;
1926 pModule->ne_autodata = 0;
1927 pModule->ne_sssp = MAKESEGPTR( 0, 1 );
1928 pModule->ne_csip = MAKESEGPTR( 0, 2 );
1929 pModule->ne_heap = 0;
1930 pModule->ne_stack = 0;
1931 pModule->ne_cseg = 2;
1932 pModule->ne_cmod = 0;
1933 pModule->ne_cbnrestab = 0;
1934 pModule->fileinfo = sizeof(NE_MODULE);
1935 pModule->ne_exetyp = NE_OSFLAGS_WINDOWS;
1936 pModule->self = hModule;
1937 pModule->module32 = module32;
1939 /* Set version and flags */
1940 pModule->ne_expver = ((nt->OptionalHeader.MajorSubsystemVersion & 0xff) << 8 ) |
1941 (nt->OptionalHeader.MinorSubsystemVersion & 0xff);
1942 if (nt->FileHeader.Characteristics & IMAGE_FILE_DLL)
1943 pModule->ne_flags |= NE_FFLAGS_LIBMODULE | NE_FFLAGS_SINGLEDATA;
1945 /* Set loaded file information */
1946 ofs = (OFSTRUCT *)(pModule + 1);
1947 memset( ofs, 0, of_size );
1948 ofs->cBytes = of_size < 256 ? of_size : 255; /* FIXME */
1949 strcpy( ofs->szPathName, filename );
1951 pSegment = (SEGTABLEENTRY*)((char*)(pModule + 1) + ((of_size + 3) & ~3));
1952 pModule->ne_segtab = (char *)pSegment - (char *)pModule;
1953 /* Data segment */
1954 pSegment->size = 0;
1955 pSegment->flags = NE_SEGFLAGS_DATA;
1956 pSegment->minsize = 0x1000;
1957 pSegment++;
1958 /* Code segment */
1959 pSegment->flags = 0;
1960 pSegment++;
1962 /* Module name */
1963 pStr = (char *)pSegment;
1964 pModule->ne_restab = pStr - (char *)pModule;
1965 assert(len<256);
1966 *pStr = len;
1967 lstrcpynA( pStr+1, basename, len+1 );
1968 pStr += len+2;
1970 /* All tables zero terminated */
1971 pModule->ne_rsrctab = pModule->ne_imptab = pModule->ne_enttab = pStr - (char *)pModule;
1973 NE_RegisterModule( pModule );
1974 pModule->owner32 = LoadLibraryA( filename ); /* increment the ref count of the 32-bit module */
1975 return hModule;
1978 /***********************************************************************
1979 * PrivateLoadLibrary (KERNEL32.@)
1981 * FIXME: rough guesswork, don't know what "Private" means
1983 HINSTANCE16 WINAPI PrivateLoadLibrary(LPCSTR libname)
1985 return LoadLibrary16(libname);
1988 /***********************************************************************
1989 * PrivateFreeLibrary (KERNEL32.@)
1991 * FIXME: rough guesswork, don't know what "Private" means
1993 void WINAPI PrivateFreeLibrary(HINSTANCE16 handle)
1995 FreeLibrary16(handle);
1998 /***********************************************************************
1999 * LoadLibrary32 (KERNEL.452)
2000 * LoadSystemLibrary32 (KERNEL.482)
2002 HMODULE WINAPI LoadLibrary32_16( LPCSTR libname )
2004 HMODULE hModule;
2005 DWORD count;
2007 ReleaseThunkLock( &count );
2008 hModule = LoadLibraryA( libname );
2009 RestoreThunkLock( count );
2010 return hModule;
2013 /***************************************************************************
2014 * MapHModuleLS (KERNEL32.@)
2016 HMODULE16 WINAPI MapHModuleLS(HMODULE hmod)
2018 HMODULE16 ret;
2019 NE_MODULE *pModule;
2021 if (!hmod)
2022 return TASK_GetCurrent()->hInstance;
2023 if (!HIWORD(hmod))
2024 return LOWORD(hmod); /* we already have a 16 bit module handle */
2025 pModule = GlobalLock16(hFirstModule);
2026 while (pModule) {
2027 if (pModule->module32 == hmod)
2028 return pModule->self;
2029 pModule = GlobalLock16(pModule->next);
2031 if ((ret = create_dummy_module( hmod )) < 32)
2033 SetLastError(ret);
2034 ret = 0;
2036 return ret;
2039 /***************************************************************************
2040 * MapHModuleSL (KERNEL32.@)
2042 HMODULE WINAPI MapHModuleSL(HMODULE16 hmod)
2044 NE_MODULE *pModule;
2046 if (!hmod) {
2047 TDB *pTask = TASK_GetCurrent();
2048 hmod = pTask->hModule;
2050 pModule = GlobalLock16(hmod);
2051 if ((pModule->ne_magic != IMAGE_OS2_SIGNATURE) || !(pModule->ne_flags & NE_FFLAGS_WIN32))
2052 return 0;
2053 return pModule->module32;
2056 /***************************************************************************
2057 * MapHInstLS (KERNEL.472)
2059 void WINAPI MapHInstLS16( CONTEXT *context )
2061 context->Eax = MapHModuleLS( (HMODULE)context->Eax );
2064 /***************************************************************************
2065 * MapHInstSL (KERNEL.473)
2067 void WINAPI MapHInstSL16( CONTEXT *context )
2069 context->Eax = (DWORD)MapHModuleSL( context->Eax );
2072 /***************************************************************************
2073 * MapHInstLS (KERNEL32.@)
2075 __ASM_STDCALL_FUNC( MapHInstLS, 0,
2076 "pushl %eax\n\t"
2077 "call " __ASM_NAME("MapHModuleLS") __ASM_STDCALL(4) "\n\t"
2078 "ret" )
2080 /***************************************************************************
2081 * MapHInstSL (KERNEL32.@)
2083 __ASM_STDCALL_FUNC( MapHInstSL, 0,
2084 "pushl %eax\n\t"
2085 "call " __ASM_NAME("MapHModuleSL") __ASM_STDCALL(4) "\n\t"
2086 "ret" )
2088 /***************************************************************************
2089 * MapHInstLS_PN (KERNEL32.@)
2091 __ASM_STDCALL_FUNC( MapHInstLS_PN, 0,
2092 "testl %eax,%eax\n\t"
2093 "jz 1f\n\t"
2094 "pushl %eax\n\t"
2095 "call " __ASM_NAME("MapHModuleLS") __ASM_STDCALL(4) "\n"
2096 "1:\tret" )
2098 /***************************************************************************
2099 * MapHInstSL_PN (KERNEL32.@)
2101 __ASM_STDCALL_FUNC( MapHInstSL_PN, 0,
2102 "andl $0xffff,%eax\n\t"
2103 "jz 1f\n\t"
2104 "pushl %eax\n\t"
2105 "call " __ASM_NAME("MapHModuleSL") __ASM_STDCALL(4) "\n"
2106 "1:\tret" )