diff options
Diffstat (limited to 'pintos-progos/tests/userprog/boundary.c')
| -rw-r--r-- | pintos-progos/tests/userprog/boundary.c | 33 |
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 | |||
| 10 | static 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. */ | ||
| 14 | void * | ||
| 15 | get_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. */ | ||
| 25 | char * | ||
| 26 | copy_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 | |||
