-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add two tests performing syscalls, to show the running syscalls themselves from within a restricted DDC environment works. I think this is useful to have for future potential work (e.g., could we provide a compartment-safe printing function, instead of crashing with `printf`, if making `printf` be compatible proves hard). Adds a harness to be able to run `so` files natively, without having to go through the compartment library. Useful for debugging / differential testing.
- Loading branch information
Showing
4 changed files
with
64 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,11 @@ | ||
#include <assert.h> | ||
#include <unistd.h> | ||
|
||
int | ||
main(void) | ||
{ | ||
long int sc_pid = syscall(20); | ||
pid_t pid = getpid(); | ||
assert(pid == sc_pid); | ||
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,16 @@ | ||
#include <unistd.h> | ||
#include <string.h> | ||
#include <err.h> | ||
|
||
int | ||
main(void) | ||
{ | ||
char* buf = "Hello World!\n"; | ||
long int sc_write = syscall(4, STDOUT_FILENO, buf, strlen(buf)); | ||
if (sc_write == -1) | ||
{ | ||
err(1, "Error calling `syscall`:"); | ||
} | ||
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,32 @@ | ||
#include <dlfcn.h> | ||
#include <err.h> | ||
|
||
#include <assert.h> | ||
#include <stdio.h> | ||
|
||
int | ||
main(int argc, char **argv) | ||
{ | ||
if (argc != 2) | ||
{ | ||
errx(1, "Expected one argument - path to `so` file to wrap.\n"); | ||
} | ||
void *handle = dlopen(argv[1], RTLD_LAZY); | ||
if (!handle) | ||
{ | ||
errx(1, "`dlopen` error: %s\n", dlerror()); | ||
} | ||
|
||
dlerror(); | ||
void (*handle_main)() = (void (*)(void)) dlsym(handle, "main"); | ||
char *sym_err = dlerror(); | ||
if (sym_err) | ||
{ | ||
errx(1, "`dlsym` error: %s\n", sym_err); | ||
} | ||
|
||
handle_main(); | ||
|
||
dlclose(handle); | ||
return 0; | ||
} |