From 67fcf127c1f23d4fd5f630e72ad8304dc53b7095 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Tue, 20 Jan 2004 19:36:35 +0000 Subject: [PATCH] * include/cygwin/version.h: Bump DLL minor number to 8. * cygmalloc.h: Make more concessions to attempts to get debugging malloc working. * debug.h: Ditto. * dlmalloc.cc: Ditto. * dlmalloc.h: Ditto. * malloc_wrapper.cc: Ditto. * perthread.h (perthread::create): Use calloc to ensure zeroed memory. --- winsup/cygwin/ChangeLog | 17 ++++++ winsup/cygwin/cygmalloc.h | 26 +++++---- winsup/cygwin/debug.cc | 1 + winsup/cygwin/dlmalloc.c | 20 +++++-- winsup/cygwin/dlmalloc.h | 24 ++++----- winsup/cygwin/include/cygwin/version.h | 2 +- winsup/cygwin/malloc_wrapper.cc | 73 ++------------------------ winsup/cygwin/perthread.h | 3 +- 8 files changed, 67 insertions(+), 99 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 16c58566d..aa2d898ac 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,7 +1,24 @@ +2004-01-20 Christopher Faylor + + * include/cygwin/version.h: Bump DLL minor number to 8. + + * cygmalloc.h: Make more concessions to attempts to get debugging + malloc working. + * debug.h: Ditto. + * dlmalloc.cc: Ditto. + * dlmalloc.h: Ditto. + * malloc_wrapper.cc: Ditto. + + * perthread.h (perthread::create): Use calloc to ensure zeroed memory. + 2004-01-20 Christopher Faylor * sec_acl.cc (setacl): Make sure sd_ret is large enough. +2004-01-19 Christopher Faylor + + * sec_acl.cc (setacl): Make sure return sd is large enough. + 2004-01-19 Christopher Faylor * sigproc.cc (sigproc_terminate): Don't close sendsig handle when diff --git a/winsup/cygwin/cygmalloc.h b/winsup/cygwin/cygmalloc.h index 3d3a0acd5..30b9ee391 100644 --- a/winsup/cygwin/cygmalloc.h +++ b/winsup/cygwin/cygmalloc.h @@ -8,16 +8,19 @@ This software is a copyrighted work licensed under the terms of the Cygwin license. Please consult the file "CYGWIN_LICENSE" for details. */ -extern "C" void dlfree (void *p) __attribute__ ((regparm (1))); -extern "C" void *dlmalloc (unsigned size) __attribute__ ((regparm (1))); -extern "C" void *dlrealloc (void *p, unsigned size) __attribute__ ((regparm (2))); -extern "C" void *dlcalloc (size_t nmemb, size_t size) __attribute__ ((regparm (2))); -extern "C" void *dlmemalign (size_t alignment, size_t bytes) __attribute__ ((regparm (2))); -extern "C" void *dlvalloc (size_t bytes) __attribute__ ((regparm (1))); -extern "C" size_t dlmalloc_usable_size (void *p) __attribute__ ((regparm (1))); -extern "C" int dlmalloc_trim (size_t) __attribute__ ((regparm (1))); -extern "C" int dlmallopt (int p, int v) __attribute__ ((regparm (2))); -extern "C" void dlmalloc_stats (); +#ifdef __cplusplus +extern "C" { +#endif +void dlfree (void *p) __attribute__ ((regparm (1))); +void *dlmalloc (unsigned size) __attribute__ ((regparm (1))); +void *dlrealloc (void *p, unsigned size) __attribute__ ((regparm (2))); +void *dlcalloc (size_t nmemb, size_t size) __attribute__ ((regparm (2))); +void *dlmemalign (size_t alignment, size_t bytes) __attribute__ ((regparm (2))); +void *dlvalloc (size_t bytes) __attribute__ ((regparm (1))); +size_t dlmalloc_usable_size (void *p) __attribute__ ((regparm (1))); +int dlmalloc_trim (size_t) __attribute__ ((regparm (1))); +int dlmallopt (int p, int v) __attribute__ ((regparm (2))); +void dlmalloc_stats (); #ifndef __INSIDE_CYGWIN__ # define USE_DL_PREFIX 1 @@ -26,3 +29,6 @@ extern "C" void dlmalloc_stats (); # define __malloc_unlock() mallock->release () extern muto *mallock; #endif +#ifdef __cplusplus +} +#endif diff --git a/winsup/cygwin/debug.cc b/winsup/cygwin/debug.cc index 05b53cf33..b02f4da5a 100644 --- a/winsup/cygwin/debug.cc +++ b/winsup/cygwin/debug.cc @@ -7,6 +7,7 @@ Cygwin license. Please consult the file "CYGWIN_LICENSE" for details. */ #include "winsup.h" +#include #include "sync.h" #include "sigproc.h" #include "pinfo.h" diff --git a/winsup/cygwin/dlmalloc.c b/winsup/cygwin/dlmalloc.c index a79a72513..3d9fafbb9 100644 --- a/winsup/cygwin/dlmalloc.c +++ b/winsup/cygwin/dlmalloc.c @@ -28,6 +28,16 @@ * malloc_usable_size(P) is equivalent to realloc(P, malloc_usable_size(P)) * * $Log$ + * Revision 1.8 2004/01/20 19:36:34 cgf + * * include/cygwin/version.h: Bump DLL minor number to 8. + * * cygmalloc.h: Make more concessions to attempts to get debugging malloc + * working. + * * debug.h: Ditto. + * * dlmalloc.cc: Ditto. + * * dlmalloc.h: Ditto. + * * malloc_wrapper.cc: Ditto. + * * perthread.h (perthread::create): Use calloc to ensure zeroed memory. + * * Revision 1.7 2003/09/25 00:37:16 cgf * * devices.cc: New file. * * devices.gperf: New file. @@ -533,7 +543,6 @@ /* Preliminaries */ -#include "winsup.h" #ifndef __STD_C #ifdef __STDC__ @@ -567,8 +576,11 @@ extern "C" { #endif +#include +#include "cygmalloc.h" +#define __INSIDE_CYGWIN__ #include /* needed for malloc_stats */ - +#include /* Compile-time options @@ -2098,9 +2110,7 @@ static void malloc_err(const char *err, mchunkptr p) /* avoid invalid pointers */ debug_file_min && p->file >= debug_file_min && - p->file <= debug_file_max && - /* try to avoid garbage file names */ - isprint(*p->file)) + p->file <= debug_file_max) errprint(p->file, p->line, "in block allocated here"); # endif } diff --git a/winsup/cygwin/dlmalloc.h b/winsup/cygwin/dlmalloc.h index b8d7ebeeb..d7bd86927 100644 --- a/winsup/cygwin/dlmalloc.h +++ b/winsup/cygwin/dlmalloc.h @@ -41,18 +41,18 @@ struct mallinfo { #ifdef MALLOC_DEBUG -#define dmalloc(size) malloc_dbg(size, __FILE__, __LINE__) -#define dfree(p) free_dbg(p, __FILE__, __LINE__) -#define drealloc(p, size) realloc_dbg(p, size, __FILE__, __LINE__) -#define dcalloc(n, size) calloc_dbg(n, size, __FILE__, __LINE__) -#define dmemalign(align, size) memalign_dbg(align, size, __FILE__, __LINE__) -#define dvalloc(size) valloc_dbg(size, __FILE__, __LINE__) -#define dpvalloc(size) pvalloc_dbg(size, __FILE__, __LINE__) -#define dmalloc_trim(pad) malloc_trim_dbg(pad, __FILE__, __LINE__) -#define dmalloc_usable_size(p) malloc_usable_size_dbg(p, __FILE__, __LINE__) -#define dmalloc_stats() malloc_stats_dbg(__FILE__, __LINE__) -#define dmallopt(flag, val) mallopt_dbg(flag, val, __FILE__, __LINE__) -#define dmallinfo() mallinfo_dbg(__FILE__, __LINE__) +#define dlmalloc(size) malloc_dbg(size, __FILE__, __LINE__) +#define dlfree(p) free_dbg(p, __FILE__, __LINE__) +#define dlrealloc(p, size) realloc_dbg(p, size, __FILE__, __LINE__) +#define dlcalloc(n, size) calloc_dbg(n, size, __FILE__, __LINE__) +#define dlmemalign(align, size) memalign_dbg(align, size, __FILE__, __LINE__) +#define dlvalloc(size) valloc_dbg(size, __FILE__, __LINE__) +#define dlpvalloc(size) pvalloc_dbg(size, __FILE__, __LINE__) +#define dlmalloc_trim(pad) malloc_trim_dbg(pad, __FILE__, __LINE__) +#define dlmalloc_usable_size(p) malloc_usable_size_dbg(p, __FILE__, __LINE__) +#define dlmalloc_stats() malloc_stats_dbg(__FILE__, __LINE__) +#define dlmallopt(flag, val) mallopt_dbg(flag, val, __FILE__, __LINE__) +#define dlmallinfo() mallinfo_dbg(__FILE__, __LINE__) #ifdef __cplusplus diff --git a/winsup/cygwin/include/cygwin/version.h b/winsup/cygwin/include/cygwin/version.h index adb992432..c341be8f5 100644 --- a/winsup/cygwin/include/cygwin/version.h +++ b/winsup/cygwin/include/cygwin/version.h @@ -42,7 +42,7 @@ details. */ changes to the DLL and is mainly informative in nature. */ #define CYGWIN_VERSION_DLL_MAJOR 1005 -#define CYGWIN_VERSION_DLL_MINOR 7 +#define CYGWIN_VERSION_DLL_MINOR 8 /* Major numbers before CYGWIN_VERSION_DLL_EPOCH are incompatible. */ diff --git a/winsup/cygwin/malloc_wrapper.cc b/winsup/cygwin/malloc_wrapper.cc index 7bcd181c5..718f0b22f 100644 --- a/winsup/cygwin/malloc_wrapper.cc +++ b/winsup/cygwin/malloc_wrapper.cc @@ -24,7 +24,9 @@ details. */ #include "sync.h" #include "perprocess.h" #include "cygmalloc.h" +#ifndef MALLOC_DEBUG #include +#endif extern "C" struct mallinfo dlmallinfo (); /* we provide these stubs to call into a user's @@ -36,71 +38,6 @@ extern "C" struct mallinfo dlmallinfo (); static int export_malloc_called; static int use_internal_malloc = 1; -#ifdef MALLOC_DEBUG -extern "C" void * _sbrk (size_t incr_arg); - -#if 0 -extern "C" void * -_sbrk_r (struct _reent *, size_t incr_arg) -{ - return _sbrk (incr_arg); -} -#endif - -extern "C" void * -_malloc_r (struct _reent *, size_t size) -{ - export_malloc_called = 1; - return malloc (size); -} -#undef malloc - -extern "C" void * -_calloc_r (struct _reent *, size_t nmemb, size_t size) -{ - export_malloc_called = 1; - return calloc (nmemb, size); -} -#undef calloc - -extern "C" void -_free_r (struct _reent *, void *p) -{ - export_malloc_called = 1; - assert (!incygheap (p)); - assert (inheap (p)); - free (p); -} -#undef free - -extern "C" void * -_realloc_r (struct _reent *, void *p, size_t size) -{ - export_malloc_called = 1; - assert (!incygheap (p)); - assert (inheap (p)); - return realloc (p, size); -} -#undef realloc - -extern "C" char * -strdup_dbg (const char *s, const char *file, int line) -{ - char *p; - export_malloc_called = 1; - if ((p = (char *) malloc_dbg (strlen (s) + 1, file, line)) != NULL) - strcpy (p, s); - return p; -} - -#undef strdup -extern "C" char * -strdup (const char *s) -{ - return strdup_dbg (s, __FILE__, __LINE__); -} -#else -#endif /* These routines are used by the application if it doesn't provide its own malloc. */ @@ -317,18 +254,16 @@ malloc_init () { new_muto (mallock); +#ifndef MALLOC_DEBUG /* Check if mallock is provided by application. If so, redirect all calls to malloc/free/realloc to application provided. This may happen if some other dll calls cygwin's malloc, but main code provides its own malloc */ if (!user_data->forkee) { -#ifdef MALLOC_DEBUG - _free_r (NULL, _malloc_r (NULL, 16)); -#else user_data->free (user_data->malloc (16)); -#endif if (!export_malloc_called) use_internal_malloc = 0; } +#endif } diff --git a/winsup/cygwin/perthread.h b/winsup/cygwin/perthread.h index 2b4b0fdba..add07e3d5 100644 --- a/winsup/cygwin/perthread.h +++ b/winsup/cygwin/perthread.h @@ -28,8 +28,7 @@ public: virtual void set (int n) {TlsSetValue (get_tls (), (void *)n);} virtual void *create () { - void *s = new char [size ()]; - memset (s, 0, size ()); + void *s = calloc (1, size ()); set (s); return s; }