mem.c (676B)
1 #include <u.h> 2 #include <libc.h> 3 #include <fcall.h> 4 #include <thread.h> 5 #include "9p.h" 6 7 void* 8 emalloc9p(ulong sz) 9 { 10 void *v; 11 12 if((v = malloc(sz)) == nil) 13 sysfatal("out of memory allocating %lud", sz); 14 memset(v, 0, sz); 15 setmalloctag(v, getcallerpc(&sz)); 16 return v; 17 } 18 19 void* 20 erealloc9p(void *v, ulong sz) 21 { 22 void *nv; 23 24 if((nv = realloc(v, sz)) == nil) 25 sysfatal("out of memory reallocating %lud", sz); 26 if(v == nil) 27 setmalloctag(nv, getcallerpc(&v)); 28 setrealloctag(nv, getcallerpc(&v)); 29 return nv; 30 } 31 32 char* 33 estrdup9p(char *s) 34 { 35 char *t; 36 37 if((t = strdup(s)) == nil) 38 sysfatal("out of memory in strdup(%.20s)", s); 39 setmalloctag(t, getcallerpc(&s)); 40 return t; 41 }