Skip to content

Commit

Permalink
print where the zmalloc failures are coming from.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Jones committed Apr 22, 2014
1 parent 8286178 commit c975ad4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion include/utils.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
#pragma once

#include <sys/mman.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <types.h>

#define MB (1024 * 1024UL)
#define GB (1024 * MB)

void * alloc_shared(unsigned int size);
void * zmalloc(size_t size);

void * __zmalloc(size_t size, const char *func);
#define zmalloc(size) __zmalloc(size, __func__)

#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))

Expand Down
4 changes: 2 additions & 2 deletions utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ void * alloc_shared(unsigned int size)
return ret;
}

void * zmalloc(size_t size)
void * __zmalloc(size_t size, const char *func)
{
void *p;

p = malloc(size);
if (p == NULL) {
printf("malloc(%zu) failure.\n", size);
printf("%s: malloc(%zu) failure.\n", func, size);
exit(EXIT_FAILURE);
}

Expand Down

0 comments on commit c975ad4

Please sign in to comment.