Bläddra i källkod

4.682u-mm: fix a bug for alloc_page

rain 5 år sedan
förälder
incheckning
3b68644692
4 ändrade filer med 13 tillägg och 4 borttagningar
  1. 3 2
      LINES
  2. 4 0
      README.md
  3. 2 0
      init/main.c
  4. 4 2
      kernel/mm.c

+ 3 - 2
LINES

@@ -18,5 +18,6 @@
 2021-7-11 3.455: 3455 lines, 32 files, rain
 2021-7-18 3.831: 3831 lines, 33 files, rain
 2021-7-18 3.913: 3913 lines, 35 files, rain
-2021-7-21 4.618: 4618 lines, 39 files, rain
- 
+2021-7-21 4.678: 4678 lines, 39 files, rain
+2021-7-21 4.682: 4682 lines, 39 files, rain
+

+ 4 - 0
README.md

@@ -83,3 +83,7 @@ source software, you can get its source code from <https://gitee.com/pengruiyang
 
 4.678u-mm:  
 &nbsp;&nbsp;&nbsp;&nbsp;setup TSS and memory pool. now we can use `kmalloc()` and `kfree()` to allocate memory, not `alloc_page()`. 
+
+4.682u-mm:  
+&nbsp;&nbsp;&nbsp;&nbsp;`alloc_page` returns a wrong address that isn't that it get from `mapping()`. 
+

+ 2 - 0
init/main.c

@@ -66,6 +66,8 @@ int init(void) {
 
 	int *i = kmalloc(&pool, 128);
 
+	*i = 0;
+
 	printk(0x00ffffff, 0x000000, "kmalloc: %q\n", i);
 
 	kfree(&pool, i, 128);

+ 4 - 2
kernel/mm.c

@@ -247,12 +247,14 @@ void *alloc_page(void) {
 
 	/* we must map it to page-table */
 
-	if (!mapping((void *) (i << PAGE_SHIFT), PATT_KERNEL)) {
+	void *addr = mapping((void *) (i << PAGE_SHIFT), PATT_KERNEL);
+
+	if (!addr) {
 		bitmap_set(mm->bitmap, i, 0);
 		return NULL;
 	}
 
-	return (void *) (i << PAGE_SHIFT);
+	return addr;
 }