lib.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 <thread.h>
  12. #include "threadimpl.h"
  13. static int32_t totalmalloc;
  14. void*
  15. _threadmalloc(int32_t size, int z)
  16. {
  17. void *m;
  18. m = malloc(size);
  19. if (m == nil)
  20. sysfatal("Malloc of size %ld failed: %r", size);
  21. setmalloctag(m, getcallerpc());
  22. totalmalloc += size;
  23. if (size > 100000000) {
  24. fprint(2, "Malloc of size %ld, total %ld\n", size, totalmalloc);
  25. abort();
  26. }
  27. if (z)
  28. memset(m, 0, size);
  29. return m;
  30. }
  31. void
  32. _threadsysfatal(char *fmt, ...)
  33. {
  34. va_list arg;
  35. char buf[1024]; /* size doesn't matter; we're about to exit */
  36. va_start(arg, fmt);
  37. vseprint(buf, buf+sizeof(buf), fmt, arg);
  38. va_end(arg);
  39. if(argv0)
  40. fprint(2, "%s: %s\n", argv0, buf);
  41. else
  42. fprint(2, "%s\n", buf);
  43. threadexitsall(buf);
  44. }