X-Git-Url: https://git.saurik.com/apple/security.git/blobdiff_plain/80e2389990082500d76eb566d4946be3e786c3ef..d8f41ccd20de16f8ebe2ccc84d47bf1cb2b26bbb:/Security/libsecurity_cryptkit/lib/falloc.c?ds=sidebyside diff --git a/Security/libsecurity_cryptkit/lib/falloc.c b/Security/libsecurity_cryptkit/lib/falloc.c new file mode 100644 index 00000000..8a41af7b --- /dev/null +++ b/Security/libsecurity_cryptkit/lib/falloc.c @@ -0,0 +1,109 @@ +/* Copyright (c) 1998,2011,2014 Apple Inc. All Rights Reserved. + * + * NOTICE: USE OF THE MATERIALS ACCOMPANYING THIS NOTICE IS SUBJECT + * TO THE TERMS OF THE SIGNED "FAST ELLIPTIC ENCRYPTION (FEE) REFERENCE + * SOURCE CODE EVALUATION AGREEMENT" BETWEEN APPLE, INC. AND THE + * ORIGINAL LICENSEE THAT OBTAINED THESE MATERIALS FROM APPLE, + * INC. ANY USE OF THESE MATERIALS NOT PERMITTED BY SUCH AGREEMENT WILL + * EXPOSE YOU TO LIABILITY. + *************************************************************************** + * + * falloc.c - FEE malloc routines + * + * Revision History + * ---------------- + * 28 May 98 at Apple + * Added Mac-specific allocators from temp memory + * 20 Aug 96 at NeXT + * Created. + */ + +#include "platform.h" +#include "falloc.h" +#include + +/* watchpoint emulator */ +#define FALLOC_WATCH 0 +#if FALLOC_WATCH +#include +/* set these with debugger */ +void *mallocWatchAddrs; +void *freeWatchAddrs; +#endif + +/* if NULL, use our own */ +static mallocExternFcn *mallocExt = NULL; +static freeExternFcn *freeExt = NULL; +static reallocExternFcn *reallocExt = NULL; + +void fallocRegister(mallocExternFcn *mallocExtern, + freeExternFcn *freeExtern, + reallocExternFcn *reallocExtern) +{ + mallocExt = mallocExtern; + freeExt = freeExtern; + reallocExt = reallocExtern; +} + +/* + * All this can be optimized and tailored to specific platforms, of course... + */ + +void *fmalloc(unsigned size) +{ + void *rtn; + if(mallocExt != NULL) { + rtn = (mallocExt)(size); + } + else { + rtn = malloc(size); + } + #if FALLOC_WATCH + if(rtn == mallocWatchAddrs) { + printf("====fmalloc watchpoint (0x%x) hit\n", + (unsigned)mallocWatchAddrs); + } + #endif + return rtn; +} + +void *fmallocWithData(const void *origData, + unsigned origDataLen) +{ + void *rtn = fmalloc(origDataLen); + + bcopy(origData, rtn, origDataLen); + return rtn; +} + +void ffree(void *data) +{ + #if FALLOC_WATCH + if(data == freeWatchAddrs) { + printf("====ffree watchpoint (0x%x) hit\n", + (unsigned)freeWatchAddrs); + } + #endif + if(freeExt != NULL) { + (freeExt)(data); + } + else { + free(data); + } +} + +void *frealloc(void *oldPtr, unsigned newSize) +{ + #if FALLOC_WATCH + if(oldPtr == freeWatchAddrs) { + printf("====frealloc watchpoint (0x%x) hit\n", + (unsigned)freeWatchAddrs); + } + #endif + if(reallocExt != NULL) { + return (reallocExt)(oldPtr, newSize); + } + else { + return realloc(oldPtr, newSize); + } +}