BSD 4_3 release
[unix-history] / usr / src / sys / sys / subr_mcount.c
index 6a5f4ed..9a78ae1 100644 (file)
@@ -1,11 +1,17 @@
-/*     subr_mcount.c   6.1     83/07/29        */
+/*
+ * Copyright (c) 1982, 1986 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ *
+ *     @(#)subr_mcount.c       7.1 (Berkeley) 6/5/86
+ */
 
 /* last integrated from: gmon.c        4.10 (Berkeley) 1/14/83 */
 
 #ifdef GPROF
 
 /* last integrated from: gmon.c        4.10 (Berkeley) 1/14/83 */
 
 #ifdef GPROF
-#include "../h/gprof.h"
-#include "../h/param.h"
-#include "../h/systm.h"
+#include "gprof.h"
+#include "param.h"
+#include "systm.h"
 
 /*
  * Froms is actually a bunch of unsigned shorts indexing tos
 
 /*
  * Froms is actually a bunch of unsigned shorts indexing tos
@@ -40,17 +46,17 @@ kmstartup()
        printf("Profiling kernel, s_textsize=%d [%x..%x]\n",
                s_textsize, s_lowpc, s_highpc);
        ssiz = (s_textsize / HISTFRACTION) + sizeof(struct phdr);
        printf("Profiling kernel, s_textsize=%d [%x..%x]\n",
                s_textsize, s_lowpc, s_highpc);
        ssiz = (s_textsize / HISTFRACTION) + sizeof(struct phdr);
-       sbuf = (u_short *)wmemall(memall, ssiz);
+       sbuf = (u_short *)calloc(ssiz);
        if (sbuf == 0) {
                printf("No space for monitor buffer(s)\n");
                return;
        }
        blkclr((caddr_t)sbuf, ssiz);
        fromssize = s_textsize / HASHFRACTION;
        if (sbuf == 0) {
                printf("No space for monitor buffer(s)\n");
                return;
        }
        blkclr((caddr_t)sbuf, ssiz);
        fromssize = s_textsize / HASHFRACTION;
-       froms = (u_short *)wmemall(memall, fromssize);
+       froms = (u_short *)calloc(fromssize);
        if (froms == 0) {
                printf("No space for monitor buffer(s)\n");
        if (froms == 0) {
                printf("No space for monitor buffer(s)\n");
-               wmemfree(sbuf, ssiz);
+               cfreemem(sbuf, ssiz);
                sbuf = 0;
                return;
        }
                sbuf = 0;
                return;
        }
@@ -62,12 +68,12 @@ kmstartup()
                tolimit = 65534;
        }
        tossize = tolimit * sizeof(struct tostruct);
                tolimit = 65534;
        }
        tossize = tolimit * sizeof(struct tostruct);
-       tos = (struct tostruct *)wmemall(memall, tossize);
+       tos = (struct tostruct *)calloc(tossize);
        if (tos == 0) {
                printf("No space for monitor buffer(s)\n");
        if (tos == 0) {
                printf("No space for monitor buffer(s)\n");
-               wmemfree(sbuf, ssiz);
+               cfreemem(sbuf, ssiz);
                sbuf = 0;
                sbuf = 0;
-               wmemfree(froms, fromssize);
+               cfreemem(froms, fromssize);
                froms = 0;
                return;
        }
                froms = 0;
                return;
        }
@@ -100,6 +106,7 @@ mcount()
        register struct tostruct        *top;           /* r9  => r3 */
        register struct tostruct        *prevtop;       /* r8  => r2 */
        register long                   toindex;        /* r7  => r1 */
        register struct tostruct        *top;           /* r9  => r3 */
        register struct tostruct        *prevtop;       /* r8  => r2 */
        register long                   toindex;        /* r7  => r1 */
+       static int s;
 
 #ifdef lint
        selfpc = (char *)0;
 
 #ifdef lint
        selfpc = (char *)0;
@@ -115,12 +122,16 @@ mcount()
 #endif not lint
        /*
         *      check that we are profiling
 #endif not lint
        /*
         *      check that we are profiling
-        *      and that we aren't recursively invoked.
         */
        if (profiling) {
                goto out;
        }
         */
        if (profiling) {
                goto out;
        }
-       profiling++;
+       /*
+        *      insure that we cannot be recursively invoked.
+        *      this requires that splhigh() and splx() below
+        *      do NOT call mcount!
+        */
+       s = splhigh();
        /*
         *      check that frompcindex is a reasonable pc value.
         *      for example:    signal catchers get called from the stack,
        /*
         *      check that frompcindex is a reasonable pc value.
         *      for example:    signal catchers get called from the stack,
@@ -202,7 +213,7 @@ mcount()
 
        }
 done:
 
        }
 done:
-       profiling--;
+       splx(s);
        /* and fall through */
 out:
        asm("   rsb");
        /* and fall through */
 out:
        asm("   rsb");