lib.c 709 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <thread.h>
  4. #include "threadimpl.h"
  5. static long totalmalloc;
  6. void*
  7. _threadmalloc(long size, int z)
  8. {
  9. void *m;
  10. m = malloc(size);
  11. if (m == nil)
  12. sysfatal("Malloc of size %ld failed: %r\n", size);
  13. setmalloctag(m, getcallerpc(&size));
  14. totalmalloc += size;
  15. if (size > 1000000) {
  16. fprint(2, "Malloc of size %ld, total %ld\n", size, totalmalloc);
  17. abort();
  18. }
  19. if (z)
  20. memset(m, 0, size);
  21. return m;
  22. }
  23. void
  24. _threadsysfatal(char *fmt, va_list arg)
  25. {
  26. char buf[1024]; /* size doesn't matter; we're about to exit */
  27. vseprint(buf, buf+sizeof(buf), fmt, arg);
  28. if(argv0)
  29. fprint(2, "%s: %s\n", argv0, buf);
  30. else
  31. fprint(2, "%s\n", buf);
  32. threadexitsall(buf);
  33. }