# 2.11BSD#431 - /usr/src/usr.sbin/named/named/storage.c

##### Functions

    calloc            X
    cfree             X
    openlog           X
    rt_free           X
    rt_malloc         X
    rt_prmem          X
    syslog            X

##### Variables

    rt_mdb            X

##### Macros

    LOG_ERR           X
    MDB_MAGIC         X
    MDB_SIZE          X

##### struct's

    memdebug          X

       1: /*
       2:  *			S T O R A G E . C
       3:  *
       4:  * Ray Tracing program, storage manager.
       5:  *
       6:  *  Functions -
       7:  *	rt_malloc	Allocate storage, with visibility & checking
       8:  *	rt_free		Similarly, free storage
       9:  *	rt_prmem	When debugging, print memory map
      10:  *	calloc, cfree	Which call rt_malloc, rt_free
      11:  *
      12:  *  Author -
      13:  *	Michael John Muuss
      14:  *
      15:  *  Source -
      16:  *	SECAD/VLD Computing Consortium, Bldg 394
      17:  *	The U. S. Army Ballistic Research Laboratory
      18:  *	Aberdeen Proving Ground, Maryland  21005-5066
      19:  *
      20:  *  Copyright Notice -
      21:  *	This software is Copyright (C) 1987 by the United States Army.
      22:  *	All rights reserved.
      23:  */
      24: #if defined(DOSCCS) && !defined(lint)
      25: static char RCSstorage[] = "@(#)$Header: /us1/cr/work/named/named/RCS/storage.c,v 1.1 94/01/01 03:13:33 cr Exp Locker: cr $";
      26: #endif
      27:
      28: #include <sys/param.h>
      29: #if BSD >= 43
      30: #include <sys/syslog.h>
      31: #else
      32: #include <stdio.h>
      33: #define LOG_ERR 0
      34: #endif BSD
      35:
      36: #undef malloc
      37: #undef free
      38:
      39: #define MDB_SIZE    20000
      40: #define MDB_MAGIC   0x12348969
      41: struct memdebug {
      42:     char    *mdb_addr;
      43:     char    *mdb_str;
      44:     int mdb_len;
      45: } rt_mdb[MDB_SIZE];
      46:
      47: /*
      48:  *			R T _ M A L L O C
      49:  */
      50: char *
      51: rt_malloc(cnt)
      52: unsigned int cnt;
      53: {
      54:     register char *ptr;
      55:     extern char *malloc();
      56:
      57:     cnt = (cnt+2*sizeof(int)-1)&(~(sizeof(int)-1));
      58:     ptr = malloc(cnt);
      59:
      60:     if( ptr==(char *)0 ) {
      61:         syslog(LOG_ERR, "rt_malloc: malloc failure");
      62:         abort();
      63:     } else  {
      64:         register struct memdebug *mp = rt_mdb;
      65:         for( ; mp < &rt_mdb[MDB_SIZE]; mp++ )  {
      66:             if( mp->mdb_len > 0 )  continue;
      67:             mp->mdb_addr = ptr;
      68:             mp->mdb_len = cnt;
      69:             mp->mdb_str = "???";
      70:             goto ok;
      71:         }
      72:         syslog(LOG_ERR, "rt_malloc:  memdebug overflow\n");
      73:     }
      74: ok: ;
      75:     {
      76:         register int *ip = (int *)(ptr+cnt-sizeof(int));
      77:         *ip = MDB_MAGIC;
      78:     }
      79:     return(ptr);
      80: }
      81:
      82: /*
      83:  *			R T _ F R E E
      84:  */
      85: void
      86: rt_free(ptr)
      87: char *ptr;
      88: {
      89:     register struct memdebug *mp = rt_mdb;
      90:     for( ; mp < &rt_mdb[MDB_SIZE]; mp++ )  {
      91:             if( mp->mdb_len <= 0 )  continue;
      92:         if( mp->mdb_addr != ptr )  continue;
      93:         {
      94:             register int *ip = (int *)(ptr+mp->mdb_len-sizeof(int));
      95:             if( *ip != MDB_MAGIC )  {
      96:                 syslog(LOG_ERR, "ERROR rt_free(x%x, %s) corrupted! x%x!=x%x\n", ptr, "???", *ip, MDB_MAGIC);
      97:                 abort();
      98:             }
      99:         }
     100:         mp->mdb_len = 0;    /* successful free */
     101:         goto ok;
     102:     }
     103:     syslog(LOG_ERR, "ERROR rt_free(x%x, %s) bad pointer!\n", ptr, "???");
     104:     abort();
     105: ok: ;
     106:
     107:     *((int *)ptr) = -1; /* zappo! */
     108:     free(ptr);
     109: }
     110:
     111: /*
     112:  *			R T _ P R M E M
     113:  *
     114:  *  Print map of memory currently in use.
     115:  */
     116: void
     117: rt_prmem(str)
     118: char *str;
     119: {
     120:     register struct memdebug *mp = rt_mdb;
     121:     register int *ip;
     122:
     123:     printf("\nRT memory use\t\t%s\n", str);
     124:     for( ; mp < &rt_mdb[MDB_SIZE]; mp++ )  {
     125:         if( mp->mdb_len <= 0 )  continue;
     126:         ip = (int *)(mp->mdb_addr+mp->mdb_len-sizeof(int));
     127:         printf("%7x %5x %s %s\n",
     128:             mp->mdb_addr, mp->mdb_len, mp->mdb_str,
     129:             *ip!=MDB_MAGIC ? "-BAD-" : "" );
     130:         if( *ip != MDB_MAGIC )
     131:             printf("\t%x\t%x\n", *ip, MDB_MAGIC);
     132:     }
     133: }
     134:
     135: char *
     136: calloc(num, size)
     137:     register unsigned num, size;
     138: {
     139:     extern char *malloc();
     140:     register char *p;
     141:
     142:     size *= num;
     143:     if (p = rt_malloc(size))
     144:         bzero(p, size);
     145:     return (p);
     146: }
     147:
     148: cfree(p, num, size)
     149:     char *p;
     150:     unsigned num;
     151:     unsigned size;
     152: {
     153:     rt_free(p);
     154: }
     155:
     156: #if BSD < 43
     157: openlog() {}
     158:
     159: syslog(x, str, a, b, c, d, e, f)
     160: int x;
     161: char    *str;
     162: int a, b, c, d, e, f;
     163: {
     164:     fprintf(stderr, str, a, b, c, d, e, f);
     165: }
     166: #endif BSD

#### Defined functions

calloc defined in line 135; used 6 times

- in /usr/src/usr.sbin/named/named/db.h line 109
- in /usr/src/usr.sbin/named/named/ns_forw.c line 58, 513
- in /usr/src/usr.sbin/named/named/ns_main.c line 344, 440, 1072

cfree defined in line 148; never used
openlog defined in line 157; used 2 times

- in /usr/src/usr.sbin/named/named/ns_main.c line 248-250(2)

rt_free defined in line 85; used 1 times

- in line 153

rt_malloc defined in line 50; used 1 times

- in line 143

rt_prmem defined in line 116; never used
syslog defined in line 159; used 76 times

- in line 61, 72, 96, 103
- in /usr/src/usr.sbin/named/named/db_dump.c line 90, 483, 491
- in /usr/src/usr.sbin/named/named/db_load.c line 135, 151, 250, 286, 298, 439, 448, 476, 523, 645, 688, 759, 803, 814, 826
- in /usr/src/usr.sbin/named/named/db_reload.c line 40
- in /usr/src/usr.sbin/named/named/db_save.c line 45, 73, 130, 167, 186
- in /usr/src/usr.sbin/named/named/db_update.c line 94
- in /usr/src/usr.sbin/named/named/ns_forw.c line 113, 518
- in /usr/src/usr.sbin/named/named/ns_init.c line 61, 95, 120, 126, 148, 159, 182, 189, 446
- in /usr/src/usr.sbin/named/named/ns_main.c line 259, 310-315(2), 322, 334, 340, 350, 383, 393, 415, 446, 535, 557, 577, 648, 668, 721, 964, 1078, 1145, 1172
- in /usr/src/usr.sbin/named/named/ns_maint.c line 154, 175, 220, 302, 469
- in /usr/src/usr.sbin/named/named/ns_req.c line 323, 921, 1119, 1168
- in /usr/src/usr.sbin/named/named/ns_resp.c line 575, 659, 1232, 1243, 1443
- in /usr/src/usr.sbin/named/named/ns_stats.c line 109

#### Defined variables

RCSstorage defined in line 25; never used
rt_mdb defined in line 45; used 6 times

- in line 64-65(2), 89-90(2), 120-124(2)

#### Defined struct's

memdebug defined in line 41; used 6 times

- in line 64(2), 89(2), 120(2)

#### Defined macros

LOG_ERR defined in line 33; used 4 times

- in line 61, 72, 96, 103

MDB_MAGIC defined in line 40; used 6 times

- in line 77, 95-96(2), 129-131(3)

MDB_SIZE defined in line 39; used 4 times

- in line 45, 65, 90, 124

Last modified: 1994-01-01 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 1426 |