PKUOS - Pintos
Pintos source browser for PKU Operating System course
boundary.c
Go to the documentation of this file.
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>
9
10/** Together with statements in src/lib/user/user.lds, arranges
11 for the following array to be at the very end of the .bss
12 segment (needed for get_bad_boundary below). */
13static char dst[8192] __attribute__ ((section (".testEndmem,\"aw\",@nobits#")));
14
15/** Returns the beginning of a page. There are at least 2048
16 modifiable bytes on either side of the pointer returned. */
17void *
19{
20 char *p = (char *) ROUND_UP ((uintptr_t) dst, 4096);
21 if (p - dst < 2048)
22 p += 4096;
23 return p;
24}
25
26/** Returns a copy of SRC split across the boundary between two
27 pages. */
28char *
30{
31 char *p = get_boundary_area ();
32 p -= strlen (src) < 4096 ? strlen (src) / 2 : 4096;
33 strlcpy (p, src, 4096);
34 return p;
35}
36
37/** Returns an address that is invalid, but the preceding bytes
38 * are all valid (the highest address in the bss segment). Used
39 * to position information such that the first byte of the
40 * information is valid, but not all the information is valid. */
41void *
43{
44 /* This code assumes that dst will be in the highest page
45 * allocated to the user process. */
46 return (void *) ROUND_UP ((uintptr_t) (dst + sizeof(dst) - 1), 4096);
47}
void * get_boundary_area(void)
Returns the beginning of a page.
Definition: boundary.c:18
static char dst[8192] __attribute__((section(".testEndmem,\"aw\",@nobits#")))
Utility function for tests that try to break system calls by passing them data that crosses from one ...
char * copy_string_across_boundary(const char *src)
Returns a copy of SRC split across the boundary between two pages.
Definition: boundary.c:29
void * get_bad_boundary(void)
Returns an address that is invalid, but the preceding bytes are all valid (the highest address in the...
Definition: boundary.c:42
#define ROUND_UP(X, STEP)
Yields X rounded up to the nearest multiple of STEP.
Definition: round.h:6
uint32_t uintptr_t
Definition: stdint.h:36
size_t strlen(const char *string)
Returns the length of STRING.
Definition: string.c:293
size_t strlcpy(char *dst, const char *src, size_t size)
Copies string SRC to DST.
Definition: string.c:326