home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / ibm / common / ibmMalloc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-16  |  3.0 KB  |  112 lines

  1. /*
  2.  * $XConsortium: ibmMalloc.h,v 1.2 91/07/16 13:08:24 jap Exp $
  3.  *
  4.  * Copyright IBM Corporation 1987,1988,1989,1990,1991
  5.  *
  6.  * All Rights Reserved
  7.  *
  8.  * License to use, copy, modify, and distribute this software and its
  9.  * documentation for any purpose and without fee is hereby granted,
  10.  * provided that the above copyright notice appear in all copies and that
  11.  * both that copyright notice and this permission notice appear in
  12.  * supporting documentation, and that the name of IBM not be
  13.  * used in advertising or publicity pertaining to distribution of the
  14.  * software without specific, written prior permission.
  15.  *
  16.  * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  17.  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS, AND 
  18.  * NONINFRINGEMENT OF THIRD PARTY RIGHTS, IN NO EVENT SHALL
  19.  * IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  20.  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21.  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  22.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  23.  * SOFTWARE.
  24.  *
  25. */
  26.  
  27. /*
  28.     malloc.h - definitions for memory allocation
  29.  
  30.     author: WJHansen, CMU/ITC
  31.     (c) Copyright IBM Corporation, 1986
  32. */
  33.  
  34. /*
  35.  *    a different implementation may need to redefine
  36.  *    INT WORD BLOCK ACTIVE PREACTIVE
  37.  *    where INT is integer type to which a pointer can be cast
  38.  *    and INT is the number of bytes given by WORD
  39.  *    WORD needs to be at least 4 so there are two zero bits
  40.  *    at the bottom of a Size field
  41.  */
  42.  
  43. #define INT int
  44. #define WORD 4
  45. #define EPSILON  (sizeof(struct freehdr)+sizeof(struct freetrlr))
  46. #define SEGGRAIN 4096 /* granularity for sbrk requests (in bytes) */
  47. #define ACTIVE    0x1
  48. #define PREACTIVE 0x2
  49. #define testbit(p, b) ((p)&(b))
  50. #define setbits(p, b) ((p)|(b))
  51. #define clearbits(p) ((p)&(~ACTIVE)&(~PREACTIVE))
  52. #define clearbit(p, b) ((p)&~(b))
  53. #define NEXTBLOCK(p) ((struct freehdr *)((char *)p+clearbits(p->Size)))
  54. #define PREVFRONT(p) (((struct freetrlr *)(p)-(sizeof (struct freetrlr)/WORD))->Front)
  55.  
  56. #define RETADDROFF (6)
  57.  
  58. #ifndef IDENTIFY
  59.  
  60. struct hdr { int Size };
  61. struct freehdr {
  62.     int Size;
  63.     struct freehdr *Next, *Prev;
  64. };
  65. struct freetrlr { struct freehdr *Front };
  66. struct segtrlr {
  67.     int Size;
  68.     struct freehdr *Next, *Prev;
  69.     struct freehdr *Front;
  70. };
  71.  
  72. #else
  73.  
  74. /* two additional words on every free block identify the caller that created the block
  75.    and it sequence number among all block creations */
  76. struct hdr { 
  77.     char *caller;
  78.     int seqno;
  79.     int Size;
  80. };
  81. struct freehdr {
  82.     char *caller;
  83.     int seqno;
  84.     int Size;
  85.     struct freehdr *Next, *Prev;
  86. };
  87. struct freetrlr { struct freehdr *Front; };
  88. struct segtrlr {
  89.     char *caller;
  90.     int seqno;
  91.     int Size;
  92.     struct freehdr *Next, *Prev;
  93.     struct freehdr *Front;
  94. };
  95.  
  96. #endif
  97.  
  98. struct arenastate {
  99.     struct freehdr *arenastart;
  100.     struct freehdr *arenaend;
  101.     struct freehdr *allocp;    /*free list ptr*/
  102.     struct hdr *PendingFree;
  103.     int SeqNo;
  104.     char arenahasbeenreset;
  105.     char InProgress;
  106.     char RecurringM0;
  107.     
  108. };
  109.  
  110. struct arenastate *GetMallocArena();
  111. char *malloc(), *realloc();
  112.