2 * Win32 builtin functions
4 * Copyright 1997 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include <sys/types.h>
28 #ifdef HAVE_SYS_MMAN_H
33 #include "wine/winbase16.h"
34 #include "wine/library.h"
38 #include "wine/server.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(module
);
42 WINE_DECLARE_DEBUG_CHANNEL(relay
);
44 extern void RELAY_SetupDLL( const char *module
);
46 static HMODULE main_module
;
48 /***********************************************************************
51 void *BUILTIN32_dlopen( const char *name
)
56 if (!(handle
= wine_dll_load( name
, error
, sizeof(error
) )))
58 if (strstr(error
, "cannot open") || strstr(error
, "open failed") ||
59 (strstr(error
, "Shared object") && strstr(error
, "not found"))) {
60 /* The file does not exist -> WARN() */
61 WARN("cannot open .so lib for builtin %s: %s\n", name
, error
);
63 /* ERR() for all other errors (missing functions, ...) */
64 ERR("failed to load .so lib for builtin %s: %s\n", name
, error
);
70 /***********************************************************************
73 int BUILTIN32_dlclose( void *handle
)
75 /* FIXME: should unregister descriptors first */
76 /* wine_dll_unload( handle ); */
81 /***********************************************************************
84 * Load a library in memory; callback function for wine_dll_register
86 static void load_library( void *base
, const char *filename
)
88 HMODULE module
= (HMODULE
)base
;
93 ERR("could not map image for %s\n", filename
? filename
: "main exe" );
97 if (!(PE_HEADER(module
)->FileHeader
.Characteristics
& IMAGE_FILE_DLL
))
99 /* if we already have an executable, ignore this one */
100 if (!main_module
) main_module
= module
;
101 return; /* don't create the modref here, will be done later on */
104 if (GetModuleHandleA( filename
))
105 MESSAGE( "Warning: loading builtin %s, but native version already present. Expect trouble.\n", filename
);
107 /* Create 32-bit MODREF */
108 if (!(wm
= PE_CreateModule( module
, filename
, 0, 0, TRUE
)))
110 ERR( "can't load %s\n", filename
);
111 SetLastError( ERROR_OUTOFMEMORY
);
114 TRACE( "loaded %s %p %x\n", filename
, wm
, module
);
115 wm
->refCount
++; /* we don't support freeing builtin dlls (FIXME)*/
117 /* setup relay debugging entry points */
118 if (TRACE_ON(relay
)) RELAY_SetupDLL( (void *)module
);
122 /***********************************************************************
123 * BUILTIN32_LoadLibraryExA
125 * Partly copied from the original PE_ version.
128 WINE_MODREF
*BUILTIN32_LoadLibraryExA(LPCSTR path
, DWORD flags
)
131 char dllname
[20], *p
;
135 /* Fix the name in case we have a full path and extension */
137 if ((p
= strrchr( name
, '\\' ))) name
= p
+ 1;
138 if ((p
= strrchr( name
, '/' ))) name
= p
+ 1;
140 if (strlen(name
) >= sizeof(dllname
)-4) goto error
;
142 strcpy( dllname
, name
);
143 p
= strrchr( dllname
, '.' );
144 if (!p
) strcat( dllname
, ".dll" );
145 for (p
= dllname
; *p
; p
++) *p
= FILE_tolower(*p
);
147 if (!(handle
= BUILTIN32_dlopen( dllname
))) goto error
;
149 if (!(wm
= MODULE_FindModule( path
))) wm
= MODULE_FindModule( dllname
);
152 ERR( "loaded .so but dll %s still not found - library environment problem or version conflict, check your setup.\n", dllname
);
153 /* wine_dll_unload( handle );*/
156 wm
->dlhandle
= handle
;
160 SetLastError( ERROR_FILE_NOT_FOUND
);
164 /***********************************************************************
167 * Initialize loading callbacks and return HMODULE of main exe.
168 * 'main' is the main exe in case it was already loaded from a PE file.
170 HMODULE
BUILTIN32_LoadExeModule( HMODULE main
)
173 wine_dll_set_callback( load_library
);
175 MESSAGE( "No built-in EXE module loaded! Did you create a .spec file?\n" );
180 /***********************************************************************
181 * BUILTIN32_RegisterDLL
183 * Register a built-in DLL descriptor.
185 void BUILTIN32_RegisterDLL( const IMAGE_NT_HEADERS
*header
, const char *filename
)
187 extern void __wine_dll_register( const IMAGE_NT_HEADERS
*header
, const char *filename
);
188 __wine_dll_register( header
, filename
);