]>
git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_ssl/lib/sslMemory.c
2 * Copyright (c) 1999-2001,2005-2007,2010-2012,2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 * sslMemory.c - Memory allocator implementation
28 /* THIS FILE CONTAINS KERNEL CODE */
30 #include "sslMemory.h"
33 #include <string.h> /* memset */
34 #include <AssertMacros.h>
37 // MARK: Basic low-level malloc/free
40 * For now, all allocs/frees go thru here.
46 #include <sys/malloc.h>
47 #include <IOKit/IOLib.h>
48 #include <libkern/libkern.h>
50 /* Define this for debugging sslMalloc and sslFree */
54 sslMalloc(size_t length
)
62 p
= _MALLOC(length
, M_TEMP
, M_WAITOK
);
69 *(uint32_t *)p
=(uint32_t)length
-8;
70 printf("sslMalloc @%p of 0x%08lx bytes\n", p
, length
-8);
71 *(uint32_t *)(p
+length
-4)=0xdeadbeed;
85 uint32_t len
=*(uint32_t *)p
;
86 uint32_t marker
=*(uint32_t *)(p
+4+len
);
87 printf("sslFree @%p len=0x%08x\n", p
, len
);
88 if(marker
!=0xdeadbeef)
89 panic("Buffer overflow in SSL!\n");
101 sslMalloc(size_t length
)
103 return malloc(length
);
117 // MARK: SSLBuffer-level alloc/free
123 buf
->data
= (uint8_t *)sslMalloc(length
);
124 if(buf
->data
== NULL
) {
125 sslErrorLog("SSLAllocBuffer: NULL buf!\n");
130 buf
->length
= length
;
135 SSLFreeBuffer(SSLBuffer
*buf
)
138 sslErrorLog("SSLFreeBuffer: NULL buf!\n");
148 uint8_t *sslAllocCopy(
154 dst
= (uint8_t *)sslMalloc(len
);
158 memmove(dst
, src
, len
);
162 int SSLCopyBufferFromData(
165 SSLBuffer
*dst
) // data mallocd and returned
167 dst
->data
= sslAllocCopy((const uint8_t *)src
, len
);
168 if(dst
->data
== NULL
) {
169 sslErrorLog("SSLCopyBufferFromData: NULL buf!\n");
178 const SSLBuffer
*src
,
179 SSLBuffer
*dst
) // data mallocd and returned
181 return SSLCopyBufferFromData(src
->data
, src
->length
, dst
);