kernel: preparatory work for Split I/D and for out of memory buffers
authorAlan Cox <alan@linux.intel.com>
Thu, 19 Oct 2017 20:04:39 +0000 (21:04 +0100)
committerAlan Cox <alan@linux.intel.com>
Thu, 19 Oct 2017 20:04:39 +0000 (21:04 +0100)
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
Kernel/dev/mbr.c
Kernel/devio.c
Kernel/include/kernel.h
Kernel/syscall_exec16.c
Kernel/syscall_exec32.c

index 819f83f..bbb829f 100644 (file)
@@ -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;
index 8c4006c..bef5aef 100644 (file)
@@ -101,5 +101,5 @@ void mbr_parse(char letter)
        kputs("> ");
 
     /* release temporary memory */
-    brelse((bufptr)br);
+    tmpfree(br);
 }
index 4bfc985..e00262c 100644 (file)
@@ -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;
index 8cb576c..5c9a847 100644 (file)
@@ -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
index 0e9d806..2ca5fa3 100644 (file)
@@ -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
index 392b950..f859077 100644 (file)
@@ -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 */