if (!in_placep &&
((new_start<=start && start<new_start+size) || (new_start<start+size && start+size<=new_start+size))) {
- emsg("Toggling relblock when resizing hole to %lu\n",hp);
+ if (sSAnotify_gbcA->s.s_dbind != Cnil)
+ emsg("Toggling relblock when resizing hole to %lu\n",hp);
tm_table[t_relocatable].tm_adjgbccnt--;
GBC(t_relocatable);
return resize_hole(hp,tp,in_placep);
d=d<0 ? 0 : d;
d=(available_pages/3)<d ? (available_pages/3) : d;
- emsg("Hole overrun\n");
+ if (sSAnotify_gbcA && sSAnotify_gbcA->s.s_dbind != Cnil)
+ emsg("Hole overrun\n");
resize_hole(d+nn,t_relocatable,0);
case t_relocatable:
if (rb_high() && m>((rb_start-heap_end)>>PAGEWIDTH)) {
- emsg("Moving relblock low before expanding relblock pages\n");
+ if (sSAnotify_gbcA->s.s_dbind != Cnil)
+ emsg("Moving relblock low before expanding relblock pages\n");
tm_table[t_relocatable].tm_adjgbccnt--;
GBC(t_relocatable);
}
if (!gprof_on)
return Cnil;
- if (!getcwd(b,sizeof(b)))
- FEerror("Cannot get working directory", 0);
- if (chdir(P_tmpdir))
- FEerror("Cannot change directory to tmpdir", 0);
+ massert(getcwd(b,sizeof(b)));
+ massert(!chdir(P_tmpdir));
_mcleanup();
- if (snprintf(b1,sizeof(b1),"gprof %s",kcl_self)<=0)
- FEerror("Cannot write gprof command line", 0);
- if (!(pp=popen(b1,"r")))
- FEerror("Cannot open gprof pipe", 0);
+ massert(snprintf(b1,sizeof(b1),"gprof %s",kcl_self)>0);
+ massert((pp=popen(b1,"r")));
while ((n=fread(b1,1,sizeof(b1),pp)))
- if (!fwrite(b1,1,n,stdout))
- FEerror("Cannot write gprof output",0);
- if (pclose(pp)<0)
- FEerror("Cannot close gprof pipe", 0);
- if (chdir(b))
- FEerror("Cannot restore working directory", 0);
+ massert(fwrite(b1,1,n,stdout));
+ massert(pclose(pp)>=0);
+ massert(!chdir(b));
gprof_on=0;
return Cnil;
bool writable_malloc=0;
-void *
-malloc(size_t size) {
-
- static bool in_malloc;
-
- if (in_malloc)
- return NULL;
- in_malloc=1;
+static void *
+malloc_internal(size_t size) {
- if (!gcl_alloc_initialized)
- gcl_init_alloc(&size);
#ifdef CAN_UNRANDOMIZE_SBRK
- else if (!gcl_unrandomized)
- return sbrk(size);
+ if (core_end && core_end!=sbrk(0))/*malloc before main in saved_image*/
+ return sbrk(size);/*will never get to gcl_init_alloc, so brk point irrelevant*/
#endif
-
+ if (!gcl_alloc_initialized) {
+ static bool recursive_malloc;
+ if (recursive_malloc)
+ error("Bad malloc");
+ recursive_malloc=1;
+ gcl_init_alloc(&size);
+ recursive_malloc=0;
+ }
+
CHECK_INTERRUPT;
malloc_list = make_cons(alloc_simple_string(size), malloc_list);
malloc_list->c.c_car->st.st_self = alloc_contblock(size);
malloc_list->c.c_car->st.st_adjustable=writable_malloc;
+ return(malloc_list->c.c_car->st.st_self);
+
+}
+
+void *
+malloc(size_t size) {
+
+ void *v=malloc_internal(size);;
+
/* FIXME: this is just to handle clean freeing of the
monstartup memory allocated automatically on raw image
startup. In saved images, monstartup memory is only
#ifdef GCL_GPROF
if (raw_image && size>(textend-textstart) && !initial_monstartup_pointer) {
massert(!atexit(gprof_cleanup));
- initial_monstartup_pointer=malloc_list->c.c_car->st.st_self;
+ initial_monstartup_pointer=v;
}
#endif
- in_malloc=0;
- return(malloc_list->c.c_car->st.st_self);
+ return v;
}
gc_time=0;
#ifdef SGC
- printf("[%s for %ld %s pages..",
- (sgc_enabled ? "SGC" : "GC"),
- (sgc_enabled ? sgc_count_type(t) : tm_of(t)->tm_npage),
- (tm_table[(int)t].tm_name)+1);
+ emsg("[%s for %ld %s pages..",
+ (sgc_enabled ? "SGC" : "GC"),
+ (sgc_enabled ? sgc_count_type(t) : tm_of(t)->tm_npage),
+ (tm_table[(int)t].tm_name)+1);
#else
- printf("[%s for %ld %s pages..",
- ("GC"),
- (tm_of(t)->tm_npage),
- (tm_table[(int)t].tm_name)+1);
+ emsg("[%s for %ld %s pages..",
+ ("GC"),
+ (tm_of(t)->tm_npage),
+ (tm_table[(int)t].tm_name)+1);
#endif
#ifdef SGC
if (sSAnotify_gbcA->s.s_dbind != Cnil) {
if (gc_recursive)
- fprintf(stdout, "(T=...).GC finished]\n");
+ emsg("(T=...).GC finished]\n");
else
- fprintf(stdout, "(T=%d).GC finished]\n",gc_start);
- fflush(stdout);
+ emsg("(T=%d).GC finished]\n",gc_start);
}
return n>>(PAGEWIDTH-10);
}
+#include <sys/sysinfo.h>
+
static ufixnum
get_phys_pages_no_malloc(char freep) {
- return freep ?
- get_proc_meminfo_value_in_pages("MemFree:")+
- get_proc_meminfo_value_in_pages("Buffers:")+
- get_proc_meminfo_value_in_pages("Cached:") :
- get_proc_meminfo_value_in_pages("MemTotal:");
+ struct sysinfo s;
+ sysinfo(&s);
+ return (freep ? s.freeram : s.totalram)>>PAGEWIDTH;
}
#endif
static ufixnum
-get_phys_pages(char freep) {
+get_phys_pages1(char freep) {
return get_phys_pages_no_malloc(freep);
}
massert(!mbrk(cur));
- phys_pages=ufmin(get_phys_pages(0)+page(beg),real_maxpage)-page(beg);
+ phys_pages=ufmin(get_phys_pages1(0)+page(beg),real_maxpage)-page(beg);
get_gc_environ();
setup_maxpages(mem_multiple);
#define HAVE_GCL_CLEANUP
-#ifdef CAN_UNRANDOMIZE_SBRK
-bool gcl_unrandomized=FALSE;
-#endif
-
void
gcl_cleanup(int gc) {
cs_org=0;
initial_sbrk=core_end;
-#ifdef CAN_UNRANDOMIZE_SBRK
- gcl_unrandomized=FALSE;
-#endif
-
}
close_pool();
#include <stdio.h>
#include <stdlib.h>
#include "unrandomize.h"
- gcl_unrandomized=TRUE;
#endif
gcl_init_alloc(&argv);