28#define RTLD_NEXT ((void *) -1L)
36static int oomstub_countdown = 0;
42static void *(*real_malloc)(size_t);
48static void *(*real_calloc)(size_t, size_t);
54static void *(*real_realloc)(
void *, size_t);
63 oomstub_countdown = counter;
73 return oomstub_countdown;
89 *(
void **) (&real_malloc) = dlsym(
RTLD_NEXT,
"malloc");
91 if (oomstub_countdown == 1) {
92 oomstub_countdown = 0;
95 if (oomstub_countdown > 0) {
98 return real_malloc(size);
115 *(
void **) (&real_calloc) = dlsym(
RTLD_NEXT,
"calloc");
117 if (oomstub_countdown == 1) {
118 oomstub_countdown = 0;
121 if (oomstub_countdown > 0) {
124 return real_calloc(count, size);
155 *(
void **) (&real_realloc) = dlsym(
RTLD_NEXT,
"realloc");
157 if (oomstub_countdown == 1) {
158 oomstub_countdown = 0;
164 if (oomstub_countdown > 0) {
168 return real_realloc(ptr, new_size);
void * realloc(void *ptr, size_t new_size)
stdc realloc stub function
int oomstub_getcountdown()
Gets the current malloc countdown before triggering a failure.
void * malloc(size_t size)
stdc malloc stub function
void oomstub_setcountdown(const int counter)
Sets the malloc countdown before triggering a failure.
void * calloc(size_t count, size_t size)
stdc calloc stub function
C memory management diverters.