Skip to content

Commit

Permalink
Remove from config
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean T. Allen committed Sep 24, 2020
1 parent 95d1467 commit 16f380d
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 146 deletions.
15 changes: 2 additions & 13 deletions src/enclave/enclave_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ static void _enter_user_space(
int argc,
char** argv,
void* stack,
size_t num_ethreads,
struct timespec clock_res[4])
size_t num_ethreads)
{
extern void* __oe_get_isolated_image_entry_point(void);
extern const void* __oe_get_isolated_image_base();
Expand Down Expand Up @@ -139,7 +138,6 @@ typedef struct startmain_args
{
int argc;
char** argv;
struct timespec clock_res[8];
}
startmain_args_t;

Expand All @@ -164,8 +162,7 @@ static int app_main_thread(void* args_)
args->argc,
args->argv,
&sgxlkl_enclave_state.elf64_stack,
sgxlkl_enclave_state.config->ethreads,
args->clock_res);
sgxlkl_enclave_state.config->ethreads);
#else
/* Launch stage 3 dynamic linker, passing in top of stack to overwrite.
* The dynamic linker will then load the application proper; here goes! */
Expand Down Expand Up @@ -238,13 +235,6 @@ int __libc_init_enclave(int argc, char** argv)

init_sysconf(cfg->ethreads, cfg->ethreads);

struct timespec tmp[8] = {0};
for (size_t i = 0; i < 8; i++)
{
tmp[i].tv_sec = hex_to_int(cfg->clock_res[i].resolution, 8);
tmp[i].tv_nsec = hex_to_int(cfg->clock_res[i].resolution + 8, 8);
}

size_t max_lthreads =
cfg->max_user_threads * sizeof(*__scheduler_queue.buffer);
max_lthreads = next_power_of_2(max_lthreads);
Expand All @@ -266,7 +256,6 @@ int __libc_init_enclave(int argc, char** argv)
static startmain_args_t args;
args.argc = argc;
args.argv = argv;
memcpy(args.clock_res, tmp, sizeof(args.clock_res));

if (lthread_create(&lt, NULL, kernel_main_thread, &args) != 0)
sgxlkl_fail("Failed to create lthread for kernel_main_thread()\n");
Expand Down
17 changes: 1 addition & 16 deletions src/main-oe/serialize_enclave_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,6 @@ static json_obj_t* encode_string_array(
return res;
}

static json_obj_t* encode_clock_res(
const char* key,
const sgxlkl_clock_res_config_t* clock_res)
{
json_obj_t* res = create_json_array(key, 8);
for (size_t i = 0; i < 8; i++)
{
res->array[i] = create_json_objects(NULL, 1);
res->array[i]->objects[0] =
create_json_string("resolution", clock_res[i].resolution);
}
return res;
}

static json_obj_t* encode_root(
const char* key,
const sgxlkl_enclave_root_config_t* root)
Expand Down Expand Up @@ -449,7 +435,7 @@ void serialize_enclave_config(
// Catch modifications to sgxlkl_enclave_config_t early. If this fails,
// the code above/below needs adjusting for the added/removed settings.
_Static_assert(
sizeof(sgxlkl_enclave_config_t) == 464,
sizeof(sgxlkl_enclave_config_t) == 328,
"sgxlkl_enclave_config_t size has changed");

#define FPFBOOL(N) root->objects[cnt++] = encode_boolean(#N, config->N)
Expand Down Expand Up @@ -484,7 +470,6 @@ void serialize_enclave_config(
FPFU64(espins);
FPFU64(esleep);
FPFU64(ethreads);
root->objects[cnt++] = encode_clock_res("clock_res", config->clock_res);

FPFBOOL(fsgsbase);
FPFBOOL(verbose);
Expand Down
29 changes: 0 additions & 29 deletions src/main-oe/sgxlkl_run_oe.c
Original file line number Diff line number Diff line change
Expand Up @@ -792,34 +792,6 @@ void get_libsgxlkl_user_path(char* path_buf, size_t len)
find_lib("libsgxlkl-user.so", path_buf, len);
}

void mk_clock_res_string(int clock)
{
sgxlkl_enclave_config_t* econf = &sgxlkl_host_state.enclave_config;
size_t sz = sizeof(sgxlkl_clock_res_config_t);
struct timespec tmpt;
char tmps[8 * 2 * 2 + 1];
clock_getres(clock, &tmpt);
snprintf(tmps, sizeof(tmps), "%08lx%08lx", tmpt.tv_sec, tmpt.tv_nsec);
memcpy(econf->clock_res[clock].resolution, tmps, sz);
}

void set_clock_res(bool have_enclave_config)
{
/* The enclave config file has a specified default for these settings,
* so we auto-detect them only if we don't have an enclave config file.
*/

if (!have_enclave_config)
{
mk_clock_res_string(CLOCK_REALTIME);
mk_clock_res_string(CLOCK_MONOTONIC);
mk_clock_res_string(CLOCK_MONOTONIC_RAW);
mk_clock_res_string(CLOCK_REALTIME_COARSE);
mk_clock_res_string(CLOCK_MONOTONIC_COARSE);
mk_clock_res_string(CLOCK_BOOTTIME);
}
}

static void rdfsbase_sigill_handler(int sig, siginfo_t* si, void* data)
{
rdfsbase_caused_sigill = 1;
Expand Down Expand Up @@ -1883,7 +1855,6 @@ int main(int argc, char* argv[], char* envp[])
econf->kernel_cmd);

bool have_enclave_config_file = enclave_config_path != NULL;
set_clock_res(have_enclave_config_file);
sgxlkl_host_state.shared_memory.env = envp;
set_tls(have_enclave_config_file);
register_hds(root_hd);
Expand Down
17 changes: 3 additions & 14 deletions src/shared/sgxlkl_enclave_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ static json_result_t json_read_callback(
else if (MATCH("wg.peers"))
ALLOC_ARRAY(
wg.num_peers, wg.peers, sgxlkl_enclave_wg_peer_config_t);
else if (!(MATCH("clock_res")))
else
FAIL("unknown json array '%s'\n", make_path(parser));
break;
case JSON_REASON_END_ARRAY:
Expand Down Expand Up @@ -359,17 +359,6 @@ static json_result_t json_read_callback(
JU64("espins", cfg->espins);
JU64("esleep", cfg->esleep);

JPATHT("clock_res.resolution", JSON_TYPE_STRING, {
if (strlen(un->string) != 16)
FAIL("invalid length of value for clock_res item");
i = json_get_array_index(parser);
if (i == -1)
FAIL("invalid array index\n");
if (i >= 8)
FAIL("too many values for clock_res");
memcpy(&cfg->clock_res[i].resolution, un->string, 17);
});

JPATHT("mode", JSON_TYPE_STRING, {
cfg->mode = string_to_sgxlkl_enclave_mode_t(un->string);
});
Expand Down Expand Up @@ -481,7 +470,7 @@ void sgxlkl_read_enclave_config(
// Catch modifications to sgxlkl_enclave_config_t early. If this fails,
// the code above/below needs adjusting for the added/removed settings.
_Static_assert(
sizeof(sgxlkl_enclave_config_t) == 464,
sizeof(sgxlkl_enclave_config_t) == 328,
"sgxlkl_enclave_config_t size has changed");

if (!from)
Expand Down Expand Up @@ -589,4 +578,4 @@ void sgxlkl_free_enclave_config(sgxlkl_enclave_config_t* config)
bool is_encrypted(sgxlkl_enclave_mount_config_t* cfg)
{
return cfg->key || cfg->key_id || cfg->fresh_key;
}
}
28 changes: 1 addition & 27 deletions tests/tools/sgx-lkl-cfg/create/enclave-config-complete-ref.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,32 +41,6 @@
"max_user_threads": 256,
"espins": 500,
"esleep": 16000,
"clock_res": [
{
"resolution": "0000000000000001"
},
{
"resolution": "0000000000000001"
},
{
"resolution": "0000000000000000"
},
{
"resolution": "0000000000000000"
},
{
"resolution": "0000000000000001"
},
{
"resolution": "00000000003d0900"
},
{
"resolution": "00000000003d0900"
},
{
"resolution": "0000000000000001"
}
],
"stacksize": 524288,
"mmap_files": "shared",
"oe_heap_pagecount": 8192,
Expand All @@ -87,4 +61,4 @@
"block": true,
"console": true
}
}
}
47 changes: 0 additions & 47 deletions tools/schemas/enclave-config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,6 @@
"EXIT_STATUS_NONE"
]
},
"sgxlkl_clock_res_config_t": {
"type": "object",
"properties": {
"resolution": {
"type": "string",
"minLength": 16,
"maxLength": 16,
"pattern": "^[0-9A-Fa-f]+$",
"default": "0000000000000000"
}
}
},
"sgxlkl_enclave_mount_config_t": {
"type": "object",
"description": "Disk configuration",
Expand Down Expand Up @@ -394,41 +382,6 @@
"default": 16000,
"overridable": "SGXLKL_ESLEEP"
},
"clock_res": {
"type": "array",
"description": "",
"minLength": 8,
"maxLength": 8,
"items": {
"$ref": "#/definitions/sgxlkl_clock_res_config_t"
},
"default": [
{
"resolution": "0000000000000001"
},
{
"resolution": "0000000000000001"
},
{
"resolution": "0000000000000000"
},
{
"resolution": "0000000000000000"
},
{
"resolution": "0000000000000001"
},
{
"resolution": "00000000003d0900"
},
{
"resolution": "00000000003d0900"
},
{
"resolution": "0000000000000001"
}
]
},
"stacksize": {
"$ref": "#/definitions/safe_size_t",
"description": "Stack size of in-enclave user-level threads.",
Expand Down

0 comments on commit 16f380d

Please sign in to comment.