123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504 |
- #ifdef HAVE_CONFIG_H
- # include <config.h>
- #endif
- #if HAVE_STRING_H
- # include <string.h>
- #endif
- #if HAVE_STDLIB_H
- # include <stdlib.h>
- #endif
- #ifdef emacs
- # include "blockinput.h"
- #endif
- #if !defined (__GNUC__) || __GNUC__ < 2
- # ifndef alloca
- # ifdef emacs
- # ifdef static
- # ifndef STACK_DIRECTION
- you
- lose
- -- must know STACK_DIRECTION at compile-time
- # endif
- # endif
- # endif
- # if defined (CRAY) && defined (CRAY_STACKSEG_END)
- long i00afunc ();
- # define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg))
- # else
- # define ADDRESS_FUNCTION(arg) &(arg)
- # endif
- # if __STDC__
- typedef void *pointer;
- # else
- typedef char *pointer;
- # endif
- # ifndef NULL
- # define NULL 0
- # endif
- # ifndef emacs
- # undef malloc
- # define malloc xmalloc
- # endif
- extern pointer malloc ();
- # ifndef STACK_DIRECTION
- # define STACK_DIRECTION 0
- # endif
- # if STACK_DIRECTION != 0
- # define STACK_DIR STACK_DIRECTION
- # else
- static int stack_dir;
- # define STACK_DIR stack_dir
- static void
- find_stack_direction ()
- {
- static char *addr = NULL;
- auto char dummy;
- if (addr == NULL)
- {
- addr = ADDRESS_FUNCTION (dummy);
- find_stack_direction ();
- }
- else
- {
-
- if (ADDRESS_FUNCTION (dummy) > addr)
- stack_dir = 1;
- else
- stack_dir = -1;
- }
- }
- # endif
- # ifndef ALIGN_SIZE
- # define ALIGN_SIZE sizeof(double)
- # endif
- typedef union hdr
- {
- char align[ALIGN_SIZE];
- struct
- {
- union hdr *next;
- char *deep;
- } h;
- } header;
- static header *last_alloca_header = NULL;
- pointer
- alloca (size_t size)
- {
- auto char probe;
- register char *depth = ADDRESS_FUNCTION (probe);
- # if STACK_DIRECTION == 0
- if (STACK_DIR == 0)
- find_stack_direction ();
- # endif
-
- {
- register header *hp;
- # ifdef emacs
- BLOCK_INPUT;
- # endif
- for (hp = last_alloca_header; hp != NULL;)
- if ((STACK_DIR > 0 && hp->h.deep > depth)
- || (STACK_DIR < 0 && hp->h.deep < depth))
- {
- register header *np = hp->h.next;
- free ((pointer) hp);
- hp = np;
- }
- else
- break;
- last_alloca_header = hp;
- # ifdef emacs
- UNBLOCK_INPUT;
- # endif
- }
- if (size == 0)
- return NULL;
-
- {
- register pointer new = malloc (sizeof (header) + size);
-
- if (new == 0)
- abort();
- ((header *) new)->h.next = last_alloca_header;
- ((header *) new)->h.deep = depth;
- last_alloca_header = (header *) new;
-
- return (pointer) ((char *) new + sizeof (header));
- }
- }
- # if defined (CRAY) && defined (CRAY_STACKSEG_END)
- # ifdef DEBUG_I00AFUNC
- # include <stdio.h>
- # endif
- # ifndef CRAY_STACK
- # define CRAY_STACK
- # ifndef CRAY2
- struct stack_control_header
- {
- long shgrow:32;
- long shaseg:32;
- long shhwm:32;
- long shsize:32;
- };
- struct stack_segment_linkage
- {
- long ss[0200];
- long sssize:32;
- long ssbase:32;
- long:32;
- long sspseg:32;
- long:32;
- long sstcpt:32;
- long sscsnm;
- long ssusr1;
- long ssusr2;
- long sstpid;
- long ssgvup;
- long sscray[7];
- long ssa0;
- long ssa1;
- long ssa2;
- long ssa3;
- long ssa4;
- long ssa5;
- long ssa6;
- long ssa7;
- long sss0;
- long sss1;
- long sss2;
- long sss3;
- long sss4;
- long sss5;
- long sss6;
- long sss7;
- };
- # else
- struct stk_stat
- {
- long now;
- long maxc;
- long high_water;
- long overflows;
- long hits;
- long extends;
- long stko_mallocs;
- long underflows;
- long stko_free;
- long stkm_free;
- long segments;
- long maxs;
- long pad_size;
- long current_address;
- long current_size;
- long initial_address;
- long initial_size;
- };
- struct stk_trailer
- {
- long this_address;
- long this_size;
- long unknown2;
- long unknown3;
- long link;
- long unknown5;
- long unknown6;
- long unknown7;
- long unknown8;
- long unknown9;
- long unknown10;
- long unknown11;
- long unknown12;
- long unknown13;
- long unknown14;
- };
- # endif
- # endif
- # ifdef CRAY2
- static long
- i00afunc (long *address)
- {
- struct stk_stat status;
- struct stk_trailer *trailer;
- long *block, size;
- long result = 0;
-
- STKSTAT (&status);
-
- trailer = (struct stk_trailer *) (status.current_address
- + status.current_size
- - 15);
-
- if (trailer == 0)
- abort ();
-
- while (trailer != 0)
- {
- block = (long *) trailer->this_address;
- size = trailer->this_size;
- if (block == 0 || size == 0)
- abort ();
- trailer = (struct stk_trailer *) trailer->link;
- if ((block <= address) && (address < (block + size)))
- break;
- }
-
- result = address - block;
- if (trailer == 0)
- {
- return result;
- }
- do
- {
- if (trailer->this_size <= 0)
- abort ();
- result += trailer->this_size;
- trailer = (struct stk_trailer *) trailer->link;
- }
- while (trailer != 0);
-
- return (result);
- }
- # else
- static long
- i00afunc (long address)
- {
- long stkl = 0;
- long size, pseg, this_segment, stack;
- long result = 0;
- struct stack_segment_linkage *ssptr;
-
- stkl = CRAY_STACKSEG_END ();
- ssptr = (struct stack_segment_linkage *) stkl;
-
- pseg = ssptr->sspseg;
- size = ssptr->sssize;
- this_segment = stkl - size;
-
- while (!(this_segment <= address && address <= stkl))
- {
- # ifdef DEBUG_I00AFUNC
- fprintf (stderr, "%011o %011o %011o\n", this_segment, address, stkl);
- # endif
- if (pseg == 0)
- break;
- stkl = stkl - pseg;
- ssptr = (struct stack_segment_linkage *) stkl;
- size = ssptr->sssize;
- pseg = ssptr->sspseg;
- this_segment = stkl - size;
- }
- result = address - this_segment;
-
- while (pseg != 0)
- {
- # ifdef DEBUG_I00AFUNC
- fprintf (stderr, "%011o %011o\n", pseg, size);
- # endif
- stkl = stkl - pseg;
- ssptr = (struct stack_segment_linkage *) stkl;
- size = ssptr->sssize;
- pseg = ssptr->sspseg;
- result += size;
- }
- return (result);
- }
- # endif
- # endif
- # endif
- #endif
|