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:
authorcvs2svn <>2002-09-22 16:04:17 +0400
committercvs2svn <>2002-09-22 16:04:17 +0400
commite8038acb1b5f441fe7b2570c9448cf73b2038477 (patch)
tree9bc675d4928360fc4998eb5a43727fd1a4ce427d /winsup/cygwin/malloc_wrapper.cc
parent9783ce28caf426c5ab39d1d6aefa31cfdb1b8234 (diff)
This commit was manufactured by cvs2svn to create tagZ-cygwin_daemon_merge_HEAD
'Z-cygwin_daemon_merge_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/malloc_wrapper.cc')
-rw-r--r--winsup/cygwin/malloc_wrapper.cc229
1 files changed, 153 insertions, 76 deletions
diff --git a/winsup/cygwin/malloc_wrapper.cc b/winsup/cygwin/malloc_wrapper.cc
index 2fa93b1a1..51cc81832 100644
--- a/winsup/cygwin/malloc_wrapper.cc
+++ b/winsup/cygwin/malloc_wrapper.cc
@@ -1,6 +1,6 @@
-/* malloc.cc
+/* malloc_wrapper.cc
- Copyright 1996, 1997, 1998, 1999, 2000, 2001 Red Hat, Inc.
+ Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
Originally written by Steve Chamberlain of Cygnus Support
sac@cygnus.com
@@ -18,10 +18,13 @@ details. */
#include "fhandler.h"
#include "path.h"
#include "dtable.h"
+#include <errno.h>
+#include "cygerrno.h"
#include "cygheap.h"
#include "heap.h"
#include "sync.h"
#include "perprocess.h"
+#include "cygmalloc.h"
/* we provide these stubs to call into a user's
provided malloc if there is one - otherwise
@@ -101,105 +104,191 @@ strdup (const char *s)
return strdup_dbg (s, __FILE__, __LINE__);
}
#else
-/* Call though the application pointer,
- which either points to export_malloc, or the application's
- own version. */
+#endif
+/* These routines are used by the application if it
+ doesn't provide its own malloc. */
-void *
-malloc (size_t size)
+extern "C" void
+free (void *p)
{
- void *res;
- res = user_data->malloc (size);
- return res;
+ malloc_printf ("(%p), called by %p", p, __builtin_return_address (0));
+ if (!use_internal_malloc)
+ user_data->free (p);
+ else
+ {
+ __malloc_lock ();
+ dlfree (p);
+ __malloc_unlock ();
+ }
}
-void
-free (void *p)
+extern "C" void *
+malloc (size_t size)
{
- user_data->free (p);
+ void *res;
+ export_malloc_called = 1;
+ if (!use_internal_malloc)
+ res = user_data->malloc (size);
+ else
+ {
+ __malloc_lock ();
+ res = dlmalloc (size);
+ __malloc_unlock ();
+ }
+ malloc_printf ("(%d) = %x, called by %p", size, res, __builtin_return_address (0));
+ return res;
}
-void *
+extern "C" void *
realloc (void *p, size_t size)
{
void *res;
- res = user_data->realloc (p, size);
+ if (!use_internal_malloc)
+ res = user_data->realloc (p, size);
+ else
+ {
+ __malloc_lock ();
+ res = dlrealloc (p, size);
+ __malloc_unlock ();
+ }
+ malloc_printf ("(%x, %d) = %x, called by %x", p, size, res, __builtin_return_address (0));
return res;
}
-void *
+extern "C" void *
calloc (size_t nmemb, size_t size)
{
void *res;
- res = user_data->calloc (nmemb, size);
+ if (!use_internal_malloc)
+ res = user_data->calloc (nmemb, size);
+ else
+ {
+ __malloc_lock ();
+ res = dlcalloc (nmemb, size);
+ __malloc_unlock ();
+ }
+ malloc_printf ("(%d, %d) = %x, called by %x", nmemb, size, res, __builtin_return_address (0));
return res;
}
-extern "C" char *
-strdup (const char *s)
+extern "C" void *
+memalign (size_t alignment, size_t bytes)
{
- char *p;
- size_t len = strlen (s) + 1;
- if ((p = (char *) malloc (len)) != NULL)
- memcpy (p, s, len);
- return p;
+ void *res;
+ if (!use_internal_malloc)
+ {
+ set_errno (ENOSYS);
+ res = NULL;
+ }
+ else
+ {
+ __malloc_lock ();
+ res = dlmemalign (alignment, bytes);
+ __malloc_unlock ();
+ }
+
+ return res;
}
-extern "C" char *
-_strdup_r (struct _reent *, const char *s)
+extern "C" void *
+valloc (size_t bytes)
{
- return strdup (s);
-}
-#endif
+ void *res;
+ if (!use_internal_malloc)
+ {
+ set_errno (ENOSYS);
+ res = NULL;
+ }
+ else
+ {
+ __malloc_lock ();
+ res = dlvalloc (bytes);
+ __malloc_unlock ();
+ }
-/* These routines are used by the application if it
- doesn't provide its own malloc. */
+ return res;
+}
-extern "C" void
-export_free (void *p)
+extern "C" size_t
+malloc_usable_size (void *p)
{
- malloc_printf ("(%p), called by %x", p, ((int *)&p)[-1]);
- if (use_internal_malloc)
- _free_r (_impure_ptr, p);
+ size_t res;
+ if (!use_internal_malloc)
+ {
+ set_errno (ENOSYS);
+ res = 0;
+ }
else
- user_data->free (p);
+ {
+ __malloc_lock ();
+ res = dlmalloc_usable_size (p);
+ __malloc_unlock ();
+ }
+
+ return res;
}
-extern "C" void *
-export_malloc (int size)
+extern "C" int
+malloc_trim (size_t pad)
{
- void *res;
- export_malloc_called = 1;
- if (use_internal_malloc)
- res = _malloc_r (_impure_ptr, size);
+ size_t res;
+ if (!use_internal_malloc)
+ {
+ set_errno (ENOSYS);
+ res = 0;
+ }
else
- res = user_data->malloc (size);
- malloc_printf ("(%d) = %x, called by %x", size, res, ((int *)&size)[-1]);
+ {
+ __malloc_lock ();
+ res = dlmalloc_trim (pad);
+ __malloc_unlock ();
+ }
+
return res;
}
-extern "C" void *
-export_realloc (void *p, int size)
+extern "C" int
+mallopt (int p, int v)
{
- void *res;
- if (use_internal_malloc)
- res = _realloc_r (_impure_ptr, p, size);
+ int res;
+ if (!use_internal_malloc)
+ {
+ set_errno (ENOSYS);
+ res = 0;
+ }
else
- res = user_data->realloc (p, size);
- malloc_printf ("(%x, %d) = %x, called by %x", p, size, res, ((int *)&p)[-1]);
+ {
+ __malloc_lock ();
+ res = dlmallopt (p, v);
+ __malloc_unlock ();
+ }
+
return res;
}
-extern "C" void *
-export_calloc (size_t nmemb, size_t size)
+extern "C" void
+malloc_stats ()
{
- void *res;
- if (use_internal_malloc)
- res = _calloc_r (_impure_ptr, nmemb, size);
+ if (!use_internal_malloc)
+ set_errno (ENOSYS);
else
- res = user_data->calloc (nmemb, size);
- malloc_printf ("(%d, %d) = %x, called by %x", nmemb, size, res, ((int *)&nmemb)[-1]);
- return res;
+ {
+ __malloc_lock ();
+ dlmalloc_stats ();
+ __malloc_unlock ();
+ }
+
+ return;
+}
+
+extern "C" char *
+strdup (const char *s)
+{
+ char *p;
+ size_t len = strlen (s) + 1;
+ if ((p = (char *) malloc (len)) != NULL)
+ memcpy (p, s, len);
+ return p;
}
/* We use a critical section to lock access to the malloc data
@@ -209,14 +298,14 @@ export_calloc (size_t nmemb, size_t size)
newlib will call __malloc_lock and __malloc_unlock at appropriate
times. */
-static NO_COPY muto *mprotect = NULL;
+NO_COPY muto *mallock = NULL;
void
malloc_init ()
{
- mprotect = new_muto (FALSE, "mprotect");
+ new_muto (mallock);
/* Check if mallock is provided by application. If so, redirect all
- calls to export_malloc/free/realloc to application provided. This may
+ 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)
@@ -224,21 +313,9 @@ malloc_init ()
#ifdef MALLOC_DEBUG
_free_r (NULL, _malloc_r (NULL, 16));
#else
- free (malloc (16));
+ user_data->free (user_data->malloc (16));
#endif
if (!export_malloc_called)
use_internal_malloc = 0;
}
}
-
-extern "C" void
-__malloc_lock (struct _reent *)
-{
- mprotect->acquire ();
-}
-
-extern "C" void
-__malloc_unlock (struct _reent *)
-{
- mprotect->release ();
-}