00001 /* Utility function for tests that try to break system calls by 00002 passing them data that crosses from one virtual page to 00003 another. */ 00004 00005 #include <inttypes.h> 00006 #include <round.h> 00007 #include <string.h> 00008 #include "tests/userprog/boundary.h" 00009 00010 static char dst[8192]; 00011 00012 /* Returns the beginning of a page. There are at least 2048 00013 modifiable bytes on either side of the pointer returned. */ 00014 void * 00015 get_boundary_area (void) 00016 { 00017 char *p = (char *) ROUND_UP ((uintptr_t) dst, 4096); 00018 if (p - dst < 2048) 00019 p += 4096; 00020 return p; 00021 } 00022 00023 /* Returns a copy of SRC split across the boundary between two 00024 pages. */ 00025 char * 00026 copy_string_across_boundary (const char *src) 00027 { 00028 char *p = get_boundary_area (); 00029 p -= strlen (src) < 4096 ? strlen (src) / 2 : 4096; 00030 strlcpy (p, src, 4096); 00031 return p; 00032 } 00033