提交 44c215b1 创建 作者: Austin Clements's avatar Austin Clements

Record type names of kmalloc'd memory and pass names to mtrace

上级 1efb8580
......@@ -133,7 +133,7 @@ extern void *__dso_handle;
#define NEW_DELETE_OPS(classname) \
static void* operator new(unsigned long nbytes) { \
assert(nbytes == sizeof(classname)); \
return kmalloc(sizeof(classname)); \
return kmalloc(sizeof(classname), #classname); \
} \
\
static void* operator new(unsigned long nbytes, classname *buf) { \
......
......@@ -129,9 +129,9 @@ char* kalloc(void);
void kfree(void*);
void* ksalloc(int slabtype);
void ksfree(int slabtype, void*);
void* kmalloc(u64 nbytes);
void* kmalloc(u64 nbytes, const char *name);
void kmfree(void*, u64 nbytes);
int kmalign(void **p, int align, u64 size);
int kmalign(void **p, int align, u64 size, const char *name);
void kmalignfree(void *, int align, u64 size);
void verifyfree(char *ptr, u64 nbytes);
void kminit(void);
......
......@@ -35,7 +35,7 @@ struct cwork : public work {
#define xmalloc(n) malloc(n)
#define xfree(p, sz) free(p)
#elif defined(XV6_KERNEL)
#define xmalloc(n) kmalloc(n)
#define xmalloc(n) kmalloc(n, "xmalloc")
#define xfree(p, sz) kmfree(p, sz)
#else
#define xmalloc(n) malloc(n)
......
......@@ -7,7 +7,7 @@
void *
operator new[](unsigned long nbytes)
{
u64 *x = (u64*) kmalloc(nbytes + sizeof(u64));
u64 *x = (u64*) kmalloc(nbytes + sizeof(u64), "array");
*x = nbytes + sizeof(u64);
return x+1;
}
......
......@@ -78,7 +78,7 @@ bucket(u64 nbytes)
}
void *
kmalloc(u64 nbytes)
kmalloc(u64 nbytes, const char *name)
{
int b = bucket(nbytes);
......@@ -106,7 +106,7 @@ kmalloc(u64 nbytes)
if (ALLOC_MEMSET)
memset(h, 4, (1<<b));
mtlabel(mtrace_label_heap, (void*) h, nbytes, "kmalloc'ed", sizeof("kmalloc'ed"));
mtlabel(mtrace_label_heap, (void*) h, nbytes, name, strlen(name));
return h;
}
......@@ -132,9 +132,9 @@ kmfree(void *ap, u64 nbytes)
}
int
kmalign(void **p, int align, u64 size)
kmalign(void **p, int align, u64 size, const char *name)
{
void *mem = kmalloc(size + (align-1) + sizeof(void*));
void *mem = kmalloc(size + (align-1) + sizeof(void*), name);
char *amem = ((char*)mem) + sizeof(void*);
amem += align - ((uptr)amem & (align - 1));
((void**)amem)[-1] = mem;
......
......@@ -278,7 +278,7 @@ netbind(int sock, void *xaddr, int xaddrlen)
void *addr;
long r;
addr = kmalloc(xaddrlen);
addr = kmalloc(xaddrlen, "sockaddr");
if (addr == nullptr)
return -1;
......@@ -314,7 +314,7 @@ netaccept(int sock, void *xaddr, void *xaddrlen)
if (umemcpy(&len, lenptr, sizeof(*lenptr)))
return -1;
addr = kmalloc(len);
addr = kmalloc(len, "sockaddr");
if (addr == nullptr)
return -1;
......
......@@ -30,7 +30,7 @@ pipealloc(struct file **f0, struct file **f1)
*f0 = *f1 = 0;
if((*f0 = file::alloc()) == 0 || (*f1 = file::alloc()) == 0)
goto bad;
if((p = (pipe*)kmalloc(sizeof(*p))) == 0)
if((p = (pipe*)kmalloc(sizeof(*p), "pipe")) == 0)
goto bad;
p->readopen = 1;
p->writeopen = 1;
......
......@@ -188,7 +188,7 @@ sampread(struct inode *ip, char *dst, u32 off, u32 n)
u64 len = LOGHEADER_SZ;
u64 cc;
hdr = (logheader*) kmalloc(len);
hdr = (logheader*) kmalloc(len, "logheader");
if (hdr == nullptr)
return -1;
hdr->ncpus = NCPU;
......
......@@ -24,7 +24,7 @@ void*
klockstat::operator new(unsigned long nbytes)
{
assert(nbytes == sizeof(klockstat));
return kmalloc(sizeof(klockstat));
return kmalloc(sizeof(klockstat), "klockstat");
}
void
......
......@@ -208,7 +208,7 @@ sys_thread_new(const char *name, lwip_thread_fn thread, void *arg,
struct lwip_thread *lt;
struct proc *p;
lt = (struct lwip_thread*) kmalloc(sizeof(*lt));
lt = (struct lwip_thread*) kmalloc(sizeof(*lt), "lwip_thread");
if (lt == nullptr)
return 0;
lt->thread = thread;
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论