blob: 59907ec935d36d8e498766730138741f0143e89d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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;
}
|