From 8d774afb2d45592d85725474a704ac99b0624d2c Mon Sep 17 00:00:00 2001 From: Robert Morris Date: Tue, 31 Aug 2010 15:39:25 -0400 Subject: no more pminit, or ELF header at 0x10000 kinit() knows about end and PHYSTOP map all of kernel read/write (rather than r/o instructions) thanks, austin --- kalloc.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'kalloc.c') diff --git a/kalloc.c b/kalloc.c index 65de759..8c9ff93 100644 --- a/kalloc.c +++ b/kalloc.c @@ -19,11 +19,13 @@ struct { // Initialize free list of physical pages. void -kinit(char *p, uint len) +kinit(void) { + extern char end[]; + initlock(&kmem.lock, "kmem"); - char *p1 = (char*)PGROUNDUP((uint)p); - char *p2 = PGROUNDDOWN(p + len); + char *p1 = (char*)PGROUNDUP((uint)end); + char *p2 = PGROUNDDOWN(PHYSTOP); for( ; p1 < p2; p1 += 4096) kfree(p1); } -- cgit v1.2.3 From 5048762c7e27789a014cc1e74e1002e749c924ce Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Tue, 31 Aug 2010 17:52:03 -0400 Subject: Page break kalloc.c --- kalloc.c | 1 + 1 file changed, 1 insertion(+) (limited to 'kalloc.c') diff --git a/kalloc.c b/kalloc.c index 8c9ff93..7653242 100644 --- a/kalloc.c +++ b/kalloc.c @@ -30,6 +30,7 @@ kinit(void) kfree(p1); } +//PAGEBREAK: 21 // Free the page of physical memory pointed at by v, // which normally should have been returned by a // call to kalloc(). (The exception is when -- cgit v1.2.3 From 3597d5dc704c192a85b9902f7264fe9025aad277 Mon Sep 17 00:00:00 2001 From: Robert Morris Date: Tue, 31 Aug 2010 19:21:33 -0400 Subject: oops. last minute simplicifaction to kalloc(). --- kalloc.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'kalloc.c') diff --git a/kalloc.c b/kalloc.c index 8c9ff93..43e80e8 100644 --- a/kalloc.c +++ b/kalloc.c @@ -24,10 +24,9 @@ kinit(void) extern char end[]; initlock(&kmem.lock, "kmem"); - char *p1 = (char*)PGROUNDUP((uint)end); - char *p2 = PGROUNDDOWN(PHYSTOP); - for( ; p1 < p2; p1 += 4096) - kfree(p1); + char *p = (char*)PGROUNDUP((uint)end); + for( ; p + PGSIZE - 1 < (char*) PHYSTOP; p += PGSIZE) + kfree(p); } // Free the page of physical memory pointed at by v, -- cgit v1.2.3 From 4587b35847b116057e3ef1058da914b8837ff343 Mon Sep 17 00:00:00 2001 From: Robert Morris Date: Sun, 19 Sep 2010 07:18:42 -0400 Subject: exec questions --- kalloc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'kalloc.c') diff --git a/kalloc.c b/kalloc.c index 5f690f5..72ce58a 100644 --- a/kalloc.c +++ b/kalloc.c @@ -17,12 +17,12 @@ struct { struct run *freelist; } kmem; +extern char end[]; // first address after kernel loaded from ELF file + // Initialize free list of physical pages. void kinit(void) { - extern char end[]; - initlock(&kmem.lock, "kmem"); char *p = (char*)PGROUNDUP((uint)end); for( ; p + PGSIZE - 1 < (char*) PHYSTOP; p += PGSIZE) @@ -39,7 +39,7 @@ kfree(char *v) { struct run *r; - if(((uint) v) % PGSIZE || (uint)v < 1024*1024 || (uint)v >= PHYSTOP) + if(((uint) v) % PGSIZE || v < end || (uint)v >= PHYSTOP) panic("kfree"); // Fill with junk to catch dangling refs. -- cgit v1.2.3 From 1a81e38b17144624415d252a521fd5a06079d681 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 11 Jan 2011 13:01:13 -0500 Subject: make new code like old code Variable declarations at top of function, separate from initialization. Use == 0 instead of ! for checking pointers. Consistent spacing around {, *, casts. Declare 0-parameter functions as (void) not (). Integer valued functions return -1 on failure, 0 on success. --- kalloc.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'kalloc.c') 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; } -- cgit v1.2.3 From 417c37115e0c7fc3b2a65c3c4d213e566cbc8807 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 11 Jan 2011 13:51:40 -0500 Subject: more trivial cleanup --- kalloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'kalloc.c') diff --git a/kalloc.c b/kalloc.c index e31d71d..bf1616a 100644 --- a/kalloc.c +++ b/kalloc.c @@ -27,7 +27,7 @@ kinit(void) initlock(&kmem.lock, "kmem"); p = (char*)PGROUNDUP((uint)end); - for(; p + PGSIZE - 1 < (char*)PHYSTOP; p += PGSIZE) + for(; p + PGSIZE <= (char*)PHYSTOP; p += PGSIZE) kfree(p); } -- cgit v1.2.3