Skip to content

Commit c96fdb1

Browse files
authored
Merge branch 'master' into master
2 parents c008673 + 6a75b62 commit c96fdb1

File tree

5 files changed

+23
-0
lines changed

5 files changed

+23
-0
lines changed

BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ cc_library(
3333
copts = COPTS,
3434
deps = [
3535
":include",
36+
"@boringssl//:crypto",
3637
"@com_google_protobuf//:protobuf_lite",
3738
"@proxy_wasm_cpp_sdk//:api_lib",
3839
],

WORKSPACE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ git_repository(
3838
shallow_since = "1565024848 -0700",
3939
)
4040

41+
http_archive(
42+
name = "boringssl",
43+
sha256 = "bb55b0ed2f0cb548b5dce6a6b8307ce37f7f748eb9f1be6bfe2d266ff2b4d52b",
44+
strip_prefix = "boringssl-2192bbc878822cf6ab5977d4257a1339453d9d39",
45+
urls = ["https://github.com/google/boringssl/archive/2192bbc878822cf6ab5977d4257a1339453d9d39.tar.gz"],
46+
)
47+
4148
http_archive(
4249
name = "com_google_googletest",
4350
sha256 = "9dc9157a9a1551ec7a7e43daea9a694a0bb5fb8bec81235d8a1e6ef64c716dcb",

include/proxy-wasm/exports.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ Word wasi_unstable_args_get(void *raw_context, Word argc_ptr, Word argv_buf_size
145145
Word wasi_unstable_args_sizes_get(void *raw_context, Word argc_ptr, Word argv_buf_size_ptr);
146146
void wasi_unstable_proc_exit(void *, Word);
147147
Word wasi_unstable_clock_time_get(void *, Word, uint64_t, Word);
148+
Word wasi_unstable_random_get(void *, Word, Word);
148149
Word pthread_equal(void *, Word left, Word right);
149150

150151
// Support for embedders, not exported to Wasm.

src/exports.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
//
1616
#include "include/proxy-wasm/wasm.h"
1717

18+
#include <openssl/rand.h>
19+
1820
#define WASM_CONTEXT(_c) \
1921
(ContextOrEffectiveContext(static_cast<ContextBase *>((void)_c, current_context_)))
2022

@@ -814,6 +816,17 @@ Word wasi_unstable_clock_time_get(void *raw_context, Word clock_id, uint64_t pre
814816
return 0; // __WASI_ESUCCESS
815817
}
816818

819+
// __wasi_errno_t __wasi_random_get(uint8_t *buf, size_t buf_len);
820+
Word wasi_unstable_random_get(void *raw_context, Word result_buf_ptr, Word buf_len) {
821+
auto context = WASM_CONTEXT(raw_context);
822+
std::vector<uint8_t> random(buf_len);
823+
RAND_bytes(random.data(), random.size());
824+
if (!context->wasmVm()->setMemory(result_buf_ptr, random.size(), random.data())) {
825+
return 21; // __WASI_EFAULT
826+
}
827+
return 0; // __WASI_ESUCCESS
828+
}
829+
817830
// void __wasi_proc_exit(__wasi_exitcode_t rval);
818831
void wasi_unstable_proc_exit(void *raw_context, Word) {
819832
auto context = WASM_CONTEXT(raw_context);

src/wasm.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ void WasmBase::registerCallbacks() {
132132
_REGISTER_WASI(args_get);
133133
_REGISTER_WASI(args_sizes_get);
134134
_REGISTER_WASI(clock_time_get);
135+
_REGISTER_WASI(random_get);
135136
_REGISTER_WASI(proc_exit);
136137
#undef _REGISTER_WASI
137138

0 commit comments

Comments
 (0)