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
Zsolt Vadász
wine
Commits
be900ebd
Commit
be900ebd
authored
22 years ago
by
Alexandre Julliard
Browse files
Options
Downloads
Patches
Plain Diff
Moved wine_anon_mmap to loader.c.
parent
69dc0d93
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
library/loader.c
+130
-0
130 additions, 0 deletions
library/loader.c
library/port.c
+0
-124
0 additions, 124 deletions
library/port.c
with
130 additions
and
124 deletions
library/loader.c
+
130
−
0
View file @
be900ebd
...
...
@@ -23,12 +23,16 @@
#include
<assert.h>
#include
<ctype.h>
#include
<fcntl.h>
#include
<stdlib.h>
#include
<string.h>
#include
<sys/types.h>
#ifdef HAVE_SYS_MMAN_H
#include
<sys/mman.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#define NONAMELESSUNION
#define NONAMELESSSTRUCT
...
...
@@ -407,6 +411,132 @@ void *wine_dll_load_main_exe( const char *name, char *error, int errorsize, int
}
#if defined(__svr4__) || defined(__NetBSD__)
/***********************************************************************
* try_mmap_fixed
*
* The purpose of this routine is to emulate the behaviour of
* the Linux mmap() routine if a non-NULL address is passed,
* but the MAP_FIXED flag is not set. Linux in this case tries
* to place the mapping at the specified address, *unless* the
* range is already in use. Solaris, however, completely ignores
* the address argument in this case.
*
* As Wine code occasionally relies on the Linux behaviour, e.g. to
* be able to map non-relocateable PE executables to their proper
* start addresses, or to map the DOS memory to 0, this routine
* emulates the Linux behaviour by checking whether the desired
* address range is still available, and placing the mapping there
* using MAP_FIXED if so.
*/
static
int
try_mmap_fixed
(
void
*
addr
,
size_t
len
,
int
prot
,
int
flags
,
int
fildes
,
off_t
off
)
{
char
*
volatile
result
=
NULL
;
int
pagesize
=
getpagesize
();
pid_t
pid
;
/* We only try to map to a fixed address if
addr is non-NULL and properly aligned,
and MAP_FIXED isn't already specified. */
if
(
!
addr
)
return
0
;
if
(
(
uintptr_t
)
addr
&
(
pagesize
-
1
)
)
return
0
;
if
(
flags
&
MAP_FIXED
)
return
0
;
/* We use vfork() to freeze all threads of the
current process. This allows us to check without
race condition whether the desired memory range is
already in use. Note that because vfork() shares
the address spaces between parent and child, we
can actually perform the mapping in the child. */
if
(
(
pid
=
vfork
())
==
-
1
)
{
perror
(
"try_mmap_fixed: vfork"
);
exit
(
1
);
}
if
(
pid
==
0
)
{
int
i
;
char
vec
;
/* We call mincore() for every page in the desired range.
If any of these calls succeeds, the page is already
mapped and we must fail. */
for
(
i
=
0
;
i
<
len
;
i
+=
pagesize
)
if
(
mincore
(
(
caddr_t
)
addr
+
i
,
pagesize
,
&
vec
)
!=
-
1
)
_exit
(
1
);
/* Perform the mapping with MAP_FIXED set. This is safe
now, as none of the pages is currently in use. */
result
=
mmap
(
addr
,
len
,
prot
,
flags
|
MAP_FIXED
,
fildes
,
off
);
if
(
result
==
addr
)
_exit
(
0
);
if
(
result
!=
(
void
*
)
-
1
)
/* This should never happen ... */
munmap
(
result
,
len
);
_exit
(
1
);
}
/* vfork() lets the parent continue only after the child
has exited. Furthermore, Wine sets SIGCHLD to SIG_IGN,
so we don't need to wait for the child. */
return
result
==
addr
;
}
#endif
/* __svr4__ || __NetBSD__ */
/***********************************************************************
* wine_anon_mmap
*
* Portable wrapper for anonymous mmaps
*/
void
*
wine_anon_mmap
(
void
*
start
,
size_t
size
,
int
prot
,
int
flags
)
{
#ifdef HAVE_MMAP
static
int
fdzero
=
-
1
;
#ifdef MAP_ANON
flags
|=
MAP_ANON
;
#else
if
(
fdzero
==
-
1
)
{
if
((
fdzero
=
open
(
"/dev/zero"
,
O_RDONLY
))
==
-
1
)
{
perror
(
"/dev/zero: open"
);
exit
(
1
);
}
}
#endif
/* MAP_ANON */
#ifdef MAP_SHARED
flags
&=
~
MAP_SHARED
;
#endif
/* Linux EINVAL's on us if we don't pass MAP_PRIVATE to an anon mmap */
#ifdef MAP_PRIVATE
flags
|=
MAP_PRIVATE
;
#endif
#if defined(__svr4__) || defined(__NetBSD__)
if
(
try_mmap_fixed
(
start
,
size
,
prot
,
flags
,
fdzero
,
0
)
)
return
start
;
#endif
return
mmap
(
start
,
size
,
prot
,
flags
,
fdzero
,
0
);
#else
return
(
void
*
)
-
1
;
#endif
}
/*
* These functions provide wrappers around dlopen() and associated
* functions. They work around a bug in glibc 2.1.x where calling
...
...
This diff is collapsed.
Click to expand it.
library/port.c
+
0
−
124
View file @
be900ebd
...
...
@@ -65,130 +65,6 @@
#endif
#if defined(__svr4__) || defined(__NetBSD__)
/***********************************************************************
* try_mmap_fixed
*
* The purpose of this routine is to emulate the behaviour of
* the Linux mmap() routine if a non-NULL address is passed,
* but the MAP_FIXED flag is not set. Linux in this case tries
* to place the mapping at the specified address, *unless* the
* range is already in use. Solaris, however, completely ignores
* the address argument in this case.
*
* As Wine code occasionally relies on the Linux behaviour, e.g. to
* be able to map non-relocateable PE executables to their proper
* start addresses, or to map the DOS memory to 0, this routine
* emulates the Linux behaviour by checking whether the desired
* address range is still available, and placing the mapping there
* using MAP_FIXED if so.
*/
static
int
try_mmap_fixed
(
void
*
addr
,
size_t
len
,
int
prot
,
int
flags
,
int
fildes
,
off_t
off
)
{
char
*
volatile
result
=
NULL
;
int
pagesize
=
getpagesize
();
pid_t
pid
;
/* We only try to map to a fixed address if
addr is non-NULL and properly aligned,
and MAP_FIXED isn't already specified. */
if
(
!
addr
)
return
0
;
if
(
(
uintptr_t
)
addr
&
(
pagesize
-
1
)
)
return
0
;
if
(
flags
&
MAP_FIXED
)
return
0
;
/* We use vfork() to freeze all threads of the
current process. This allows us to check without
race condition whether the desired memory range is
already in use. Note that because vfork() shares
the address spaces between parent and child, we
can actually perform the mapping in the child. */
if
(
(
pid
=
vfork
())
==
-
1
)
{
perror
(
"try_mmap_fixed: vfork"
);
exit
(
1
);
}
if
(
pid
==
0
)
{
int
i
;
char
vec
;
/* We call mincore() for every page in the desired range.
If any of these calls succeeds, the page is already
mapped and we must fail. */
for
(
i
=
0
;
i
<
len
;
i
+=
pagesize
)
if
(
mincore
(
(
caddr_t
)
addr
+
i
,
pagesize
,
&
vec
)
!=
-
1
)
_exit
(
1
);
/* Perform the mapping with MAP_FIXED set. This is safe
now, as none of the pages is currently in use. */
result
=
mmap
(
addr
,
len
,
prot
,
flags
|
MAP_FIXED
,
fildes
,
off
);
if
(
result
==
addr
)
_exit
(
0
);
if
(
result
!=
(
void
*
)
-
1
)
/* This should never happen ... */
munmap
(
result
,
len
);
_exit
(
1
);
}
/* vfork() lets the parent continue only after the child
has exited. Furthermore, Wine sets SIGCHLD to SIG_IGN,
so we don't need to wait for the child. */
return
result
==
addr
;
}
#endif
/***********************************************************************
* wine_anon_mmap
*
* Portable wrapper for anonymous mmaps
*/
void
*
wine_anon_mmap
(
void
*
start
,
size_t
size
,
int
prot
,
int
flags
)
{
#ifdef HAVE_MMAP
static
int
fdzero
=
-
1
;
#ifdef MAP_ANON
flags
|=
MAP_ANON
;
#else
if
(
fdzero
==
-
1
)
{
if
((
fdzero
=
open
(
"/dev/zero"
,
O_RDONLY
))
==
-
1
)
{
perror
(
"/dev/zero: open"
);
exit
(
1
);
}
}
#endif
/* MAP_ANON */
#ifdef MAP_SHARED
flags
&=
~
MAP_SHARED
;
#endif
/* Linux EINVAL's on us if we don't pass MAP_PRIVATE to an anon mmap */
#ifdef MAP_PRIVATE
flags
|=
MAP_PRIVATE
;
#endif
#if defined(__svr4__) || defined(__NetBSD__)
if
(
try_mmap_fixed
(
start
,
size
,
prot
,
flags
,
fdzero
,
0
)
)
return
start
;
#endif
return
mmap
(
start
,
size
,
prot
,
flags
,
fdzero
,
0
);
#else
return
(
void
*
)
-
1
;
#endif
}
/***********************************************************************
* pthread functions
*/
...
...
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