summaryrefslogtreecommitdiff
path: root/extra
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2017-06-13 23:41:10 +0300
committerIvan Maidanski <ivmai@mail.ru>2017-06-13 23:41:10 +0300
commit55d4370c5b5c308e8fd298882105add233a2a54a (patch)
treec9bf5bc9d42e86df897c96573343c5705be8d758 /extra
parent8ca98464c200519e2c1e587cb31682c3af5e958f (diff)
downloadbdwgc-55d4370c5b5c308e8fd298882105add233a2a54a.tar.gz
Move pcr_interface.c, real_malloc.c to 'extra' folder
(code refactoring) * Makefile.am (EXTRA_DIST): Add extra/ prefix to pcr_interface.c, real_malloc.c. * PCR-Makefile (CSRC): Likewise. * PCR-Makefile (COBJ): Add extra/ prefix to pcr_interface.o, real_malloc.o. * extra/gc.c: Remove include pcr_interface.c; update comment about files which are not included. * pcr_interface.c: Move to "extra" folder. * real_malloc.c: Likewise. * include/private/gc_priv.h (GC_INNER, GC_EXTERN): Update comment.
Diffstat (limited to 'extra')
-rw-r--r--extra/gc.c3
-rw-r--r--extra/pcr_interface.c179
-rw-r--r--extra/real_malloc.c39
3 files changed, 219 insertions, 2 deletions
diff --git a/extra/gc.c b/extra/gc.c
index a77fba65..ea3648e6 100644
--- a/extra/gc.c
+++ b/extra/gc.c
@@ -65,7 +65,6 @@
#include "../dyn_load.c"
#include "../gc_dlopen.c"
#include "../mach_dep.c"
-#include "../pcr_interface.c"
#include "../pthread_stop_world.c"
#include "../pthread_support.c"
#include "../specific.c"
@@ -84,4 +83,4 @@
# include "gc_pthread_redirects.h"
#endif
-/* real_malloc.c, extra/MacOS.c, extra/msvc_dbg.c are not included. */
+/* The files from "extra" folder are not included. */
diff --git a/extra/pcr_interface.c b/extra/pcr_interface.c
new file mode 100644
index 00000000..c7033055
--- /dev/null
+++ b/extra/pcr_interface.c
@@ -0,0 +1,179 @@
+/*
+ * Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
+ *
+ * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
+ * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
+ *
+ * Permission is hereby granted to use or copy this program
+ * for any purpose, provided the above notices are retained on all copies.
+ * Permission to modify the code and to distribute modified code is granted,
+ * provided the above notices are retained, and a notice that the code was
+ * modified is included with the above copyright notice.
+ */
+# include "private/gc_priv.h"
+
+# ifdef PCR
+/*
+ * We wrap all of the allocator functions to avoid questions of
+ * compatibility between the prototyped and nonprototyped versions of the f
+ */
+# include "config/PCR_StdTypes.h"
+# include "mm/PCR_MM.h"
+# include <errno.h>
+
+# define MY_MAGIC 17L
+# define MY_DEBUGMAGIC 42L
+
+void * GC_AllocProc(size_t size, PCR_Bool ptrFree, PCR_Bool clear )
+{
+ if (ptrFree) {
+ void * result = (void *)GC_malloc_atomic(size);
+ if (clear && result != 0) BZERO(result, size);
+ return(result);
+ } else {
+ return((void *)GC_malloc(size));
+ }
+}
+
+void * GC_DebugAllocProc(size_t size, PCR_Bool ptrFree, PCR_Bool clear )
+{
+ if (ptrFree) {
+ void * result = (void *)GC_debug_malloc_atomic(size, __FILE__,
+ __LINE__);
+ if (clear && result != 0) BZERO(result, size);
+ return(result);
+ } else {
+ return((void *)GC_debug_malloc(size, __FILE__, __LINE__));
+ }
+}
+
+# define GC_ReallocProc GC_realloc
+void * GC_DebugReallocProc(void * old_object, size_t new_size_in_bytes)
+{
+ return(GC_debug_realloc(old_object, new_size_in_bytes, __FILE__, __LINE__));
+}
+
+# define GC_FreeProc GC_free
+# define GC_DebugFreeProc GC_debug_free
+
+typedef struct {
+ PCR_ERes (*ed_proc)(void *p, size_t size, PCR_Any data);
+ GC_bool ed_pointerfree;
+ PCR_ERes ed_fail_code;
+ PCR_Any ed_client_data;
+} enumerate_data;
+
+void GC_enumerate_block(struct hblk *h; enumerate_data * ed)
+{
+ register hdr * hhdr;
+ register int sz;
+ ptr_t p;
+ ptr_t lim;
+ word descr;
+
+# if !defined(CPPCHECK)
+# error This code was updated without testing.
+# error and its precursor was clearly broken.
+# endif
+ hhdr = HDR(h);
+ descr = hhdr -> hb_descr;
+ sz = hhdr -> hb_sz;
+ if (descr != 0 && ed -> ed_pointerfree
+ || descr == 0 && !(ed -> ed_pointerfree)) return;
+ lim = (ptr_t)(h+1) - sz;
+ p = (ptr_t)h;
+ do {
+ if (PCR_ERes_IsErr(ed -> ed_fail_code)) return;
+ ed -> ed_fail_code =
+ (*(ed -> ed_proc))(p, sz, ed -> ed_client_data);
+ p+= sz;
+ } while ((word)p <= (word)lim);
+}
+
+struct PCR_MM_ProcsRep * GC_old_allocator = 0;
+
+PCR_ERes GC_EnumerateProc(
+ PCR_Bool ptrFree,
+ PCR_ERes (*proc)(void *p, size_t size, PCR_Any data),
+ PCR_Any data
+)
+{
+ enumerate_data ed;
+
+ ed.ed_proc = proc;
+ ed.ed_pointerfree = ptrFree;
+ ed.ed_fail_code = PCR_ERes_okay;
+ ed.ed_client_data = data;
+ GC_apply_to_all_blocks(GC_enumerate_block, &ed);
+ if (ed.ed_fail_code != PCR_ERes_okay) {
+ return(ed.ed_fail_code);
+ } else {
+ /* Also enumerate objects allocated by my predecessors */
+ return((*(GC_old_allocator->mmp_enumerate))(ptrFree, proc, data));
+ }
+}
+
+void GC_DummyFreeProc(void *p) {}
+
+void GC_DummyShutdownProc(void) {}
+
+struct PCR_MM_ProcsRep GC_Rep = {
+ MY_MAGIC,
+ GC_AllocProc,
+ GC_ReallocProc,
+ GC_DummyFreeProc, /* mmp_free */
+ GC_FreeProc, /* mmp_unsafeFree */
+ GC_EnumerateProc,
+ GC_DummyShutdownProc /* mmp_shutdown */
+};
+
+struct PCR_MM_ProcsRep GC_DebugRep = {
+ MY_DEBUGMAGIC,
+ GC_DebugAllocProc,
+ GC_DebugReallocProc,
+ GC_DummyFreeProc, /* mmp_free */
+ GC_DebugFreeProc, /* mmp_unsafeFree */
+ GC_EnumerateProc,
+ GC_DummyShutdownProc /* mmp_shutdown */
+};
+
+GC_bool GC_use_debug = 0;
+
+void GC_pcr_install()
+{
+ PCR_MM_Install((GC_use_debug? &GC_DebugRep : &GC_Rep), &GC_old_allocator);
+}
+
+PCR_ERes
+PCR_GC_Setup(void)
+{
+ return PCR_ERes_okay;
+}
+
+PCR_ERes
+PCR_GC_Run(void)
+{
+
+ if( !PCR_Base_TestPCRArg("-nogc") ) {
+ GC_quiet = ( PCR_Base_TestPCRArg("-gctrace") ? 0 : 1 );
+ GC_use_debug = (GC_bool)PCR_Base_TestPCRArg("-debug_alloc");
+ GC_init();
+ if( !PCR_Base_TestPCRArg("-nogc_incremental") ) {
+ /*
+ * awful hack to test whether VD is implemented ...
+ */
+ if( PCR_VD_Start( 0, NIL, 0) != PCR_ERes_FromErr(ENOSYS) ) {
+ GC_enable_incremental();
+ }
+ }
+ }
+ return PCR_ERes_okay;
+}
+
+void GC_push_thread_structures(void)
+{
+ /* PCR doesn't work unless static roots are pushed. Can't get here. */
+ ABORT("In GC_push_thread_structures()");
+}
+
+# endif
diff --git a/extra/real_malloc.c b/extra/real_malloc.c
new file mode 100644
index 00000000..145e73f3
--- /dev/null
+++ b/extra/real_malloc.c
@@ -0,0 +1,39 @@
+/*
+ * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
+ * Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
+ *
+ * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
+ * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
+ *
+ * Permission is hereby granted to use or copy this program
+ * for any purpose, provided the above notices are retained on all copies.
+ * Permission to modify the code and to distribute modified code is granted,
+ * provided the above notices are retained, and a notice that the code was
+ * modified is included with the above copyright notice.
+ */
+
+# ifdef HAVE_CONFIG_H
+# include "config.h"
+# endif
+
+# ifdef PCR
+/*
+ * This definition should go in its own file that includes no other
+ * header files. Otherwise, we risk not getting the underlying system
+ * malloc.
+ */
+# define PCR_NO_RENAME
+# include <stdlib.h>
+
+void * real_malloc(size_t size)
+{
+ return(malloc(size));
+}
+
+# else
+
+extern int GC_quiet;
+ /* ANSI C doesn't allow translation units to be empty. */
+ /* So we guarantee this one is nonempty. */
+
+#endif /* PCR */