2 * Win32 builtin functions
4 * Copyright 1997 Alexandre Julliard
16 #include <sys/types.h>
17 #ifdef HAVE_SYS_MMAN_H
22 #include "wine/winbase16.h"
23 #include "wine/library.h"
30 #include "debugtools.h"
32 DEFAULT_DEBUG_CHANNEL(module
);
33 DECLARE_DEBUG_CHANNEL(relay
);
35 extern void RELAY_SetupDLL( const char *module
);
37 static HMODULE main_module
;
39 /***********************************************************************
42 void *BUILTIN32_dlopen( const char *name
)
47 if (!(handle
= wine_dll_load( name
)))
51 p
= strchr(pErr
, ':');
53 (!strncmp(p
, ": undefined symbol", 18))) /* undef symbol -> ERR() */
54 ERR("failed to load %s: %s\n", name
, pErr
);
55 else /* WARN() for libraries that are supposed to be native */
56 WARN("failed to load %s: %s\n", name
, pErr
);
64 /***********************************************************************
67 int BUILTIN32_dlclose( void *handle
)
70 /* FIXME: should unregister descriptors first */
71 /* return dlclose( handle ); */
77 /***********************************************************************
80 * Load a library in memory; callback function for wine_dll_register
82 static void load_library( void *base
, const char *filename
)
84 HMODULE module
= (HMODULE
)base
;
89 ERR("could not map image for %s\n", filename
? filename
: "main exe" );
93 if (!(PE_HEADER(module
)->FileHeader
.Characteristics
& IMAGE_FILE_DLL
))
95 /* if we already have an executable, ignore this one */
96 if (!main_module
) main_module
= module
;
97 return; /* don't create the modref here, will be done later on */
100 if (GetModuleHandleA( filename
))
101 MESSAGE( "Warning: loading builtin %s, but native version already present. Expect trouble.\n", filename
);
103 /* Create 32-bit MODREF */
104 if (!(wm
= PE_CreateModule( module
, filename
, 0, -1, TRUE
)))
106 ERR( "can't load %s\n", filename
);
107 SetLastError( ERROR_OUTOFMEMORY
);
110 TRACE( "loaded %s %p %x\n", filename
, wm
, module
);
111 wm
->refCount
++; /* we don't support freeing builtin dlls (FIXME)*/
113 /* setup relay debugging entry points */
114 if (TRACE_ON(relay
)) RELAY_SetupDLL( (void *)module
);
118 /***********************************************************************
119 * BUILTIN32_LoadLibraryExA
121 * Partly copied from the original PE_ version.
124 WINE_MODREF
*BUILTIN32_LoadLibraryExA(LPCSTR path
, DWORD flags
)
127 char dllname
[20], *p
;
131 /* Fix the name in case we have a full path and extension */
133 if ((p
= strrchr( name
, '\\' ))) name
= p
+ 1;
134 if ((p
= strrchr( name
, '/' ))) name
= p
+ 1;
136 if (strlen(name
) >= sizeof(dllname
)-4) goto error
;
138 strcpy( dllname
, name
);
139 p
= strrchr( dllname
, '.' );
140 if (!p
) strcat( dllname
, ".dll" );
142 if (!(handle
= BUILTIN32_dlopen( dllname
))) goto error
;
144 if (!(wm
= MODULE_FindModule( path
))) wm
= MODULE_FindModule( dllname
);
147 ERR( "loaded .so but dll %s still not found\n", dllname
);
148 /* wine_dll_unload( handle );*/
151 wm
->dlhandle
= handle
;
155 SetLastError( ERROR_FILE_NOT_FOUND
);
159 /***********************************************************************
162 * Initialize loading callbacks and return HMODULE of main exe.
163 * 'main' is the main exe in case if was already loaded from a PE file.
165 HMODULE
BUILTIN32_LoadExeModule( HMODULE main
)
168 wine_dll_set_callback( load_library
);
170 MESSAGE( "No built-in EXE module loaded! Did you create a .spec file?\n" );
175 /***********************************************************************
176 * BUILTIN32_RegisterDLL
178 * Register a built-in DLL descriptor.
180 void BUILTIN32_RegisterDLL( const IMAGE_NT_HEADERS
*header
, const char *filename
)
182 extern void __wine_dll_register( const IMAGE_NT_HEADERS
*header
, const char *filename
);
183 __wine_dll_register( header
, filename
);