Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
wine
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
James Carthew
wine
Commits
526522ca
Commit
526522ca
authored
4 years ago
by
Alexandre Julliard
Browse files
Options
Downloads
Patches
Plain Diff
loader: Try to load ntdll.so before libwine initialization.
Signed-off-by:
Alexandre Julliard
<
julliard@winehq.org
>
parent
7e6a67d8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
loader/Makefile.in
+2
-0
2 additions, 0 deletions
loader/Makefile.in
loader/main.c
+121
-0
121 additions, 0 deletions
loader/main.c
with
123 additions
and
0 deletions
loader/Makefile.in
+
2
−
0
View file @
526522ca
...
...
@@ -18,6 +18,8 @@ INSTALL_LIB = $(WINELOADER_PROGRAMS)
preloader_EXTRADEFS
=
-fno-builtin
main_EXTRADEFS
=
-DDLLDIR
=
\"
${
dlldir
}
\"
-DBIN_TO_DLLDIR
=
\"
`
$(
MAKEDEP
)
-R
${
bindir
}
${
dlldir
}
`
\"
wine_OBJS
=
main.o
wine_DEPS
=
$(
WINELOADER_DEPENDS
)
wine_LDFLAGS
=
$(
WINELOADER_LDFLAGS
)
$(
LDEXECFLAGS
)
-lwine
$(
PTHREAD_LIBS
)
...
...
This diff is collapsed.
Click to expand it.
loader/main.c
+
121
−
0
View file @
526522ca
...
...
@@ -40,6 +40,8 @@
#include
"wine/library.h"
#include
"main.h"
extern
char
**
environ
;
/* the preloader will set this variable */
const
struct
wine_preload_info
*
wine_main_preload_info
=
NULL
;
...
...
@@ -158,6 +160,116 @@ static int pre_exec(void)
#endif
/* canonicalize path and return its directory name */
static
char
*
realpath_dirname
(
const
char
*
name
)
{
char
*
p
,
*
fullpath
=
realpath
(
name
,
NULL
);
if
(
fullpath
)
{
p
=
strrchr
(
fullpath
,
'/'
);
if
(
p
==
fullpath
)
p
++
;
if
(
p
)
*
p
=
0
;
}
return
fullpath
;
}
/* if string ends with tail, remove it */
static
char
*
remove_tail
(
const
char
*
str
,
const
char
*
tail
)
{
size_t
len
=
strlen
(
str
);
size_t
tail_len
=
strlen
(
tail
);
char
*
ret
;
if
(
len
<
tail_len
)
return
NULL
;
if
(
strcmp
(
str
+
len
-
tail_len
,
tail
))
return
NULL
;
ret
=
malloc
(
len
-
tail_len
+
1
);
memcpy
(
ret
,
str
,
len
-
tail_len
);
ret
[
len
-
tail_len
]
=
0
;
return
ret
;
}
/* build a path from the specified dir and name */
static
char
*
build_path
(
const
char
*
dir
,
const
char
*
name
)
{
size_t
len
=
strlen
(
dir
);
char
*
ret
=
malloc
(
len
+
strlen
(
name
)
+
2
);
memcpy
(
ret
,
dir
,
len
);
if
(
len
&&
ret
[
len
-
1
]
!=
'/'
)
ret
[
len
++
]
=
'/'
;
strcpy
(
ret
+
len
,
name
);
return
ret
;
}
static
const
char
*
get_self_exe
(
char
*
argv0
)
{
#if defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)
return
"/proc/self/exe"
;
#elif defined (__FreeBSD__) || defined(__DragonFly__)
return
"/proc/curproc/file"
;
#else
if
(
!
strchr
(
argv0
,
'/'
))
/* search in PATH */
{
char
*
p
,
*
path
=
getenv
(
"PATH"
);
if
(
!
path
||
!
(
path
=
strdup
(
path
)))
return
NULL
;
for
(
p
=
strtok
(
path
,
":"
);
p
;
p
=
strtok
(
NULL
,
":"
))
{
char
*
name
=
build_path
(
p
,
argv0
);
int
found
=
!
access
(
name
,
X_OK
);
free
(
name
);
if
(
found
)
break
;
}
if
(
p
)
p
=
strdup
(
p
);
free
(
path
);
return
p
;
}
return
argv0
;
#endif
}
static
void
*
try_dlopen
(
const
char
*
dir
,
const
char
*
name
)
{
char
*
path
=
build_path
(
dir
,
name
);
void
*
handle
=
dlopen
(
path
,
RTLD_NOW
);
free
(
path
);
return
handle
;
}
static
void
*
load_ntdll
(
char
*
argv0
)
{
const
char
*
self
=
get_self_exe
(
argv0
);
char
*
path
,
*
p
;
void
*
handle
=
NULL
;
if
(
self
&&
((
path
=
realpath_dirname
(
self
))))
{
if
((
p
=
remove_tail
(
path
,
"/loader"
)))
{
handle
=
try_dlopen
(
p
,
"dlls/ntdll/ntdll.so"
);
free
(
p
);
}
else
handle
=
try_dlopen
(
path
,
BIN_TO_DLLDIR
"/ntdll.so"
);
free
(
path
);
}
if
(
!
handle
&&
(
path
=
getenv
(
"WINEDLLPATH"
)))
{
path
=
strdup
(
path
);
for
(
p
=
strtok
(
path
,
":"
);
p
;
p
=
strtok
(
NULL
,
":"
))
{
handle
=
try_dlopen
(
p
,
"ntdll.so"
);
if
(
handle
)
break
;
}
free
(
path
);
}
if
(
!
handle
&&
!
self
)
handle
=
try_dlopen
(
DLLDIR
,
"ntdll.so"
);
return
handle
;
}
/**********************************************************************
* main
*/
...
...
@@ -165,6 +277,7 @@ int main( int argc, char *argv[] )
{
char
error
[
1024
];
int
i
;
void
*
handle
;
if
(
!
getenv
(
"WINELOADERNOEXEC"
))
/* first time around */
{
...
...
@@ -181,6 +294,14 @@ int main( int argc, char *argv[] )
}
}
if
((
handle
=
load_ntdll
(
argv
[
0
]
)))
{
void
(
*
init_func
)(
int
,
char
**
,
char
**
)
=
dlsym
(
handle
,
"__wine_main"
);
if
(
init_func
)
init_func
(
argc
,
argv
,
environ
);
fprintf
(
stderr
,
"wine: __wine_main function not found in ntdll.so
\n
"
);
exit
(
1
);
}
if
(
wine_main_preload_info
)
{
for
(
i
=
0
;
wine_main_preload_info
[
i
].
size
;
i
++
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment