summaryrefslogtreecommitdiff
path: root/kalloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'kalloc.c')
-rw-r--r--kalloc.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/kalloc.c b/kalloc.c
index 72ce58a..e31d71d 100644
--- a/kalloc.c
+++ b/kalloc.c
@@ -23,9 +23,11 @@ extern char end[]; // first address after kernel loaded from ELF file
void
kinit(void)
{
+ char *p;
+
initlock(&kmem.lock, "kmem");
- char *p = (char*)PGROUNDUP((uint)end);
- for( ; p + PGSIZE - 1 < (char*) PHYSTOP; p += PGSIZE)
+ p = (char*)PGROUNDUP((uint)end);
+ for(; p + PGSIZE - 1 < (char*)PHYSTOP; p += PGSIZE)
kfree(p);
}
@@ -39,14 +41,14 @@ kfree(char *v)
{
struct run *r;
- if(((uint) v) % PGSIZE || v < end || (uint)v >= PHYSTOP)
+ if((uint)v % PGSIZE || v < end || (uint)v >= PHYSTOP)
panic("kfree");
// Fill with junk to catch dangling refs.
memset(v, 1, PGSIZE);
acquire(&kmem.lock);
- r = (struct run *) v;
+ r = (struct run*)v;
r->next = kmem.freelist;
kmem.freelist = r;
release(&kmem.lock);
@@ -56,7 +58,7 @@ kfree(char *v)
// Returns a pointer that the kernel can use.
// Returns 0 if the memory cannot be allocated.
char*
-kalloc()
+kalloc(void)
{
struct run *r;
@@ -65,6 +67,6 @@ kalloc()
if(r)
kmem.freelist = r->next;
release(&kmem.lock);
- return (char*) r;
+ return (char*)r;
}