4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-01-31 11:30:56 +08:00

* shared_info.h (cygwin_shared_address): Bump to a higher value to avoid

collision with large data areas.
* fhandler_console.cc (fhandler_console::get_tty_stuff): Accommodate changes to
open_shared arguments.
* fhandler_tape.cc (mtinfo_init): Ditto.
* pinfo.cc (pinfo::init): Use open_shared rather than win32 mmap calls.
* shared.cc (user_shared_initialize): Ditto.
(memory_init): Ditto.
(open_shared): Change to allow use a smore general mmap handler.
* shared_info.h (shared_locations): Add SH_JUSTCREATE, SH_JUSTOPEN.
(open_shared): Change declaration to match new usage.
* autoload.cc (LoadDLLfuncEx2): Define in terms of LoadDLLfuncEx3.
(LoadDLLfuncEx3): New macro.
This commit is contained in:
Christopher Faylor 2005-04-28 23:59:44 +00:00
parent e525f6d51a
commit c4ffa3c427
8 changed files with 99 additions and 69 deletions

View File

@ -1,3 +1,23 @@
2005-04-28 Corinna Vinschen <corinna@vinschen.de>
* shared_info.h (cygwin_shared_address): Bump to a higher value to avoid
collision with large data areas.
2005-04-28 Christopher Faylor <cgf@timesys.com>
* fhandler_console.cc (fhandler_console::get_tty_stuff): Accommodate
changes to open_shared arguments.
* fhandler_tape.cc (mtinfo_init): Ditto.
* pinfo.cc (pinfo::init): Use open_shared rather than win32 mmap calls.
* shared.cc (user_shared_initialize): Ditto.
(memory_init): Ditto.
(open_shared): Change to allow use a smore general mmap handler.
* shared_info.h (shared_locations): Add SH_JUSTCREATE, SH_JUSTOPEN.
(open_shared): Change declaration to match new usage.
* autoload.cc (LoadDLLfuncEx2): Define in terms of LoadDLLfuncEx3.
(LoadDLLfuncEx3): New macro.
2005-04-27 Christopher Faylor <cgf@timesys.com> 2005-04-27 Christopher Faylor <cgf@timesys.com>
* fhandler.cc (fhandler_base::open_9x): Remove (broken) check for * fhandler.cc (fhandler_base::open_9x): Remove (broken) check for

View File

@ -75,11 +75,15 @@ details. */
/* Standard DLL load macro. May invoke a fatal error if the function isn't /* Standard DLL load macro. May invoke a fatal error if the function isn't
found. */ found. */
#define LoadDLLfunc(name, n, dllname) LoadDLLfuncEx (name, n, dllname, 0) #define LoadDLLfunc(name, n, dllname) \
#define LoadDLLfuncEx(name, n, dllname, notimp) LoadDLLfuncEx2(name, n, dllname, notimp, 0) LoadDLLfuncEx (name, n, dllname, 0)
#define LoadDLLfuncEx(name, n, dllname, notimp) \
LoadDLLfuncEx2(name, n, dllname, notimp, 0)
#define LoadDLLfuncEx2(name, n, dllname, notimp, err) \
LoadDLLfuncEx3(name, n, dllname, notimp, err, 0)
/* Main DLL setup stuff. */ /* Main DLL setup stuff. */
#define LoadDLLfuncEx2(name, n, dllname, notimp, err) \ #define LoadDLLfuncEx3(name, n, dllname, notimp, err, fn) \
LoadDLLprime (dllname, dll_func_load) \ LoadDLLprime (dllname, dll_func_load) \
__asm__ (" \n\ __asm__ (" \n\
.section ." #dllname "_text,\"wx\" \n\ .section ." #dllname "_text,\"wx\" \n\
@ -93,7 +97,7 @@ _win32_" mangle (name, n) ": \n\
1:movl (2f),%eax \n\ 1:movl (2f),%eax \n\
call *(%eax) \n\ call *(%eax) \n\
2:.long ." #dllname "_info \n\ 2:.long ." #dllname "_info \n\
.long (" #n "+" #notimp ") | (((" #err ") & 0xffff) <<16) \n\ .long (" #n "+" #notimp ") | (((" #err ") & 0xff) <<16) | (((" #fn ") & 0xff) << 24) \n\
.asciz \"" #name "\" \n\ .asciz \"" #name "\" \n\
.text \n\ .text \n\
"); ");

View File

@ -24,7 +24,7 @@ sumit() {
while [ -n "$1" ]; do while [ -n "$1" ]; do
define=$1; shift define=$1; shift
struct=$1; shift struct=$1; shift
sum=`$gcc -E $file | sed -n "/^$struct/,/^};/p" | sed -e 's/[ ]//g' -e '/^$/d' | sumit | awk '{printf "0x%xU", $1}'` sum=`$gcc -E $file | tee /tmp/1 | sed -n "/^$struct/,/^};/p" | sed -e 's/[ ]//g' -e '/^$/d' | tee /tmp/2 | sumit | tee /tmp/3 | awk '{printf "0x%xU", $1}'`
echo "#define $define $sum" echo "#define $define $sum"
curr=`sed -n "s/^#[ ]*define CURR_$define[ ][ ]*\([^ ][^ ]*\)/\1/p" $file` curr=`sed -n "s/^#[ ]*define CURR_$define[ ][ ]*\([^ ][^ ]*\)/\1/p" $file`
[ "$curr" != "$sum" ] && echo "*** WARNING WARNING WARNING WARNING WARNING *** [ "$curr" != "$sum" ] && echo "*** WARNING WARNING WARNING WARNING WARNING ***

View File

@ -81,10 +81,11 @@ fhandler_console::get_tty_stuff (int flags = 0)
if (dev_state) if (dev_state)
return &shared_console_info->tty_min_state; return &shared_console_info->tty_min_state;
shared_locations sh_shared_console = SH_SHARED_CONSOLE;
shared_console_info = shared_console_info =
(console_state *) open_shared (NULL, 0, cygheap->console_h, (console_state *) open_shared (NULL, 0, cygheap->console_h,
sizeof (*shared_console_info), sizeof (*shared_console_info),
SH_SHARED_CONSOLE); sh_shared_console);
dev_state = &shared_console_info->dev_state; dev_state = &shared_console_info->dev_state;
ProtectHandleINH (cygheap->console_h); ProtectHandleINH (cygheap->console_h);

View File

@ -1171,7 +1171,8 @@ mtinfo *mt;
void __stdcall void __stdcall
mtinfo_init () mtinfo_init ()
{ {
mt = (mtinfo *) open_shared ("mtinfo", MTINFO_VERSION, cygheap->mt_h, sizeof (mtinfo), SH_MTINFO); shared_locations sh_mtinfo = SH_MTINFO;
mt = (mtinfo *) open_shared ("mtinfo", MTINFO_VERSION, cygheap->mt_h, sizeof (mtinfo), sh_mtinfo);
ProtectHandleINH (cygheap->mt_h); ProtectHandleINH (cygheap->mt_h);
mt->initialize (); mt->initialize ();
} }

View File

@ -174,6 +174,7 @@ pinfo::exit (DWORD n)
void void
pinfo::init (pid_t n, DWORD flag, HANDLE h0) pinfo::init (pid_t n, DWORD flag, HANDLE h0)
{ {
shared_locations shloc;
h = NULL; h = NULL;
if (myself && !(flag & PID_EXECED) if (myself && !(flag & PID_EXECED)
&& (n == myself->pid || (DWORD) n == myself->dwProcessId)) && (n == myself->pid || (DWORD) n == myself->dwProcessId))
@ -185,72 +186,60 @@ pinfo::init (pid_t n, DWORD flag, HANDLE h0)
void *mapaddr; void *mapaddr;
int createit = flag & (PID_IN_USE | PID_EXECED); int createit = flag & (PID_IN_USE | PID_EXECED);
bool created = false;
DWORD access = FILE_MAP_READ DWORD access = FILE_MAP_READ
| (flag & (PID_IN_USE | PID_EXECED | PID_MAP_RW) | (flag & (PID_IN_USE | PID_EXECED | PID_MAP_RW)
? FILE_MAP_WRITE : 0); ? FILE_MAP_WRITE : 0);
if (!h0) if (!h0)
mapaddr = NULL; shloc = (flag & (PID_IN_USE | PID_EXECED)) ? SH_JUSTCREATE : SH_JUSTOPEN;
else else
{ {
/* Try to enforce that myself is always created in the same place */ shloc = SH_MYSELF;
mapaddr = open_shared (NULL, 0, h0, 0, SH_MYSELF);
if (h0 == INVALID_HANDLE_VALUE) if (h0 == INVALID_HANDLE_VALUE)
h0 = NULL; h0 = NULL;
} }
procinfo = NULL; procinfo = NULL;
char sa_buf[1024];
PSECURITY_ATTRIBUTES sec_attribs = sec_user_nih (sa_buf, cygheap->user.sid(),
well_known_world_sid,
FILE_MAP_READ);
for (int i = 0; i < 20; i++) for (int i = 0; i < 20; i++)
{ {
if (!h0) DWORD mapsize;
{
char mapname[CYG_MAX_PATH];
shared_name (mapname, "cygpid", n);
int mapsize;
if (flag & PID_EXECED) if (flag & PID_EXECED)
mapsize = PINFO_REDIR_SIZE; mapsize = PINFO_REDIR_SIZE;
else else
mapsize = sizeof (_pinfo); mapsize = sizeof (_pinfo);
if (!createit) procinfo = (_pinfo *) open_shared ("cygpid", n, h0, mapsize, shloc,
{ sec_attribs, access);
h0 = OpenFileMapping (access, FALSE, mapname);
created = false;
}
else
{
char sa_buf[1024];
PSECURITY_ATTRIBUTES sec_attribs =
sec_user_nih (sa_buf, cygheap->user.sid(), well_known_world_sid,
FILE_MAP_READ);
h0 = CreateFileMapping (INVALID_HANDLE_VALUE, sec_attribs,
PAGE_READWRITE, 0, mapsize, mapname);
created = GetLastError () != ERROR_ALREADY_EXISTS;
}
if (!h0) if (!h0)
{ {
if (createit) if (createit)
__seterrno (); __seterrno ();
return; return;
} }
}
procinfo = (_pinfo *) MapViewOfFileEx (h0, access, 0, 0, 0, mapaddr);
if (!procinfo) if (!procinfo)
{ {
if (exit_state) if (exit_state)
return; return;
if (GetLastError () == ERROR_INVALID_HANDLE) switch (GetLastError ())
{
case ERROR_INVALID_HANDLE:
api_fatal ("MapViewOfFileEx h0 %p, i %d failed, %E", h0, i); api_fatal ("MapViewOfFileEx h0 %p, i %d failed, %E", h0, i);
case ERROR_INVALID_ADDRESS:
mapaddr = NULL;
}
debug_printf ("MapViewOfFileEx h0 %p, i %d failed, %E", h0, i); debug_printf ("MapViewOfFileEx h0 %p, i %d failed, %E", h0, i);
continue; continue;
} }
bool created = shloc != SH_JUSTOPEN;
if ((procinfo->process_state & PID_INITIALIZING) && (flag & PID_NOREDIR) if ((procinfo->process_state & PID_INITIALIZING) && (flag & PID_NOREDIR)
&& cygwin_pid (procinfo->dwProcessId) != procinfo->pid) && cygwin_pid (procinfo->dwProcessId) != procinfo->pid)
{ {

View File

@ -75,23 +75,20 @@ static char *offsets[] =
void * __stdcall void * __stdcall
open_shared (const char *name, int n, HANDLE& shared_h, DWORD size, open_shared (const char *name, int n, HANDLE& shared_h, DWORD size,
shared_locations m, PSECURITY_ATTRIBUTES psa) shared_locations& m, PSECURITY_ATTRIBUTES psa, DWORD access)
{ {
void *shared; void *shared;
void *addr; void *addr;
if (!wincap.needs_memory_protection () && offsets[0]) if ((m == SH_JUSTCREATE || m == SH_JUSTOPEN)
|| !wincap.needs_memory_protection () && offsets[0])
addr = NULL; addr = NULL;
else else
{
addr = offsets[m]; addr = offsets[m];
(void) VirtualFree (addr, 0, MEM_RELEASE);
}
if (!size) if (shared_h)
return addr; m = SH_JUSTOPEN;
else
if (!shared_h)
{ {
char *mapname; char *mapname;
char map_buf[CYG_MAX_PATH]; char map_buf[CYG_MAX_PATH];
@ -99,20 +96,32 @@ open_shared (const char *name, int n, HANDLE& shared_h, DWORD size,
mapname = NULL; mapname = NULL;
else else
mapname = shared_name (map_buf, name, n); mapname = shared_name (map_buf, name, n);
if (!(shared_h = CreateFileMapping (INVALID_HANDLE_VALUE, psa, if (m == SH_JUSTOPEN)
PAGE_READWRITE, 0, size, mapname))) shared_h = OpenFileMapping (access, FALSE, mapname);
else
{
shared_h = CreateFileMapping (INVALID_HANDLE_VALUE, psa, PAGE_READWRITE,
0, size, mapname);
if (GetLastError () == ERROR_ALREADY_EXISTS)
m = SH_JUSTOPEN;
}
if (shared_h)
/* ok! */;
else if (m != SH_JUSTOPEN)
api_fatal ("CreateFileMapping %s, %E. Terminating.", mapname); api_fatal ("CreateFileMapping %s, %E. Terminating.", mapname);
else
return NULL;
} }
shared = (shared_info *) shared = (shared_info *)
MapViewOfFileEx (shared_h, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0, addr); MapViewOfFileEx (shared_h, access, 0, 0, 0, addr);
if (!shared) if (!shared && addr)
{ {
/* Probably win95, so try without specifying the address. */ /* Probably win95, so try without specifying the address. */
shared = (shared_info *) MapViewOfFileEx (shared_h, shared = (shared_info *) MapViewOfFileEx (shared_h,
FILE_MAP_READ|FILE_MAP_WRITE, FILE_MAP_READ|FILE_MAP_WRITE,
0, 0, 0, 0); 0, 0, 0, NULL);
#ifdef DEBUGGING #ifdef DEBUGGING
if (wincap.is_winnt ()) if (wincap.is_winnt ())
system_printf ("relocating shared object %s(%d) from %p to %p on Windows NT", name, n, addr, shared); system_printf ("relocating shared object %s(%d) from %p to %p on Windows NT", name, n, addr, shared);
@ -165,9 +174,10 @@ user_shared_initialize (bool reinit)
if (!cygwin_user_h) if (!cygwin_user_h)
cygheap->user.get_windows_id (name); cygheap->user.get_windows_id (name);
shared_locations sh_user_shared = SH_USER_SHARED;
user_shared = (user_info *) open_shared (name, USER_VERSION, user_shared = (user_info *) open_shared (name, USER_VERSION,
cygwin_user_h, sizeof (user_info), cygwin_user_h, sizeof (user_info),
SH_USER_SHARED, &sec_none); sh_user_shared, &sec_none);
debug_printf ("opening user shared for '%s' at %p", name, user_shared); debug_printf ("opening user shared for '%s' at %p", name, user_shared);
ProtectHandleINH (cygwin_user_h); ProtectHandleINH (cygwin_user_h);
debug_printf ("user shared version %x", user_shared->version); debug_printf ("user shared version %x", user_shared->version);
@ -236,11 +246,12 @@ memory_init ()
} }
/* Initialize general shared memory */ /* Initialize general shared memory */
shared_locations sh_cygwin_shared = SH_CYGWIN_SHARED;
cygwin_shared = (shared_info *) open_shared ("shared", cygwin_shared = (shared_info *) open_shared ("shared",
CYGWIN_VERSION_SHARED_DATA, CYGWIN_VERSION_SHARED_DATA,
cygheap->shared_h, cygheap->shared_h,
sizeof (*cygwin_shared), sizeof (*cygwin_shared),
SH_CYGWIN_SHARED); sh_cygwin_shared);
cygwin_shared->initialize (); cygwin_shared->initialize ();
ProtectHandleINH (cygheap->shared_h); ProtectHandleINH (cygheap->shared_h);

View File

@ -173,7 +173,10 @@ enum shared_locations
SH_SHARED_CONSOLE, SH_SHARED_CONSOLE,
SH_MYSELF, SH_MYSELF,
SH_MTINFO, SH_MTINFO,
SH_TOTAL_SIZE SH_TOTAL_SIZE,
SH_JUSTCREATE,
SH_JUSTOPEN
}; };
void __stdcall memory_init (); void __stdcall memory_init ();
@ -182,7 +185,7 @@ void __stdcall memory_init ();
(((DWORD) ((p) + 1) + system_info.dwAllocationGranularity - 1) / \ (((DWORD) ((p) + 1) + system_info.dwAllocationGranularity - 1) / \
system_info.dwAllocationGranularity))) system_info.dwAllocationGranularity)))
#define cygwin_shared_address ((void *) 0xa000000) #define cygwin_shared_address ((void *) 0x60000000)
#ifdef _FHANDLER_H_ #ifdef _FHANDLER_H_
struct console_state struct console_state
@ -194,6 +197,7 @@ struct console_state
char *__stdcall shared_name (char *, const char *, int); char *__stdcall shared_name (char *, const char *, int);
void *__stdcall open_shared (const char *name, int n, HANDLE &shared_h, DWORD size, void *__stdcall open_shared (const char *name, int n, HANDLE &shared_h, DWORD size,
shared_locations, PSECURITY_ATTRIBUTES psa = &sec_all); shared_locations&, PSECURITY_ATTRIBUTES psa = &sec_all,
DWORD access = FILE_MAP_READ | FILE_MAP_WRITE);
extern void user_shared_initialize (bool reinit); extern void user_shared_initialize (bool reinit);