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