Cygwin: drop fixed addresses for standard shared regions
With the previous commit 9ddd48ee1b
("Cygwin: /proc/<PID>/maps:
print real shared region addresses"), the real addresses of
the standard shared regions (cygwin, user, myself, shared console)
are read from the printed process itself. We don't need fixed
addresses anymore, so drop the definitions and simplify open_shared.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
parent
9ddd48ee1b
commit
31302b267b
|
@ -16,16 +16,9 @@ details. */
|
||||||
dynamicbase is accidentally not set in the PE/COFF header of the DLL. */
|
dynamicbase is accidentally not set in the PE/COFF header of the DLL. */
|
||||||
#define CYGWIN_DLL_ADDRESS 0x180040000UL
|
#define CYGWIN_DLL_ADDRESS 0x180040000UL
|
||||||
|
|
||||||
/* Default addresses of required standard shared regions (Cygwin shared,
|
|
||||||
user shared, myself, shared console). */
|
|
||||||
#define CYGWIN_REGION_ADDRESS 0x1a0000000UL
|
|
||||||
#define USER_REGION_ADDRESS 0x1a1000000UL
|
|
||||||
#define MYSELF_REGION_ADDRESS 0x1a2000000UL
|
|
||||||
#define SHARED_CONSOLE_REGION_ADDRESS 0x1a3000000UL
|
|
||||||
|
|
||||||
/* Area for non-fixed-address Cygwin-specific shared memory regions. Fallback
|
/* Area for non-fixed-address Cygwin-specific shared memory regions. Fallback
|
||||||
for standard shared regions if the can't load at their default address. */
|
for standard shared regions if the can't load at their default address. */
|
||||||
#define SHARED_REGIONS_ADDRESS_LOW 0x1a4000000UL
|
#define SHARED_REGIONS_ADDRESS_LOW 0x1a0000000UL
|
||||||
#define SHARED_REGIONS_ADDRESS_HIGH 0x200000000UL
|
#define SHARED_REGIONS_ADDRESS_HIGH 0x200000000UL
|
||||||
|
|
||||||
/* Rebased DLLs are located in this 16 Gigs arena. Will be kept for
|
/* Rebased DLLs are located in this 16 Gigs arena. Will be kept for
|
||||||
|
|
|
@ -113,15 +113,6 @@ shared_name (WCHAR *ret_buf, const WCHAR *str, int num)
|
||||||
#define page_const ((ptrdiff_t) 65535)
|
#define page_const ((ptrdiff_t) 65535)
|
||||||
#define pround(n) ((ptrdiff_t)(((n) + page_const) & ~page_const))
|
#define pround(n) ((ptrdiff_t)(((n) + page_const) & ~page_const))
|
||||||
|
|
||||||
/* FIXME: With ASLR, maybe we should ASLR the shared regions, too? */
|
|
||||||
static uintptr_t region_address[] =
|
|
||||||
{
|
|
||||||
CYGWIN_REGION_ADDRESS, /* SH_CYGWIN_SHARED */
|
|
||||||
USER_REGION_ADDRESS, /* SH_USER_SHARED */
|
|
||||||
MYSELF_REGION_ADDRESS, /* SH_MYSELF */
|
|
||||||
SHARED_CONSOLE_REGION_ADDRESS, /* SH_SHARED_CONSOLE */
|
|
||||||
0
|
|
||||||
};
|
|
||||||
static NO_COPY uintptr_t next_address = SHARED_REGIONS_ADDRESS_LOW;
|
static NO_COPY uintptr_t next_address = SHARED_REGIONS_ADDRESS_LOW;
|
||||||
|
|
||||||
void *
|
void *
|
||||||
|
@ -139,7 +130,7 @@ open_shared (const WCHAR *name, int n, HANDLE& shared_h, DWORD size,
|
||||||
{
|
{
|
||||||
WCHAR map_buf[MAX_PATH];
|
WCHAR map_buf[MAX_PATH];
|
||||||
WCHAR *mapname = NULL;
|
WCHAR *mapname = NULL;
|
||||||
void *shared = NULL;
|
void *shared;
|
||||||
void *addr;
|
void *addr;
|
||||||
|
|
||||||
created = false;
|
created = false;
|
||||||
|
@ -166,47 +157,30 @@ open_shared (const WCHAR *name, int n, HANDLE& shared_h, DWORD size,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m < SH_TOTAL_SIZE && !dynamically_loaded)
|
/* Locate shared regions in the area between SHARED_REGIONS_ADDRESS_LOW
|
||||||
{
|
and SHARED_REGIONS_ADDRESS_HIGH, retrying until we have a slot.
|
||||||
/* Fixed regions. Don't do that if Cygwin gets dynamically loaded.
|
Don't use MapViewOfFile3 (loader deadlock during fork. */
|
||||||
The process loading the DLL might be configured with High-Entropy
|
bool loop = false;
|
||||||
ASLR. Chances for collisions are pretty high.
|
|
||||||
|
|
||||||
Note that we don't actually *need* fixed addresses. The only
|
addr = (void *) next_address;
|
||||||
advantage is reproducibility to help /proc/<PID>/maps along. */
|
do
|
||||||
addr = (void *) region_address[m];
|
{
|
||||||
shared = MapViewOfFileEx (shared_h, FILE_MAP_READ | FILE_MAP_WRITE,
|
shared = MapViewOfFileEx (shared_h, FILE_MAP_READ | FILE_MAP_WRITE,
|
||||||
0, 0, 0, addr);
|
0, 0, 0, addr);
|
||||||
}
|
if (!shared)
|
||||||
/* Also catch the unlikely case that a fixed region can't be mapped at the
|
|
||||||
fixed address. */
|
|
||||||
if (!shared)
|
|
||||||
{
|
|
||||||
/* Locate shared regions in the area between SHARED_REGIONS_ADDRESS_LOW
|
|
||||||
and SHARED_REGIONS_ADDRESS_HIGH, retrying until we have a slot.
|
|
||||||
Don't use MapViewOfFile3 (loader deadlock during fork. */
|
|
||||||
bool loop = false;
|
|
||||||
|
|
||||||
addr = (void *) next_address;
|
|
||||||
do
|
|
||||||
{
|
{
|
||||||
shared = MapViewOfFileEx (shared_h, FILE_MAP_READ | FILE_MAP_WRITE,
|
next_address += wincap.allocation_granularity ();
|
||||||
0, 0, 0, addr);
|
if (next_address >= SHARED_REGIONS_ADDRESS_HIGH)
|
||||||
if (!shared)
|
|
||||||
{
|
{
|
||||||
next_address += wincap.allocation_granularity ();
|
if (loop)
|
||||||
if (next_address >= SHARED_REGIONS_ADDRESS_HIGH)
|
break;
|
||||||
{
|
next_address = SHARED_REGIONS_ADDRESS_LOW;
|
||||||
if (loop)
|
loop = true;
|
||||||
break;
|
|
||||||
next_address = SHARED_REGIONS_ADDRESS_LOW;
|
|
||||||
loop = true;
|
|
||||||
}
|
|
||||||
addr = (void *) next_address;
|
|
||||||
}
|
}
|
||||||
|
addr = (void *) next_address;
|
||||||
}
|
}
|
||||||
while (!shared);
|
|
||||||
}
|
}
|
||||||
|
while (!shared);
|
||||||
|
|
||||||
if (!shared)
|
if (!shared)
|
||||||
api_fatal ("MapViewOfFileEx '%W'(%p, size %u, m %d, created %d), %E. "
|
api_fatal ("MapViewOfFileEx '%W'(%p, size %u, m %d, created %d), %E. "
|
||||||
|
|
Loading…
Reference in New Issue