Files
mercury/runtime/mercury_context.c
Tyson Dowd aa641c6121 Clean up memory management code. This mostly involves cleaning up
Estimated hours taken: 5

Clean up memory management code.  This mostly involves cleaning up
the #defines and removing duplicate code.  This is just an incremental
improvement, more changes are expected.

runtime/mercury_conf_param.h:
	Add definitions for MR_CAN_GET_PC_AT_SIGNAL and
	MR_CHECK_OVERFLOW_VIA_MPROTECT.

runtime/mercury_context.c:
	Rename reset_zone() as reset_redzone().

runtime/mercury_memory_handlers.c:
	Define one set of functions with conditional bodies, rather
	than conditional defintions of functions.

runtime/mercury_memory_zones.c:
	Use MR_CHECK_OVERFLOW_VIA_MPROTECT rather than just looking
	for HAVE_MPROTECT and HAVE_SIGINFO.

runtime/mercury_memory_zones.h:
	Only use redzones with MR_CHECK_OVERFLOW_VIA_MPROTECT.

	Correct a comment about how much memory is should be
	given to construct_zone.
	The correct caculation is
		size + unit (for offset) + unit (for hardmax)

	Rename reset_zone as reset_redzone.
1998-05-11 08:23:26 +00:00

119 lines
2.5 KiB
C

/*
INIT mercury_sys_init_context
ENDINIT
*/
/*
** Copyright (C) 1995-1998 The University of Melbourne.
** This file may only be copied under the terms of the GNU Library General
** Public License - see the file COPYING.LIB in the Mercury distribution.
*/
/* context.mod - handles multithreading stuff. */
#include "mercury_imp.h"
#include <stdio.h>
#include <unistd.h> /* for getpid() and fork() */
#ifdef PARALLEL
#include <signal.h>
#endif
#include "mercury_memory_handlers.h"
#include "mercury_context.h"
#include "mercury_engine.h" /* for `memdebug' */
Context *this_context;
static Context *free_context_list = NULL;
void
init_process_context(void)
{
init_heap();
this_context = new_context();
/* load the registers so we don't clobber hp */
restore_transient_registers();
load_context(this_context);
save_transient_registers();
if (memdebug) debug_memory();
}
Context *
new_context(void)
{
Context *c;
if (free_context_list == NULL) {
c = (Context *) make(Context);
c->detstack_zone = NULL;
c->nondetstack_zone = NULL;
#ifdef MR_USE_TRAIL
c->trail_zone = NULL;
#endif
} else {
c = free_context_list;
free_context_list = c->next;
}
c->next = NULL;
c->resume = NULL;
c->context_succip = ENTRY(do_not_reached);
if (c->detstack_zone != NULL) {
reset_redzone(c->detstack_zone);
} else {
c->detstack_zone = create_zone("detstack", 0,
detstack_size, next_offset(), detstack_zone_size,
default_handler);
}
c->context_sp = c->detstack_zone->min;
if (c->nondetstack_zone != NULL) {
reset_redzone(c->nondetstack_zone);
} else {
c->nondetstack_zone = create_zone("nondetstack", 0,
nondstack_size, next_offset(), nondstack_zone_size,
default_handler);
}
c->context_maxfr = c->nondetstack_zone->min;
c->context_curfr = c->nondetstack_zone->min;
bt_redoip(c->context_curfr) = ENTRY(do_not_reached);
bt_prevfr(c->context_curfr) = NULL;
bt_succip(c->context_curfr) = ENTRY(do_not_reached);
bt_succfr(c->context_curfr) = NULL;
#ifdef MR_USE_TRAIL
if (c->trail_zone != NULL) {
reset_redzone(c->trail_zone);
} else {
c->trail_zone = create_zone("trail", 0,
trail_size, next_offset(), trail_zone_size,
default_handler);
}
c->context_trail_ptr = (MR_TrailEntry *) c->trail_zone->min;
c->context_ticket_counter = 0;
#endif
c->context_hp = NULL;
return c;
}
void
delete_context(Context *c)
{
c->next = free_context_list;
free_context_list = c;
}
void
flounder(void)
{
fatal_error("computation floundered");
}
void mercury_sys_init_context(void); /* suppress gcc warning */
void mercury_sys_init_context(void) {
}