forked from roastedroot/proxy-wasm-java-host
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExports.java
More file actions
186 lines (146 loc) · 6.51 KB
/
Exports.java
File metadata and controls
186 lines (146 loc) · 6.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
package io.roastedroot.proxywasm.impl;
import com.dylibso.chicory.runtime.Instance;
import io.roastedroot.proxywasm.v1.WasmException;
import io.roastedroot.proxywasm.v1.WasmResult;
// @WasmModuleInterface("main.wasm")
public class Exports {
private final Instance.Exports exports;
public String getMallocFunctionName() {
return mallocFunctionName;
}
public void setMallocFunctionName(String mallocFunctionName) {
this.mallocFunctionName = mallocFunctionName;
}
String mallocFunctionName = "malloc";
public Exports(Instance.Exports exports) {
this.exports = exports;
}
int malloc(int size) throws WasmException {
// I've noticed guests fail on malloc(0) so lets avoid that
assert size > 0 : "malloc size must be greater than zero";
long ptr = exports.function(mallocFunctionName).apply(size)[0];
if (ptr == 0) {
throw new WasmException(WasmResult.INVALID_MEMORY_ACCESS);
}
return (int) ptr;
}
public boolean proxyOnVmStart(int arg0, int arg1) {
long result = exports.function("proxy_on_vm_start").apply(arg0, arg1)[0];
return result != 0;
}
public int proxyValidateConfiguration(int arg0, int arg1) {
long result = exports.function("proxy_validate_configuration").apply(arg0, arg1)[0];
return (int) result;
}
public boolean proxyOnConfigure(int arg0, int arg1) {
long result = exports.function("proxy_on_configure").apply(arg0, arg1)[0];
return result != 0;
}
public void proxyOnTick(int arg0) {
exports.function("proxy_on_tick").apply(arg0);
}
public void proxyOnContextCreate(int contextID, int parentContextID) {
exports.function("proxy_on_context_create").apply(contextID, parentContextID);
}
// This can be used to change active context, e.g. during proxy_on_http_call_response,
// proxy_on_grpc_receive and/or proxy_on_queue_ready callbacks.
public void proxySetEffectiveContext(int contextID) throws WasmException {
long result = exports.function("proxy_set_effective_context").apply(contextID)[0];
WasmResult.fromInt((int) result).expect(WasmResult.OK);
}
public int proxyOnNewConnection(int arg0) {
long result = exports.function("proxy_on_new_connection").apply(arg0)[0];
return (int) result;
}
public int proxyOnDownstreamData(int contextId, int dataSize, int endOfStream) {
long result =
exports.function("proxy_on_downstream_data")
.apply(contextId, dataSize, endOfStream)[0];
return (int) result;
}
public int proxyOnUpstreamData(int arg0, int arg1, int arg2) {
long result = exports.function("proxy_on_upstream_data").apply(arg0, arg1, arg2)[0];
return (int) result;
}
public void proxyOnDownstreamConnectionClose(int arg0, int arg1) {
exports.function("proxy_on_downstream_connection_close").apply(arg0, arg1);
}
public void proxyOnUpstreamConnectionClose(int arg0, int arg1) {
exports.function("proxy_on_upstream_connection_close").apply(arg0, arg1);
}
public int proxyOnRequestHeaders(int contextID, int headers, int endOfStream) {
long result =
exports.function("proxy_on_request_headers")
.apply(contextID, headers, endOfStream)[0];
return (int) result;
}
public int proxyOnRequestMetadata(int arg0, int arg1) {
long result = exports.function("proxy_on_request_metadata").apply(arg0, arg1)[0];
return (int) result;
}
public int proxyOnRequestBody(int contextId, int bodySize, int arg2) {
long result = exports.function("proxy_on_request_body").apply(contextId, bodySize, arg2)[0];
return (int) result;
}
public int proxyOnRequestTrailers(int arg0, int arg1) {
long result = exports.function("proxy_on_request_trailers").apply(arg0, arg1)[0];
return (int) result;
}
public int proxyOnResponseHeaders(int arg0, int arg1, int arg2) {
long result = exports.function("proxy_on_response_headers").apply(arg0, arg1, arg2)[0];
return (int) result;
}
public int proxyOnResponseMetadata(int arg0, int arg1) {
long result = exports.function("proxy_on_response_metadata").apply(arg0, arg1)[0];
return (int) result;
}
public int proxyOnResponseBody(int arg0, int arg1, int arg2) {
long result = exports.function("proxy_on_response_body").apply(arg0, arg1, arg2)[0];
return (int) result;
}
public int proxyOnResponseTrailers(int arg0, int arg1) {
long result = exports.function("proxy_on_response_trailers").apply(arg0, arg1)[0];
return (int) result;
}
public void proxyOnLog(int context_id) {
exports.function("proxy_on_log").apply(context_id);
}
public boolean proxyOnDone(int context_id) {
long result = exports.function("proxy_on_done").apply(context_id)[0];
return result != 0;
}
public void proxyOnDelete(int context_id) {
exports.function("proxy_on_delete").apply(context_id);
}
public void proxyOnHttpCallResponse(int arg0, int arg1, int arg2, int arg3, int arg4) {
exports.function("proxy_on_http_call_response").apply(arg0, arg1, arg2, arg3, arg4);
}
public void proxyOnGrpcReceiveInitialMetadata(int arg0, int arg1, int arg2) {
exports.function("proxy_on_grpc_receive_initial_metadata").apply(arg0, arg1, arg2);
}
public void proxyOnGrpcReceiveTrailingMetadata(int arg0, int arg1, int arg2) {
exports.function("proxy_on_grpc_receive_trailing_metadata").apply(arg0, arg1, arg2);
}
public void proxyOnGrpcReceive(int arg0, int arg1, int arg2) {
exports.function("proxy_on_grpc_receive").apply(arg0, arg1, arg2);
}
public void proxyOnGrpcClose(int arg0, int arg1, int arg2) {
exports.function("proxy_on_grpc_close").apply(arg0, arg1, arg2);
}
public void proxyOnQueueReady(int arg0, int arg1) {
exports.function("proxy_on_queue_ready").apply(arg0, arg1);
}
public void proxyOnForeignFunction(int arg0, int arg1, int arg2) {
exports.function("proxy_on_foreign_function").apply(arg0, arg1, arg2);
}
public void initialize() {
exports.function("_initialize").apply();
}
public int main(int arg0, int arg1) {
long result = exports.function("main").apply(arg0, arg1)[0];
return (int) result;
}
public void start() {
exports.function("_start").apply();
}
}