malloc.h
来自「基于组件方式开发操作系统的OSKIT源代码」· C头文件 代码 · 共 447 行 · 第 1/2 页
H
447 行
"LFS segment", /* 43 M_SEGMENT */ \ "LFS node", /* 44 M_LFSNODE */ \ "FFS node", /* 45 M_FFSNODE */ \ "MFS node", /* 46 M_MFSNODE */ \ "NQNFS Lease", /* 47 M_NQLEASE */ \ "NQNFS Host", /* 48 M_NQMHOST */ \ "Export Host", /* 49 M_NETADDR */ \ "NFS srvsock", /* 50 M_NFSSVC */ \ "NFS uid", /* 51 M_NFSUID */ \ "NFS daemon", /* 52 M_NFSD */ \ "ip_moptions", /* 53 M_IPMOPTS */ \ "in_multi", /* 54 M_IPMADDR */ \ "ether_multi", /* 55 M_IFMADDR */ \ "mrt", /* 56 M_MRTABLE */ \ "ISOFS mount", /* 57 M_ISOFSMNT */ \ "ISOFS node", /* 58 M_ISOFSNODE */ \ "MSDOSFS mount", /* 59 M_MSDOSFSMNT */ \ "MSDOSFS fat", /* 60 M_MSDOSFSFAT */ \ "MSDOSFS node", /* 61 M_MSDOSFSNODE */ \ "ttys", /* 62 M_TTYS */ \ "exec", /* 63 M_EXEC */ \ "miscfs mount", /* 64 M_MISCFSMNT */ \ "miscfs node", /* 65 M_MISCFSNODE */ \ "adosfs mount", /* 66 M_ADOSFSMNT */ \ "adosfs node", /* 67 M_ADOSFSNODE */ \ "adosfs anode", /* 68 M_ANODE */ \ "IP queue ent", /* 69 M_IPQ */ \ "afs", /* 70 M_AFS */ \ "adosfs bitmap", /* 71 M_ADOSFSBITMAP */ \ "NFS srvdesc", /* 72 M_NFSRVDESC */ \ "NFS diroff", /* 73 M_NFSDIROFF */ \ "NFS bigfh", /* 74 M_NFSBIGFH */ \ "EXT2FS node", /* 75 M_EXT2FSNODE */ \ "VM swap", /* 76 M_VMSWAP */ \ "VM page", /* 77 M_VMPAGE */ \ "VM page bucket", /* 78 M_VMPBUCKET */ \ NULL, /* 79 */ \ NULL, /* 80 */ \ NULL, /* 81 */ \ "UVM amap", /* 82 M_UVMAMAP */ \ "UVM aobj", /* 83 M_UVMAOBJ */ \ "temp", /* 84 M_TEMP */ \ "DMA map", /* 85 M_DMAMAP */ \ "IP flow", /* 86 M_IPFLOW */ \ "USB", /* 87 M_USB */ \ "USB device", /* 88 M_USBDEV */ \ "Pool", /* 89 M_POOL */ \ "coda", /* 90 M_CODA */ \ "filecore mount", /* 91 M_FILECOREMNT */ \ "filecore node", /* 92 M_FILECORENODE */ \ "RAIDframe", /* 93 M_RAIDFRAME */ \ "USB HC", /* 94 M_USBHC */ \ "key mgmt", /* 95 M_SECA */ \ "ip6_options", /* 96 M_IP6OPT */ \ "NDP", /* 97 M_IP6NDP */ \ "NTFS", /* 98 M_NTFS */ \ "pagedep", /* 99 M_PAGEDEP */ \ "inodedep", /* 100 M_INODEDEP */ \ "newblk", /* 101 M_NEWBLK */ \ "bmsafemap", /* 102 M_BMSAFEMAP */ \ "allocdirect", /* 103 M_ALLOCDIRECT */ \ "indirdep", /* 104 M_INDIRDEP */ \ "allocindir", /* 105 M_ALLOCINDIR */ \ "freefrag", /* 106 M_FREEFRAG */ \ "freeblks", /* 107 M_FREEBLKS */ \ "freefile", /* 108 M_FREEFILE */ \ "diradd", /* 109 M_DIRADD */ \ "mkdir", /* 110 M_MKDIR */ \ "dirrem", /* 111 M_DIRREM */ \ "ip6rr", /* 112 M_IP6RR */ \ "rp_addr", /* 113 M_RR_ADDR */ \ "softintr", /* 114 M_SOFTINTR */ \ "emuldata", /* 115 M_EMULDATA */ \ "1394ctl", /* 116 M_1394CTL */ \ "1394data", /* 117 M_1394DATA */ \ NULL, /* 118 */ \}struct kmemstats { long ks_inuse; /* # of packets of this type currently in use */ long ks_calls; /* total packets of this type ever allocated */ long ks_memuse; /* total memory held in bytes */ u_short ks_limblocks; /* number of times blocked for hitting limit */ u_short ks_mapblocks; /* number of times blocked for kernel map */ long ks_maxused; /* maximum number ever used */ long ks_limit; /* most that are allowed to exist */ long ks_size; /* sizes of this thing that are allocated */ long ks_spare;};/* * Array of descriptors that describe the contents of each page */struct kmemusage { short ku_indx; /* bucket index */ union { u_short freecnt;/* for small allocations, free pieces in page */ u_short pagecnt;/* for large allocations, pages alloced */ } ku_un;};#define ku_freecnt ku_un.freecnt#define ku_pagecnt ku_un.pagecnt/* * Set of buckets for each size of memory block that is retained */struct kmembuckets { caddr_t kb_next; /* list of free blocks */ caddr_t kb_last; /* last free block */ long kb_calls; /* total calls to allocate this size */ long kb_total; /* total number of blocks allocated */ long kb_totalfree; /* # of free elements in this bucket */ long kb_elmpercl; /* # of elements in this sized allocation */ long kb_highwat; /* high water mark */ long kb_couldfree; /* over high water mark and could free */};#ifdef _KERNEL#define MINALLOCSIZE (1 << MINBUCKET)#define BUCKETINDX(size) \ ((size) <= (MINALLOCSIZE * 128) \ ? (size) <= (MINALLOCSIZE * 8) \ ? (size) <= (MINALLOCSIZE * 2) \ ? (size) <= (MINALLOCSIZE * 1) \ ? (MINBUCKET + 0) \ : (MINBUCKET + 1) \ : (size) <= (MINALLOCSIZE * 4) \ ? (MINBUCKET + 2) \ : (MINBUCKET + 3) \ : (size) <= (MINALLOCSIZE* 32) \ ? (size) <= (MINALLOCSIZE * 16) \ ? (MINBUCKET + 4) \ : (MINBUCKET + 5) \ : (size) <= (MINALLOCSIZE * 64) \ ? (MINBUCKET + 6) \ : (MINBUCKET + 7) \ : (size) <= (MINALLOCSIZE * 2048) \ ? (size) <= (MINALLOCSIZE * 512) \ ? (size) <= (MINALLOCSIZE * 256) \ ? (MINBUCKET + 8) \ : (MINBUCKET + 9) \ : (size) <= (MINALLOCSIZE * 1024) \ ? (MINBUCKET + 10) \ : (MINBUCKET + 11) \ : (size) <= (MINALLOCSIZE * 8192) \ ? (size) <= (MINALLOCSIZE * 4096) \ ? (MINBUCKET + 12) \ : (MINBUCKET + 13) \ : (size) <= (MINALLOCSIZE * 16384) \ ? (MINBUCKET + 14) \ : (MINBUCKET + 15))/* * Turn virtual addresses into kmem map indicies */#define kmemxtob(alloc) (kmembase + (alloc) * NBPG)#define btokmemx(addr) (((caddr_t)(addr) - kmembase) / NBPG)#define btokup(addr) (&kmemusage[((caddr_t)(addr) - kmembase) >> PGSHIFT])/* * Macro versions for the usual cases of malloc/free */#if defined(KMEMSTATS) || defined(DIAGNOSTIC) || defined(_LKM) || \ defined(MALLOCLOG) || defined(LOCKDEBUG)#define MALLOC(space, cast, size, type, flags) \ (space) = (cast)malloc((u_long)(size), type, flags)#define FREE(addr, type) free((caddr_t)(addr), type)#else /* do not collect statistics */#define MALLOC(space, cast, size, type, flags) do { \ register struct kmembuckets *kbp = &bucket[BUCKETINDX(size)]; \ long s = splmem(); \ if (kbp->kb_next == NULL) { \ (space) = (cast)malloc((u_long)(size), type, flags); \ } else { \ (space) = (cast)kbp->kb_next; \ kbp->kb_next = *(caddr_t *)(space); \ } \ splx(s); \} while (0)#define FREE(addr, type) do { \ register struct kmembuckets *kbp; \ register struct kmemusage *kup = btokup(addr); \ long s = splmem(); \ if (1 << kup->ku_indx > MAXALLOCSAVE) { \ free((caddr_t)(addr), type); \ } else { \ kbp = &bucket[kup->ku_indx]; \ if (kbp->kb_next == NULL) \ kbp->kb_next = (caddr_t)(addr); \ else \ *(caddr_t *)(kbp->kb_last) = (caddr_t)(addr); \ *(caddr_t *)(addr) = NULL; \ kbp->kb_last = (caddr_t)(addr); \ } \ splx(s); \} while(0)#endif /* do not collect statistics */extern struct kmemstats kmemstats[];extern struct kmemusage *kmemusage;extern char *kmembase;extern struct kmembuckets bucket[];#ifdef MALLOCLOGextern void *_malloc __P((unsigned long size, int type, int flags, const char *file, long line));extern void _free __P((void *addr, int type, const char *file, long line));#define malloc(size, type, flags) \ _malloc((size), (type), (flags), __FILE__, __LINE__)#define free(addr, type) \ _free((addr), (type), __FILE__, __LINE__)#elseextern void *malloc __P((unsigned long size, int type, int flags));extern void free __P((void *addr, int type));#endif /* MALLOCLOG */extern void *realloc __P((void *curaddr, unsigned long newsize, int type, int flags));#endif /* _KERNEL */#endif /* !_SYS_MALLOC_H_ */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?