ack/util/int/segment.c

85 lines
1.4 KiB
C
Raw Permalink Normal View History

1988-06-22 16:57:09 +00:00
/*
AB_list[s] holds the actual base of stack frame s; this
is the highest stack pointer of frame s-1.
Segments have the following numbers:
-2 DATA_SEGMENT
-1 HEAP_SEGMENT
0, 1, .., curr_frame stackframes
Note that AB_list[s] increases for decreasing s.
*/
1994-06-24 11:31:16 +00:00
/* $Id$ */
1988-06-22 16:57:09 +00:00
#include "segcheck.h"
2019-03-17 14:42:00 +00:00
#include "segment.h"
1988-06-22 16:57:09 +00:00
#include "global.h"
#include "mem.h"
#include "alloc.h"
#ifdef SEGCHECK
#define ABLISTSIZE 100L /* initial AB_list size */
#define DATA_SEGMENT -2
#define HEAP_SEGMENT -1
PRIVATE ptr *AB_list;
PRIVATE size frame_limit;
PRIVATE size curr_frame;
2019-03-17 14:42:00 +00:00
/** Allocate space for AB_list & initialize frame variables */
void init_AB_list(void)
{
1988-06-22 16:57:09 +00:00
frame_limit = ABLISTSIZE;
curr_frame = 0L;
AB_list = (ptr *) Malloc(frame_limit * sizeof (ptr), "AB_list");
AB_list[curr_frame] = AB;
}
2019-03-17 14:42:00 +00:00
void push_frame(ptr p)
1988-06-22 16:57:09 +00:00
{
if (++curr_frame == frame_limit) {
frame_limit = allocfrac(frame_limit);
AB_list = (ptr *) Realloc((char *) AB_list,
frame_limit * sizeof (ptr), "AB_list");
}
AB_list[curr_frame] = p;
}
2019-03-17 14:42:00 +00:00
void pop_frames(void)
{
1988-06-22 16:57:09 +00:00
while (AB_list[curr_frame] < AB) {
curr_frame--;
}
}
2019-03-17 14:42:00 +00:00
int ptr2seg(ptr p)
1988-06-22 16:57:09 +00:00
{
register int s;
if (in_gda(p)) {
s = DATA_SEGMENT;
}
else if (!in_stack(p)) {
s = HEAP_SEGMENT;
}
else {
for (s = curr_frame; s > 0; s--) {
if (AB_list[s] > p)
break;
}
}
return s;
}
#else /* SEGCHECK */
1988-06-22 16:57:09 +00:00
2019-03-17 14:42:00 +00:00
void init_AB_list(void) {}
1988-06-22 16:57:09 +00:00
2019-03-17 14:42:00 +00:00
void push_frame(ptr) {}
1988-06-22 16:57:09 +00:00
2019-03-17 14:42:00 +00:00
void pop_frames(void) {}
1988-06-22 16:57:09 +00:00
#endif /* SEGCHECK */
1988-06-22 16:57:09 +00:00