This repository was archived by the owner on Nov 1, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.c
1053 lines (960 loc) · 19.4 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "runtime.h"
#define EXTERN
#include "vars.h"
#undef EXTERN
#include "tagtable.h"
#ifdef HPROFILE
#include "sample.h"
int USE_heap=1;
#else
int USE_none=1, USE_time=1;
#endif
#ifdef sun
#include <math.h>
#ifdef SUNOS4
#include <floatingpoint.h>
#endif
#endif
/*
** Flags to the runtime system.
*/
#if DUMP
int dflag = 0; /* Stack dump at error */
int Gflag = 0; /* Stack dump before and after GC */
#endif /* DUMP */
#if GCSTAT
int sflag = 0; /* Produce a brief STAT file */
int Sflag = 0; /* Produce a verbose STAT file */
char *Sfile = 0;
int Bflag = 0; /* And sound the bell at GC */
#endif /* GCSTAT */
int uflag = 0; /* Use unbuffered input and output */
int Hflag = 0; /* Hiatonic input */
int Ttime = 0; /* Hiaton timeout time */
int Cflag = 0; /* Want core on BUS or SEGV */
#if 0
int aflag = 0; /* print extra space between outputs */
#endif
int zapthem = 0;/* ZAP at gc time */
int debug = 0;
int MergeHiaton = 0;
int traceflag = 0;
int fullheap; /* Set MinHeapsize = Heapsize */
#ifdef HSHOW
int showing = 0;
char *argColours = 0;
char *argOldColours = 0;
char *argDstColours = 0;
double milliseconds;
double sampleinterval = 0.1;
double nextsampletime;
#endif
int gcflag = gcOrg;
int nodecodeflags; /* Defaults to 0, can be set to 1 by linking in an ordinary .o file (from C). */
int minheap, maxheap; /* These can be used to set the heapsize if argument nodecodeflags=1 */
extern Node *CCPmain; /* Pointer to main function */
extern Node argvnp;
extern Node envpnp;
extern Node prognp;
extern Node PROCESSNO;
static int decode PROTO((char *));
static int s2i PROTO((char *));
static long atox PROTO((char *));
static void setupsigs PROTO((void));
SIGTYPE sighandl () /*PROTO((int, int, struct sigcontext *, char *))*/;
char *copystring PROTO((char *));
int decodehparg PROTO((char *));
#ifdef HPROFILE
void setuphpfile PROTO((void));
void setuptimer PROTO((void));
void DoSample PROTO((void));
void putres PROTO((FILE *, struct restrlist *));
#endif
void inittrace PROTO((void));
void inittrace0 PROTO((void));
#ifdef __ARM
int stacksize = 16000;
int Heapsize = 200000;
#else
int stacksize = 100000;
int Heapsize = 10000000/4;
#endif
int Utilize = 80;
int MinHeapsize = 500000/4;
int heapsize;
int tpmul = 1;
int Minleft; /* minimum heap left to continue execution */
#if defined(sparc) || defined(hppa)
int vsize = 200000;
#endif
int cafflag = 0;
FILE *mystdin;
#define Bcopy(x,y,z) bcopy((char *)x, (char *)y, z)
int max(x, y)
int x, y;
{
return x>y?x:y;
}
void
cleansig()
{
sigsetmask(0);
}
int intrflag = 0;
int doinggc = 0;
void
sigintr()
{
extern int *csbegin[], **cspointer;
if (debug)
fprintf(stderr, "sigintr %d\n", intrflag);
intrflag++;
if (intrflag > 1) {
if (debug)
fprintf(stderr, "many sigintr %d\n", doinggc);
if (!doinggc) {
intrflag = 0;
ehp = realehp;
cleansig();
failintr();
}
} else {
if (debug)
fprintf(stderr, "first sigintr %d\n", cspointer < csbegin);
if (cspointer < csbegin) {
/* There is an active catch */
ehp = 0;
} else {
/* No active catch, remember that we had an intr */
/* intrflag is polled in catch */
}
}
}
#ifdef CRAY
static PTR
mkpstr(n, s)
PTR n;
char *s;
{
return mkcons(mkestring(s), n);
}
#else
static PTR
mkpstr(n, s)
PTR n;
char *s;
{
/* assume that mkpstr is only called with enough memory to avoid gc */
return mkcons(mkcstring(s), n);
}
#endif
void
mkstrs(n, sp, pp)
int n;
char **sp;
PTR pp;
{
PTR sap;
int i;
sap = mknil();
for (i = n-1; i >= 0; i--) {
sap = mkpstr(sap, sp[i]);
}
update(pp, sap);
}
int iswhite(c) int c; { return c == ' ' || c == '\t'; }
char *flagtext[] = {
"The following run time flags are available:",
"",
" -B Sound the bell at the start of garbage collection.",
" -H Set heap size, e.g. -H30000. Default is 2600000.",
" -h Set start size of heap. Default is 50000.",
" -S Produce a verbose 'STAT' file.",
" - Marks the end of decoded arguments.",
"and many many more...",
"",
0
};
extern int argcOrg;
extern char **argvOrg;
void
main(argc, argv, envp)
int argc;
char **argv, **envp;
{
char *s;
int tenureUpdate = -1; /* -1 == use default */
int tenurePointer = -1;
int tenureWord = -1;
mystdin = stdin;
progname = *argv;
argvOrg = argv;
argcOrg = argc;
argc--;
argv++;
if ((s = getenv("LMLARGS"))) {
int n;
char *q;
char *a[1000]; /* hope this is enough */
char **na;
q = copystring(s);
while(iswhite(*q))
q++;
for(n = 0; *q; ) {
a[n++] = q;
while(*q && !iswhite(*q))
q++;
while(iswhite(*q))
*q++ = 0;
}
na = (char **)xmalloc((argc+n+1) * sizeof(char *));
Bcopy(a, na, n * sizeof(char *));
Bcopy(argv, na+n, argc * sizeof(char *));
argc += n;
na[argc] = 0;
argv = na;
}
#ifndef __ARM
if ((s = getenv("LMLHEAP")))
Heapsize = decode(s) / sizeof(UInt);
#endif
if (argc && strcmp(argv[0], "+RTS") == 0) argc--, argv++, nodecodeflags = 0;
if (!nodecodeflags) {
while (argc && argv[0][0] == '-') {
if (argv[0][1] == '\0' || strcmp(argv[0], "-RTS") == 0) {
argv++, argc--;
break;
}
if (strcmp("-gc-caf", *argv) == 0) {
cafflag++;
goto nextarg;
}
if (strcmp("-gc-slide", *argv) == 0) {
if(gcflag)
gcflag = gcError;
else
gcflag = gcSlide;
goto nextarg;
} else if (strcmp("-gc-baker", *argv) == 0) {
if(gcflag)
gcflag = gcError;
else
gcflag = gcChenney;
goto nextarg;
} else if (strcmp("-gc-gen", *argv) == 0) {
if(gcflag)
gcflag = gcError;
else
gcflag = gcGenSeward;
goto nextarg;
} else if (strcmp("-gc-gen2", *argv) == 0) {
if(gcflag)
gcflag = gcError;
else
gcflag = gcGen2;
goto nextarg;
} else if (strncmp("-tenureUpdate", *argv,13) == 0) {
fprintf(stderr,"tenureUpdate = %d\n",
tenureUpdate = s2i((*argv)+13));
goto nextarg;
} else if (strncmp("-tenurePointer", *argv,14) == 0) {
fprintf(stderr,"tenurePointer = %d\n",
tenurePointer = s2i((*argv)+14));
goto nextarg;
} else if (strncmp("-tenureWord", *argv,11) == 0) {
fprintf(stderr,"tenureWord = %d\n",
tenureWord = s2i((*argv)+11));
goto nextarg;
} else if (strncmp("-tpmul", *argv,6) == 0) {
fprintf(stderr,"tpmul = %d\n",
tpmul = decode((*argv)+6));
goto nextarg;
} else if (strcmp("-no-zap", *argv) == 0) {
zapthem = 0;
goto nextarg;
} else if (strcmp("-zap", *argv) == 0) {
zapthem = 1;
goto nextarg;
} else {
char *ap = *argv;
while (*++ap) {
switch (*ap) {
#if defined(HPROFILE) || defined(HSHOW)
case 'i':
sampleinterval = atof(ap + 1);
if (sampleinterval < 0.05) {
fprintf(stderr, "-i: too small\n"); finish(1);
}
#ifndef HSHOW
noautosample++;
#endif
goto nextarg;
#endif
#ifdef HPROFILE
case 'g':
case 'm':
case 'p':
case 'c':
case 't':
if (decodehparg(ap))
goto nextarg;
break;
case 'k':
gengcmark ^= 1;
break;
#endif
#if DUMP
case 'M':
maxdump = atoi(ap + 1);
goto nextarg;
case 'E':
dumpdepth = atoi(ap + 1);
goto nextarg;
case 'd':
dflag++;
break;
case 'G':
Gflag++;
if (ap + 1)
Gno = atoi(ap + 1);
goto nextarg;
case 'K':
stopaddr = atox(ap + 1);
goto nextarg;
case 'Q':
chkaddr = (int **)atox(ap + 1);
goto nextarg;
#endif /* DUMP */
#if GCSTAT
case 'B':
Bflag++;
break;
case 'S':
Sflag++;
if (ap[1]) {
Sfile = ap+1;
goto nextarg;
}
break;
case 's':
sflag++;
break;
#endif /* GCSTAT */
case 'C':
Cflag++;
break;
#if 0
case 'u':
uflag++;
break;
case 'a':
aflag++;
break;
#endif
case 'h':
MinHeapsize = decode(ap + 1) / sizeof(UInt);
goto nextarg;
case 'H':
Heapsize = decode(ap + 1) / sizeof(UInt);
goto nextarg;
break;
case 'U':
Utilize = decode(ap + 1);
goto nextarg;
break;
case 'A':
stacksize = decode(ap + 1);
#if defined(sparc) || defined(hppa)
vsize = stacksize;
#endif
goto nextarg;
break;
#if defined(sparc) || defined(hppa)
case 'V':
vsize = decode(ap + 1);
goto nextarg;
break;
#endif
case 'X':
debug++;
break;
#ifdef HSHOW
case 'x':
showing = max(showing,1);
if(*++ap == 'c') {
showing = max(showing,2);
argColours = ap+1;
} else {
if(*ap == 'o') {
showing = max(showing,3);
argOldColours = ap+1;
} else {
if(*ap == 'p') {
showing = max(showing,4);
argDstColours = ap+1;
}
}
}
goto nextarg;
break;
#endif
case 'T':
traceflag++;
break;
#if 0
case 'R':
Hflag++;
Ttime = atoi(ap + 1);
goto nextarg;
break;
#endif
default:
fprintf(stderr, "**** Illegal flag ****\n");
/* fall into ... */
case 'f': /* Print an explanation of the v
* run-time flags, and exit. */
{
char **p;
for (p = flagtext; *p; p++)
fprintf(stderr, "%s\n", *p);
}
finish(1);
}
}
}
nextarg: ;
argc--;
argv++;
}
} else {
if (minheap) MinHeapsize = minheap/sizeof (UInt);
if (maxheap) Heapsize = maxheap/sizeof (UInt);
}
{
/* Sanity check */
extern Tag TAGFIRST, TAGLAST;
if (((UInt)&TAGLAST - (UInt)&TAGFIRST) != TAGTABLESIZE * NTAGS * sizeof(PTR)) {
fprintf(stderr, "Corrupted tag table size %d instead of %d!\n",(UInt)&TAGLAST - (UInt)&TAGFIRST,TAGTABLESIZE * NTAGS * sizeof(PTR));
#if 0
exit(1);
#else
fprintf(stderr, "... but I will try anyway!\n");
#endif
}
}
if(!gcflag)
gcflag = gcOrg;
if(gcflag == gcError) {
fprintf(stderr,"Only one garbage collector at a time, please.\n");
finish(1);
}
heapsize = MinHeapsize;
#if DUMP
if (Gflag)
loadsymbols();
#endif
if (traceflag)
inittrace();
else
inittrace0();
#if defined(sun) && defined(SUNOS4)
ieee_handler("set", "common", failfloat);
signal(SIGIOT, failfloat); /* integer zero divide */
#else /* sun */
#ifndef __ARM
signal(SIGFPE, failfloat);
#endif
#endif /* sun */
#ifdef mips
signal(SIGTRAP, failfloat); /* mips generates SIGTRAP on fixed point divide by zero */
#endif
setuptenure(tenureUpdate,tenurePointer,tenureWord);
setupstack();
setupheap();
#ifndef __ARM
{
int i;
for(i=0; envp[i] != 0; i++)
;
mkstrs(i, envp, &envpnp);
}
#endif
mkstrs(argc, argv, &argvnp);
/* set program name */
update(&prognp, mkcstring(progname));
setupsigs();
#ifndef __ARM
if (!Cflag) {
#ifndef linux
(void)signal(SIGBUS, sighandl);
#endif
(void)signal(SIGINT, sighandl);
(void)signal(SIGSEGV, sighandl);
(void)signal(SIGILL, sighandl);
}
#endif
if (uflag) {
setbuf(stdout, NULL);
}
setbuf(stderr, NULL);
GCstartup();
update(&PROCESSNO, mkint(getpid()));
{
extern Tag INPUT;
*--ep = &argvnp;
*--ep = &envpnp;
*--ep = mkap(CCPmain, mknode2(&INPUT, (Int)mystdin, (Int)-1));
}
initcaf();
#ifdef HSHOW
if(showing) { /* setupheap must be done before calling setupDisplay */
setupDisplay(sampleinterval);
/* setupShowTimer(); */
}
#endif
initfiles();
#ifdef HPROFILE
if (profiling) {
setuphpfile();
setuptimer();
DoSample();
}
#endif
printtop(stdout); /* evaluate and print the user program */
#if 0
if (aflag) fprintf(ofiles[1], "\n");
#endif
GCfinal(starthp, hp);
#ifdef HPROFILE
if (profiling) {
DoSample();
}
#endif
finish(0);
}
char *
copystring(s)
char *s;
{
char *r;
r = (char *)xmalloc(strlen(s)+1);
strcpy(r, s);
return r;
}
void
finish(r)
int r;
{
set_tty(0);
exit(r);
}
void
lfinish(r)
PTR r;
{
finish((int)INTOF(r));
}
void
xsignal(s, intr)
int s;
SIGTYPE (*intr)();
{
if (signal(s, SIG_IGN) != SIG_IGN)
(void)signal(s, intr);
}
SIGTYPE
killme()
{
finish(2);
SIGLAST;
}
static void
setupsigs()
{
if (traceflag != 1)
xsignal(SIGINT, killme);
#ifndef __ARM
xsignal(SIGHUP, killme);
#endif
xsignal(SIGTERM, killme);
}
#ifdef __ARM
void
set_tty(set) /* !!! */
int set;
{
return;
}
#else
#if defined(SYSV) || defined(linux) || defined(SOLARIS) || defined(HPUX) || defined(__NetBSD__) || defined(__FreeBSD__) || defined(__CYGWIN32__)
void
set_tty(set)
int set;
{
static struct termio save, modes;
static int sset = 0;
if (set) {
if (!sset)
ioctl(2, TCGETA, &save);
modes = save;
modes.c_iflag &= ~(IXON | IXOFF | ISTRIP);
/*modes.c_oflag &= ~OPOST;*/
modes.c_lflag &= ~(ICANON | ECHO);
modes.c_cc[VMIN] = 1;
modes.c_cc[VTIME] = 0;
ioctl(2, TCSETA, &modes);
sset = 1;
} else if (sset) {
ioctl(2, TCSETA, &save);
}
}
#else
void
set_tty(set)
int set;
{
static struct sgttyb save, modes;
static int sset = 0;
if (set) {
if (!sset)
ioctl(2, TIOCGETP, &save);
modes = save;
modes.sg_flags |= CBREAK;
modes.sg_flags &= ~ECHO;
ioctl(2, TIOCSETP, &modes);
sset = 1;
} else if (sset) {
ioctl(2, TIOCSETP, &save);
}
}
#endif
#endif /* __ARM */
static int
s2i(s)
char *s;
{
if(*s) {
int res = 0;
while(*s) {
res = res*10 + *s++ -'0';
}
return res;
}
return -1; /* default */
}
static int
decode(s)
char *s;
{
int c;
double m;
#ifndef atof
/* atof might be a macro */
extern double atof();
#endif
if (!*s) {
fprintf(stderr, "Missing number.\n");
exit(1);
}
m = atof(s);
c = s[strlen(s)-1];
if (c == 'g') {
gcflag = gcGenSeward;
c = s[strlen(s)-2];
}
if (c == 'G')
m *= 1000000000;
else if (c == 'm' || c == 'M')
m *= 1000000;
else if (c == 'k' || c == 'K')
m *= 1000;
m *= sizeof(PTR)/sizeof(int); /* To simplify life on 64 bit machines */
return (int)m;
}
#ifdef CRAY
STOFERR()
{
printf("Stack overflow\n");
finish(1);
}
STOFJMP()
{
printf("Stack failed to allocate in same chunk\n");
finish(1);
}
#endif
#if defined(sun) && !defined(SOLARIS)
#include <errno.h>
extern int sys_nerr;
char *
strerror(i)
int i;
{
if (i < 0 || i >= sys_nerr)
return "Unknown error";
return sys_errlist[i];
}
#endif
static long
atox(s)
char *s;
{
long i;
sscanf(s, "%lx", &i);
return i;
}
#ifdef sun
int
matherr(exc)
struct exception *exc;
{
return 0; /* use default value */
}
#endif
/* For gcc */
void __main() {}
#ifdef sparc
int old_npc;
extern int zero_g7();
#endif
#ifdef hppa
int old_npc;
#endif
#ifdef HSHOW
/*
* Called every 20ms...
*/
SIGTYPE
timerTickShow(sig,code,sigcx,addr)
int sig, code;
struct sigcontext *sigcx;
char *addr;
{
if (showflag || doinggc)
SIGLAST; /* clock is frozen during sampling and gc */
milliseconds += 20.0; /* another 20ms */
showflag = (milliseconds >= nextsampletime);
if (showflag) {
#ifdef sparc
#define JMPMASK 0x81c00000
#define ISJMP(x) (((x)&JMPMASK) == JMPMASK)
if(ISJMP(*(int *)sigcx->sc_pc) ||
ISJMP(*(int *)sigcx->sc_npc) ) { /* Wait ! */
showflag =0;
SIGLAST;
}
old_npc = sigcx->sc_npc;
sigcx->sc_npc = (int)zero_g7;
#endif
#if mips
if(sigcx->sc_regs[30] != (int)ehp) {
showflag =0;
SIGLAST;
}
sigcx->sc_regs[30] = 0;
#endif
ehp = 0;
nextsampletime += 1000.0 * sampleinterval;
}
SIGLAST;
}
void
setupShowTimer()
{
struct itimerval inttimer;
inttimer.it_value.tv_sec = 0;
inttimer.it_value.tv_usec = 20000;
inttimer.it_interval = inttimer.it_value;
signal(SIGVTALRM, timerTickShow);
setitimer(ITIMER_VIRTUAL, &inttimer, (struct itimerval *)0);
milliseconds = 0.0;
nextsampletime = 1000.0 * sampleinterval;
}
#endif
#ifdef HPROFILE
/*
* Set up the heap profile file.
*/
void
setuphpfile()
{
long thetime;
char* timestr;
char b[10000];
strcpy(b, progname);
strcat(b, ".hp");
hpfilename = copystring(b);
if ((hpfile = fopen(hpfilename, "w")) == NULL) {
fprintf(stderr, "cannot open %s\n", hpfilename);
finish(1);
}
fprintf(hpfile, "JOB \"%s", progname);
switch(hashon) {
case GROUP:
fprintf(hpfile, " -g");
putres(hpfile, grpres);
break;
case MODULE :
fprintf(hpfile, " -m");
putres(hpfile, modres);
break;
case PRODUCER :
fprintf(hpfile, " -p");
putres(hpfile, prores);
break;
case CONSTRUCTION :
fprintf(hpfile, " -c");
putres(hpfile, conres);
break;
case TYPE:
fprintf(hpfile, " -t");
putres(hpfile, typres);
break;
default:
fprintf(hpfile, " -?");
break;
}
if (hashon != GROUP && grpresflag) {
fprintf(hpfile, " -g");
putres(hpfile, grpres);
}
if (hashon != MODULE && modresflag) {
fprintf(hpfile, " -m");
putres(hpfile, modres);
}
if (hashon != PRODUCER && proresflag) {
fprintf(hpfile, " -p");
putres(hpfile, prores);
}
if (hashon != CONSTRUCTION && conresflag) {
fprintf(hpfile, " -c");
putres(hpfile, conres);
}
if (hashon != TYPE && typresflag) {
fprintf(hpfile, " -t");
putres(hpfile, typres);
}
if (noautosample)
fprintf(hpfile, " -i%.2f", sampleinterval);
fprintf(hpfile, "\"\n");
thetime = time((long*) 0);
timestr = ctime(&thetime);
timestr[ strlen(timestr) - 1 ] = '\0'; /* blat '\n' */
fprintf(hpfile, "DATE \"%s\"\n", timestr);
fprintf(hpfile, "SAMPLE_UNIT \"seconds\"\n");
fprintf(hpfile, "VALUE_UNIT \"bytes\"\n");
}
/*
* Called every 20ms...
*/
SIGTYPE
timertick()
{
#if defined(HPUX) || defined(SOLARIS)
signal(SIGVTALRM, timertick); /* gotta re-establish the interrupt handler on stupid systems */
#endif
if (sampleflag)
SIGLAST; /* clock is frozen during sampling */
milliseconds += 20.0; /* another 20ms */
sampleflag = (milliseconds >= nextsampletime);
if (sampleflag)
nextsampletime += 1000.0 * sampleinterval;
SIGLAST;
}
void
setuptimer()
{
struct itimerval inttimer;
inttimer.it_value.tv_sec = 0;
inttimer.it_value.tv_usec = 20000;
inttimer.it_interval = inttimer.it_value;
signal(SIGVTALRM, timertick);
setitimer(ITIMER_VIRTUAL, &inttimer, (struct itimerval *)0);
milliseconds = 0.0;
nextsampletime = 1000.0 * sampleinterval;
}
#endif
#if 0
scanvap(f)
int (*f)();
{
extern int etext, edata;
int *p;
extern Tag VAP;
for(p = &etext; p<&edata; p++) {
if (*p == (Int)&VAP && p[1] == (Int)(p+3)) {
/* found a VAP outside the heap */
f(p);
}
}
}
PTR *vaps, *svaps;
noticevap(p)
PTR *p;
{
*vaps++ = p;
}
scandata()
{
svaps = vaps = xmalloc(2000 * sizeof(PTR*));
scanvap(noticevap);
printf("%d CAFs found\n", vaps-svaps);
}
chkcafs()
{
PTR *p;
for(p = svaps; p<vaps; p++) {
dumpgraph(*p, dumpdepth);
fprintf(stderr, "\n");
}
}
#endif
void *
xmalloc(n)
size_t n;