diff options
author | cvs2svn <> | 2002-09-22 16:04:16 +0400 |
---|---|---|
committer | cvs2svn <> | 2002-09-22 16:04:16 +0400 |
commit | b9fbe9492e000511d0b2b7db6b81c0fc98ab6f80 (patch) | |
tree | 9bc675d4928360fc4998eb5a43727fd1a4ce427d /winsup/cygwin/cygheap.cc | |
parent | 9783ce28caf426c5ab39d1d6aefa31cfdb1b8234 (diff) |
This commit was manufactured by cvs2svn to create tag 'ZZ-cygwin_daemon_merge-new_HEAD
-cygwin_daemon_merge-new_HEAD'.
Sprout from cygwin_daemon 2002-01-02 00:06:36 UTC cvs2svn 'This commit was manufactured by cvs2svn to create branch 'cygwin_daemon'.'
Cherrypick from cygwin_daemon 2002-02-25 17:47:52 UTC cvs2svn 'This commit was manufactured by cvs2svn to create branch 'cygwin_daemon'.':
winsup/cygwin/how-spawn-works.txt
winsup/cygwin/wsock_event.h
Cherrypick from cygwin_daemon 2002-06-06 15:35:10 UTC cvs2svn 'This commit was manufactured by cvs2svn to create branch 'cygwin_daemon'.':
winsup/cygwin/include/netinet/udp.h
winsup/cygwin/stackdump.sgml
Cherrypick from cygwin_daemon 2002-01-17 10:39:38 UTC cvs2svn 'This commit was manufactured by cvs2svn to create branch 'cygwin_daemon'.':
winsup/cygwin/libc/fnmatch.c
Cherrypick from cygwin_daemon 2002-07-03 20:31:40 UTC cvs2svn 'This commit was manufactured by cvs2svn to create branch 'cygwin_daemon'.':
winsup/cygwin/include/sys/statfs.h
Cherrypick from cygwin_daemon 2002-09-04 15:17:25 UTC cvs2svn 'This commit was manufactured by cvs2svn to create branch 'cygwin_daemon'.':
winsup/cygwin/how-autoload-works.txt
Cherrypick from master 2002-09-22 12:04:15 UTC Conrad Scott <conrad.scott@dsl.pipex.com> '2002-09-22 Conrad Scott <conrad.scott@dsl.pipex.com>':
winsup/cygserver/threaded_queue.cc
winsup/cygserver/woutsup.h
winsup/cygwin/CYGWIN_LICENSE
winsup/cygwin/ChangeLog
winsup/cygwin/ChangeLog-1998
winsup/cygwin/ChangeLog-1999
winsup/cygwin/ChangeLog-2000
winsup/cygwin/Makefile.in
winsup/cygwin/assert.cc
winsup/cygwin/autoload.cc
winsup/cygwin/child_info.h
winsup/cygwin/configure
winsup/cygwin/configure.in
winsup/cygwin/cygerrno.h
winsup/cygwin/cygheap.cc
winsup/cygwin/cygheap.h
winsup/cygwin/cygmagic
winsup/cygwin/cygmalloc.h
winsup/cygwin/cygrun.c
winsup/cygwin/cygserver.cc
winsup/cygwin/cygserver_client.cc
winsup/cygwin/cygserver_ipc.h
winsup/cygwin/cygserver_process.cc
winsup/cygwin/cygserver_shm.cc
winsup/cygwin/cygserver_shm.h
winsup/cygwin/cygserver_transport.cc
winsup/cygwin/cygserver_transport_pipes.cc
winsup/cygwin/cygserver_transport_sockets.cc
winsup/cygwin/cygthread.cc
winsup/cygwin/cygthread.h
winsup/cygwin/cygwin.din
winsup/cygwin/cygwin.sc
winsup/cygwin/dcrt0.cc
winsup/cygwin/debug.cc
winsup/cygwin/debug.h
winsup/cygwin/dir.cc
winsup/cygwin/dlfcn.cc
winsup/cygwin/dll_init.cc
winsup/cygwin/dll_init.h
winsup/cygwin/dlmalloc.c
winsup/cygwin/dtable.cc
winsup/cygwin/dtable.h
winsup/cygwin/environ.cc
winsup/cygwin/environ.h
winsup/cygwin/errno.cc
winsup/cygwin/exceptions.cc
winsup/cygwin/exec.cc
winsup/cygwin/external.cc
winsup/cygwin/fcntl.cc
winsup/cygwin/fhandler.cc
winsup/cygwin/fhandler.h
winsup/cygwin/fhandler_clipboard.cc
winsup/cygwin/fhandler_console.cc
winsup/cygwin/fhandler_disk_file.cc
winsup/cygwin/fhandler_dsp.cc
winsup/cygwin/fhandler_floppy.cc
winsup/cygwin/fhandler_mem.cc
winsup/cygwin/fhandler_proc.cc
winsup/cygwin/fhandler_process.cc
winsup/cygwin/fhandler_random.cc
winsup/cygwin/fhandler_raw.cc
winsup/cygwin/fhandler_registry.cc
winsup/cygwin/fhandler_serial.cc
winsup/cygwin/fhandler_socket.cc
winsup/cygwin/fhandler_tape.cc
winsup/cygwin/fhandler_termios.cc
winsup/cygwin/fhandler_tty.cc
winsup/cygwin/fhandler_virtual.cc
winsup/cygwin/fhandler_windows.cc
winsup/cygwin/fhandler_zero.cc
winsup/cygwin/fork.cc
winsup/cygwin/glob.c
winsup/cygwin/gmon.c
winsup/cygwin/grp.cc
winsup/cygwin/heap.cc
winsup/cygwin/heap.h
winsup/cygwin/hires.h
winsup/cygwin/how-cygheap-works.txt
winsup/cygwin/how-fhandlers-work.txt
winsup/cygwin/how-signals-work.txt
winsup/cygwin/how-to-debug-cygwin.txt
winsup/cygwin/include/cygwin/acl.h
winsup/cygwin/include/cygwin/cygserver.h
winsup/cygwin/include/cygwin/cygserver_process.h
winsup/cygwin/include/cygwin/cygserver_transport.h
winsup/cygwin/include/cygwin/cygserver_transport_pipes.h
winsup/cygwin/include/cygwin/cygserver_transport_sockets.h
winsup/cygwin/include/cygwin/grp.h
winsup/cygwin/include/cygwin/if.h
winsup/cygwin/include/cygwin/ipc.h
winsup/cygwin/include/cygwin/msg.h
winsup/cygwin/include/cygwin/mtio.h
winsup/cygwin/include/cygwin/sem.h
winsup/cygwin/include/cygwin/shm.h
winsup/cygwin/include/cygwin/socket.h
winsup/cygwin/include/cygwin/stat.h
winsup/cygwin/include/cygwin/types.h
winsup/cygwin/include/cygwin/version.h
winsup/cygwin/include/fnmatch.h
winsup/cygwin/include/getopt.h
winsup/cygwin/include/glob.h
winsup/cygwin/include/limits.h
winsup/cygwin/include/netdb.h
winsup/cygwin/include/netinet/ip.h
winsup/cygwin/include/netinet/tcp.h
winsup/cygwin/include/pthread.h
winsup/cygwin/include/sys/cygwin.h
winsup/cygwin/include/sys/ioctl.h
winsup/cygwin/include/sys/mount.h
winsup/cygwin/include/sys/resource.h
winsup/cygwin/include/sys/socket.h
winsup/cygwin/include/sys/soundcard.h
winsup/cygwin/include/sys/strace.h
winsup/cygwin/include/sys/sysmacros.h
winsup/cygwin/include/sys/termios.h
winsup/cygwin/include/sys/uio.h
winsup/cygwin/include/sys/un.h
winsup/cygwin/include/sys/vfs.h
winsup/cygwin/init.cc
winsup/cygwin/ioctl.cc
winsup/cygwin/ipc.cc
winsup/cygwin/lib/cygwin_crt0.c
winsup/cygwin/lib/dll_main.cc
winsup/cygwin/lib/getopt.c
winsup/cygwin/localtime.cc
winsup/cygwin/malloc.cc
winsup/cygwin/malloc_wrapper.cc
winsup/cygwin/miscfuncs.cc
winsup/cygwin/mkvers.sh
winsup/cygwin/mmap.cc
winsup/cygwin/msg.cc
winsup/cygwin/net.cc
winsup/cygwin/ntdll.h
winsup/cygwin/ntea.cc
winsup/cygwin/passwd.cc
winsup/cygwin/path.cc
winsup/cygwin/path.h
winsup/cygwin/perthread.h
winsup/cygwin/pinfo.cc
winsup/cygwin/pinfo.h
winsup/cygwin/pipe.cc
winsup/cygwin/poll.cc
winsup/cygwin/pthread.cc
winsup/cygwin/pwdgrp.h
winsup/cygwin/regex/regcomp.c
winsup/cygwin/registry.cc
winsup/cygwin/resource.cc
winsup/cygwin/safe_memory.h
winsup/cygwin/sched.cc
winsup/cygwin/sec_acl.cc
winsup/cygwin/sec_helper.cc
winsup/cygwin/security.cc
winsup/cygwin/security.h
winsup/cygwin/select.cc
winsup/cygwin/sem.cc
winsup/cygwin/shared.cc
winsup/cygwin/shared_info.h
winsup/cygwin/shm.cc
winsup/cygwin/signal.cc
winsup/cygwin/sigproc.cc
winsup/cygwin/sigproc.h
winsup/cygwin/smallprint.c
winsup/cygwin/spawn.cc
winsup/cygwin/speclib
winsup/cygwin/strace.cc
winsup/cygwin/sync.cc
winsup/cygwin/sync.h
winsup/cygwin/syscalls.cc
winsup/cygwin/sysconf.cc
winsup/cygwin/syslog.cc
winsup/cygwin/termios.cc
winsup/cygwin/thread.cc
winsup/cygwin/thread.h
winsup/cygwin/threaded_queue.cc
winsup/cygwin/threaded_queue.h
winsup/cygwin/times.cc
winsup/cygwin/tty.cc
winsup/cygwin/tty.h
winsup/cygwin/uinfo.cc
winsup/cygwin/uname.cc
winsup/cygwin/wait.cc
winsup/cygwin/winbase.h
winsup/cygwin/wincap.cc
winsup/cygwin/wincap.h
winsup/cygwin/window.cc
winsup/cygwin/winsup.h
winsup/cygwin/winver.rc
winsup/cygwin/woutsup.h
Delete:
winsup/cygwin/include/cygwin/ip.h
winsup/cygwin/include/sys/ipc.h
winsup/cygwin/include/sys/shm.h
winsup/cygwin/include/wchar.h
winsup/cygwin/lib/_cygwin_S_IEXEC.cc
winsup/cygwin/regexp/regerror.c
winsup/cygwin/regexp/regexp.3
winsup/cygwin/regexp/regexp.c
winsup/cygwin/regexp/regsub.c
winsup/cygwin/shortcut.c
winsup/cygwin/shortcut.h
winsup/cygwin/test.c
Diffstat (limited to 'winsup/cygwin/cygheap.cc')
-rw-r--r-- | winsup/cygwin/cygheap.cc | 157 |
1 files changed, 81 insertions, 76 deletions
diff --git a/winsup/cygwin/cygheap.cc b/winsup/cygwin/cygheap.cc index a0e00d3c7..937c3392c 100644 --- a/winsup/cygwin/cygheap.cc +++ b/winsup/cygwin/cygheap.cc @@ -1,6 +1,6 @@ /* cygheap.cc: Cygwin heap manager. - Copyright 2000, 2001 Red Hat, Inc. + Copyright 2000, 2001, 2002 Red Hat, Inc. This file is part of Cygwin. @@ -17,10 +17,10 @@ #include "fhandler.h" #include "path.h" #include "dtable.h" +#include "cygerrno.h" #include "cygheap.h" #include "child_info.h" #include "heap.h" -#include "cygerrno.h" #include "sync.h" #include "shared_info.h" @@ -45,7 +45,6 @@ struct cygheap_entry extern "C" { static void __stdcall _cfree (void *ptr) __attribute__((regparm(1))); -extern void *_cygheap_start; } inline static void @@ -57,11 +56,11 @@ init_cheap () MEMORY_BASIC_INFORMATION m; if (!VirtualQuery ((LPCVOID) &_cygheap_start, &m, sizeof m)) system_printf ("couldn't get memory info, %E"); - small_printf ("AllocationBase %p, BaseAddress %p, RegionSize %p, State %p\n", - m.AllocationBase, m.BaseAddress, m.RegionSize, m.State); - api_fatal ("Couldn't reserve space for cygwin's heap, %E"); + system_printf ("Couldn't reserve space for cygwin's heap, %E"); + api_fatal ("AllocationBase %p, BaseAddress %p, RegionSize %p, State %p\n", + m.AllocationBase, m.BaseAddress, m.RegionSize, m.State); } - cygheap_max = cygheap + 1; + cygheap_max = cygheap; } static void dup_now (void *, child_info *, unsigned) __attribute__ ((regparm(3))); @@ -82,7 +81,7 @@ cygheap_setup_for_child (child_info *ci, bool dup_later) ci->cygheap_h = CreateFileMapping (INVALID_HANDLE_VALUE, &sec_none, CFMAP_OPTIONS, 0, CYGHEAPSIZE, NULL); newcygheap = MapViewOfFileEx (ci->cygheap_h, MVMAP_OPTIONS, 0, 0, 0, NULL); - ProtectHandle1 (ci->cygheap_h, passed_cygheap_h); + ProtectHandle1INH (ci->cygheap_h, passed_cygheap_h); if (!dup_later) dup_now (newcygheap, ci, n); cygheap_protect->release (); @@ -93,12 +92,12 @@ cygheap_setup_for_child (child_info *ci, bool dup_later) void __stdcall cygheap_setup_for_child_cleanup (void *newcygheap, child_info *ci, - bool dup_it_now) + bool dup_it_now) { if (dup_it_now) { /* NOTE: There is an assumption here that cygheap_max has not changed - between the time that cygheap_setup_for_child was called and now. + between the time that cygheap_setup_for_child was called and now. Make sure that this is a correct assumption. */ cygheap_protect->acquire (); dup_now (newcygheap, ci, (char *) cygheap_max - (char *) cygheap); @@ -110,31 +109,31 @@ cygheap_setup_for_child_cleanup (void *newcygheap, child_info *ci, /* Called by fork or spawn to reallocate cygwin heap */ void __stdcall -cygheap_fixup_in_child (child_info *ci, bool execed) +cygheap_fixup_in_child (bool execed) { - cygheap = ci->cygheap; - cygheap_max = ci->cygheap_max; + cygheap = child_proc_info->cygheap; + cygheap_max = child_proc_info->cygheap_max; void *addr = !wincap.map_view_of_file_ex_sucks () ? cygheap : NULL; void *newaddr; - newaddr = MapViewOfFileEx (ci->cygheap_h, MVMAP_OPTIONS, 0, 0, 0, addr); + newaddr = MapViewOfFileEx (child_proc_info->cygheap_h, MVMAP_OPTIONS, 0, 0, 0, addr); if (newaddr != cygheap) { if (!newaddr) - newaddr = MapViewOfFileEx (ci->cygheap_h, MVMAP_OPTIONS, 0, 0, 0, NULL); + newaddr = MapViewOfFileEx (child_proc_info->cygheap_h, MVMAP_OPTIONS, 0, 0, 0, NULL); DWORD n = (DWORD) cygheap_max - (DWORD) cygheap; /* Reserve cygwin heap in same spot as parent */ if (!VirtualAlloc (cygheap, CYGHEAPSIZE, MEM_RESERVE, PAGE_NOACCESS)) - { - MEMORY_BASIC_INFORMATION m; - memset (&m, 0, sizeof m); - if (!VirtualQuery ((LPCVOID) cygheap, &m, sizeof m)) - system_printf ("couldn't get memory info, %E"); - - small_printf ("m.AllocationBase %p, m.BaseAddress %p, m.RegionSize %p, m.State %p\n", - m.AllocationBase, m.BaseAddress, m.RegionSize, m.State); - api_fatal ("Couldn't reserve space for cygwin's heap (%p <%p>) in child, %E", cygheap, newaddr); - } + { + MEMORY_BASIC_INFORMATION m; + memset (&m, 0, sizeof m); + if (!VirtualQuery ((LPCVOID) cygheap, &m, sizeof m)) + system_printf ("couldn't get memory info, %E"); + + system_printf ("Couldn't reserve space for cygwin's heap (%p <%p>) in child, %E", cygheap, newaddr); + api_fatal ("m.AllocationBase %p, m.BaseAddress %p, m.RegionSize %p, m.State %p\n", + m.AllocationBase, m.BaseAddress, m.RegionSize, m.State); + } /* Allocate same amount of memory as parent */ if (!VirtualAlloc (cygheap, n, MEM_COMMIT, PAGE_READWRITE)) @@ -144,9 +143,10 @@ cygheap_fixup_in_child (child_info *ci, bool execed) UnmapViewOfFile (newaddr); } - ForceCloseHandle1 (ci->cygheap_h, passed_cygheap_h); + ForceCloseHandle1 (child_proc_info->cygheap_h, passed_cygheap_h); cygheap_init (); + debug_fixup_after_fork_exec (); if (execed) { @@ -171,34 +171,26 @@ cygheap_fixup_in_child (child_info *ci, bool execed) static void *__stdcall _csbrk (int sbs) { - void *lastheap; - bool needalloc; - - if (cygheap) - needalloc = 0; - else - { - init_cheap (); - needalloc = 1; - } - - lastheap = cygheap_max; + void *prebrk = cygheap_max; + void *prebrka = pagetrunc (prebrk); (char *) cygheap_max += sbs; - void *heapalign = (void *) pagetrunc (lastheap); - - if (!needalloc) - needalloc = sbs && ((heapalign == lastheap) || heapalign != pagetrunc (cygheap_max)); - if (needalloc && !VirtualAlloc (lastheap, (DWORD) sbs ?: 1, MEM_COMMIT, PAGE_READWRITE)) + if (!sbs || (prebrk != prebrka && prebrka == pagetrunc (cygheap_max))) + /* nothing to do */; + else if (!VirtualAlloc (prebrk, (DWORD) sbs, MEM_COMMIT, PAGE_READWRITE)) api_fatal ("couldn't commit memory for cygwin heap, %E"); - return lastheap; + return prebrk; } extern "C" void __stdcall cygheap_init () { - cygheap_protect = new_muto (FALSE, "cygheap_protect"); - _csbrk (0); + new_muto (cygheap_protect); + if (!cygheap) + { + init_cheap (); + (void) _csbrk (sizeof (*cygheap)); + } if (!cygheap->fdtab) cygheap->fdtab.init (); } @@ -322,12 +314,19 @@ crealloc (void *s, DWORD n) extern "C" void __stdcall cfree (void *s) { - MALLOC_CHECK; assert (!inheap (s)); (void) _cfree (tocygheap (s)); MALLOC_CHECK; } +extern "C" void __stdcall +cfree_and_set (char *&s, char *what) +{ + if (s && s != almost_null) + cfree (s); + s = what; +} + extern "C" void *__stdcall ccalloc (cygheap_types x, DWORD n, DWORD size) { @@ -378,13 +377,13 @@ init_cygheap::etc_changed () FILE_NOTIFY_CHANGE_LAST_WRITE); if (etc_changed_h == INVALID_HANDLE_VALUE) system_printf ("Can't open /etc for checking, %E", (char *) pwd, - etc_changed_h); + etc_changed_h); else if (!DuplicateHandle (hMainProc, etc_changed_h, hMainProc, - &etc_changed_h, 0, TRUE, + &etc_changed_h, 0, TRUE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE)) { system_printf ("Can't inherit /etc handle, %E", (char *) pwd, - etc_changed_h); + etc_changed_h); etc_changed_h = INVALID_HANDLE_VALUE; } } @@ -430,7 +429,7 @@ cygheap_user::~cygheap_user () if (pname) cfree (pname); if (plogsrv) - cfree (plogsrv); + cfree (plogsrv - 2); if (pdomain) cfree (pdomain); if (psid) @@ -441,41 +440,47 @@ cygheap_user::~cygheap_user () void cygheap_user::set_name (const char *new_name) { - if (pname) - cfree (pname); - pname = cstrdup (new_name ? new_name : ""); -} + bool allocated = !!pname; -void -cygheap_user::set_logsrv (const char *new_logsrv) -{ - if (plogsrv) - cfree (plogsrv); - plogsrv = (new_logsrv && *new_logsrv) ? cstrdup (new_logsrv) : NULL; -} + if (allocated) + { + if (strcasematch (new_name, pname)) + return; + cfree (pname); + } -void -cygheap_user::set_domain (const char *new_domain) -{ - if (pdomain) - cfree (pdomain); - pdomain = (new_domain && *new_domain) ? cstrdup (new_domain) : NULL; + pname = cstrdup (new_name ? new_name : ""); + if (!allocated) + return; /* Initializing. Don't bother with other stuff. */ + + cfree_and_set (homedrive); + cfree_and_set (homepath); + cfree_and_set (plogsrv); + cfree_and_set (pdomain); + cfree_and_set (pwinname); } BOOL cygheap_user::set_sid (PSID new_sid) { - if (!new_sid) + if (new_sid) { + if (!psid) + psid = cmalloc (HEAP_STR, MAX_SID_LEN); if (psid) - cfree (psid); - psid = NULL; - return TRUE; + return CopySid (MAX_SID_LEN, psid, new_sid); } - else + return FALSE; +} + +BOOL +cygheap_user::set_orig_sid () +{ + if (psid) { - if (!psid) - psid = cmalloc (HEAP_STR, MAX_SID_LEN); - return CopySid (MAX_SID_LEN, psid, new_sid); + if (!orig_psid) orig_psid = cmalloc (HEAP_STR, MAX_SID_LEN); + if (orig_psid) + return CopySid (MAX_SID_LEN, orig_psid, psid); } + return FALSE; } |