summaryrefslogtreecommitdiffstats
path: root/pintos-progos/tests/userprog/boundary.c
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2012-03-26 12:54:45 +0200
committermanuel <manuel@mausz.at>2012-03-26 12:54:45 +0200
commitb5f0874cd96ee2a62aabc645b9626c2749cb6a01 (patch)
tree1262e4bbe0634de6650be130c36e0538240f4cbf /pintos-progos/tests/userprog/boundary.c
downloadprogos-b5f0874cd96ee2a62aabc645b9626c2749cb6a01.tar.gz
progos-b5f0874cd96ee2a62aabc645b9626c2749cb6a01.tar.bz2
progos-b5f0874cd96ee2a62aabc645b9626c2749cb6a01.zip
initial pintos checkin
Diffstat (limited to 'pintos-progos/tests/userprog/boundary.c')
-rw-r--r--pintos-progos/tests/userprog/boundary.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/pintos-progos/tests/userprog/boundary.c b/pintos-progos/tests/userprog/boundary.c
new file mode 100644
index 0000000..59907ec
--- /dev/null
+++ b/pintos-progos/tests/userprog/boundary.c
@@ -0,0 +1,33 @@
1/* Utility function for tests that try to break system calls by
2 passing them data that crosses from one virtual page to
3 another. */
4
5#include <inttypes.h>
6#include <round.h>
7#include <string.h>
8#include "tests/userprog/boundary.h"
9
10static char dst[8192];
11
12/* Returns the beginning of a page. There are at least 2048
13 modifiable bytes on either side of the pointer returned. */
14void *
15get_boundary_area (void)
16{
17 char *p = (char *) ROUND_UP ((uintptr_t) dst, 4096);
18 if (p - dst < 2048)
19 p += 4096;
20 return p;
21}
22
23/* Returns a copy of SRC split across the boundary between two
24 pages. */
25char *
26copy_string_across_boundary (const char *src)
27{
28 char *p = get_boundary_area ();
29 p -= strlen (src) < 4096 ? strlen (src) / 2 : 4096;
30 strlcpy (p, src, 4096);
31 return p;
32}
33