(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-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
#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
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
#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
{
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)
{
{
void *newcygheap;
cygheap_protect->acquire ();
-if (!ci) try_to_debug ();
unsigned n = (char *) cygheap_max - (char *) cygheap;
unsigned size = CYGHEAPSIZE;
if (size < n)
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;
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))
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);
{
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",
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
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
}
}
- 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)
}
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;
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);
}
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]; }
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 ());
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;
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);
#include "perprocess.h"
#include "dll_init.h"
#include "sync.h"
+#include "shared_info.h"
#include "cygmalloc.h"
#ifdef DEBUGGING
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);
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
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 ()
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. */
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++)
{
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)
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 ();
#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
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);
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 * \