mem.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <auth.h>
  12. #include <fcall.h>
  13. #include <thread.h>
  14. #include "9p.h"
  15. void*
  16. emalloc9p(uint32_t sz)
  17. {
  18. void *v;
  19. if((v = malloc(sz)) == nil) {
  20. fprint(2, "out of memory allocating %lu\n", sz);
  21. exits("mem");
  22. }
  23. memset(v, 0, sz);
  24. setmalloctag(v, getcallerpc());
  25. return v;
  26. }
  27. void*
  28. erealloc9p(void *v, uint32_t sz)
  29. {
  30. void *nv;
  31. if((nv = realloc(v, sz)) == nil) {
  32. fprint(2, "out of memory allocating %lu\n", sz);
  33. exits("mem");
  34. }
  35. if(v == nil)
  36. setmalloctag(nv, getcallerpc());
  37. setrealloctag(nv, getcallerpc());
  38. return nv;
  39. }
  40. char*
  41. estrdup9p(char *s)
  42. {
  43. char *t;
  44. if((t = strdup(s)) == nil) {
  45. fprint(2, "out of memory in strdup(%.10s)\n", s);
  46. exits("mem");
  47. }
  48. setmalloctag(t, getcallerpc());
  49. return t;
  50. }