4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-02-01 03:50:28 +08:00

* cygheap.cc (cygheap_init): Born again function.

(_cmalloc): Reorganize to accomodate muto locking.
(_cfree): Use muto lock to avoid multi-thread problems.
* cygheap.h (incygheap): Just use cygheap_max to find upper cygwin heap bounds.
* dcrt0.cc (dll_crt0_1): Reinstitute cygheap_init call.
* path.cc (getcwd): Just return cwdstuff::get result, allowing correct handling
of negative length.
(cwdstuff::get): Malloc a buffer if one is not available.
This commit is contained in:
Christopher Faylor 2000-10-02 02:26:04 +00:00
parent 0ce83ef6b8
commit 9fc09d00f7
7 changed files with 60 additions and 44 deletions

View File

@ -1,3 +1,15 @@
Sun Oct 1 22:20:39 2000 Christopher Faylor <cgf@cygnus.com>
* cygheap.cc (cygheap_init): Born again function.
(_cmalloc): Reorganize to accomodate muto locking.
(_cfree): Use muto lock to avoid multi-thread problems.
* cygheap.h (incygheap): Just use cygheap_max to find upper cygwin heap
bounds.
* dcrt0.cc (dll_crt0_1): Reinstitute cygheap_init call.
* path.cc (getcwd): Just return cwdstuff::get result, allowing correct
handling of negative length.
(cwdstuff::get): Malloc a buffer if one is not available.
Sun Oct 1 2:56:00 2000 Corinna Vinschen <corinna@vinschen.de>
* Makefile.in: Add fhandler_mem.o to the dependencies.
@ -115,7 +127,8 @@ Sun Sep 17 22:18:39 2000 Christopher Faylor <cgf@cygnus.com>
Fri Sep 15 22:30:40 2000 Christopher Faylor <cgf@cygnus.com>
* exceptions.cc (handle_exceptions): Just "core dump" if SIGSEGV in signal thread.
* exceptions.cc (handle_exceptions): Just "core dump" if SIGSEGV in
signal thread.
* external.cc (fillout_pinfo): Fix compiler warning.
* sigproc.h: Eliminate special asm naming for sig_dispatch_pending.
* sigproc.cc (sig_send): Remove debugging statements.

View File

@ -12,13 +12,23 @@
#include <errno.h>
#include <fhandler.h>
#include <assert.h>
#include <stdlib.h>
#include "cygheap.h"
#include "heap.h"
#include "cygerrno.h"
#include "sync.h"
void *cygheap = NULL;
void *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 ()
{
@ -116,30 +126,35 @@ _cmalloc (int size)
init_buckets ();
b = size2bucket (size);
cygheap_protect->acquire ();
if (buckets[b])
{
rvc = (_cmalloc_entry *) buckets[b];
buckets[b] = rvc->ptr;
rvc->b = b;
return rvc->data;
}
else
{
size = bucket2size[b] + sizeof (_cmalloc_entry);
rvc = (_cmalloc_entry *) _csbrk (size);
size = bucket2size[b] + sizeof (_cmalloc_entry);
rvc = (_cmalloc_entry *) _csbrk (size);
rvc->b = b;
rvc->prev = *cygheap_chain;
*cygheap_chain = rvc;
rvc->b = b;
rvc->prev = *cygheap_chain;
*cygheap_chain = rvc;
}
cygheap_protect->release ();
return rvc->data;
}
static void __stdcall
_cfree (void *ptr)
{
cygheap_protect->acquire ();
_cmalloc_entry *rvc = to_cmalloc (ptr);
DWORD b = rvc->b;
rvc->ptr = buckets[b];
buckets[b] = (char *) rvc;
cygheap_protect->release ();
}
static void *__stdcall
@ -226,6 +241,7 @@ creturn (cygheap_types x, cygheap_entry * c, int len)
c->type = x;
if (cygheap_max < ((char *) c + len))
cygheap_max = (char *) c + len;
MALLOC_CHECK;
return (void *) c->data;
}
@ -233,6 +249,7 @@ extern "C" void *__stdcall
cmalloc (cygheap_types x, DWORD n)
{
cygheap_entry *c;
MALLOC_CHECK;
c = (cygheap_entry *) _cmalloc (sizeof_cygheap (n));
if (!c)
system_printf ("cmalloc returned NULL");
@ -242,6 +259,7 @@ cmalloc (cygheap_types x, DWORD n)
extern "C" void *__stdcall
crealloc (void *s, DWORD n)
{
MALLOC_CHECK;
if (s == NULL)
return cmalloc (HEAP_STR, n); // kludge
@ -257,14 +275,17 @@ 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
ccalloc (cygheap_types x, DWORD n, DWORD size)
{
cygheap_entry *c;
MALLOC_CHECK;
c = (cygheap_entry *) _cmalloc (sizeof_cygheap (n * size));
if (c)
memset (c->data, 0, size);
@ -276,19 +297,23 @@ ccalloc (cygheap_types x, DWORD n, DWORD size)
extern "C" char *__stdcall
cstrdup (const char *s)
{
MALLOC_CHECK;
char *p = (char *) cmalloc (HEAP_STR, strlen (s) + 1);
if (!p)
return NULL;
strcpy (p, s);
MALLOC_CHECK;
return p;
}
extern "C" char *__stdcall
cstrdup1 (const char *s)
{
MALLOC_CHECK;
char *p = (char *) cmalloc (HEAP_1_STR, strlen (s) + 1);
if (!p)
return NULL;
strcpy (p, s);
MALLOC_CHECK;
return p;
}

View File

@ -29,7 +29,7 @@ enum cygheap_types
extern HANDLE cygheap;
extern HANDLE cygheap_max;
#define incygheap(s) (cygheap && ((char *) (s) >= (char *) cygheap) && ((char *) (s) <= ((char *) cygheap) + CYGHEAPSIZE))
#define incygheap(s) (cygheap && ((char *) (s) >= (char *) cygheap) && ((char *) (s) <= ((char *) cygheap_max)))
extern "C" {
void __stdcall cfree (void *);
@ -39,4 +39,5 @@ void *__stdcall crealloc (void *, DWORD);
void *__stdcall ccalloc (cygheap_types, DWORD, DWORD);
char *__stdcall cstrdup (const char *);
char *__stdcall cstrdup1 (const char *);
void __stdcall cygheap_init ();
}

View File

@ -654,6 +654,7 @@ dll_crt0_1 ()
threadname_init ();
debug_init ();
cygheap_init (); /* Initialize cygheap muto */
regthread ("main", GetCurrentThreadId ());

View File

@ -87,7 +87,7 @@ thread_stub (VOID *arg)
exception_list except_entry;
/* Give up our slot in the start_buf array */
InterlockedExchange (&((thread_start *) arg)->notavail, 0);
(void) InterlockedExchange (&((thread_start *) arg)->notavail, 0);
/* Initialize this thread's ability to respond to things like
SIGSEGV or SIGFPE. */

View File

@ -2436,36 +2436,7 @@ hashit:
char *
getcwd (char *buf, size_t ulen)
{
char *res;
char *usebuf, uselen;
if (buf != NULL)
{
usebuf = buf;
uselen = TRUE;
}
else
{
if (ulen >= 0)
uselen = TRUE;
else
{
uselen = FALSE;
ulen = MAX_PATH + 1;
}
usebuf = (char *) malloc (ulen);
usebuf [ulen - 1] = '\0';
}
res = cygcwd.get (usebuf, 1, 1, ulen);
if (res && !uselen)
usebuf = (char *) realloc (usebuf, strlen (usebuf) + 1);
else if (!res && buf == NULL)
free (usebuf);
return res;
return cygcwd.get (buf, 1, 1, ulen);
}
/* getwd: standards? */
@ -2481,6 +2452,7 @@ extern "C"
int
chdir (const char *dir)
{
MALLOC_CHECK;
syscall_printf ("dir %s", dir);
path_conv path (dir, PC_FULL | PC_SYM_FOLLOW);
@ -2529,6 +2501,7 @@ chdir (const char *dir)
it was worth locking just for strace. */
syscall_printf ("%d = chdir() cygcwd.posix '%s' native '%s'", res,
cygcwd.posix, native_dir);
MALLOC_CHECK;
return res;
}
@ -2962,8 +2935,7 @@ cwdstuff::set (const char *win32_cwd, const char *posix_cwd)
char *
cwdstuff::get (char *buf, int need_posix, int with_chroot, unsigned ulen)
{
size_t len = ulen;
MALLOC_CHECK;
if (!get_initial ()) /* Get initial cwd and set cwd lock */
return NULL;
@ -2982,6 +2954,8 @@ cwdstuff::get (char *buf, int need_posix, int with_chroot, unsigned ulen)
}
else
{
if (need_posix && !buf)
buf = (char *) malloc (strlen (tocopy) + 1);
strcpy (buf, tocopy);
if (!buf[0]) /* Should only happen when chroot */
strcpy (buf, "/");
@ -2989,7 +2963,8 @@ cwdstuff::get (char *buf, int need_posix, int with_chroot, unsigned ulen)
lock->release ();
syscall_printf ("(%s) = cwdstuff::get (%p, %d, %d, %d)",
buf, buf, len, need_posix, with_chroot);
buf, buf, ulen, need_posix, with_chroot);
MALLOC_CHECK;
return buf;
}
@ -3002,5 +2977,6 @@ cwdstuff::copy (char * &posix_cwd, char * &win32_cwd, DWORD hash_cwd)
posix_cwd = cstrdup (posix);
win32_cwd = cstrdup (win32);
hash_cwd = hash;
MALLOC_CHECK;
lock->release ();
}

View File

@ -116,7 +116,7 @@ muto::release ()
if (!--visits)
{
tid = 0; /* We were the last unlocker. */
InterlockedExchange (&sync, 0); /* Reset trigger. */
(void) InterlockedExchange (&sync, 0); /* Reset trigger. */
/* This thread had incremented waiters but had never decremented it.
Decrement it now. If it is >= 0 then there are possibly other
threads waiting for the lock, so trigger bruteforce. */