-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d25aba
commit 3df0c00
Showing
6 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
set(STDOUT_REF ${CMAKE_CURRENT_SOURCE_DIR}/Output/mmap_loop.out) | ||
configure_file(${STDOUT_REF} ${CMAKE_CURRENT_BINARY_DIR}/mmap_loop.out) | ||
|
||
define_shared_lib( | ||
SRCS mmap_loop.c | ||
PKEY 2 | ||
) | ||
|
||
define_test( | ||
SRCS main.c | ||
PKEY 1 | ||
NEEDS_LD_WRAP | ||
) | ||
|
||
define_ia2_wrapper() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
program started | ||
mmap buf | ||
res=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#pragma once | ||
#include <stdlib.h> | ||
|
||
// LINKARGS: --wrap=lib_mmap_buf | ||
char *lib_mmap_buf(size_t size); | ||
|
||
// LINKARGS: --wrap=lib_malloc_buf | ||
char *lib_malloc_buf(size_t size); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
RUN: sh -c 'if [ ! -s "mmap_loop_call_gates_0.ld" ]; then echo "No link args as expected"; exit 0; fi; echo "Unexpected link args"; exit 1;' | ||
RUN: %binary_dir/tests/mmap_loop/mmap_loop_main_wrapped | diff %S/Output/mmap_loop.out - | ||
*/ | ||
#include "mmap_loop.h" | ||
#include <assert.h> | ||
#include <ia2.h> | ||
#include <math.h> | ||
#include <stdio.h> | ||
|
||
#define IA2_DEFINE_TEST_HANDLER | ||
#include "test_fault_handler.h" | ||
|
||
/* | ||
This program tests that mmap and heap allocations are handled properly. | ||
*/ | ||
|
||
INIT_RUNTIME(2); | ||
#define IA2_COMPARTMENT 1 | ||
#include <ia2_compartment_init.inc> | ||
|
||
int main() { | ||
puts("program started"); | ||
|
||
char *buf = malloc(4096); | ||
buf[0] = 'r'; | ||
assert(buf[0] == 'r'); | ||
|
||
char *lib_buf_malloc = lib_malloc_buf(4096); | ||
|
||
puts("mmap buf"); | ||
char *lib_buf_mmap = lib_mmap_buf(4096); | ||
|
||
free(buf); | ||
|
||
/* syscall tracing should forbid us to unmap compartment 2's buffer */ | ||
int res = munmap(lib_buf_mmap, 4096); | ||
if (res < 0) { | ||
perror("munmap"); | ||
} | ||
printf("res=%d\n", res); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
RUN: cat mmap_loop_call_gates_1.ld | FileCheck --check-prefix=LINKARGS %s | ||
*/ | ||
|
||
#include "mmap_loop.h" | ||
#include "ia2.h" | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <sys/mman.h> | ||
|
||
#define IA2_COMPARTMENT 2 | ||
#include <ia2_compartment_init.inc> | ||
|
||
// LINKARGS: --wrap=lib_malloc_buf | ||
char *lib_malloc_buf(size_t size) { | ||
char *buf = malloc(size); | ||
memset(buf, 0, size); | ||
return buf; | ||
} | ||
|
||
// LINKARGS: --wrap=lib_mmap_buf | ||
char *lib_mmap_buf(size_t size) { | ||
// mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0); | ||
char *buf = mmap(NULL, size, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0); | ||
pkey_mprotect(buf, size, PROT_READ | PROT_WRITE, 2); | ||
memset(buf, 0, size); | ||
return buf; | ||
} |