Hi

I was looking into some Hardware debugging issues, thats when I thought of
writing a small little OS so that I understand Protected mode properly. I
immidiately remembered bochs and freemware. 

When I was trying to get my bare ELF image to boot on freemware I noticed that
it crashed so I looked into the code and found these problems at memcpy (in
bin.c) so I have patched it. Also I have patched freemware.c so that it
verifies the values for Segment offsets and Total memory given in fmw.conf to
be valid before continuing.

I noted that one is allowed to specify the Data and BSS offset (along with
Code and Stack) but its nevered used anywhere.  Shouldn't we be setting the
VM's DS to vm_conf.data_address in bin.c . Also should we be allowing setting
of BSS as its got nothing to do with Hardware (VM) directly (as far as I know
but I may be wrong). As I have joined the list only today I don't know if there
was any idea behind keeping them the way they are. So I thought instead of
changing anything let me put across the idea.

---------
Keep :-)
HanishKVC
http://HanishKVC.tripod.com/

diff -Naur fmw-20000213/user/bin.c fmw-20000213.hankvc/user/bin.c
--- fmw-20000213/user/bin.c	Mon Jan 24 01:43:03 2000
+++ fmw-20000213.hankvc/user/bin.c	Fri Mar 10 01:00:08 2000
@@ -99,7 +99,13 @@
     {
     case TYPE_BIN:
         /* Load complete binary image */
-	memcpy (ptr + vm_conf.text_address, image, stat_buf.st_size);
+        if((vm_conf.max_memory*1024*1024) >= (vm_conf.text_address+stat_buf.st_size))
+	  memcpy (ptr + vm_conf.text_address, image, stat_buf.st_size);
+        else  
+        {
+          fprintf (stderr, "Trying to load beyond available VM memory, Quiting...\n");
+          exit (1);
+        }  
 
         /* Set up initial context */
         context.eip = vm_conf.text_address;
@@ -128,8 +134,15 @@
         /* Load all sections that occupy space and have bits */
 	for (i = 0; i < eh->e_shnum; i++)
 	    if ((sh[i].sh_flags & SHF_ALLOC) && (sh[i].sh_type != SHT_NOBITS))
-		memcpy (ptr + sh[i].sh_addr, image + sh[i].sh_offset, sh[i].sh_size);
-
+            {
+                if((vm_conf.max_memory*1024*1024) >= (sh[i].sh_addr+sh[i].sh_size))
+		  memcpy (ptr + sh[i].sh_addr, image + sh[i].sh_offset, sh[i].sh_size);
+                else
+                {
+                  fprintf (stderr, "Trying to load beyond available VM memory, Quiting...\n");
+                  exit (1);
+                }  
+            }
         /* Retrieve entry point address and set up initial context */
         context.eip = eh->e_entry;
         context.esp = vm_conf.stack_address;
diff -Naur fmw-20000213/user/fmw.conf fmw-20000213.hankvc/user/fmw.conf
--- fmw-20000213/user/fmw.conf	Sun Jan 23 04:16:55 2000
+++ fmw-20000213.hankvc/user/fmw.conf	Fri Mar 10 00:52:45 2000
@@ -9,9 +9,10 @@
 ####################################################################
 
 # fully qualified path to guest code
+guest = ../guest/os1
 #guest = ../guest/virtcode/virtcode
 #guest = ../guest/cooperative/kernel
-guest = ../guest/preemptive/kernel
+#guest = ../guest/preemptive/kernel
 
 
 
diff -Naur fmw-20000213/user/freemware.c fmw-20000213.hankvc/user/freemware.c
--- fmw-20000213/user/freemware.c	Mon Jan 24 01:43:03 2000
+++ fmw-20000213.hankvc/user/freemware.c	Fri Mar 10 00:52:06 2000
@@ -296,6 +296,27 @@
     if (vm_conf.text_address == -1)
 	vm_conf.text_address = 0;
 
+    /* Verify if addresses specified are valid */
+    
+    /* DEBUG: HanishKVC (PLEASE VERIFY BEFORE PATCHING)
+       We aren't using data_address for anything 
+         (like setting the default ds value when VM boots).
+         Shouldn't we be doing this in bin.c.
+       Similarly bss_address is also not used any where. 
+         As its not directly mapped to any hardware feature 
+         should we be providing this for VM ?
+    */     
+    if ( ((vm_conf.max_memory*1024*1024) < vm_conf.text_address) ||
+         ((vm_conf.max_memory*1024*1024) < vm_conf.data_address) ||
+         ((vm_conf.max_memory*1024*1024) < vm_conf.stack_address) ||
+         ((vm_conf.max_memory*1024*1024) < vm_conf.bss_address) )
+    {
+      fprintf (stderr, "Total memory for VM less than some of the \n");
+      fprintf (stderr, "  specified segment addresses, Quiting...\n");
+      exit (1);
+    }
+       
+
     if (vm_conf.verbose)
     {
 	fprintf (stderr, "Memory:\t\t%d\n",      vm_conf.max_memory);

Reply via email to