* include/sys/cygwin.h: Protect class definitions.

This commit is contained in:
Christopher Faylor 2000-08-23 14:53:25 +00:00
parent 644b7f266b
commit c19e7ba723
8 changed files with 42 additions and 12 deletions

View File

@ -1,3 +1,7 @@
Wed Aug 23 10:51:57 2000 Christopher Faylor <cgf@cygnus.com>
* include/sys/cygwin.h: Protect class definitions.
Tue Aug 22 13:57:36 2000 Christopher Faylor <cgf@cygnus.com> Tue Aug 22 13:57:36 2000 Christopher Faylor <cgf@cygnus.com>
* path.cc (symlink_info::check): Clear error on each iteration of * path.cc (symlink_info::check): Clear error on each iteration of

View File

@ -666,7 +666,7 @@ dll_crt0_1 ()
// should be blocked. // should be blocked.
if (mypid) if (mypid)
set_myself ((pid_t) mypid); set_myself ((pid_t) mypid, NULL);
(void) SetErrorMode (SEM_FAILCRITICALERRORS); (void) SetErrorMode (SEM_FAILCRITICALERRORS);
@ -834,6 +834,7 @@ _dll_crt0 ()
DuplicateHandle (hMainProc, GetCurrentThread (), hMainProc, DuplicateHandle (hMainProc, GetCurrentThread (), hMainProc,
&hMainThread, 0, FALSE, DUPLICATE_SAME_ACCESS); &hMainThread, 0, FALSE, DUPLICATE_SAME_ACCESS);
HANDLE h;
GetStartupInfo (&si); GetStartupInfo (&si);
if (si.cbReserved2 >= EXEC_MAGIC_SIZE && if (si.cbReserved2 >= EXEC_MAGIC_SIZE &&
memcmp (ciresrv->zero, zeros, sizeof (zeros)) == 0) memcmp (ciresrv->zero, zeros, sizeof (zeros)) == 0)
@ -868,6 +869,14 @@ _dll_crt0 ()
case PROC_EXEC: case PROC_EXEC:
case PROC_SPAWN: case PROC_SPAWN:
info = si.lpReserved2 + ciresrv->cb; info = si.lpReserved2 + ciresrv->cb;
if (child_proc_info->myself_pinfo &&
DuplicateHandle (hMainProc, child_proc_info->myself_pinfo,
hMainProc, &h, 0, 0,
DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE))
{
set_myself (mypid, h);
mypid = 0;
}
break; break;
case PROC_FORK: case PROC_FORK:
case PROC_FORK1: case PROC_FORK1:

View File

@ -109,8 +109,10 @@ enum
SIZEOF_PER_PROCESS) to make sure you remember to make the adjustment. SIZEOF_PER_PROCESS) to make sure you remember to make the adjustment.
*/ */
#ifdef __cplusplus
class ResourceLocks; class ResourceLocks;
class MTinterface; class MTinterface;
#endif
struct per_process struct per_process
{ {

View File

@ -30,17 +30,17 @@ static pinfo NO_COPY myself_identity ((_pinfo *)&pinfo_dummy);
This is done once when the dll is first loaded. */ This is done once when the dll is first loaded. */
void __stdcall void __stdcall
set_myself (pid_t pid) set_myself (pid_t pid, HANDLE h)
{ {
DWORD winpid = GetCurrentProcessId (); DWORD winpid = GetCurrentProcessId ();
if (pid == 1) if (pid == 1)
pid = cygwin_pid (winpid); pid = cygwin_pid (winpid);
myself.init (pid, 1); myself.init (pid, 1, h);
myself->dwProcessId = winpid; myself->dwProcessId = winpid;
myself->process_state |= PID_IN_USE; myself->process_state |= PID_IN_USE;
myself->start_time = time (NULL); /* Register our starting time. */ myself->start_time = time (NULL); /* Register our starting time. */
pid_t myself_cyg_pid = cygwin_pid (myself->dwProcessId); pid_t myself_cyg_pid = cygwin_pid (myself->dwProcessId);
if (pid != myself_cyg_pid) if (pid != myself_cyg_pid && parent_alive)
myself_identity.init (myself_cyg_pid, PID_EXECED); myself_identity.init (myself_cyg_pid, PID_EXECED);
char buf[30]; char buf[30];
@ -95,7 +95,7 @@ pinfo_init (LPBYTE info)
{ {
/* Invent our own pid. */ /* Invent our own pid. */
set_myself (1); set_myself (1, NULL);
myself->ppid = 1; myself->ppid = 1;
myself->pgid = myself->sid = myself->pid; myself->pgid = myself->sid = myself->pid;
myself->ctty = -1; myself->ctty = -1;
@ -197,7 +197,7 @@ _pinfo::record_death ()
} }
void void
pinfo::init (pid_t n, DWORD create) pinfo::init (pid_t n, DWORD create, HANDLE in_h)
{ {
if (n == myself->pid) if (n == myself->pid)
{ {
@ -217,7 +217,12 @@ pinfo::init (pid_t n, DWORD create)
else else
mapsize = sizeof (_pinfo); mapsize = sizeof (_pinfo);
if (!create) if (in_h)
{
h = in_h;
created = 0;
}
else if (!create)
{ {
/* CGF FIXME -- deal with inheritance after an exec */ /* CGF FIXME -- deal with inheritance after an exec */
h = OpenFileMappingA (FILE_MAP_READ | FILE_MAP_WRITE, FALSE, mapname); h = OpenFileMappingA (FILE_MAP_READ | FILE_MAP_WRITE, FALSE, mapname);
@ -225,7 +230,7 @@ pinfo::init (pid_t n, DWORD create)
} }
else else
{ {
h = CreateFileMapping ((HANDLE) 0xffffffff, &sec_none_nih, h = CreateFileMapping ((HANDLE) 0xffffffff, &sec_all_nih,
PAGE_READWRITE, 0, mapsize, mapname); PAGE_READWRITE, 0, mapsize, mapname);
created = h && GetLastError () != ERROR_ALREADY_EXISTS; created = h && GetLastError () != ERROR_ALREADY_EXISTS;
} }
@ -238,11 +243,13 @@ pinfo::init (pid_t n, DWORD create)
return; return;
} }
ProtectHandle1 (h, pinfo_shared_handle);
child = (_pinfo *) MapViewOfFile (h, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0); child = (_pinfo *) MapViewOfFile (h, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0);
if (child->process_state & PID_EXECED) if (child->process_state & PID_EXECED)
{ {
pid_t realpid = child->pid; pid_t realpid = child->pid;
debug_printf ("execed process windows pid %d, cygwin pid %d", n, realpid);
release (); release ();
if (realpid == n) if (realpid == n)
api_fatal ("retrieval of execed process info for pid %d failed due to recursion.", n); api_fatal ("retrieval of execed process info for pid %d failed due to recursion.", n);

View File

@ -117,7 +117,7 @@ class pinfo
_pinfo *child; _pinfo *child;
int destroy; int destroy;
public: public:
void init (pid_t n, DWORD create = 0); void init (pid_t n, DWORD create = 0, HANDLE h = NULL);
pinfo () {} pinfo () {}
pinfo (_pinfo *x): child (x) {} pinfo (_pinfo *x): child (x) {}
pinfo (pid_t n) {init (n);} pinfo (pid_t n) {init (n);}
@ -127,7 +127,7 @@ public:
if (h) if (h)
{ {
UnmapViewOfFile (child); UnmapViewOfFile (child);
CloseHandle (h); ForceCloseHandle1 (h, pinfo_shared_handle);
h = NULL; h = NULL;
} }
} }
@ -145,7 +145,9 @@ public:
int operator == (char *x) const {return (char *) child == x;} int operator == (char *x) const {return (char *) child == x;}
_pinfo *operator * () const {return child;} _pinfo *operator * () const {return child;}
operator _pinfo * () const {return child;} operator _pinfo * () const {return child;}
// operator bool () const {return (int) h;}
void remember () {destroy = 0; proc_subproc (PROC_ADDCHILD, (DWORD) this);} void remember () {destroy = 0; proc_subproc (PROC_ADDCHILD, (DWORD) this);}
HANDLE shared_handle () {return h;}
}; };
#define ISSTATE(p, f) (!!((p)->process_state & f)) #define ISSTATE(p, f) (!!((p)->process_state & f))
@ -168,5 +170,7 @@ cygwin_pid (pid_t pid)
{ {
return (pid_t) (os_being_run == winNT) ? pid : -(int) pid; return (pid_t) (os_being_run == winNT) ? pid : -(int) pid;
} }
void __stdcall pinfo_init (PBYTE);
void __stdcall pinfo_init (BYTE *);
void __stdcall set_myself (pid_t pid, HANDLE h = NULL);
extern pinfo myself; extern pinfo myself;

View File

@ -67,6 +67,7 @@ public:
HANDLE shared_h; HANDLE shared_h;
HANDLE console_h; HANDLE console_h;
HANDLE parent_alive; // handle of thread used to track children HANDLE parent_alive; // handle of thread used to track children
HANDLE myself_pinfo;
}; };
class child_info_fork: public child_info class child_info_fork: public child_info

View File

@ -494,6 +494,10 @@ skip_arg_parsing:
} }
init_child_info (chtype, ciresrv, (mode == _P_OVERLAY) ? myself->pid : 1, spr); init_child_info (chtype, ciresrv, (mode == _P_OVERLAY) ? myself->pid : 1, spr);
if (mode != _P_OVERLAY ||
!DuplicateHandle (hMainProc, myself.shared_handle (), hMainProc, &ciresrv->myself_pinfo, 0,
TRUE, DUPLICATE_SAME_ACCESS))
ciresrv->myself_pinfo = NULL;
LPBYTE resrv = si.lpReserved2 + sizeof *ciresrv; LPBYTE resrv = si.lpReserved2 + sizeof *ciresrv;
# undef ciresrv # undef ciresrv

View File

@ -283,7 +283,6 @@ long __stdcall to_time_t (FILETIME * ptr);
int __stdcall lock_pinfo_for_update (DWORD timeout); int __stdcall lock_pinfo_for_update (DWORD timeout);
#endif #endif
void unlock_pinfo (void); void unlock_pinfo (void);
void _stdcall set_myself (pid_t pid);
/* Retrieve a security descriptor that allows all access */ /* Retrieve a security descriptor that allows all access */
SECURITY_DESCRIPTOR *__stdcall get_null_sd (void); SECURITY_DESCRIPTOR *__stdcall get_null_sd (void);