diff options
Diffstat (limited to 'src/tests/userprog/boundary.c')
| -rw-r--r-- | src/tests/userprog/boundary.c | 33 |
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; +} + |
