mem.c 765 B

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