Fixes exec-bound-3 failures
[pintos-anon] / src / tests / userprog / boundary.c
index 50f2618d3db62852a7368630e267eba22afeb27d..ca4fb73e5a52a5470e251ed1476a991cdb9be5c5 100644 (file)
@@ -1,9 +1,16 @@
+/* Utility function for tests that try to break system calls by
+   passing them data that crosses from one virtual page to
+   another. */
+
 #include <inttypes.h>
 #include <round.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. */
@@ -27,3 +34,14 @@ copy_string_across_boundary (const char *src)
   return p;
 }
 
+/* Returns an address that is invalid, but the preceding bytes
+ * 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)
+{
+  /* This code assumes that dst will be in the highest page
+   * allocated to the user process. */
+  return (void *) ROUND_UP ((uintptr_t) (dst + sizeof(dst) - 1), 4096);
+}