forked from RehabMan/OS-X-Voodoo-PS2-Controller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
new_kext.cpp
executable file
·75 lines (63 loc) · 1.79 KB
/
new_kext.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//
// new_kext.cpp
//
// Created by RehabMan on 2/3/13.
// Copyright (c) 2013 rehabman. All rights reserved.
//
// Full complement of operator new/delete for use within kext environment.
//
#include "new_kext.h"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
// Note: Originally these helper functions were exported as C++ functions
// instead of extern "C", and they had much longer names.
//
// But that causes problems for Snow Leopard (crash using Kernel Cache at startup).
// Not sure if it is related to the C++ names, or just the long names, but
// this does work with the shorter extern "C" names, even on Snow Leopard.
//
// Also realize that the calls to IOMallocAligned/IOFreeAligned are mapped to
// IOMalloc/IOFree because there appears to be a bug in the aligned variants.
// See new_kext.h for the macros...
//
// Note: For now we are not using this code, as it is easier to just use the
// built-in operator new/delete. I'm keeping it here, just in case it becomes
// useful in the future.
//
extern "C"
{
void* _opnew(size_t size)
{
size_t* p = (size_t*)IOMallocAligned(sizeof(size_t) + size, sizeof(void*));
if (p)
*p++ = size;
return p;
}
void _opdel(void* p)
{
assert(p);
if (p)
{
size_t* t = (size_t*)p-1;
IOFreeAligned(t, *t);
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void* _opnewa(size_t size)
{
size_t* p = (size_t*)IOMallocAligned(sizeof(size_t) + size, sizeof(void*));
if (p)
*p++ = size;
return p;
}
void _opdela(void* p)
{
assert(p);
if (p)
{
size_t* t = (size_t*)p-1;
IOFreeAligned(t, *t);
}
}
} // extern "C"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -