Fixes exec-bound-3 failures
authorJohn Ousterhout <ouster@cs.stanford.edu>
Thu, 17 Dec 2015 19:29:13 +0000 (11:29 -0800)
committerJohn Ousterhout <ouster@cs.stanford.edu>
Thu, 17 Dec 2015 19:29:13 +0000 (11:29 -0800)
The boundary position wasn't being properly chosen (must ensure that
the dst array in boundary.c is always in the last page of the .bss
segment).

src/lib/user/user.lds
src/tests/userprog/boundary.c
src/tests/userprog/exec-bound-3.c

index cc6d6c03a60791071ba91663cfdaaebee67dbb78..1bf30b159c18e58eb6ceb52e44167cb880d789aa 100644 (file)
@@ -16,7 +16,7 @@ SECTIONS
   . = DATA_SEGMENT_ALIGN (0x1000, 0x1000);
 
   .data : { *(.data) }
   . = DATA_SEGMENT_ALIGN (0x1000, 0x1000);
 
   .data : { *(.data) }
-  .bss : { *(.bss) }
+  .bss : { *(.bss) *(.testEndmem) }
 
   /* Stabs debugging sections.  */
   .stab          0 : { *(.stab) }
 
   /* Stabs debugging sections.  */
   .stab          0 : { *(.stab) }
index 2e81df48e0beb5c75489e6bdb8c781c39b771213..ca4fb73e5a52a5470e251ed1476a991cdb9be5c5 100644 (file)
@@ -7,7 +7,10 @@
 #include <string.h>
 #include "tests/userprog/boundary.h"
 
 #include <string.h>
 #include "tests/userprog/boundary.h"
 
-static char dst[8192];
+/* Together with statements in src/lib/user/user.lds, arranges
+   for the following array to be at the very end of the .bss
+   segment (needed for get_bad_boundary below). */
+static char dst[8192] __attribute__ ((section (".testEndmem,\"aw\",@nobits#")));
 
 /* Returns the beginning of a page.  There are at least 2048
    modifiable bytes on either side of the pointer returned. */
 
 /* Returns the beginning of a page.  There are at least 2048
    modifiable bytes on either side of the pointer returned. */
@@ -32,9 +35,9 @@ copy_string_across_boundary (const char *src)
 }
 
 /* Returns an address that is invalid, but the preceding bytes
 }
 
 /* Returns an address that is invalid, but the preceding bytes
- * are all valid. Used to position information such that the
- * first byte of the information is valid, but not all the
- * information is valid. */
+ * are all valid (the highest address in the bss segment). Used
+ * to position information such that the first byte of the
+ * information is valid, but not all the information is valid. */
 void *
 get_bad_boundary (void)
 {
 void *
 get_bad_boundary (void)
 {
index 67937c8ff0c8d94f70fa9052839fa60b419d6e78..41f1cd993cc0b347e7ce73544bf4eaf0ad2d843c 100644 (file)
@@ -14,5 +14,15 @@ test_main (void)
   char *p = get_bad_boundary () - 1;
   *p = 'a';
   exec(p);
   char *p = get_bad_boundary () - 1;
   *p = 'a';
   exec(p);
+
+  /* Note: if this test fails to pass even with the official solutions,
+     it's probably because memory layout has changed and p no longer
+     refers to the proper page boundary. To fix the problem, uncomment
+     the line below to print out the boundary address. In addition,
+     add a printf line in load_segment to print out the address range
+     of each segment. From that, you'll be able to figure out how to
+     modify get_bad_boundary to make things work again. */
+
+  // msg("boundary address: 0x%x", p);
   fail ("should have killed process");
 }
   fail ("should have killed process");
 }