[Kos-cvs]
kos/modules/kmem _kmem_alloc.c, 1.6, 1.7 _kmem_free.c, 1.7,
1.8 _kslab_cache_alloc.c, 1.15, 1.16 _kslab_cache_free.c, 1.17,
1.18 _kvmem_alloc.c, 1.13, 1.14 _kvmem_free.c, 1.14, 1.15
thomas at kos.enix.org
thomas at kos.enix.org
Sun Jan 30 17:11:23 CET 2005
Update of /home/kos/cvs/kos/modules/kmem
In directory the-doors:/tmp/cvs-serv3480/modules/kmem
Modified Files:
_kmem_alloc.c _kmem_free.c _kslab_cache_alloc.c
_kslab_cache_free.c _kvmem_alloc.c _kvmem_free.c
Log Message:
2005-01-30 Thomas Petazzoni <thomas at crazy.kos.nx>
* modules/x86/mm/Makefile (DEBUG_LEVEL): 1 -> 0
* modules/vmm/_vmm_as.c: Moved as_dump and vr_dump, create
as_dump_unsafe.
* modules/vmm/Makefile (DEBUG_LEVEL): 3 -> 0
* modules/tty/_tty.c, modules/tty/_tty_kres.c: DEBUG_PRINTx
conformance + memset().
* modules/lib/blockfile/libblockfile.c,
modules/lib/charfile/libcharfile.c,
modules/lib/filemap/libfilemap.c: Added memset() needed when
allocated buffer is poisoned. Whitespaces.
* modules/kmem/_kvmem_free.c: DEBUG_PRINTx conformance +
whitespaces.
* modules/kmem/_kvmem_alloc.c (kvalloc): Poison the allocated
memory + DEBUG_PRINTx conformance.
* modules/kmem/_kslab_cache_free.c (__kslab_cache_free_by_slab):
Poison the freed buffer.
* modules/kmem/_kslab_cache_alloc.c (kslab_cache_alloc): Poison
the allocated buffer.
* modules/kmem/_kmem_free.c (kfree): DEBUG_PRINTx conformance.
* modules/kmem/_kmem_alloc.c (kmalloc): Whitespaces + DEBUG_PRINTx
conformance.
* modules/kitc/_kmutex.c: Remove [function] as they are generated
by DEBUG_PRINTx now.
* modules/karm/open.c: Whitespaces.
* modules/karm/mount.c (mount): Cleaned the way of calling
fs->attach().
* modules/ide/_ide_karm.c: More debugging messages.
* modules/ide/_ide.h (ide_device_info): Correct position of packed
attribute to make gcc happy.
* modules/part/Makefile (DEBUG_LEVEL), modules/karm/Makefile
(DEBUG_LEVEL), modules/ide/Makefile
(DEBUG_LEVEL), modules/fs/devfs/Makefile
(DEBUG_LEVEL), modules/fs/fat/Makefile
(DEBUG_LEVEL) : New variable.
* modules/fs/devfs/devfs.c, modules/fs/fat/_fat.c,
modules/fs/fat/_fat_karm.c: Added memset() found using the
poisoning stuff in kmem. More debugging messages using
DEBUG_PRINTx.
* modules/debug/debug.h: DEBUG_PRINTx macros now call
DEBUG_PRINT_VERBOSE instead of __dbg_printk, so that the line
number, function and file names are printed before the debug
message.
* TODO: More things to do.
Index: _kvmem_alloc.c
===================================================================
RCS file: /home/kos/cvs/kos/modules/kmem/_kvmem_alloc.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- _kvmem_alloc.c 28 Dec 2004 18:44:38 -0000 1.13
+++ _kvmem_alloc.c 30 Jan 2005 16:11:20 -0000 1.14
@@ -34,7 +34,7 @@
current_range = __kvmem_find_suitable_range_in_free_list(nb_pages);
if (! current_range) {
- DEBUG_PRINT("[kvalloc] No VM left for %d pages\n", nb_pages);
+ DEBUG_PRINT2("No VM left for %d pages\n", nb_pages);
RETURN(0);
}
@@ -86,10 +86,19 @@
{
if(__kvmem_map_range(virt_base_addr, nb_pages, is_swappable) != 0)
{
- DEBUG_PRINT("No more physical memory to map pages");
+ DEBUG_PRINT2("No more physical memory to map pages\n");
return 0;
}
}
+ /*
+ * Poison the allocated memory to make sure it will be correctly
+ * initialized by the user
+ */
+ if(needs_mapping)
+ {
+ memset((void*) virt_base_addr, 0xA5A5A5A5, nb_pages*PAGE_SIZE);
+ }
+
return virt_base_addr;
}
Index: _kvmem_free.c
===================================================================
RCS file: /home/kos/cvs/kos/modules/kmem/_kvmem_free.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- _kvmem_free.c 19 Aug 2003 00:13:32 -0000 1.14
+++ _kvmem_free.c 30 Jan 2005 16:11:20 -0000 1.15
@@ -25,18 +25,16 @@
int nb_elements;
/* Find range in used_page_range_list list */
-
list_foreach(used_page_range_list, current_range, nb_elements)
if(current_range->start == range_start)
{
this_range = current_range;
- __dbg_printk(_B_BLUE "[kvfree] Range found with start 0x%x, size %d\n" _B_NORM,
- this_range->start, this_range->nb_pages);
+ DEBUG_PRINT3(_B_BLUE "Range found with start 0x%x, size %d\n" _B_NORM,
+ this_range->start, this_range->nb_pages);
break;
}
/* Check whether a range with start range_start has been found */
-
if(this_range == NULL)
return -1;
@@ -55,7 +53,7 @@
/* Look for preceding range in free_page_range_list list, for insertion */
if (free_page_range_list->start > this_range->start)
current_range = NULL;
- else
+ else
{
list_foreach(free_page_range_list, current_range, nb_elements)
{
@@ -75,25 +73,25 @@
ASSERT_FATAL((! current_range)
||
(RANGE_END(current_range) <= this_range->start));
-
+
/* Must insert before the head AND this range is next to the current
head => expand the head range */
if((! current_range)
&&
(RANGE_END(this_range) == free_page_range_list->start))
{
- __dbg_printk("Range is the first and is close to its next\n");
+ DEBUG_PRINT3("Range is the first and is close to its next\n");
free_page_range_list->start = this_range->start;
free_page_range_list->nb_pages += this_range->nb_pages;
__kvmem_reclaim_free_range(this_range);
- __dbg_printk("After reclaiming this_range\n");
+ DEBUG_PRINT3("After reclaiming this_range\n");
}
/* Or this range is to be inserted before the head, but not next to
this head */
else if(! current_range)
{
- __dbg_printk("Range is the first, and not close to its first\n");
+ DEBUG_PRINT3("Range is the first, and not close to its first\n");
list_add_head(free_page_range_list, this_range);
}
@@ -101,13 +99,13 @@
this range is close to its next, and that the preceding range is
close to the new range, merge those three ranges */
- else if (current_range->next &&
- (RANGE_END(this_range) == current_range->next->start) &&
+ else if (current_range->next &&
+ (RANGE_END(this_range) == current_range->next->start) &&
(RANGE_END(current_range) == this_range->start))
{
chained_page_range_t *tmp_range;
-
- __dbg_printk("Range is near its next and its prev\n");
+
+ DEBUG_PRINT3("Range is near its next and its prev\n");
current_range->nb_pages += current_range->next->nb_pages
+ this_range->nb_pages;
@@ -128,7 +126,7 @@
else if (current_range->next &&
(RANGE_END(this_range) == current_range->next->start))
{
- __dbg_printk("Range is near its next\n");
+ DEBUG_PRINT3("Range is near its next\n");
current_range->next->start = this_range->start;
current_range->next->nb_pages += this_range->nb_pages;
__kvmem_reclaim_free_range(this_range);
@@ -136,13 +134,13 @@
else if (RANGE_END(current_range) == this_range->start)
{
- // __dbg_printk("Range is near its prev\n");
+ DEBUG_PRINT3("Range is near its prev\n");
current_range->nb_pages += this_range->nb_pages;
__kvmem_reclaim_free_range(this_range);
}
else
{
- // __dbg_printk("Range is near nothing\n");
+ DEBUG_PRINT3("Range is near nothing\n");
list_insert_after(free_page_range_list, current_range, this_range);
}
@@ -158,7 +156,6 @@
write_spin_lock(kernel_kvalloc_lock, flags);
ret = __kvfree_unsafe(range_start, needs_unmapping);
write_spin_unlock(kernel_kvalloc_lock, flags);
-
+
return ret;
}
-
Index: _kslab_cache_free.c
===================================================================
RCS file: /home/kos/cvs/kos/modules/kmem/_kslab_cache_free.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- _kslab_cache_free.c 28 Dec 2004 18:44:38 -0000 1.17
+++ _kslab_cache_free.c 30 Jan 2005 16:11:20 -0000 1.18
@@ -2,7 +2,7 @@
* Copyright (C) 2000, Thomas Petazzoni
* http://kos.enix.org
*
- * Free space from a cache.
+ * Free space from a cache.
*
* @(#) $Id$
*/
@@ -15,6 +15,12 @@
kslab_free_blk_t *freed_block = (kslab_free_blk_t *) block;
k_ui32_t flags;
+ /*
+ * Poison the buffer to make sure nobody will use it after it has
+ * been freed
+ */
+ memset(block, 0xBEAAEBEF, slab->cache->size);
+
write_spin_lock(slab->cache->lock, flags);
freed_block->next = slab->free;
slab->free = freed_block;
@@ -82,6 +88,3 @@
/* Free the block */
return __kslab_cache_free_by_slab(slab, block);
}
-
-
-
Index: _kslab_cache_alloc.c
===================================================================
RCS file: /home/kos/cvs/kos/modules/kmem/_kslab_cache_alloc.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- _kslab_cache_alloc.c 28 Dec 2004 18:44:38 -0000 1.15
+++ _kslab_cache_alloc.c 30 Jan 2005 16:11:20 -0000 1.16
@@ -96,6 +96,11 @@
UNLOCK_CACHE(cache);
}
+ /*
+ * Poison the buffer
+ */
+ memset(block, 0xBEABEAAB, cache->size);
+
return block;
}
Index: _kmem_free.c
===================================================================
RCS file: /home/kos/cvs/kos/modules/kmem/_kmem_free.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- _kmem_free.c 19 Aug 2003 00:13:32 -0000 1.7
+++ _kmem_free.c 30 Jan 2005 16:11:20 -0000 1.8
@@ -8,8 +8,8 @@
{
kslab_slab_t *slab;
- // __dbg_printk("Free(%p)\n", block);
-
+ DEBUG_PRINT3("Free(%p)\n", block);
+
slab = __kslab_get_slab(block);
/* If not slab was found, the block might have been allocated by
@@ -18,14 +18,13 @@
{
if(kvfree((vaddr_t)block, TRUE) < 0)
return -1;
- else
+ else
return 0;
}
/* Slab was found, free the block */
if (__kslab_cache_free_by_slab(slab, block) < 0)
return -1;
-
+
return 0;
}
-
Index: _kmem_alloc.c
===================================================================
RCS file: /home/kos/cvs/kos/modules/kmem/_kmem_alloc.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- _kmem_alloc.c 17 Aug 2003 22:01:54 -0000 1.6
+++ _kmem_alloc.c 30 Jan 2005 16:11:20 -0000 1.7
@@ -16,19 +16,17 @@
for(i = 0; kmem_caches[i].size != 0; i++)
if(kmem_caches[i].size >= size)
break;
-
+
ptr = kslab_cache_alloc(kmem_caches[i].cache);
-
+
}
/* Blocks of size > 2048 bytes are handled by kvmem */
else
{
ptr = (void *) kvalloc(PAGE_ALIGN_SUP(size)/PAGE_SIZE, FALSE, TRUE);
}
-
- // __dbg_printk("Malloc(%d) = %p\n", size, ptr);
-
- return ptr;
-}
+ DEBUG_PRINT3("Malloc(%d) = %p\n", size, ptr);
+ return ptr;
+}
More information about the Kos-cvs
mailing list