winealsa.drv: Inject handle_underrun=1 setting for pulse-backed devices.
[wine] / dlls / kernel32 / module.c
1 /*
2  * Modules
3  *
4  * Copyright 1995 Alexandre Julliard
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22 #include "wine/port.h"
23
24 #include <fcntl.h>
25 #include <stdarg.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <sys/types.h>
30 #ifdef HAVE_UNISTD_H
31 # include <unistd.h>
32 #endif
33 #include "ntstatus.h"
34 #define WIN32_NO_STATUS
35 #include "winerror.h"
36 #include "windef.h"
37 #include "winbase.h"
38 #include "winternl.h"
39 #include "kernel_private.h"
40 #include "psapi.h"
41
42 #include "wine/exception.h"
43 #include "wine/debug.h"
44 #include "wine/unicode.h"
45
46 WINE_DEFAULT_DEBUG_CHANNEL(module);
47
48 #define NE_FFLAGS_LIBMODULE 0x8000
49
50 static WCHAR *dll_directory;  /* extra path for SetDllDirectoryW */
51
52 static CRITICAL_SECTION dlldir_section;
53 static CRITICAL_SECTION_DEBUG critsect_debug =
54 {
55     0, 0, &dlldir_section,
56     { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
57       0, 0, { (DWORD_PTR)(__FILE__ ": dlldir_section") }
58 };
59 static CRITICAL_SECTION dlldir_section = { &critsect_debug, -1, 0, 0, 0, 0 };
60
61
62 /****************************************************************************
63  *              GetDllDirectoryA   (KERNEL32.@)
64  */
65 DWORD WINAPI GetDllDirectoryA( DWORD buf_len, LPSTR buffer )
66 {
67     DWORD len;
68
69     RtlEnterCriticalSection( &dlldir_section );
70     len = dll_directory ? FILE_name_WtoA( dll_directory, strlenW(dll_directory), NULL, 0 ) : 0;
71     if (buffer && buf_len > len)
72     {
73         if (dll_directory) FILE_name_WtoA( dll_directory, -1, buffer, buf_len );
74         else *buffer = 0;
75     }
76     else
77     {
78         len++;  /* for terminating null */
79         if (buffer) *buffer = 0;
80     }
81     RtlLeaveCriticalSection( &dlldir_section );
82     return len;
83 }
84
85
86 /****************************************************************************
87  *              GetDllDirectoryW   (KERNEL32.@)
88  */
89 DWORD WINAPI GetDllDirectoryW( DWORD buf_len, LPWSTR buffer )
90 {
91     DWORD len;
92
93     RtlEnterCriticalSection( &dlldir_section );
94     len = dll_directory ? strlenW( dll_directory ) : 0;
95     if (buffer && buf_len > len)
96     {
97         if (dll_directory) memcpy( buffer, dll_directory, (len + 1) * sizeof(WCHAR) );
98         else *buffer = 0;
99     }
100     else
101     {
102         len++;  /* for terminating null */
103         if (buffer) *buffer = 0;
104     }
105     RtlLeaveCriticalSection( &dlldir_section );
106     return len;
107 }
108
109
110 /****************************************************************************
111  *              SetDllDirectoryA   (KERNEL32.@)
112  */
113 BOOL WINAPI SetDllDirectoryA( LPCSTR dir )
114 {
115     WCHAR *dirW;
116     BOOL ret;
117
118     if (!(dirW = FILE_name_AtoW( dir, TRUE ))) return FALSE;
119     ret = SetDllDirectoryW( dirW );
120     HeapFree( GetProcessHeap(), 0, dirW );
121     return ret;
122 }
123
124
125 /****************************************************************************
126  *              SetDllDirectoryW   (KERNEL32.@)
127  */
128 BOOL WINAPI SetDllDirectoryW( LPCWSTR dir )
129 {
130     WCHAR *newdir = NULL;
131
132     if (dir)
133     {
134         DWORD len = (strlenW(dir) + 1) * sizeof(WCHAR);
135         if (!(newdir = HeapAlloc( GetProcessHeap(), 0, len )))
136         {
137             SetLastError( ERROR_NOT_ENOUGH_MEMORY );
138             return FALSE;
139         }
140         memcpy( newdir, dir, len );
141     }
142
143     RtlEnterCriticalSection( &dlldir_section );
144     HeapFree( GetProcessHeap(), 0, dll_directory );
145     dll_directory = newdir;
146     RtlLeaveCriticalSection( &dlldir_section );
147     return TRUE;
148 }
149
150
151 /****************************************************************************
152  *              DisableThreadLibraryCalls (KERNEL32.@)
153  *
154  * Inform the module loader that thread notifications are not required for a dll.
155  *
156  * PARAMS
157  *  hModule [I] Module handle to skip calls for
158  *
159  * RETURNS
160  *  Success: TRUE. Thread attach and detach notifications will not be sent
161  *           to hModule.
162  *  Failure: FALSE. Use GetLastError() to determine the cause.
163  *
164  * NOTES
165  *  This is typically called from the dll entry point of a dll during process
166  *  attachment, for dlls that do not need to process thread notifications.
167  */
168 BOOL WINAPI DisableThreadLibraryCalls( HMODULE hModule )
169 {
170     NTSTATUS    nts = LdrDisableThreadCalloutsForDll( hModule );
171     if (nts == STATUS_SUCCESS) return TRUE;
172
173     SetLastError( RtlNtStatusToDosError( nts ) );
174     return FALSE;
175 }
176
177
178 /* Check whether a file is an OS/2 or a very old Windows executable
179  * by testing on import of KERNEL.
180  *
181  * FIXME: is reading the module imports the only way of discerning
182  *        old Windows binaries from OS/2 ones ? At least it seems so...
183  */
184 static DWORD MODULE_Decide_OS2_OldWin(HANDLE hfile, const IMAGE_DOS_HEADER *mz, const IMAGE_OS2_HEADER *ne)
185 {
186     DWORD currpos = SetFilePointer( hfile, 0, NULL, SEEK_CUR);
187     DWORD ret = BINARY_OS216;
188     LPWORD modtab = NULL;
189     LPSTR nametab = NULL;
190     DWORD len;
191     int i;
192
193     /* read modref table */
194     if ( (SetFilePointer( hfile, mz->e_lfanew + ne->ne_modtab, NULL, SEEK_SET ) == -1)
195       || (!(modtab = HeapAlloc( GetProcessHeap(), 0, ne->ne_cmod*sizeof(WORD))))
196       || (!(ReadFile(hfile, modtab, ne->ne_cmod*sizeof(WORD), &len, NULL)))
197       || (len != ne->ne_cmod*sizeof(WORD)) )
198         goto broken;
199
200     /* read imported names table */
201     if ( (SetFilePointer( hfile, mz->e_lfanew + ne->ne_imptab, NULL, SEEK_SET ) == -1)
202       || (!(nametab = HeapAlloc( GetProcessHeap(), 0, ne->ne_enttab - ne->ne_imptab)))
203       || (!(ReadFile(hfile, nametab, ne->ne_enttab - ne->ne_imptab, &len, NULL)))
204       || (len != ne->ne_enttab - ne->ne_imptab) )
205         goto broken;
206
207     for (i=0; i < ne->ne_cmod; i++)
208     {
209         LPSTR module = &nametab[modtab[i]];
210         TRACE("modref: %.*s\n", module[0], &module[1]);
211         if (!(strncmp(&module[1], "KERNEL", module[0])))
212         { /* very old Windows file */
213             MESSAGE("This seems to be a very old (pre-3.0) Windows executable. Expect crashes, especially if this is a real-mode binary !\n");
214             ret = BINARY_WIN16;
215             goto good;
216         }
217     }
218
219 broken:
220     ERR("Hmm, an error occurred. Is this binary file broken?\n");
221
222 good:
223     HeapFree( GetProcessHeap(), 0, modtab);
224     HeapFree( GetProcessHeap(), 0, nametab);
225     SetFilePointer( hfile, currpos, NULL, SEEK_SET); /* restore filepos */
226     return ret;
227 }
228
229 /***********************************************************************
230  *           MODULE_GetBinaryType
231  */
232 void MODULE_get_binary_info( HANDLE hfile, struct binary_info *info )
233 {
234     union
235     {
236         struct
237         {
238             unsigned char magic[4];
239             unsigned char class;
240             unsigned char data;
241             unsigned char version;
242             unsigned char ignored[9];
243             unsigned short type;
244             unsigned short machine;
245         } elf;
246         struct
247         {
248             unsigned int magic;
249             unsigned int cputype;
250             unsigned int cpusubtype;
251             unsigned int filetype;
252         } macho;
253         IMAGE_DOS_HEADER mz;
254     } header;
255
256     DWORD len;
257
258     memset( info, 0, sizeof(*info) );
259
260     /* Seek to the start of the file and read the header information. */
261     if (SetFilePointer( hfile, 0, NULL, SEEK_SET ) == -1) return;
262     if (!ReadFile( hfile, &header, sizeof(header), &len, NULL ) || len != sizeof(header)) return;
263
264     if (!memcmp( header.elf.magic, "\177ELF", 4 ))
265     {
266         if (header.elf.class == 2) info->flags |= BINARY_FLAG_64BIT;
267         /* FIXME: we don't bother to check byte order, architecture, etc. */
268         switch(header.elf.type)
269         {
270         case 2: info->type = BINARY_UNIX_EXE; break;
271         case 3: info->type = BINARY_UNIX_LIB; break;
272         }
273     }
274     /* Mach-o File with Endian set to Big Endian or Little Endian */
275     else if (header.macho.magic == 0xfeedface || header.macho.magic == 0xcefaedfe)
276     {
277         if ((header.macho.cputype >> 24) == 1) info->flags |= BINARY_FLAG_64BIT;
278         switch(header.macho.filetype)
279         {
280         case 2: info->type = BINARY_UNIX_EXE; break;
281         case 8: info->type = BINARY_UNIX_LIB; break;
282         }
283     }
284     /* Not ELF, try DOS */
285     else if (header.mz.e_magic == IMAGE_DOS_SIGNATURE)
286     {
287         union
288         {
289             IMAGE_OS2_HEADER os2;
290             IMAGE_NT_HEADERS32 nt;
291         } ext_header;
292
293         /* We do have a DOS image so we will now try to seek into
294          * the file by the amount indicated by the field
295          * "Offset to extended header" and read in the
296          * "magic" field information at that location.
297          * This will tell us if there is more header information
298          * to read or not.
299          */
300         info->type = BINARY_DOS;
301         if (SetFilePointer( hfile, header.mz.e_lfanew, NULL, SEEK_SET ) == -1) return;
302         if (!ReadFile( hfile, &ext_header, sizeof(ext_header), &len, NULL ) || len < 4) return;
303
304         /* Reading the magic field succeeded so
305          * we will try to determine what type it is.
306          */
307         if (!memcmp( &ext_header.nt.Signature, "PE\0\0", 4 ))
308         {
309             if (len >= sizeof(ext_header.nt.FileHeader))
310             {
311                 info->type = BINARY_PE;
312                 if (ext_header.nt.FileHeader.Characteristics & IMAGE_FILE_DLL)
313                     info->flags |= BINARY_FLAG_DLL;
314                 if (len < sizeof(ext_header.nt))  /* clear remaining part of header if missing */
315                     memset( (char *)&ext_header.nt + len, 0, sizeof(ext_header.nt) - len );
316                 switch (ext_header.nt.OptionalHeader.Magic)
317                 {
318                 case IMAGE_NT_OPTIONAL_HDR32_MAGIC:
319                     info->res_start = (void *)(ULONG_PTR)ext_header.nt.OptionalHeader.ImageBase;
320                     info->res_end = (void *)((ULONG_PTR)ext_header.nt.OptionalHeader.ImageBase +
321                                                      ext_header.nt.OptionalHeader.SizeOfImage);
322                     break;
323                 case IMAGE_NT_OPTIONAL_HDR64_MAGIC:
324                     info->flags |= BINARY_FLAG_64BIT;
325                     break;
326                 }
327             }
328         }
329         else if (!memcmp( &ext_header.os2.ne_magic, "NE", 2 ))
330         {
331             /* This is a Windows executable (NE) header.  This can
332              * mean either a 16-bit OS/2 or a 16-bit Windows or even a
333              * DOS program (running under a DOS extender).  To decide
334              * which, we'll have to read the NE header.
335              */
336             if (len >= sizeof(ext_header.os2))
337             {
338                 if (ext_header.os2.ne_flags & NE_FFLAGS_LIBMODULE) info->flags |= BINARY_FLAG_DLL;
339                 switch ( ext_header.os2.ne_exetyp )
340                 {
341                 case 1:  info->type = BINARY_OS216; break; /* OS/2 */
342                 case 2:  info->type = BINARY_WIN16; break; /* Windows */
343                 case 3:  info->type = BINARY_DOS; break; /* European MS-DOS 4.x */
344                 case 4:  info->type = BINARY_WIN16; break; /* Windows 386; FIXME: is this 32bit??? */
345                 case 5:  info->type = BINARY_DOS; break; /* BOSS, Borland Operating System Services */
346                 /* other types, e.g. 0 is: "unknown" */
347                 default: info->type = MODULE_Decide_OS2_OldWin(hfile, &header.mz, &ext_header.os2); break;
348                 }
349             }
350         }
351     }
352 }
353
354 /***********************************************************************
355  *             GetBinaryTypeW                     [KERNEL32.@]
356  *
357  * Determine whether a file is executable, and if so, what kind.
358  *
359  * PARAMS
360  *  lpApplicationName [I] Path of the file to check
361  *  lpBinaryType      [O] Destination for the binary type
362  *
363  * RETURNS
364  *  TRUE, if the file is an executable, in which case lpBinaryType is set.
365  *  FALSE, if the file is not an executable or if the function fails.
366  *
367  * NOTES
368  *  The type of executable is a property that determines which subsystem an
369  *  executable file runs under. lpBinaryType can be set to one of the following
370  *  values:
371  *   SCS_32BIT_BINARY: A Win32 based application
372  *   SCS_64BIT_BINARY: A Win64 based application
373  *   SCS_DOS_BINARY: An MS-Dos based application
374  *   SCS_WOW_BINARY: A Win16 based application
375  *   SCS_PIF_BINARY: A PIF file that executes an MS-Dos based app
376  *   SCS_POSIX_BINARY: A POSIX based application ( Not implemented )
377  *   SCS_OS216_BINARY: A 16bit OS/2 based application
378  *
379  *  To find the binary type, this function reads in the files header information.
380  *  If extended header information is not present it will assume that the file
381  *  is a DOS executable. If extended header information is present it will
382  *  determine if the file is a 16, 32 or 64 bit Windows executable by checking the
383  *  flags in the header.
384  *
385  *  ".com" and ".pif" files are only recognized by their file name extension,
386  *  as per native Windows.
387  */
388 BOOL WINAPI GetBinaryTypeW( LPCWSTR lpApplicationName, LPDWORD lpBinaryType )
389 {
390     BOOL ret = FALSE;
391     HANDLE hfile;
392     struct binary_info binary_info;
393
394     TRACE("%s\n", debugstr_w(lpApplicationName) );
395
396     /* Sanity check.
397      */
398     if ( lpApplicationName == NULL || lpBinaryType == NULL )
399         return FALSE;
400
401     /* Open the file indicated by lpApplicationName for reading.
402      */
403     hfile = CreateFileW( lpApplicationName, GENERIC_READ, FILE_SHARE_READ,
404                          NULL, OPEN_EXISTING, 0, 0 );
405     if ( hfile == INVALID_HANDLE_VALUE )
406         return FALSE;
407
408     /* Check binary type
409      */
410     MODULE_get_binary_info( hfile, &binary_info );
411     switch (binary_info.type)
412     {
413     case BINARY_UNKNOWN:
414     {
415         static const WCHAR comW[] = { '.','C','O','M',0 };
416         static const WCHAR pifW[] = { '.','P','I','F',0 };
417         const WCHAR *ptr;
418
419         /* try to determine from file name */
420         ptr = strrchrW( lpApplicationName, '.' );
421         if (!ptr) break;
422         if (!strcmpiW( ptr, comW ))
423         {
424             *lpBinaryType = SCS_DOS_BINARY;
425             ret = TRUE;
426         }
427         else if (!strcmpiW( ptr, pifW ))
428         {
429             *lpBinaryType = SCS_PIF_BINARY;
430             ret = TRUE;
431         }
432         break;
433     }
434     case BINARY_PE:
435         *lpBinaryType = (binary_info.flags & BINARY_FLAG_64BIT) ? SCS_64BIT_BINARY : SCS_32BIT_BINARY;
436         ret = TRUE;
437         break;
438     case BINARY_WIN16:
439         *lpBinaryType = SCS_WOW_BINARY;
440         ret = TRUE;
441         break;
442     case BINARY_OS216:
443         *lpBinaryType = SCS_OS216_BINARY;
444         ret = TRUE;
445         break;
446     case BINARY_DOS:
447         *lpBinaryType = SCS_DOS_BINARY;
448         ret = TRUE;
449         break;
450     case BINARY_UNIX_EXE:
451     case BINARY_UNIX_LIB:
452         ret = FALSE;
453         break;
454     }
455
456     CloseHandle( hfile );
457     return ret;
458 }
459
460 /***********************************************************************
461  *             GetBinaryTypeA                     [KERNEL32.@]
462  *             GetBinaryType                      [KERNEL32.@]
463  *
464  * See GetBinaryTypeW.
465  */
466 BOOL WINAPI GetBinaryTypeA( LPCSTR lpApplicationName, LPDWORD lpBinaryType )
467 {
468     ANSI_STRING app_nameA;
469     NTSTATUS status;
470
471     TRACE("%s\n", debugstr_a(lpApplicationName));
472
473     /* Sanity check.
474      */
475     if ( lpApplicationName == NULL || lpBinaryType == NULL )
476         return FALSE;
477
478     RtlInitAnsiString(&app_nameA, lpApplicationName);
479     status = RtlAnsiStringToUnicodeString(&NtCurrentTeb()->StaticUnicodeString,
480                                           &app_nameA, FALSE);
481     if (!status)
482         return GetBinaryTypeW(NtCurrentTeb()->StaticUnicodeString.Buffer, lpBinaryType);
483
484     SetLastError(RtlNtStatusToDosError(status));
485     return FALSE;
486 }
487
488 /***********************************************************************
489  *              GetModuleHandleExA         (KERNEL32.@)
490  */
491 BOOL WINAPI GetModuleHandleExA( DWORD flags, LPCSTR name, HMODULE *module )
492 {
493     WCHAR *nameW;
494
495     if (!name || (flags & GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS))
496         return GetModuleHandleExW( flags, (LPCWSTR)name, module );
497
498     if (!(nameW = FILE_name_AtoW( name, FALSE ))) return FALSE;
499     return GetModuleHandleExW( flags, nameW, module );
500 }
501
502 /***********************************************************************
503  *              GetModuleHandleExW         (KERNEL32.@)
504  */
505 BOOL WINAPI GetModuleHandleExW( DWORD flags, LPCWSTR name, HMODULE *module )
506 {
507     NTSTATUS status = STATUS_SUCCESS;
508     HMODULE ret;
509     ULONG magic;
510
511     /* if we are messing with the refcount, grab the loader lock */
512     if ((flags & GET_MODULE_HANDLE_EX_FLAG_PIN) ||
513         !(flags & GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT))
514         LdrLockLoaderLock( 0, NULL, &magic );
515
516     if (!name)
517     {
518         ret = NtCurrentTeb()->Peb->ImageBaseAddress;
519     }
520     else if (flags & GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS)
521     {
522         void *dummy;
523         if (!(ret = RtlPcToFileHeader( (void *)name, &dummy ))) status = STATUS_DLL_NOT_FOUND;
524     }
525     else
526     {
527         UNICODE_STRING wstr;
528         RtlInitUnicodeString( &wstr, name );
529         status = LdrGetDllHandle( NULL, 0, &wstr, &ret );
530     }
531
532     if (status == STATUS_SUCCESS)
533     {
534         if (flags & GET_MODULE_HANDLE_EX_FLAG_PIN)
535             FIXME( "should pin refcount for %p\n", ret );
536         else if (!(flags & GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT))
537             LdrAddRefDll( 0, ret );
538     }
539     else SetLastError( RtlNtStatusToDosError( status ) );
540
541     if ((flags & GET_MODULE_HANDLE_EX_FLAG_PIN) ||
542         !(flags & GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT))
543         LdrUnlockLoaderLock( 0, magic );
544
545     if (module) *module = ret;
546     return (status == STATUS_SUCCESS);
547 }
548
549 /***********************************************************************
550  *              GetModuleHandleA         (KERNEL32.@)
551  *
552  * Get the handle of a dll loaded into the process address space.
553  *
554  * PARAMS
555  *  module [I] Name of the dll
556  *
557  * RETURNS
558  *  Success: A handle to the loaded dll.
559  *  Failure: A NULL handle. Use GetLastError() to determine the cause.
560  */
561 HMODULE WINAPI GetModuleHandleA(LPCSTR module)
562 {
563     HMODULE ret;
564
565     if (!GetModuleHandleExA( GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, module, &ret )) ret = 0;
566     return ret;
567 }
568
569 /***********************************************************************
570  *              GetModuleHandleW (KERNEL32.@)
571  *
572  * Unicode version of GetModuleHandleA.
573  */
574 HMODULE WINAPI GetModuleHandleW(LPCWSTR module)
575 {
576     HMODULE ret;
577
578     if (!GetModuleHandleExW( GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, module, &ret )) ret = 0;
579     return ret;
580 }
581
582
583 /***********************************************************************
584  *              GetModuleFileNameA      (KERNEL32.@)
585  *
586  * Get the file name of a loaded module from its handle.
587  *
588  * RETURNS
589  *  Success: The length of the file name, excluding the terminating NUL.
590  *  Failure: 0. Use GetLastError() to determine the cause.
591  *
592  * NOTES
593  *  This function always returns the long path of hModule
594  *  The function doesn't write a terminating '\0' if the buffer is too 
595  *  small.
596  */
597 DWORD WINAPI GetModuleFileNameA(
598         HMODULE hModule,        /* [in] Module handle (32 bit) */
599         LPSTR lpFileName,       /* [out] Destination for file name */
600         DWORD size )            /* [in] Size of lpFileName in characters */
601 {
602     LPWSTR filenameW = HeapAlloc( GetProcessHeap(), 0, size * sizeof(WCHAR) );
603     DWORD len;
604
605     if (!filenameW)
606     {
607         SetLastError( ERROR_NOT_ENOUGH_MEMORY );
608         return 0;
609     }
610     if ((len = GetModuleFileNameW( hModule, filenameW, size )))
611     {
612         len = FILE_name_WtoA( filenameW, len, lpFileName, size );
613         if (len < size)
614             lpFileName[len] = '\0';
615         else
616             SetLastError( ERROR_INSUFFICIENT_BUFFER );
617     }
618     HeapFree( GetProcessHeap(), 0, filenameW );
619     return len;
620 }
621
622 /***********************************************************************
623  *              GetModuleFileNameW      (KERNEL32.@)
624  *
625  * Unicode version of GetModuleFileNameA.
626  */
627 DWORD WINAPI GetModuleFileNameW( HMODULE hModule, LPWSTR lpFileName, DWORD size )
628 {
629     ULONG magic, len = 0;
630     LDR_MODULE *pldr;
631     NTSTATUS nts;
632     WIN16_SUBSYSTEM_TIB *win16_tib;
633
634     if (!hModule && ((win16_tib = NtCurrentTeb()->Tib.SubSystemTib)) && win16_tib->exe_name)
635     {
636         len = min(size, win16_tib->exe_name->Length / sizeof(WCHAR));
637         memcpy( lpFileName, win16_tib->exe_name->Buffer, len * sizeof(WCHAR) );
638         if (len < size) lpFileName[len] = '\0';
639         goto done;
640     }
641
642     LdrLockLoaderLock( 0, NULL, &magic );
643
644     if (!hModule) hModule = NtCurrentTeb()->Peb->ImageBaseAddress;
645     nts = LdrFindEntryForAddress( hModule, &pldr );
646     if (nts == STATUS_SUCCESS)
647     {
648         len = min(size, pldr->FullDllName.Length / sizeof(WCHAR));
649         memcpy(lpFileName, pldr->FullDllName.Buffer, len * sizeof(WCHAR));
650         if (len < size)
651             lpFileName[len] = '\0';
652         else
653             SetLastError( ERROR_INSUFFICIENT_BUFFER );
654     }
655     else SetLastError( RtlNtStatusToDosError( nts ) );
656
657     LdrUnlockLoaderLock( 0, magic );
658 done:
659     TRACE( "%s\n", debugstr_wn(lpFileName, len) );
660     return len;
661 }
662
663
664 /***********************************************************************
665  *           get_dll_system_path
666  */
667 static const WCHAR *get_dll_system_path(void)
668 {
669     static WCHAR *cached_path;
670
671     if (!cached_path)
672     {
673         WCHAR *p, *path;
674         int len = 3;
675
676         len += 2 * GetSystemDirectoryW( NULL, 0 );
677         len += GetWindowsDirectoryW( NULL, 0 );
678         p = path = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
679         *p++ = '.';
680         *p++ = ';';
681         GetSystemDirectoryW( p, path + len - p);
682         p += strlenW(p);
683         /* if system directory ends in "32" add 16-bit version too */
684         if (p[-2] == '3' && p[-1] == '2')
685         {
686             *p++ = ';';
687             GetSystemDirectoryW( p, path + len - p);
688             p += strlenW(p) - 2;
689         }
690         *p++ = ';';
691         GetWindowsDirectoryW( p, path + len - p);
692         cached_path = path;
693     }
694     return cached_path;
695 }
696
697 /******************************************************************
698  *              get_module_path_end
699  *
700  * Returns the end of the directory component of the module path.
701  */
702 static inline const WCHAR *get_module_path_end(const WCHAR *module)
703 {
704     const WCHAR *p;
705     const WCHAR *mod_end = module;
706     if (!module) return mod_end;
707
708     if ((p = strrchrW( mod_end, '\\' ))) mod_end = p;
709     if ((p = strrchrW( mod_end, '/' ))) mod_end = p;
710     if (mod_end == module + 2 && module[1] == ':') mod_end++;
711     if (mod_end == module && module[0] && module[1] == ':') mod_end += 2;
712
713     return mod_end;
714 }
715
716 /******************************************************************
717  *              MODULE_get_dll_load_path
718  *
719  * Compute the load path to use for a given dll.
720  * Returned pointer must be freed by caller.
721  */
722 WCHAR *MODULE_get_dll_load_path( LPCWSTR module )
723 {
724     static const WCHAR pathW[] = {'P','A','T','H',0};
725
726     const WCHAR *system_path = get_dll_system_path();
727     const WCHAR *mod_end = NULL;
728     UNICODE_STRING name, value;
729     WCHAR *p, *ret;
730     int len = 0, path_len = 0;
731
732     /* adjust length for module name */
733
734     if (module)
735         mod_end = get_module_path_end( module );
736     /* if module is NULL or doesn't contain a path, fall back to directory
737      * process was loaded from */
738     if (module == mod_end)
739     {
740         module = NtCurrentTeb()->Peb->ProcessParameters->ImagePathName.Buffer;
741         mod_end = get_module_path_end( module );
742     }
743     len += (mod_end - module) + 1;
744
745     len += strlenW( system_path ) + 2;
746
747     /* get the PATH variable */
748
749     RtlInitUnicodeString( &name, pathW );
750     value.Length = 0;
751     value.MaximumLength = 0;
752     value.Buffer = NULL;
753     if (RtlQueryEnvironmentVariable_U( NULL, &name, &value ) == STATUS_BUFFER_TOO_SMALL)
754         path_len = value.Length;
755
756     RtlEnterCriticalSection( &dlldir_section );
757     if (dll_directory) len += strlenW(dll_directory) + 1;
758     if ((p = ret = HeapAlloc( GetProcessHeap(), 0, path_len + len * sizeof(WCHAR) )))
759     {
760         if (module)
761         {
762             memcpy( ret, module, (mod_end - module) * sizeof(WCHAR) );
763             p += (mod_end - module);
764             *p++ = ';';
765         }
766         if (dll_directory)
767         {
768             strcpyW( p, dll_directory );
769             p += strlenW(p);
770             *p++ = ';';
771         }
772     }
773     RtlLeaveCriticalSection( &dlldir_section );
774     if (!ret) return NULL;
775
776     strcpyW( p, system_path );
777     p += strlenW(p);
778     *p++ = ';';
779     value.Buffer = p;
780     value.MaximumLength = path_len;
781
782     while (RtlQueryEnvironmentVariable_U( NULL, &name, &value ) == STATUS_BUFFER_TOO_SMALL)
783     {
784         WCHAR *new_ptr;
785
786         /* grow the buffer and retry */
787         path_len = value.Length;
788         if (!(new_ptr = HeapReAlloc( GetProcessHeap(), 0, ret, path_len + len * sizeof(WCHAR) )))
789         {
790             HeapFree( GetProcessHeap(), 0, ret );
791             return NULL;
792         }
793         value.Buffer = new_ptr + (value.Buffer - ret);
794         value.MaximumLength = path_len;
795         ret = new_ptr;
796     }
797     value.Buffer[value.Length / sizeof(WCHAR)] = 0;
798     return ret;
799 }
800
801
802 /******************************************************************
803  *              load_library_as_datafile
804  */
805 static BOOL load_library_as_datafile( LPCWSTR name, HMODULE* hmod)
806 {
807     static const WCHAR dotDLL[] = {'.','d','l','l',0};
808
809     WCHAR filenameW[MAX_PATH];
810     HANDLE hFile = INVALID_HANDLE_VALUE;
811     HANDLE mapping;
812     HMODULE module;
813
814     *hmod = 0;
815
816     if (SearchPathW( NULL, name, dotDLL, sizeof(filenameW) / sizeof(filenameW[0]),
817                      filenameW, NULL ))
818     {
819         hFile = CreateFileW( filenameW, GENERIC_READ, FILE_SHARE_READ,
820                              NULL, OPEN_EXISTING, 0, 0 );
821     }
822     if (hFile == INVALID_HANDLE_VALUE) return FALSE;
823
824     mapping = CreateFileMappingW( hFile, NULL, PAGE_READONLY, 0, 0, NULL );
825     CloseHandle( hFile );
826     if (!mapping) return FALSE;
827
828     module = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, 0 );
829     CloseHandle( mapping );
830     if (!module) return FALSE;
831
832     /* make sure it's a valid PE file */
833     if (!RtlImageNtHeader(module))
834     {
835         UnmapViewOfFile( module );
836         return FALSE;
837     }
838     *hmod = (HMODULE)((char *)module + 1);  /* set low bit of handle to indicate datafile module */
839     return TRUE;
840 }
841
842
843 /******************************************************************
844  *              load_library
845  *
846  * Helper for LoadLibraryExA/W.
847  */
848 static HMODULE load_library( const UNICODE_STRING *libname, DWORD flags )
849 {
850     NTSTATUS nts;
851     HMODULE hModule;
852     WCHAR *load_path;
853     static const DWORD unsupported_flags = 
854         LOAD_IGNORE_CODE_AUTHZ_LEVEL |
855         LOAD_LIBRARY_AS_IMAGE_RESOURCE |
856         LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE |
857         LOAD_LIBRARY_REQUIRE_SIGNED_TARGET;
858
859     if( flags & unsupported_flags)
860         FIXME("unsupported flag(s) used (flags: 0x%08x)\n", flags);
861
862     load_path = MODULE_get_dll_load_path( flags & LOAD_WITH_ALTERED_SEARCH_PATH ? libname->Buffer : NULL );
863
864     if (flags & LOAD_LIBRARY_AS_DATAFILE)
865     {
866         ULONG magic;
867
868         LdrLockLoaderLock( 0, NULL, &magic );
869         if (!LdrGetDllHandle( load_path, flags, libname, &hModule ))
870         {
871             LdrAddRefDll( 0, hModule );
872             LdrUnlockLoaderLock( 0, magic );
873             goto done;
874         }
875         LdrUnlockLoaderLock( 0, magic );
876
877         /* The method in load_library_as_datafile allows searching for the
878          * 'native' libraries only
879          */
880         if (load_library_as_datafile( libname->Buffer, &hModule )) goto done;
881         flags |= DONT_RESOLVE_DLL_REFERENCES; /* Just in case */
882         /* Fallback to normal behaviour */
883     }
884
885     nts = LdrLoadDll( load_path, flags, libname, &hModule );
886     if (nts != STATUS_SUCCESS)
887     {
888         hModule = 0;
889         SetLastError( RtlNtStatusToDosError( nts ) );
890     }
891 done:
892     HeapFree( GetProcessHeap(), 0, load_path );
893     return hModule;
894 }
895
896
897 /******************************************************************
898  *              LoadLibraryExA          (KERNEL32.@)
899  *
900  * Load a dll file into the process address space.
901  *
902  * PARAMS
903  *  libname [I] Name of the file to load
904  *  hfile   [I] Reserved, must be 0.
905  *  flags   [I] Flags for loading the dll
906  *
907  * RETURNS
908  *  Success: A handle to the loaded dll.
909  *  Failure: A NULL handle. Use GetLastError() to determine the cause.
910  *
911  * NOTES
912  * The HFILE parameter is not used and marked reserved in the SDK. I can
913  * only guess that it should force a file to be mapped, but I rather
914  * ignore the parameter because it would be extremely difficult to
915  * integrate this with different types of module representations.
916  */
917 HMODULE WINAPI DECLSPEC_HOTPATCH LoadLibraryExA(LPCSTR libname, HANDLE hfile, DWORD flags)
918 {
919     WCHAR *libnameW;
920
921     if (!(libnameW = FILE_name_AtoW( libname, FALSE ))) return 0;
922     return LoadLibraryExW( libnameW, hfile, flags );
923 }
924
925 /***********************************************************************
926  *           LoadLibraryExW       (KERNEL32.@)
927  *
928  * Unicode version of LoadLibraryExA.
929  */
930 HMODULE WINAPI DECLSPEC_HOTPATCH LoadLibraryExW(LPCWSTR libnameW, HANDLE hfile, DWORD flags)
931 {
932     UNICODE_STRING      wstr;
933     HMODULE             res;
934
935     if (!libnameW)
936     {
937         SetLastError(ERROR_INVALID_PARAMETER);
938         return 0;
939     }
940     RtlInitUnicodeString( &wstr, libnameW );
941     if (wstr.Buffer[wstr.Length/sizeof(WCHAR) - 1] != ' ')
942         return load_library( &wstr, flags );
943
944     /* Library name has trailing spaces */
945     RtlCreateUnicodeString( &wstr, libnameW );
946     while (wstr.Length > sizeof(WCHAR) &&
947            wstr.Buffer[wstr.Length/sizeof(WCHAR) - 1] == ' ')
948     {
949         wstr.Length -= sizeof(WCHAR);
950     }
951     wstr.Buffer[wstr.Length/sizeof(WCHAR)] = '\0';
952     res = load_library( &wstr, flags );
953     RtlFreeUnicodeString( &wstr );
954     return res;
955 }
956
957 /***********************************************************************
958  *           LoadLibraryA         (KERNEL32.@)
959  *
960  * Load a dll file into the process address space.
961  *
962  * PARAMS
963  *  libname [I] Name of the file to load
964  *
965  * RETURNS
966  *  Success: A handle to the loaded dll.
967  *  Failure: A NULL handle. Use GetLastError() to determine the cause.
968  *
969  * NOTES
970  * See LoadLibraryExA().
971  */
972 HMODULE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR libname)
973 {
974     return LoadLibraryExA(libname, 0, 0);
975 }
976
977 /***********************************************************************
978  *           LoadLibraryW         (KERNEL32.@)
979  *
980  * Unicode version of LoadLibraryA.
981  */
982 HMODULE WINAPI DECLSPEC_HOTPATCH LoadLibraryW(LPCWSTR libnameW)
983 {
984     return LoadLibraryExW(libnameW, 0, 0);
985 }
986
987 /***********************************************************************
988  *           FreeLibrary   (KERNEL32.@)
989  *
990  * Free a dll loaded into the process address space.
991  *
992  * PARAMS
993  *  hLibModule [I] Handle to the dll returned by LoadLibraryA().
994  *
995  * RETURNS
996  *  Success: TRUE. The dll is removed if it is not still in use.
997  *  Failure: FALSE. Use GetLastError() to determine the cause.
998  */
999 BOOL WINAPI DECLSPEC_HOTPATCH FreeLibrary(HINSTANCE hLibModule)
1000 {
1001     BOOL                retv = FALSE;
1002     NTSTATUS            nts;
1003
1004     if (!hLibModule)
1005     {
1006         SetLastError( ERROR_INVALID_HANDLE );
1007         return FALSE;
1008     }
1009
1010     if ((ULONG_PTR)hLibModule & 1)
1011     {
1012         /* this is a LOAD_LIBRARY_AS_DATAFILE module */
1013         char *ptr = (char *)hLibModule - 1;
1014         return UnmapViewOfFile( ptr );
1015     }
1016
1017     if ((nts = LdrUnloadDll( hLibModule )) == STATUS_SUCCESS) retv = TRUE;
1018     else SetLastError( RtlNtStatusToDosError( nts ) );
1019
1020     return retv;
1021 }
1022
1023 /***********************************************************************
1024  *           GetProcAddress             (KERNEL32.@)
1025  *
1026  * Find the address of an exported symbol in a loaded dll.
1027  *
1028  * PARAMS
1029  *  hModule  [I] Handle to the dll returned by LoadLibraryA().
1030  *  function [I] Name of the symbol, or an integer ordinal number < 16384
1031  *
1032  * RETURNS
1033  *  Success: A pointer to the symbol in the process address space.
1034  *  Failure: NULL. Use GetLastError() to determine the cause.
1035  */
1036 FARPROC WINAPI GetProcAddress( HMODULE hModule, LPCSTR function )
1037 {
1038     NTSTATUS    nts;
1039     FARPROC     fp;
1040
1041     if (!hModule) hModule = NtCurrentTeb()->Peb->ImageBaseAddress;
1042
1043     if ((ULONG_PTR)function >> 16)
1044     {
1045         ANSI_STRING     str;
1046
1047         RtlInitAnsiString( &str, function );
1048         nts = LdrGetProcedureAddress( hModule, &str, 0, (void**)&fp );
1049     }
1050     else
1051         nts = LdrGetProcedureAddress( hModule, NULL, LOWORD(function), (void**)&fp );
1052     if (nts != STATUS_SUCCESS)
1053     {
1054         SetLastError( RtlNtStatusToDosError( nts ) );
1055         fp = NULL;
1056     }
1057     return fp;
1058 }
1059
1060 /***********************************************************************
1061  *           DelayLoadFailureHook  (KERNEL32.@)
1062  */
1063 FARPROC WINAPI DelayLoadFailureHook( LPCSTR name, LPCSTR function )
1064 {
1065     ULONG_PTR args[2];
1066
1067     if ((ULONG_PTR)function >> 16)
1068         ERR( "failed to delay load %s.%s\n", name, function );
1069     else
1070         ERR( "failed to delay load %s.%u\n", name, LOWORD(function) );
1071     args[0] = (ULONG_PTR)name;
1072     args[1] = (ULONG_PTR)function;
1073     RaiseException( EXCEPTION_WINE_STUB, EH_NONCONTINUABLE, 2, args );
1074     return NULL;
1075 }
1076
1077 typedef struct {
1078     HANDLE process;
1079     PLIST_ENTRY head, current;
1080     LDR_MODULE ldr_module;
1081 } MODULE_ITERATOR;
1082
1083 static BOOL init_module_iterator(MODULE_ITERATOR *iter, HANDLE process)
1084 {
1085     PROCESS_BASIC_INFORMATION pbi;
1086     PPEB_LDR_DATA ldr_data;
1087     NTSTATUS status;
1088
1089     /* Get address of PEB */
1090     status = NtQueryInformationProcess(process, ProcessBasicInformation,
1091                                        &pbi, sizeof(pbi), NULL);
1092     if (status != STATUS_SUCCESS)
1093     {
1094         SetLastError(RtlNtStatusToDosError(status));
1095         return FALSE;
1096     }
1097
1098     /* Read address of LdrData from PEB */
1099     if (!ReadProcessMemory(process, &pbi.PebBaseAddress->LdrData,
1100                            &ldr_data, sizeof(ldr_data), NULL))
1101         return FALSE;
1102
1103     /* Read address of first module from LdrData */
1104     if (!ReadProcessMemory(process,
1105                            &ldr_data->InLoadOrderModuleList.Flink,
1106                            &iter->current, sizeof(iter->current), NULL))
1107         return FALSE;
1108
1109     iter->head = &ldr_data->InLoadOrderModuleList;
1110     iter->process = process;
1111
1112     return TRUE;
1113 }
1114
1115 static int module_iterator_next(MODULE_ITERATOR *iter)
1116 {
1117     if (iter->current == iter->head)
1118         return 0;
1119
1120     if (!ReadProcessMemory(iter->process,
1121                            CONTAINING_RECORD(iter->current, LDR_MODULE, InLoadOrderModuleList),
1122                            &iter->ldr_module, sizeof(iter->ldr_module), NULL))
1123          return -1;
1124
1125     iter->current = iter->ldr_module.InLoadOrderModuleList.Flink;
1126     return 1;
1127 }
1128
1129 static BOOL get_ldr_module(HANDLE process, HMODULE module, LDR_MODULE *ldr_module)
1130 {
1131     MODULE_ITERATOR iter;
1132     INT ret;
1133
1134     if (!init_module_iterator(&iter, process))
1135         return FALSE;
1136
1137     while ((ret = module_iterator_next(&iter)) > 0)
1138         /* When hModule is NULL we return the process image - which will be
1139          * the first module since our iterator uses InLoadOrderModuleList */
1140         if (!module || module == iter.ldr_module.BaseAddress)
1141         {
1142             *ldr_module = iter.ldr_module;
1143             return TRUE;
1144         }
1145
1146     if (ret == 0)
1147         SetLastError(ERROR_INVALID_HANDLE);
1148
1149     return FALSE;
1150 }
1151
1152 /***********************************************************************
1153  *           K32EnumProcessModules (KERNEL32.@)
1154  *
1155  * NOTES
1156  *  Returned list is in load order.
1157  */
1158 BOOL WINAPI K32EnumProcessModules(HANDLE process, HMODULE *lphModule,
1159                                   DWORD cb, DWORD *needed)
1160 {
1161     MODULE_ITERATOR iter;
1162     INT ret;
1163
1164     if (!init_module_iterator(&iter, process))
1165         return FALSE;
1166
1167     *needed = 0;
1168
1169     while ((ret = module_iterator_next(&iter)) > 0)
1170     {
1171         if (cb >= sizeof(HMODULE))
1172         {
1173             *lphModule++ = iter.ldr_module.BaseAddress;
1174             cb -= sizeof(HMODULE);
1175         }
1176         *needed += sizeof(HMODULE);
1177     }
1178
1179     return ret == 0;
1180 }
1181
1182 /***********************************************************************
1183  *           K32GetModuleBaseNameW (KERNEL32.@)
1184  */
1185 DWORD WINAPI K32GetModuleBaseNameW(HANDLE process, HMODULE module,
1186                                    LPWSTR base_name, DWORD size)
1187 {
1188     LDR_MODULE ldr_module;
1189
1190     if (!get_ldr_module(process, module, &ldr_module))
1191         return 0;
1192
1193     size = min(ldr_module.BaseDllName.Length / sizeof(WCHAR), size);
1194     if (!ReadProcessMemory(process, ldr_module.BaseDllName.Buffer,
1195                            base_name, size * sizeof(WCHAR), NULL))
1196         return 0;
1197
1198     base_name[size] = 0;
1199     return size;
1200 }
1201
1202 /***********************************************************************
1203  *           K32GetModuleBaseNameA (KERNEL32.@)
1204  */
1205 DWORD WINAPI K32GetModuleBaseNameA(HANDLE process, HMODULE module,
1206                                    LPSTR base_name, DWORD size)
1207 {
1208     WCHAR *base_name_w;
1209     DWORD len, ret = 0;
1210
1211     if(!base_name || !size) {
1212         SetLastError(ERROR_INVALID_PARAMETER);
1213         return 0;
1214     }
1215
1216     base_name_w = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * size);
1217     if(!base_name_w)
1218         return 0;
1219
1220     len = K32GetModuleBaseNameW(process, module, base_name_w, size);
1221     TRACE("%d, %s\n", len, debugstr_w(base_name_w));
1222     if (len)
1223     {
1224         ret = WideCharToMultiByte(CP_ACP, 0, base_name_w, len,
1225                                   base_name, size, NULL, NULL);
1226         if (ret < size) base_name[ret] = 0;
1227     }
1228     HeapFree(GetProcessHeap(), 0, base_name_w);
1229     return ret;
1230 }
1231
1232 /***********************************************************************
1233  *           K32GetModuleFileNameExW (KERNEL32.@)
1234  */
1235 DWORD WINAPI K32GetModuleFileNameExW(HANDLE process, HMODULE module,
1236                                      LPWSTR file_name, DWORD size)
1237 {
1238     LDR_MODULE ldr_module;
1239
1240     if(!get_ldr_module(process, module, &ldr_module))
1241         return 0;
1242
1243     size = min(ldr_module.FullDllName.Length / sizeof(WCHAR), size);
1244     if (!ReadProcessMemory(process, ldr_module.FullDllName.Buffer,
1245                            file_name, size * sizeof(WCHAR), NULL))
1246         return 0;
1247
1248     file_name[size] = 0;
1249     return size;
1250 }
1251
1252 /***********************************************************************
1253  *           K32GetModuleFileNameExA (KERNEL32.@)
1254  */
1255 DWORD WINAPI K32GetModuleFileNameExA(HANDLE process, HMODULE module,
1256                                      LPSTR file_name, DWORD size)
1257 {
1258     WCHAR *ptr;
1259
1260     TRACE("(hProcess=%p, hModule=%p, %p, %d)\n", process, module, file_name, size);
1261
1262     if (!file_name || !size) return 0;
1263
1264     if ( process == GetCurrentProcess() )
1265     {
1266         DWORD len = GetModuleFileNameA( module, file_name, size );
1267         if (size) file_name[size - 1] = '\0';
1268         return len;
1269     }
1270
1271     if (!(ptr = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR)))) return 0;
1272
1273     if (!K32GetModuleFileNameExW(process, module, ptr, size))
1274     {
1275         file_name[0] = '\0';
1276     }
1277     else
1278     {
1279         if (!WideCharToMultiByte( CP_ACP, 0, ptr, -1, file_name, size, NULL, NULL ))
1280             file_name[size - 1] = 0;
1281     }
1282
1283     HeapFree(GetProcessHeap(), 0, ptr);
1284     return strlen(file_name);
1285 }
1286
1287 /***********************************************************************
1288  *           K32GetModuleInformation (KERNEL32.@)
1289  */
1290 BOOL WINAPI K32GetModuleInformation(HANDLE process, HMODULE module,
1291                                     MODULEINFO *modinfo, DWORD cb)
1292 {
1293     LDR_MODULE ldr_module;
1294
1295     if (cb < sizeof(MODULEINFO))
1296     {
1297         SetLastError(ERROR_INSUFFICIENT_BUFFER);
1298         return FALSE;
1299     }
1300
1301     if (!get_ldr_module(process, module, &ldr_module))
1302         return FALSE;
1303
1304     modinfo->lpBaseOfDll = ldr_module.BaseAddress;
1305     modinfo->SizeOfImage = ldr_module.SizeOfImage;
1306     modinfo->EntryPoint  = ldr_module.EntryPoint;
1307     return TRUE;
1308 }
1309
1310 #ifdef __i386__
1311
1312 /***********************************************************************
1313  *           __wine_dll_register_16 (KERNEL32.@)
1314  *
1315  * No longer used.
1316  */
1317 void __wine_dll_register_16( const IMAGE_DOS_HEADER *header, const char *file_name )
1318 {
1319     ERR( "loading old style 16-bit dll %s no longer supported\n", file_name );
1320 }
1321
1322
1323 /***********************************************************************
1324  *           __wine_dll_unregister_16 (KERNEL32.@)
1325  *
1326  * No longer used.
1327  */
1328 void __wine_dll_unregister_16( const IMAGE_DOS_HEADER *header )
1329 {
1330 }
1331
1332 #endif