Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2000-11-14 08:53:32 +0300
committerChristopher Faylor <me@cgf.cx>2000-11-14 08:53:32 +0300
commita4785603b85b80ea0cc5ea0038bbbb3a13513714 (patch)
tree3bb9ab5f76acbe2fbca946b6c4f9439a8aa42c58 /winsup/cygwin/cygheap.cc
parent70a11195b9bf3617e3dbe4b9de034b3792c65621 (diff)
* cygheap.h (init_cygheap): New struct holding values that live in the Cygwin
heap. * child_info.h (child_info): Change pointer type of cygheap to init_cygheap. * cygheap.cc (init_cheap): Point cygheap_max after contents of cygheap. Move some stuff into cygheap.h. * dir.cc (opendir): Change to use root and rootlen in cygheap rather than in myself. (mkdir): Change to use umask in cygheap rather than in myself. * path.cc: Ditto, throughout. * syscalls.cc (_open): Ditto. Change to use umask in cygheap rather than in myself. (chroot): Change to allocate root dir on the cygwin heap. (umask): Change to use umask in cygheap rather than in myself. (cygwin_bind): Ditto. * sigproc.cc (proc_subproc): Don't copy umask or root stuff as this happens automatically now. * pinfo.h (_pinfo): Migrate stuff out of here and into init_cheap. * dcrt0.cc (dll_crt0_1): Call cygheap_init later in startup for first cygwin process.
Diffstat (limited to 'winsup/cygwin/cygheap.cc')
-rw-r--r--winsup/cygwin/cygheap.cc66
1 files changed, 28 insertions, 38 deletions
diff --git a/winsup/cygwin/cygheap.cc b/winsup/cygwin/cygheap.cc
index c6503c41b..15c2667c0 100644
--- a/winsup/cygwin/cygheap.cc
+++ b/winsup/cygwin/cygheap.cc
@@ -18,24 +18,18 @@
#include "cygerrno.h"
#include "sync.h"
-void NO_COPY *cygheap = NULL;
+init_cygheap NO_COPY *cygheap;
void NO_COPY *cygheap_max = NULL;
static NO_COPY muto *cygheap_protect = NULL;
-extern "C" void __stdcall
-cygheap_init ()
-{
- cygheap_protect = new_muto (FALSE, "cygheap_protect");
-}
-
inline static void
init_cheap ()
{
- cygheap = VirtualAlloc (NULL, CYGHEAPSIZE, MEM_RESERVE, PAGE_NOACCESS);
+ cygheap = (init_cygheap *) VirtualAlloc (NULL, CYGHEAPSIZE, MEM_RESERVE, PAGE_NOACCESS);
if (!cygheap)
api_fatal ("Couldn't reserve space for cygwin's heap, %E");
- cygheap_max = (((char **) cygheap) + 1);
+ cygheap_max = cygheap + 1;
}
#define pagetrunc(x) ((void *) (((DWORD) (x)) & ~(4096 - 1)))
@@ -60,32 +54,26 @@ _csbrk (int sbs)
if (!needalloc)
needalloc = sbs && ((heapalign == lastheap) || heapalign != pagetrunc (cygheap_max));
- if (needalloc && !VirtualAlloc (lastheap, (DWORD) sbs, MEM_COMMIT, PAGE_READWRITE))
+ if (needalloc && !VirtualAlloc (lastheap, (DWORD) sbs ?: 1, MEM_COMMIT, PAGE_READWRITE))
api_fatal ("couldn't commit memory for cygwin heap, %E");
return lastheap;
}
+extern "C" void __stdcall
+cygheap_init ()
+{
+ cygheap_protect = new_muto (FALSE, "cygheap_protect");
+ _csbrk (0);
+}
+
/* Copyright (C) 1997, 2000 DJ Delorie */
#define NBUCKETS 32
char *buckets[NBUCKETS] = {0};
-struct _cmalloc_entry
-{
- union
- {
- DWORD b;
- char *ptr;
- };
- struct _cmalloc_entry *prev;
- char data[0];
-};
-
-
#define N0 ((_cmalloc_entry *) NULL)
#define to_cmalloc(s) ((_cmalloc_entry *) (((char *) (s)) - (int) (N0->data)))
-#define cygheap_chain ((_cmalloc_entry **)cygheap)
static void *_cmalloc (int size) __attribute ((regparm(1)));
static void *__stdcall _crealloc (void *ptr, int size) __attribute ((regparm(2)));
@@ -113,8 +101,8 @@ _cmalloc (int size)
rvc = (_cmalloc_entry *) _csbrk (size);
rvc->b = b;
- rvc->prev = *cygheap_chain;
- *cygheap_chain = rvc;
+ rvc->prev = cygheap->chain;
+ cygheap->chain = rvc;
}
cygheap_protect->release ();
return rvc->data;
@@ -172,7 +160,7 @@ cygheap_fixup_in_child (HANDLE parent, bool execed)
/* Reserve cygwin heap in same spot as parent */
if (!VirtualAlloc (cygheap, CYGHEAPSIZE, MEM_RESERVE, PAGE_NOACCESS))
- api_fatal ("Couldn't reserve space for cygwin's heap in child, %E");
+ api_fatal ("Couldn't reserve space for cygwin's heap (%p) in child, cygheap, %E", cygheap);
/* Allocate same amount of memory as parent */
if (!VirtualAlloc (cygheap, n, MEM_COMMIT, PAGE_READWRITE))
@@ -185,20 +173,22 @@ cygheap_fixup_in_child (HANDLE parent, bool execed)
api_fatal ("Couldn't read parent's cygwin heap %d bytes != %d, %E",
n, m);
- if (!execed)
- return; /* Forked. Nothing extra to do. */
+ cygheap_init ();
- /* Walk the allocated memory chain looking for orphaned memory from
- previous execs */
- for (_cmalloc_entry *rvc = *cygheap_chain; rvc; rvc = rvc->prev)
+ if (execed)
{
- cygheap_entry *ce = (cygheap_entry *) rvc->data;
- if (rvc->b >= NBUCKETS || ce->type <= HEAP_1_START)
- continue;
- else if (ce->type < HEAP_1_MAX)
- ce->type += HEAP_1_MAX; /* Mark for freeing after next exec */
- else
- _cfree (ce); /* Marked by parent for freeing in child */
+ /* Walk the allocated memory chain looking for orphaned memory from
+ previous execs */
+ for (_cmalloc_entry *rvc = cygheap->chain; rvc; rvc = rvc->prev)
+ {
+ cygheap_entry *ce = (cygheap_entry *) rvc->data;
+ if (rvc->b >= NBUCKETS || ce->type <= HEAP_1_START)
+ continue;
+ else if (ce->type < HEAP_1_MAX)
+ ce->type += HEAP_1_MAX; /* Mark for freeing after next exec */
+ else
+ _cfree (ce); /* Marked by parent for freeing in child */
+ }
}
}