diff options
-rw-r--r-- | winsup/cygwin/ChangeLog | 35 | ||||
-rw-r--r-- | winsup/cygwin/child_info.h | 10 | ||||
-rw-r--r-- | winsup/cygwin/cygheap.cc | 7 | ||||
-rw-r--r-- | winsup/cygwin/dcrt0.cc | 4 | ||||
-rw-r--r-- | winsup/cygwin/dll_init.cc | 8 | ||||
-rw-r--r-- | winsup/cygwin/dtable.cc | 12 | ||||
-rw-r--r-- | winsup/cygwin/dtable.h | 2 | ||||
-rw-r--r-- | winsup/cygwin/exceptions.cc | 2 | ||||
-rw-r--r-- | winsup/cygwin/fhandler_console.cc | 8 | ||||
-rw-r--r-- | winsup/cygwin/fork.cc | 3 | ||||
-rw-r--r-- | winsup/cygwin/include/sys/cygwin.h | 3 | ||||
-rw-r--r-- | winsup/cygwin/pinfo.cc | 22 | ||||
-rw-r--r-- | winsup/cygwin/pinfo.h | 1 | ||||
-rw-r--r-- | winsup/cygwin/shared.cc | 8 | ||||
-rw-r--r-- | winsup/cygwin/shared_info.h | 2 |
15 files changed, 95 insertions, 32 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index f9c2b89..80325cc 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,38 @@ +2002-10-14 Christopher Faylor <cgf@redhat.com> + + * child_info.h (CURR_CHILD_INFO_MAGIC): Reset. + (child_info_fork::heaptop): Remove obsolete element. + (child_info_fork::heabbase): Ditto. + (child_info_fork::heapptr): Ditto. + (child_info_fork::mount_table): New element. + (child_info_fork::myself_addr): Ditto. + * dcrt0.cc (dll_crt0_1): Set mount_table and myself_addr when forking. + (initial_env): Add newline to "sleeping" message. + * dll_init.cc (reserve_upto): Accommodate cygwin heap when freeing + memory. Make debugging output a little more descriptive. + * fork.cc (fork_parent): Save mount_table and myself_addr. + * pinfo.cc (myself_addr): New variable. + (set_myself): Pass PID_MYSELF flag to init. + (pinfo::Init): Honor PID_MYSELF. Save address where myself shared + memory resides in myself_addr, for fork. + * pinfo.h (myself_addr): Declare. + * shared.cc (memory_init): On fork, use previously saved address for + location of mount table. + * include/sys/cygwin.h (PID_MYSELF): New value. + + * dtable.cc (dtable::stdio_init): Don't pass access type to + init_std_file_from_handle. It's always the same. + (dtable::init_std_file_from_handle): Remove access type argument. + Assume read/write. + * dtable.h (dtable::init_std_file_from_handle): Ditto for declaration. + + * exceptions.cc (try_to_debug): Don't try to debug if already being + debugged. + + * fhandler_console.cc (shared_console_info_save): New variable. + (fhandler_console::get_tty_stuff): Save address of shared console stuff + for fork. + 2002-10-13 Christopher Faylor <cgf@redhat.com> * cygthread.cc (cygthread::stub): Reintroduce clearing of __name but do diff --git a/winsup/cygwin/child_info.h b/winsup/cygwin/child_info.h index 1aca724..4cc09b7 100644 --- a/winsup/cygwin/child_info.h +++ b/winsup/cygwin/child_info.h @@ -29,7 +29,7 @@ enum #define EXEC_MAGIC_SIZE sizeof(child_info) -#define CURR_CHILD_INFO_MAGIC 0xb3836013U +#define CURR_CHILD_INFO_MAGIC 0x64848c11U /* NOTE: Do not make gratuitous changes to the names or organization of the below class. The layout is checksummed to determine compatibility between @@ -53,14 +53,16 @@ public: unsigned fhandler_union_cb; }; +class mount_info; +class _pinfo; + class child_info_fork: public child_info { public: HANDLE forker_finished;// for synchronization with child DWORD stacksize; // size of parent stack - void *heaptop; - void *heapbase; - void *heapptr; + mount_info *mount_table;// location of mount table in parent + _pinfo *myself_addr; // where myself shared memory lives in the parent jmp_buf jmp; // where child will jump to void *stacktop; // location of top of parent stack void *stackbottom; // location of bottom of parent stack diff --git a/winsup/cygwin/cygheap.cc b/winsup/cygwin/cygheap.cc index d3d1bd6..e4ea673 100644 --- a/winsup/cygwin/cygheap.cc +++ b/winsup/cygwin/cygheap.cc @@ -25,9 +25,9 @@ #include "shared_info.h" init_cygheap NO_COPY *cygheap; -void NO_COPY *cygheap_max = NULL; +void NO_COPY *cygheap_max; -static NO_COPY muto *cygheap_protect = NULL; +static NO_COPY muto *cygheap_protect; struct cygheap_entry { @@ -63,7 +63,7 @@ init_cheap () cygheap_max = cygheap; } -// static void dup_now (void *, child_info *, unsigned) __attribute__ ((regparm(3))); +static void dup_now (void *, child_info *, unsigned) __attribute__ ((regparm(3))); static void dup_now (void *newcygheap, child_info *ci, unsigned n) { @@ -78,7 +78,6 @@ cygheap_setup_for_child (child_info *ci, bool dup_later) { void *newcygheap; cygheap_protect->acquire (); -if (!ci) try_to_debug (); unsigned n = (char *) cygheap_max - (char *) cygheap; unsigned size = CYGHEAPSIZE; if (size < n) diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index 36442fc..e7babe0 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -581,6 +581,8 @@ dll_crt0_1 () case _PROC_FORK: cygheap_fixup_in_child (0); alloc_stack (fork_info); + mount_table = fork_info->mount_table; + myself_addr = fork_info->myself_addr; set_myself (mypid); close_ppid_handle = !!child_proc_info->pppid_handle; break; @@ -793,7 +795,7 @@ initial_env () DWORD ms = atoi (buf); buf[0] = '\0'; len = GetModuleFileName (NULL, buf, MAX_PATH); - console_printf ("Sleeping %d, pid %u %s", ms, GetCurrentProcessId (), buf); + console_printf ("Sleeping %d, pid %u %s\n", ms, GetCurrentProcessId (), buf); Sleep (ms); } if (GetEnvironmentVariable ("CYGWIN_DEBUG", buf, sizeof (buf) - 1)) diff --git a/winsup/cygwin/dll_init.cc b/winsup/cygwin/dll_init.cc index ea4265e..592381c 100644 --- a/winsup/cygwin/dll_init.cc +++ b/winsup/cygwin/dll_init.cc @@ -231,7 +231,7 @@ reserve_upto (const char *name, DWORD here) MEMORY_BASIC_INFORMATION mb; for (DWORD start = 0x10000; start < here; start += size) if (!VirtualQuery ((void *) start, &mb, sizeof (mb))) - size = 64 * 1024; + size = A64K; else { size = A64K * ((mb.RegionSize + A64K - 1) / A64K); @@ -261,7 +261,8 @@ release_upto (const char *name, DWORD here) { size = mb.RegionSize; if (!(mb.State == MEM_RESERVE && mb.AllocationProtect == PAGE_NOACCESS && - ((void *) start < cygheap->heapbase || (void *) start > cygheap->heaptop))) + (((void *) start < cygheap->heapbase || (void *) start > cygheap->heaptop) && + ((void *) start < (void *) cygheap || (void *) start > (void *) ((char *) cygheap + CYGHEAPSIZE))))) continue; if (!VirtualFree ((void *) start, 0, MEM_RELEASE)) api_fatal ("couldn't release memory %p(%d) for '%s' alignment, %E\n", @@ -307,7 +308,8 @@ dll_list::load_after_fork (HANDLE parent, dll *first) LoadLibrary (d.name); } else if (try2) - api_fatal ("unable to remap %s to same address as parent -- %p", d.name, h); + api_fatal ("unable to remap %s to same address as parent(%p) != %p", + d.name, d.handle, h); else { /* It loaded in the wrong place. Dunno why this happens but it always diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc index d18f99b..6b5ee88 100644 --- a/winsup/cygwin/dtable.cc +++ b/winsup/cygwin/dtable.cc @@ -139,7 +139,7 @@ dtable::stdio_init () HANDLE out = GetStdHandle (STD_OUTPUT_HANDLE); HANDLE err = GetStdHandle (STD_ERROR_HANDLE); - init_std_file_from_handle (0, in, GENERIC_READ); + init_std_file_from_handle (0, in); /* STD_ERROR_HANDLE has been observed to be the same as STD_OUTPUT_HANDLE. We need separate handles (e.g. using pipes @@ -157,8 +157,8 @@ dtable::stdio_init () } } - init_std_file_from_handle (1, out, GENERIC_WRITE); - init_std_file_from_handle (2, err, GENERIC_WRITE); + init_std_file_from_handle (1, out); + init_std_file_from_handle (2, err); /* Assign the console as the controlling tty for this process if we actually have a console and no other controlling tty has been assigned. */ if (myself->ctty < 0 && GetConsoleCP () > 0) @@ -213,7 +213,7 @@ cygwin_attach_handle_to_fd (char *name, int fd, HANDLE handle, mode_t bin, } void -dtable::init_std_file_from_handle (int fd, HANDLE handle, DWORD myaccess) +dtable::init_std_file_from_handle (int fd, HANDLE handle) { const char *name; CONSOLE_SCREEN_BUFFER_INFO buf; @@ -269,11 +269,11 @@ dtable::init_std_file_from_handle (int fd, HANDLE handle, DWORD myaccess) path_conv pc; unsigned bin; fhandler_base *fh = build_fhandler_from_name (fd, name, handle, pc); - bin = fh->get_default_fmode (myaccess == GENERIC_READ ? O_RDONLY : O_WRONLY); + bin = fh->get_default_fmode (O_RDWR); if (!bin && name != unknown_file) bin = pc.binmode (); - fh->init (handle, myaccess, bin); + fh->init (handle, GENERIC_READ | GENERIC_WRITE, bin); set_std_handle (fd); paranoid_printf ("fd %d, handle %p", fd, handle); } diff --git a/winsup/cygwin/dtable.h b/winsup/cygwin/dtable.h index 5a8f569..c481810 100644 --- a/winsup/cygwin/dtable.h +++ b/winsup/cygwin/dtable.h @@ -68,7 +68,7 @@ public: int find_unused_handle (int start); int find_unused_handle () { return find_unused_handle (first_fd_for_open);} void release (int fd); - void init_std_file_from_handle (int fd, HANDLE handle, DWORD access); + void init_std_file_from_handle (int fd, HANDLE handle); int dup2 (int oldfd, int newfd); void fixup_after_exec (HANDLE); inline fhandler_base *operator [](int fd) const { return fds[fd]; } diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc index 9854c10..4e18e27 100644 --- a/winsup/cygwin/exceptions.cc +++ b/winsup/cygwin/exceptions.cc @@ -338,7 +338,7 @@ extern "C" int try_to_debug (bool waitloop) { debug_printf ("debugger_command '%s'", debugger_command); - if (*debugger_command == '\0') + if (*debugger_command == '\0' || being_debugged ()) return 0; __small_sprintf (strchr (debugger_command, '\0'), " %u", GetCurrentProcessId ()); diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc index 4b7c2da..a43dad1 100644 --- a/winsup/cygwin/fhandler_console.cc +++ b/winsup/cygwin/fhandler_console.cc @@ -91,7 +91,8 @@ struct console_state dev_console dev_state; }; -static console_state NO_COPY *shared_console_info = NULL; +static console_state NO_COPY *shared_console_info; +static console_state *shared_console_info_save; dev_console NO_COPY *fhandler_console::dev_state; @@ -103,9 +104,10 @@ fhandler_console::get_tty_stuff (int flags = 0) if (dev_state) return &shared_console_info->tty_min_state; - shared_console_info = + shared_console_info = shared_console_info_save = (console_state *) open_shared (NULL, 0, cygheap->console_h, - sizeof (*shared_console_info), NULL); + sizeof (*shared_console_info), + shared_console_info_save); dev_state = &shared_console_info->dev_state; ProtectHandleINH (cygheap->console_h); diff --git a/winsup/cygwin/fork.cc b/winsup/cygwin/fork.cc index 92e3803..f104e41 100644 --- a/winsup/cygwin/fork.cc +++ b/winsup/cygwin/fork.cc @@ -28,6 +28,7 @@ details. */ #include "perprocess.h" #include "dll_init.h" #include "sync.h" +#include "shared_info.h" #include "cygmalloc.h" #ifdef DEBUGGING @@ -421,6 +422,8 @@ fork_parent (HANDLE& hParent, dll *&first_dll, init_child_info (PROC_FORK, &ch, 1, subproc_ready); ch.forker_finished = forker_finished; + ch.mount_table = mount_table; + ch.myself_addr = myself_addr; stack_base (ch); diff --git a/winsup/cygwin/include/sys/cygwin.h b/winsup/cygwin/include/sys/cygwin.h index f8feda4..b912811 100644 --- a/winsup/cygwin/include/sys/cygwin.h +++ b/winsup/cygwin/include/sys/cygwin.h @@ -88,8 +88,7 @@ enum PID_CYGPARENT = 0x0080, // Set if parent was a cygwin app. PID_SPLIT_HEAP = 0x0100, // Set if the heap has been split, // which means we can't fork again. - PID_UNUSED = 0x0200, // Flag that pid should be cleared from parent's - // wait list + PID_MYSELF = 0x0200, // Flag that pid is me. PID_UNUSED1 = 0x0400, // Set if process uses Winsock. PID_INITIALIZING = 0x0800, // Set until ready to receive signals. PID_USETTY = 0x1000, // Setting this enables or disables cygwin's diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc index e9716de..3495454 100644 --- a/winsup/cygwin/pinfo.cc +++ b/winsup/cygwin/pinfo.cc @@ -33,6 +33,7 @@ static char NO_COPY pinfo_dummy[sizeof (_pinfo)] = {0}; pinfo NO_COPY myself ((_pinfo *)&pinfo_dummy); // Avoid myself != NULL checks HANDLE hexec_proc; +_pinfo NO_COPY *myself_addr; void __stdcall pinfo_fixup_after_fork () @@ -57,7 +58,7 @@ set_myself (pid_t pid, HANDLE h) DWORD winpid = GetCurrentProcessId (); if (pid == 1) pid = cygwin_pid (winpid); - myself.init (pid, 1, h); + myself.init (pid, PID_IN_USE | PID_MYSELF, h); myself->dwProcessId = winpid; myself->process_state |= PID_IN_USE; myself->start_time = time (NULL); /* Register our starting time. */ @@ -126,6 +127,20 @@ pinfo::init (pid_t n, DWORD flag, HANDLE in_h) return; } + void *mapaddr; + bool itsme; + if (!(flag & PID_MYSELF)) + { + mapaddr = NULL; + itsme = false; + } + else + { + flag &= ~PID_MYSELF; + mapaddr = myself_addr; + itsme = true; + } + int createit = flag & (PID_IN_USE | PID_EXECED); for (int i = 0; i < 10; i++) { @@ -164,8 +179,11 @@ pinfo::init (pid_t n, DWORD flag, HANDLE in_h) return; } - procinfo = (_pinfo *) MapViewOfFile (h, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0); + procinfo = (_pinfo *) MapViewOfFileEx (h, FILE_MAP_READ | FILE_MAP_WRITE, + 0, 0, 0, mapaddr); ProtectHandle1 (h, pinfo_shared_handle); + if (itsme) + myself_addr = procinfo; if ((procinfo->process_state & PID_INITIALIZING) && (flag & PID_NOREDIR) && cygwin_pid (procinfo->dwProcessId) != procinfo->pid) diff --git a/winsup/cygwin/pinfo.h b/winsup/cygwin/pinfo.h index dcb814b..f99b6aa 100644 --- a/winsup/cygwin/pinfo.h +++ b/winsup/cygwin/pinfo.h @@ -202,6 +202,7 @@ cygwin_pid (pid_t pid) void __stdcall pinfo_init (char **, int); void __stdcall set_myself (pid_t pid, HANDLE h = NULL); extern pinfo myself; +extern _pinfo *myself_addr; #define _P_VFORK 0 extern void __stdcall pinfo_fixup_after_fork (); diff --git a/winsup/cygwin/shared.cc b/winsup/cygwin/shared.cc index 1319a88..61ec95e 100644 --- a/winsup/cygwin/shared.cc +++ b/winsup/cygwin/shared.cc @@ -27,8 +27,8 @@ details. */ #include "registry.h" #include "cygwin_version.h" -shared_info NO_COPY *cygwin_shared = NULL; -mount_info NO_COPY *mount_table = NULL; +shared_info NO_COPY *cygwin_shared; +mount_info NO_COPY *mount_table; HANDLE NO_COPY cygwin_mount_h; char * __stdcall @@ -145,8 +145,8 @@ memory_init () getpagesize (); heap_init (); mount_table = (mount_info *) open_shared (user_name, MOUNT_VERSION, - cygwin_mount_h, - sizeof (mount_info), 0); + cygwin_mount_h, sizeof (mount_info), + mount_table); debug_printf ("opening mount table for '%s' at %p", cygheap->user.name (), mount_table_address); ProtectHandleINH (cygwin_mount_h); diff --git a/winsup/cygwin/shared_info.h b/winsup/cygwin/shared_info.h index 2da3293..232575b 100644 --- a/winsup/cygwin/shared_info.h +++ b/winsup/cygwin/shared_info.h @@ -161,7 +161,7 @@ extern shared_info *cygwin_shared; extern mount_info *mount_table; extern HANDLE cygwin_mount_h; -void __stdcall memory_init (void); +void __stdcall memory_init (); #define shared_align_past(p) \ ((char *) (system_info.dwAllocationGranularity * \ |