Support argc and argv for child process after spawn
This commit is contained in:
parent
ad704c421f
commit
71d119181e
@ -7,7 +7,7 @@ enclave {
|
|||||||
|
|
||||||
trusted {
|
trusted {
|
||||||
/* define ECALLs here. */
|
/* define ECALLs here. */
|
||||||
public int libos_boot([in, string] const char* executable_path, [user_check] char** argv);
|
public int libos_boot([in, string] const char* executable_path, [user_check] const char** argv);
|
||||||
public int libos_run(void);
|
public int libos_run(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -45,11 +45,20 @@ pub mod from_user {
|
|||||||
-> Result<Vec<CString>, Error>
|
-> Result<Vec<CString>, Error>
|
||||||
{
|
{
|
||||||
let mut cstrings = Vec::new();
|
let mut cstrings = Vec::new();
|
||||||
|
if user_ptr == ptr::null() { return Ok(cstrings); }
|
||||||
|
|
||||||
let mut user_ptr = user_ptr;
|
let mut user_ptr = user_ptr;
|
||||||
while user_ptr != ptr::null() {
|
loop {
|
||||||
let cstr_ptr = unsafe { *user_ptr };
|
check_ptr(user_ptr);
|
||||||
|
let cstr_ptr = {
|
||||||
|
let cstr_ptr = unsafe { *user_ptr };
|
||||||
|
if cstr_ptr == ptr::null() { break; }
|
||||||
|
check_ptr(cstr_ptr);
|
||||||
|
cstr_ptr
|
||||||
|
};
|
||||||
let cstring = clone_cstring_safely(cstr_ptr)?;
|
let cstring = clone_cstring_safely(cstr_ptr)?;
|
||||||
cstrings.push(cstring);
|
cstrings.push(cstring);
|
||||||
|
|
||||||
user_ptr = unsafe { user_ptr.offset(1) };
|
user_ptr = unsafe { user_ptr.offset(1) };
|
||||||
}
|
}
|
||||||
Ok(cstrings)
|
Ok(cstrings)
|
||||||
|
@ -207,7 +207,7 @@ void ocall_gettimeofday(long* seconds, long* microseconds) {
|
|||||||
|
|
||||||
|
|
||||||
/* Application entry */
|
/* Application entry */
|
||||||
int SGX_CDECL main(int argc, char *argv[])
|
int SGX_CDECL main(int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
sgx_status_t sgx_ret = SGX_SUCCESS;
|
sgx_status_t sgx_ret = SGX_SUCCESS;
|
||||||
int status = 0;
|
int status = 0;
|
||||||
|
@ -10,7 +10,7 @@ const char* expected_argv[EXPECTED_ARGC] = {
|
|||||||
EXPECTED_ARG3,
|
EXPECTED_ARG3,
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, const char* argv[]) {
|
||||||
if (argc != EXPECTED_ARGC) {
|
if (argc != EXPECTED_ARGC) {
|
||||||
printf("ERROR: expect %d arguments, but %d are given\n", EXPECTED_ARGC, argc);
|
printf("ERROR: expect %d arguments, but %d are given\n", EXPECTED_ARGC, argc);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
int main(void) {
|
int main(int argc, const char* argv[]) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
int main() {
|
int main(int argc, const char* argv[]) {
|
||||||
const char* file_name = "tmp.txt";
|
const char* file_name = "tmp.txt";
|
||||||
int fd, flags, mode, len;
|
int fd, flags, mode, len;
|
||||||
const char* write_msg = "Hello World\n";
|
const char* write_msg = "Hello World\n";
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
int main(void) {
|
int main(int argc, const char* argv[]) {
|
||||||
printf("Run a new process with pid = %d and ppid = %d\n", getpid(), getppid());
|
printf("Run a new process with pid = %d and ppid = %d\n", getpid(), getppid());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,13 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
static const char* msg = "Hello World\n";
|
int main(int argc, const char* argv[]) {
|
||||||
|
if (argc <= 1) {
|
||||||
int main() {
|
printf("Hello World!\n");
|
||||||
printf("%s", msg);
|
}
|
||||||
|
else {
|
||||||
|
const char* echo_msg = argv[1];
|
||||||
|
printf("%s\n", echo_msg);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#define MAX_SIZE (1*1024*1024)
|
#define MAX_SIZE (1*1024*1024)
|
||||||
#define MIN_SIZE 8
|
#define MIN_SIZE 8
|
||||||
|
|
||||||
int main(void) {
|
int main(int argc, const char* argv[]) {
|
||||||
printf("Testing malloc and free...\n");
|
printf("Testing malloc and free...\n");
|
||||||
for (size_t buf_size = MIN_SIZE; buf_size <= MAX_SIZE; buf_size *= 4) {
|
for (size_t buf_size = MIN_SIZE; buf_size <= MAX_SIZE; buf_size *= 4) {
|
||||||
printf("buf_size = %lu\n", buf_size);
|
printf("buf_size = %lu\n", buf_size);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
include ../test_common.mk
|
include ../test_common.mk
|
||||||
|
|
||||||
EXTRA_C_FLAGS :=
|
EXTRA_C_FLAGS := -Wno-incompatible-pointer-types-discards-qualifiers
|
||||||
EXTRA_LINK_FLAGS :=
|
EXTRA_LINK_FLAGS :=
|
||||||
BIN_ARGS :=
|
BIN_ARGS :=
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
#include <spawn.h>
|
#include <spawn.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
int main(void) {
|
int main(int argc, const char* argv[]) {
|
||||||
// XXX: this is a hack! remove this in the future
|
// XXX: this is a hack! remove this in the future
|
||||||
void* ptr = malloc(64);
|
void* ptr = malloc(64);
|
||||||
free(ptr);
|
free(ptr);
|
||||||
@ -24,15 +24,18 @@ int main(void) {
|
|||||||
posix_spawn_file_actions_adddup2(&file_actions, pipe_wr_fd, STDOUT_FILENO);
|
posix_spawn_file_actions_adddup2(&file_actions, pipe_wr_fd, STDOUT_FILENO);
|
||||||
posix_spawn_file_actions_addclose(&file_actions, pipe_rd_fd);
|
posix_spawn_file_actions_addclose(&file_actions, pipe_rd_fd);
|
||||||
|
|
||||||
|
const char* msg = "Echo!\n";
|
||||||
|
const char* child_prog = "hello_world/bin.encrypted";
|
||||||
|
const char* child_argv[3] = { child_prog, msg, NULL };
|
||||||
int child_pid;
|
int child_pid;
|
||||||
if (posix_spawn(&child_pid, "hello_world/bin.encrypted", &file_actions,
|
if (posix_spawn(&child_pid, child_prog, &file_actions,
|
||||||
NULL, NULL, NULL) < 0) {
|
NULL, child_argv, NULL) < 0) {
|
||||||
printf("ERROR: failed to spawn a child process\n");
|
printf("ERROR: failed to spawn a child process\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
close(pipe_wr_fd);
|
close(pipe_wr_fd);
|
||||||
|
|
||||||
const char* expected_str = "Hello World\n";
|
const char* expected_str = msg;
|
||||||
size_t expected_len = strlen(expected_str);
|
size_t expected_len = strlen(expected_str);
|
||||||
char actual_str[32] = {0};
|
char actual_str[32] = {0};
|
||||||
ssize_t actual_len;
|
ssize_t actual_len;
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <spawn.h>
|
#include <spawn.h>
|
||||||
|
|
||||||
int main(void) {
|
int main(int argc, const char* argv[]) {
|
||||||
int ret, child_pid, status;
|
int ret, child_pid, status;
|
||||||
printf("Run a parent process has pid = %d and ppid = %d\n", getpid(), getppid());
|
printf("Run a parent process has pid = %d and ppid = %d\n", getpid(), getppid());
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
int main() {
|
int main(int argc, const char* argv[]) {
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
||||||
printf("sec = %lu, usec = %lu\n", tv.tv_sec, tv.tv_usec);
|
printf("sec = %lu, usec = %lu\n", tv.tv_sec, tv.tv_usec);
|
||||||
|
Loading…
Reference in New Issue
Block a user