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 if (strstr(pErr
, "undefined symbol")) /* undef symbol -> ERR() */
52 ERR("failed to load %s: %s\n", name
, pErr
);
53 else /* WARN() for libraries that are supposed to be native */
54 WARN("failed to load %s: %s\n", name
, pErr
);
62 /***********************************************************************
65 int BUILTIN32_dlclose( void *handle
)
68 /* FIXME: should unregister descriptors first */
69 /* return dlclose( handle ); */
75 /***********************************************************************
78 * Load a library in memory; callback function for wine_dll_register
80 static void load_library( void *base
, const char *filename
)
82 HMODULE module
= (HMODULE
)base
;
87 ERR("could not map image for %s\n", filename
? filename
: "main exe" );
91 if (!(PE_HEADER(module
)->FileHeader
.Characteristics
& IMAGE_FILE_DLL
))
93 /* if we already have an executable, ignore this one */
94 if (!main_module
) main_module
= module
;
95 return; /* don't create the modref here, will be done later on */
98 if (GetModuleHandleA( filename
))
99 MESSAGE( "Warning: loading builtin %s, but native version already present. Expect trouble.\n", filename
);
101 /* Create 32-bit MODREF */
102 if (!(wm
= PE_CreateModule( module
, filename
, 0, -1, TRUE
)))
104 ERR( "can't load %s\n", filename
);
105 SetLastError( ERROR_OUTOFMEMORY
);
108 TRACE( "loaded %s %p %x\n", filename
, wm
, module
);
109 wm
->refCount
++; /* we don't support freeing builtin dlls (FIXME)*/
111 /* setup relay debugging entry points */
112 if (TRACE_ON(relay
)) RELAY_SetupDLL( (void *)module
);
116 /***********************************************************************
117 * BUILTIN32_LoadLibraryExA
119 * Partly copied from the original PE_ version.
122 WINE_MODREF
*BUILTIN32_LoadLibraryExA(LPCSTR path
, DWORD flags
)
125 char dllname
[20], *p
;
129 /* Fix the name in case we have a full path and extension */
131 if ((p
= strrchr( name
, '\\' ))) name
= p
+ 1;
132 if ((p
= strrchr( name
, '/' ))) name
= p
+ 1;
134 if (strlen(name
) >= sizeof(dllname
)-4) goto error
;
136 strcpy( dllname
, name
);
137 p
= strrchr( dllname
, '.' );
138 if (!p
) strcat( dllname
, ".dll" );
140 if (!(handle
= BUILTIN32_dlopen( dllname
))) goto error
;
142 if (!(wm
= MODULE_FindModule( path
))) wm
= MODULE_FindModule( dllname
);
145 ERR( "loaded .so but dll %s still not found\n", dllname
);
146 /* wine_dll_unload( handle );*/
149 wm
->dlhandle
= handle
;
153 SetLastError( ERROR_FILE_NOT_FOUND
);
157 /***********************************************************************
160 * Initialize loading callbacks and return HMODULE of main exe.
161 * 'main' is the main exe in case if was already loaded from a PE file.
163 HMODULE
BUILTIN32_LoadExeModule( HMODULE main
)
166 wine_dll_set_callback( load_library
);
168 MESSAGE( "No built-in EXE module loaded! Did you create a .spec file?\n" );
173 /***********************************************************************
174 * BUILTIN32_RegisterDLL
176 * Register a built-in DLL descriptor.
178 void BUILTIN32_RegisterDLL( const IMAGE_NT_HEADERS
*header
, const char *filename
)
180 extern void __wine_dll_register( const IMAGE_NT_HEADERS
*header
, const char *filename
);
181 __wine_dll_register( header
, filename
);