Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WASM Null sandbox. #63

Merged
merged 31 commits into from
May 18, 2019
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b78a36c
WASM Null sandbox.
jplevyak May 7, 2019
c147b19
Merge branch 'wasm' into wasm-null-sandbox
jplevyak May 8, 2019
c19e6d5
Make test null plugin a dependency of test.
jplevyak May 14, 2019
eb83d19
Address comments.
jplevyak May 14, 2019
696dc21
Address comments.
jplevyak May 14, 2019
368ba75
Address comments.
jplevyak May 15, 2019
622dbb0
Merge remote-tracking branch 'upstream/wasm' into wasm-null-sandbox
jplevyak May 15, 2019
0f0d43f
Address comments.
jplevyak May 15, 2019
6f71c51
Merge remote-tracking branch 'upstream/wasm' into wasm-null-sandbox
jplevyak May 16, 2019
f7e216d
Working, now to cleanup.
jplevyak May 16, 2019
4d5d895
Address commments.
jplevyak May 16, 2019
99674fb
Address comments.
jplevyak May 16, 2019
e9f5345
Address comments.
jplevyak May 16, 2019
aa24aa5
Address comments.
jplevyak May 16, 2019
e8e943c
Add wrappers for uint32_t versions of intrinsic functions.
jplevyak May 17, 2019
d0b6bf9
Fixup string_view aliases..
jplevyak May 17, 2019
73a2d3c
Fix compilation on GCC.
jplevyak May 17, 2019
168c205
Address comments.
jplevyak May 17, 2019
4a97c51
Address comments.
jplevyak May 17, 2019
8bf84af
Address comments.
jplevyak May 17, 2019
8918cf9
Address comments.
jplevyak May 17, 2019
5761d06
Merge remote-tracking branch 'upstream/wasm' into wasm-null-sandbox
jplevyak May 17, 2019
3596b52
Fix gcc issue with string_view and teting::StrEq.
jplevyak May 18, 2019
4ca5174
Address comments.
jplevyak May 18, 2019
94a0d83
Run buldifier
jplevyak May 18, 2019
296ed88
Address comment.
jplevyak May 18, 2019
a16857a
Address comments.
jplevyak May 18, 2019
6d5f066
Address comments.
jplevyak May 18, 2019
75ba838
Fix asm bug.
jplevyak May 18, 2019
e89ed13
Address comments.
jplevyak May 18, 2019
d363e6d
Comments.
jplevyak May 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .bazelignore

This file was deleted.

20 changes: 20 additions & 0 deletions api/wasm/cpp/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
licenses(["notice"]) # Apache 2
jplevyak marked this conversation as resolved.
Show resolved Hide resolved

load(
"//bazel:envoy_build_system.bzl",
"envoy_cc_library",
"envoy_package",
)

envoy_package()


jplevyak marked this conversation as resolved.
Show resolved Hide resolved
envoy_cc_library(
name = "intrinsics_hdr",
hdrs = [
"proxy_wasm_intrinsics.h",
"proxy_wasm_enums.h",
"proxy_wasm_externs.h",
"proxy_wasm_impl.h",
],
)
60 changes: 60 additions & 0 deletions api/wasm/cpp/proxy_wasm_enums.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Intrinsic functions available to WASM modules.
jplevyak marked this conversation as resolved.
Show resolved Hide resolved
*/
// NOLINT(namespace-envoy)

#pragma once

enum class LogLevel : EnumType { trace, debug, info, warn, error, critical };
enum class FilterHeadersStatus : EnumType { Continue = 0, StopIteration = 1 };
enum class FilterMetadataStatus : EnumType { Continue = 0 };
enum class FilterTrailersStatus : EnumType { Continue = 0, StopIteration = 1 };
enum class FilterDataStatus : EnumType {
Continue = 0,
StopIterationAndBuffer = 1,
StopIterationAndWatermark = 2,
StopIterationNoBuffer = 3
};
enum class StreamType : EnumType { Request = 0, Response = 1 };
enum class MetadataType : EnumType {
Request = 0,
Response = 1,
RequestRoute = 2, // Immutable
ResponseRoute = 3, // Immutable
Log = 4, // Immutable
Node = 5 // Immutable
};
enum class HeaderMapType : EnumType {
RequestHeaders = 0, // During the onLog callback these are immutable
RequestTrailers = 1, // During the onLog callback these are immutable
ResponseHeaders = 2, // During the onLog callback these are immutable
ResponseTrailers = 3, // During the onLog callback these are immutable
GrpcCreateInitialMetadata = 4,
GrpcReceiveInitialMetadata = 5, // Immutable
GrpcReceiveTrailingMetadata = 6, // Immutable
};
enum GrpcStatus : EnumType {
OK = 0,
CANCELLED = 1,
UNKNOWN = 2,
INVALID_ARGUMENT = 3,
DEADLINE_EXCEEDED = 4,
NOT_FOUND = 5,
ALREADY_EXISTS = 6,
PERMISSION_DENIED = 7,
UNAUTHENTICATED = 16,
RESOURCE_EXHAUSTED = 8,
FAILED_PRECONDITION = 9,
ABORTED = 10,
OUT_OF_RANGE = 11,
UNIMPLEMENTED = 12,
INTERNAL = 13,
UNAVAILABLE = 14,
DATA_LOSS = 15,
DO_NOT_USE = 0xFFFFFFFF
};
enum class MetricType : EnumType {
Counter = 0,
Gauge = 1,
Histogram = 2,
};
120 changes: 120 additions & 0 deletions api/wasm/cpp/proxy_wasm_externs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
* Intrinsic functions available to WASM modules.
*/
// NOLINT(namespace-envoy)

#pragma once

#include "stddef.h"

// clang-format off
/*
API Calls into the VM.

extern "C" EMSCRIPTEN_KEEPALIVE void proxy_onConfigure(char* configuration, int size);
extern "C" EMSCRIPTEN_KEEPALIVE void proxy_onStart();
extern "C" EMSCRIPTEN_KEEPALIVE int main(); // only called if proxy_onStart() is not available.
extern "C" EMSCRIPTEN_KEEPALIVE void proxy_onTick();
extern "C" EMSCRIPTEN_KEEPALIVE void proxy_onCreate(uint32_t context_id);
extern "C" EMSCRIPTEN_KEEPALIVE void proxy_onRequestHeaders(uint32_t context_id);
extern "C" EMSCRIPTEN_KEEPALIVE void proxy_onRequestBody(uint32_t context_id, uint32_t body_buffer_length, uint32_t end_of_stream);
extern "C" EMSCRIPTEN_KEEPALIVE void proxy_onRequestTrailers(uint32_t context_id);
extern "C" EMSCRIPTEN_KEEPALIVE void proxy_onRequestMetadata(uint32_t context_id);
extern "C" EMSCRIPTEN_KEEPALIVE void proxy_onResponseHeaders(uint32_t context_id);
extern "C" EMSCRIPTEN_KEEPALIVE void proxy_onResponseBody(uint32_t context_id, uint32_t body_buffer_length, uint32_t end_of_stream);
extern "C" EMSCRIPTEN_KEEPALIVE void proxy_onResponseTrailers(uint32_t context_id);
extern "C" EMSCRIPTEN_KEEPALIVE void proxy_onResponseMetadata(uint32_t context_id);
extern "C" EMSCRIPTEN_KEEPALIVE void proxy_onHttpCallResponse(uint32_t context_id uint32_t token, uint32_t header_pairs_ptr,
uint32_t header_pairs_size, uint32_t body_ptr, uint32_t body_size, uint32_t trailer_pairs_ptr, uint32_t trailer_pairs_size):
// The stream has completed.
extern "C" EMSCRIPTEN_KEEPALIVE void proxy_onDone(uint32_t context_id);
// onLog occurs after onDone.
extern "C" EMSCRIPTEN_KEEPALIVE void proxy_onLog(uint32_t context_id);
// The Context in the proxy has been destroyed and no further calls will be coming.
extern "C" ENSCRIPTEN_KEEPALIVE void proxy_onDelete(uint32_t context_id);
extern "C" EMSCRIPTEN_KEEPALIVE proxy_onGrpcCreateInitialMetadata(uint32_t context_id, uint32_t token);
extern "C" EMSCRIPTEN_KEEPALIVE proxy_onGrpcReceiveInitialMetadata(uint32_t context_id, uint32_t token);
extern "C" EMSCRIPTEN_KEEPALIVE proxy_onGrpcTrailingMetadata(uint32_t context_id, uint32_t token);
extern "C" EMSCRIPTEN_KEEPALIVE proxy_onGrpcReceive(uint32_t context_id, uint32_t token,
uint32_t response_ptr, uint32_t response_size);
extern "C" EMSCRIPTEN_KEEPALIVE proxy_onGrpcClose(uint32_t context_id, uint32_t token,
uint32_t status_code, uint32_t status_message_ptr, uint32_t status_message_size);
*/
// clang-format on

//
// Low Level API.
//

// Logging
extern "C" void proxy_log(LogLevel level, const char* logMessage, size_t messageSize);

// Timer
extern "C" void proxy_setTickPeriodMilliseconds(uint32_t millisecond);
extern "C" uint64_t proxy_getCurrentTimeNanoseconds();

// Stream Info
extern "C" void proxy_getProtocol(StreamType type, const char** value_ptr, size_t* value_size);

// Metadata
extern "C" void proxy_getMetadata(MetadataType type, const char* key_ptr, size_t key_size,
const char** value_ptr_ptr, size_t* value_size_ptr);
extern "C" void proxy_setMetadata(MetadataType type, const char* key_ptr, size_t key_size,
const char* value_ptr, size_t value_size);
extern "C" void proxy_getMetadataPairs(MetadataType type, const char** value_ptr,
size_t* value_size);
extern "C" void proxy_getMetadataStruct(MetadataType type, const char* name_ptr, size_t name_size,
const char** value_ptr_ptr, size_t* value_size_ptr);
extern "C" void proxy_setMetadataStruct(MetadataType type, const char* name_ptr, size_t name_size,
const char* value_ptr, size_t value_size);

// Continue
extern "C" void proxy_continueRequest();
extern "C" void proxy_continueResponse();

// SharedData
extern "C" void proxy_getSharedData(const char* key_ptr, size_t key_size, const char** value_ptr,
size_t* value_size, uint32_t* cas);
// If cas != 0 and cas != the current cas for 'key' return false, otherwise set the value and
// return true.
extern "C" bool proxy_setSharedData(const char* key_ptr, size_t key_size, const char* value_ptr,
size_t value_size, uint32_t cas);

// Headers/Trailers/Metadata Maps
extern "C" void proxy_addHeaderMapValue(HeaderMapType type, const char* key_ptr, size_t key_size, const char* value_ptr, size_t value_size);
extern "C" void proxy_getHeaderMapValue(HeaderMapType type, const char* key_ptr, size_t key_size, const char** value_ptr, size_t* value_size);
extern "C" void proxy_getHeaderMapPairs(HeaderMapType type, const char** ptr, size_t* size);
extern "C" void proxy_setHeaderMapPairs(HeaderMapType type, const char* ptr, size_t size);
extern "C" void proxy_replaceHeaderMapValue(HeaderMapType type, const char* key_ptr, size_t key_size, const char* value_ptr, size_t value_size);
extern "C" void proxy_removeHeaderMapValue(HeaderMapType type, const char* key_ptr, size_t key_size);

// Body
extern "C" void proxy_getRequestBodyBufferBytes(uint32_t start, uint32_t length, const char** ptr,
size_t* size);
extern "C" void proxy_getResponseBodyBufferBytes(uint32_t start, uint32_t length, const char** ptr,
size_t* size);

// HTTP
// Returns token, used in callback onHttpCallResponse
extern "C" uint32_t proxy_httpCall(const char* uri_ptr, size_t uri_size, void* header_pairs_ptr,
size_t header_pairs_size, const char* body_ptr, size_t body_size,
void* trailer_pairs_ptr, size_t trailer_pairs_size,
uint32_t timeout_milliseconds);
// gRPC
// Returns token, used in gRPC callbacks (onGrpc...)
extern "C" uint32_t proxy_grpcCall(const char* service_ptr, size_t service_size, const char* service_name_ptr,
size_t service_name_size, const char* method_name_ptr, size_t method_name_size,
const char* request_ptr, size_t request_size, uint32_t timeout_milliseconds);
extern "C" uint32_t proxy_grpcStream(const char* service_ptr, size_t service_size, const char* service_name_ptr,
size_t service_name_size, const char* method_name_ptr, size_t method_name_size);
extern "C" void proxy_grpcCancel(uint32_t token);
extern "C" void proxy_grpcClose(uint32_t token);
extern "C" void proxy_grpcSend(uint32_t token, const char* message_ptr, size_t message_size, uint32_t end_stream);

// Metrics
// Returns a metric_id which can be used to report a metric. On error returns 0.
extern "C" uint32_t proxy_defineMetric(MetricType type, const char* name_ptr, size_t name_size);
extern "C" void proxy_incrementMetric(uint32_t metric_id, int64_t offset);
extern "C" void proxy_recordMetric(uint32_t metric_id, uint64_t value);
extern "C" uint64_t proxy_getMetric(uint32_t metric_id);

Loading