|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. ! 3: * ! 4: * @APPLE_LICENSE_HEADER_START@ ! 5: * ! 6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights ! 7: * Reserved. This file contains Original Code and/or Modifications of ! 8: * Original Code as defined in and that are subject to the Apple Public ! 9: * Source License Version 1.1 (the "License"). You may not use this file ! 10: * except in compliance with the License. Please obtain a copy of the ! 11: * License at http://www.apple.com/publicsource and read it before using ! 12: * this file. ! 13: * ! 14: * The Original Code and all software distributed under the License are ! 15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER ! 16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, ! 17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, ! 18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the ! 19: * License for the specific language governing rights and limitations ! 20: * under the License. ! 21: * ! 22: * @APPLE_LICENSE_HEADER_END@ ! 23: */ ! 24: ! 25: /* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. ! 26: * ! 27: * File: driverkit/objc_support.m ! 28: * ! 29: * Run-time support for kernel ObjC library. ! 30: * ! 31: * HISTORY ! 32: * 31-Jan-92 Doug Mitchell at NeXT ! 33: * Created. ! 34: */ ! 35: ! 36: #import <streams/streams.h> ! 37: #import <bsd/sys/syslog.h> ! 38: #import <bsd/stdarg.h> ! 39: #import <bsd/machine/spl.h> ! 40: ! 41: /* ! 42: * FIXME - what the heck is this? ! 43: */ ! 44: char **NXArgv; ! 45: ! 46: int NXFlush(NXStream *s) ! 47: { ! 48: /* ! 49: * Nothing to do for now. ! 50: */ ! 51: return 0; ! 52: } ! 53: ! 54: void NXPrintf(NXStream *s, const char *format, ...) ! 55: { ! 56: register sp = splhigh(); ! 57: va_list ap; ! 58: ! 59: va_start(ap, format); ! 60: log(LOG_ERR, format, ap); ! 61: va_end(ap); ! 62: splx(sp); ! 63: } ! 64: ! 65: /* ! 66: * This should never be called... ! 67: */ ! 68: void abort() ! 69: { ! 70: panic("objc: fatal error\n"); ! 71: } ! 72: ! 73: #import <objc/zone.h> ! 74: ! 75: #import <kern/kalloc.h> ! 76: ! 77: #define MDECL(reqlen) \ ! 78: union { \ ! 79: struct _mhead hdr; \ ! 80: char _m[(reqlen) + sizeof (struct _mhead)]; \ ! 81: } ! 82: ! 83: struct _mhead { ! 84: size_t mlen; ! 85: char dat[0]; ! 86: }; ! 87: ! 88: static __inline__ ! 89: void *kern_malloc( ! 90: struct _NXZone *zonep, ! 91: size_t size) ! 92: { ! 93: MDECL(size) *mem; ! 94: size_t memsize = sizeof (*mem); ! 95: ! 96: if (size == 0) ! 97: return (0); ! 98: ! 99: mem = (void *)kalloc(memsize); ! 100: if (!mem) ! 101: return (0); ! 102: ! 103: mem->hdr.mlen = memsize; ! 104: (void) memset(mem->hdr.dat, 0, size); ! 105: ! 106: return (mem->hdr.dat); ! 107: } ! 108: ! 109: static __inline__ ! 110: void kern_free( ! 111: struct _NXZone *zonep, ! 112: void *addr) ! 113: { ! 114: struct _mhead *hdr; ! 115: ! 116: if (!addr) ! 117: return; ! 118: ! 119: hdr = addr; hdr--; ! 120: kfree((vm_offset_t)hdr, hdr->mlen); ! 121: } ! 122: ! 123: static ! 124: void *kern_realloc( ! 125: struct _NXZone *zonep, ! 126: void *addr, ! 127: size_t nsize) ! 128: { ! 129: struct _mhead *ohdr; ! 130: MDECL(nsize) *nmem; ! 131: size_t nmemsize, osize; ! 132: ! 133: if (!addr) ! 134: return (kern_malloc(zonep, nsize)); ! 135: ! 136: ohdr = addr; ohdr--; ! 137: osize = ohdr->mlen - sizeof (*ohdr); ! 138: if (nsize == osize) ! 139: return (addr); ! 140: ! 141: if (nsize == 0) { ! 142: kfree((vm_offset_t)ohdr, ohdr->mlen); ! 143: return (0); ! 144: } ! 145: ! 146: nmemsize = sizeof (*nmem); ! 147: nmem = (void *)kalloc(nmemsize); ! 148: if (!nmem) ! 149: return (0); ! 150: ! 151: nmem->hdr.mlen = nmemsize; ! 152: if (nsize > osize) ! 153: (void) memset(&nmem->hdr.dat[osize], 0, nsize - osize); ! 154: (void) memcpy(nmem->hdr.dat, ohdr->dat, ! 155: (nsize > osize) ? osize : nsize); ! 156: kfree((vm_offset_t)ohdr, ohdr->mlen); ! 157: ! 158: return (nmem->hdr.dat); ! 159: } ! 160: ! 161: static void kern_destroy(struct _NXZone *zonep) ! 162: { ! 163: } ! 164: ! 165: NXZone KernelZone = { ! 166: kern_realloc, ! 167: kern_malloc, ! 168: kern_free, ! 169: kern_destroy, ! 170: }; ! 171: ! 172: NXZone *NXDefaultMallocZone() ! 173: { ! 174: return &KernelZone; ! 175: } ! 176: ! 177: NXZone *NXZoneFromPtr(void *ptr) ! 178: { ! 179: return(&KernelZone); ! 180: } ! 181: ! 182: ! 183: NXZone *NXCreateZone(size_t startsize, size_t granularity, int canfree) ! 184: { ! 185: return(&KernelZone); ! 186: } ! 187: ! 188: void NXNameZone(NXZone *z, const char *name) ! 189: { ! 190: /* EMPTY */ ! 191: } ! 192: ! 193: void * ! 194: NXZoneCalloc(NXZone *zonep, size_t numElems, size_t byteSize) ! 195: { ! 196: return kern_malloc(zonep, numElems*byteSize); ! 197: } ! 198: ! 199: void *malloc( ! 200: size_t size) ! 201: { ! 202: return kern_malloc(&KernelZone, size); ! 203: } ! 204: ! 205: void free( ! 206: void *addr) ! 207: { ! 208: kern_free(&KernelZone, addr); ! 209: } ! 210: ! 211: void *calloc( ! 212: size_t num, ! 213: size_t size) ! 214: { ! 215: return kern_malloc(&KernelZone, num*size); ! 216: } ! 217: ! 218: void *realloc( ! 219: void *addr, ! 220: size_t size) ! 221: { ! 222: return kern_realloc(&KernelZone, addr, size); ! 223: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.