8 #include "informer/Informer.h"
10 void AC_EXPORT
*calloc(size_t nmemb
, size_t size
);
11 void AC_EXPORT
*malloc(size_t size
);
12 void AC_EXPORT
free(void *ptr
);
13 void AC_EXPORT
*realloc(void *ptr
, size_t size
);
16 void *(*AC_callocFP
)(size_t nmemb
, size_t size
);
17 void *(*AC_mallocFP
)(size_t size
);
18 void (*AC_freeFP
)(void *ptr
);
19 void *(*AC_reallocFP
)(void *ptr
, size_t size
);
21 void AC_EXPORT
*calloc(size_t nmemb
, size_t size
) {
22 static int resolving
= 0;
23 static char resolvingData
[1024];
24 static size_t usedData
= 0;
27 size_t original
= usedData
;
28 usedData
+= nmemb
* size
;
29 return resolvingData
+ original
;
32 if(AC_callocFP
== NULL
) {
34 *(void **)&AC_callocFP
= dlsym(RTLD_NEXT
, "calloc");
38 void *data
= AC_callocFP(nmemb
, size
);
40 if(AI_CollectionStatus()) {
41 AI_StartPacket(AC_moduleID
);
43 *(uint8_t *)AI_PacketSpace(1) = 1;
44 *(uint64_t *)AI_PacketSpace(8) = AI_Timestamp();
45 *(uint64_t *)AI_PacketSpace(8) = (uint64_t)data
;
46 *(uint64_t *)AI_PacketSpace(8) = size
;
54 void AC_EXPORT
*malloc(size_t size
) {
55 if(AC_mallocFP
== NULL
) {
56 *(void **)&AC_mallocFP
= dlsym(RTLD_NEXT
, "malloc");
59 void *data
= AC_mallocFP(size
);
61 if(AI_CollectionStatus()) {
62 AI_StartPacket(AC_moduleID
);
64 *(uint8_t *)AI_PacketSpace(1) = 2;
65 *(uint64_t *)AI_PacketSpace(8) = AI_Timestamp();
66 *(uint64_t *)AI_PacketSpace(8) = (uint64_t)data
;
67 *(uint64_t *)AI_PacketSpace(8) = size
;
75 void AC_EXPORT
free(void *ptr
) {
76 if(AC_freeFP
== NULL
) {
77 *(void **)&AC_freeFP
= dlsym(RTLD_NEXT
, "free");
80 if(AI_CollectionStatus()) {
81 AI_StartPacket(AC_moduleID
);
83 *(uint8_t *)AI_PacketSpace(1) = 3;
84 *(uint64_t *)AI_PacketSpace(8) = AI_Timestamp();
85 *(uint64_t *)AI_PacketSpace(8) = (uint64_t)ptr
;
93 void AC_EXPORT
*realloc(void *ptr
, size_t size
) {
94 if(AC_reallocFP
== NULL
) {
95 *(void **)&AC_reallocFP
= dlsym(RTLD_NEXT
, "realloc");
98 void *data
= AC_reallocFP(ptr
, size
);
99 if(AI_CollectionStatus()) {
100 AI_StartPacket(AC_moduleID
);
102 *(uint8_t *)AI_PacketSpace(1) = 4;
103 *(uint64_t *)AI_PacketSpace(8) = AI_Timestamp();
104 *(uint64_t *)AI_PacketSpace(8) = (uint64_t)ptr
;
105 *(uint64_t *)AI_PacketSpace(8) = (uint64_t)data
;
106 *(uint64_t *)AI_PacketSpace(8) = size
;
114 void __attribute__((constructor
)) AC_EXPORT
AM_Construct() {
117 AC_moduleID
= AI_ConfigurationLong("memory:moduleID");
119 AI_ModuleLoaded("memory", AC_moduleID
);
122 void __attribute__((destructor
)) AC_EXPORT
AM_Destruct() {