From 41341cbf5e4dcddcc97c21f8c16eba7dde45c9b3 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Thu, 19 Oct 2017 21:04:39 +0100 Subject: [PATCH] kernel: preparatory work for Split I/D and for out of memory buffers Pair tmpbuf with tmpfree (which for now is still brelse) but in future may be unrelated to bufcache Change pagemap_realloc prototype and arrange existing loaders so nothing breaks for now. --- Kernel/dev/devide_discard.c | 4 ++-- Kernel/dev/mbr.c | 2 +- Kernel/devio.c | 7 +++++-- Kernel/include/kernel.h | 3 ++- Kernel/syscall_exec16.c | 8 +++++--- Kernel/syscall_exec32.c | 4 +++- 6 files changed, 18 insertions(+), 10 deletions(-) diff --git a/Kernel/dev/devide_discard.c b/Kernel/dev/devide_discard.c index 819f83f2..bbb829f1 100644 --- a/Kernel/dev/devide_discard.c +++ b/Kernel/dev/devide_discard.c @@ -123,7 +123,7 @@ void devide_init_drive(uint8_t drive) blk->drive_lba_count = le32_to_cpu(*((uint32_t*)&buffer[120])); /* done with our temporary memory */ - brelse((bufptr)buffer); + tmpfree(buffer); /* Deselect the IDE, as we will re-select it in the partition scan and it may not recursively stack de-selections */ @@ -134,7 +134,7 @@ void devide_init_drive(uint8_t drive) return; failout: - brelse((bufptr)buffer); + tmpfree(buffer); out: ide_deselect(); return; diff --git a/Kernel/dev/mbr.c b/Kernel/dev/mbr.c index 8c4006c4..bef5aef2 100644 --- a/Kernel/dev/mbr.c +++ b/Kernel/dev/mbr.c @@ -101,5 +101,5 @@ void mbr_parse(char letter) kputs("> "); /* release temporary memory */ - brelse((bufptr)br); + tmpfree(br); } diff --git a/Kernel/devio.c b/Kernel/devio.c index 4bfc9855..e00262ce 100644 --- a/Kernel/devio.c +++ b/Kernel/devio.c @@ -104,7 +104,10 @@ int bfree(bufptr bp, uint8_t dirty) /* This returns a busy block not belonging to any device, with * garbage contents. It is essentially a malloc for the kernel. - * Free it with brelse()! + * Free it with tmpfree. + * + * API note: Nothing guarantees a connection between a bufcache entry + * and tmpbuf in future. Always free with tmpfree. */ void *tmpbuf(void) { @@ -117,7 +120,7 @@ void *tmpbuf(void) return bp->bf_data; } - +/* Allocate an empty _disk cache_ buffer */ void *zerobuf(void) { void *b; diff --git a/Kernel/include/kernel.h b/Kernel/include/kernel.h index 8cb576c8..5c9a8479 100644 --- a/Kernel/include/kernel.h +++ b/Kernel/include/kernel.h @@ -767,6 +767,7 @@ extern void bufsync(void); extern bufptr bfind(uint16_t dev, blkno_t blk); extern void bdrop(uint16_t dev); extern bufptr freebuf(void); +#define tmpfree brelse extern void bufinit(void); extern void bufdiscard(bufptr bp); extern void bufdump (void); @@ -931,7 +932,7 @@ extern void copy_common(uint8_t page); extern void pagemap_add(uint8_t page); /* FIXME: may need a page type for big boxes */ extern void pagemap_free(ptptr p); extern int pagemap_alloc(ptptr p); -extern int pagemap_realloc(usize_t p); +extern int pagemap_realloc(usize_t c, usize_t d, usize_t s); extern usize_t pagemap_mem_used(void); extern void map_init(void); #ifndef platform_discard diff --git a/Kernel/syscall_exec16.c b/Kernel/syscall_exec16.c index 0e9d8060..2ca5fa32 100644 --- a/Kernel/syscall_exec16.c +++ b/Kernel/syscall_exec16.c @@ -166,7 +166,9 @@ arg_t _execve(void) goto nogood3; /* SN */ /* This must be the last test as it makes changes if it works */ - if (pagemap_realloc(top - MAPBASE)) + /* FIXME: once we sort out chmem we can make stack and data + two elements. We never allocate 'code' as there is no split I/D */ + if (pagemap_realloc(0, top - MAPBASE, 0)) goto nogood3; /* From this point on we are commmited to the exec() completing */ @@ -236,8 +238,8 @@ arg_t _execve(void) ugets((void *) ugetw(nargv), udata.u_name, 8); memcpy(udata.u_ptab->p_name, udata.u_name, 8); - brelse(abuf); - brelse(ebuf); + tmpfree(abuf); + tmpfree(ebuf); i_deref(ino); // Shove argc and the address of argv just below envp diff --git a/Kernel/syscall_exec32.c b/Kernel/syscall_exec32.c index 392b950c..f8590773 100644 --- a/Kernel/syscall_exec32.c +++ b/Kernel/syscall_exec32.c @@ -203,7 +203,9 @@ arg_t _execve(void) goto nogood3; /* This must be the last test as it makes changes if it works */ - if (pagemap_realloc(bin_size)) + /* FIXME: need to update this to support split code/data and to fix + stack handling nicely */ + if (pagemap_realloc(0, bin_size, 0)) goto nogood3; /* From this point on we are commmited to the exec() completing */ -- 2.34.1