diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2018-02-26 15:00:46 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2018-02-26 15:00:46 +0100 |
| commit | 14dae29c2abebd8886909c7a09c5795ffdd11515 (patch) | |
| tree | 50ed602aa0d992d51393bee841b2925a459ae0d4 /executor | |
| parent | 41f6f2579b51e89b33bff9f02830510d2b74d7c3 (diff) | |
executor: use proper default values for resources
We currently use -1 as default value for resources
when the actual value is not available.
-1 is good for fd's, but is not the right default
value for pointers/keys/etc.
Pass from prog and use in executor proper default
value for resources.
Diffstat (limited to 'executor')
| -rw-r--r-- | executor/executor.h | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/executor/executor.h b/executor/executor.h index 5f4db5115..ee48981a9 100644 --- a/executor/executor.h +++ b/executor/executor.h @@ -76,11 +76,6 @@ bool collide; ALIGNED(64 << 10) char input_data[kMaxInput]; -// We use the default value instead of results of failed syscalls. -// -1 is an invalid fd and an invalid address and deterministic, -// so good enough for our purposes. -const uint64 default_value = -1; - // Checksum kinds. const uint64 arg_csum_inet = 0; @@ -187,7 +182,7 @@ uint64 read_arg(uint64** input_posp); uint64 read_const_arg(uint64** input_posp, uint64* size_p, uint64* bf_off_p, uint64* bf_len_p); uint64 read_result(uint64** input_posp); void copyin(char* addr, uint64 val, uint64 size, uint64 bf_off, uint64 bf_len); -uint64 copyout(char* addr, uint64 size); +bool copyout(char* addr, uint64 size, uint64* res); void cover_open(); void cover_enable(thread_t* th); void cover_reset(thread_t* th); @@ -503,13 +498,15 @@ void handle_completion(thread_t* th) switch (instr) { case instr_copyout: { uint64 index = read_input(&th->copyout_pos); - char* addr = (char*)read_input(&th->copyout_pos); - uint64 size = read_input(&th->copyout_pos); - uint64 val = copyout(addr, size); if (index >= kMaxCommands) fail("result idx %lld overflows kMaxCommands", index); - results[index].executed = true; - results[index].val = val; + char* addr = (char*)read_input(&th->copyout_pos); + uint64 size = read_input(&th->copyout_pos); + uint64 val = 0; + if (copyout(addr, size, &val)) { + results[index].executed = true; + results[index].val = val; + } debug("copyout 0x%llx from %p\n", val, addr); break; } @@ -706,26 +703,29 @@ void copyin(char* addr, uint64 val, uint64 size, uint64 bf_off, uint64 bf_len) }); } -uint64 copyout(char* addr, uint64 size) +bool copyout(char* addr, uint64 size, uint64* res) { - uint64 res = default_value; - NONFAILING(switch (size) { + bool ok = false; + NONFAILING( + switch (size) { case 1: - res = *(uint8*)addr; + *res = *(uint8*)addr; break; case 2: - res = *(uint16*)addr; + *res = *(uint16*)addr; break; case 4: - res = *(uint32*)addr; + *res = *(uint32*)addr; break; case 8: - res = *(uint64*)addr; + *res = *(uint64*)addr; break; default: fail("copyout: bad argument size %llu", size); - }); - return res; + } + __atomic_store_n(&ok, true, __ATOMIC_RELEASE); + ); + return ok; } uint64 read_arg(uint64** input_posp) @@ -778,9 +778,9 @@ uint64 read_result(uint64** input_posp) uint64 idx = read_input(input_posp); uint64 op_div = read_input(input_posp); uint64 op_add = read_input(input_posp); + uint64 arg = read_input(input_posp); if (idx >= kMaxCommands) fail("command refers to bad result %lld", idx); - uint64 arg = default_value; if (results[idx].executed) { arg = results[idx].val; if (op_div != 0) |
