summaryrefslogtreecommitdiffstats
path: root/src/tests/userprog/boundary.c
diff options
context:
space:
mode:
authorFelipe Boeira <felipe.boeira@liu.se>2019-01-08 18:39:03 +0100
committerFelipe Boeira <felipe.boeira@liu.se>2019-01-08 18:39:03 +0100
commitd4522b8e9854178473adcea0fbb84f23f6e744bd (patch)
treefbcf620617c5023154eba3f965b3a982daa64a47 /src/tests/userprog/boundary.c
downloadpintos-d4522b8e9854178473adcea0fbb84f23f6e744bd.tar.gz
Initial commit
Diffstat (limited to 'src/tests/userprog/boundary.c')
-rw-r--r--src/tests/userprog/boundary.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/tests/userprog/boundary.c b/src/tests/userprog/boundary.c
new file mode 100644
index 0000000..59907ec
--- /dev/null
+++ b/src/tests/userprog/boundary.c
@@ -0,0 +1,33 @@
+/* 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];
+
+/* Returns the beginning of a page. There are at least 2048
+ modifiable bytes on either side of the pointer returned. */
+void *
+get_boundary_area (void)
+{
+ char *p = (char *) ROUND_UP ((uintptr_t) dst, 4096);
+ if (p - dst < 2048)
+ p += 4096;
+ return p;
+}
+
+/* Returns a copy of SRC split across the boundary between two
+ pages. */
+char *
+copy_string_across_boundary (const char *src)
+{
+ char *p = get_boundary_area ();
+ p -= strlen (src) < 4096 ? strlen (src) / 2 : 4096;
+ strlcpy (p, src, 4096);
+ return p;
+}
+