Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into bats_test
Browse files Browse the repository at this point in the history
  • Loading branch information
baluchicken committed May 9, 2024
2 parents 3ec559c + 90d7b5b commit 6282288
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 6 deletions.
4 changes: 2 additions & 2 deletions include/proxywasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ proxywasm *proxywasm_for_vm(wasm_vm *vm);
proxywasm *this_cpu_proxywasm(void);
void proxywasm_lock(proxywasm *p, proxywasm_context *c);
void proxywasm_unlock(proxywasm *p);
proxywasm_context *proxywasm_get_context(proxywasm *p);
void proxywasm_set_context(proxywasm *p, proxywasm_context *context);
void free_proxywasms(void);

wasm_vm_result init_proxywasm_for(wasm_vm *vm, wasm_vm_module *module);

Expand All @@ -100,8 +102,6 @@ wasm_vm_result proxy_on_upstream_connection_close(proxywasm *p, PeerType peer_ty
wasm_vm_result proxywasm_create_context(proxywasm *p, buffer_t *upstream_buffer, buffer_t *downstream_buffer);
wasm_vm_result proxywasm_destroy_context(proxywasm *p);

proxywasm_context *proxywasm_get_context(proxywasm *p);

// set_property_v is convenience funtion for setting a property on a context, with simple C string paths,
// use the '.' as delimiter, those will be replaced to a '0' delimiter
void set_property_v(proxywasm_context *p, const char *key, const void *value, const int value_len);
Expand Down
4 changes: 3 additions & 1 deletion src/device_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ wasm_vm_result load_module(const char *name, const char *code, unsigned length,
}
}

result = wasm_vm_compile_module(module);
// since for proxywasm we don't expose a lot of host functions required for compilation
if (strstr(name, PROXY_WASM) == NULL)
result = wasm_vm_compile_module(module);

wasm_vm_unlock(vm);
wasm_vm_dump_symbols(vm);
Expand Down
6 changes: 3 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ MODULE_PARM_DESC(ktls_available, "Marks if kTLS is available on the system");
typedef struct camblet_init_status
{
bool wasm;
bool wasm_opa;
bool wasm_csr;
bool wasm_opa;
bool wasm_proxywasm;
bool chardev;
bool socket;
bool sd_table;
Expand Down Expand Up @@ -136,6 +137,7 @@ static int __init camblet_init(void)
goto out;
}
}
__camblet_init_status.wasm_proxywasm = true;

result = load_module("csr_module", csr_wasm, csr_wasm_len, NULL);
if (result.err)
Expand All @@ -144,7 +146,6 @@ static int __init camblet_init(void)
ret = -1;
goto out;
}

__camblet_init_status.wasm_csr = true;

result = load_module("socket_opa", socket_wasm, socket_wasm_len, NULL);
Expand All @@ -154,7 +155,6 @@ static int __init camblet_init(void)
ret = -1;
goto out;
}

__camblet_init_status.wasm_opa = true;

out:
Expand Down
42 changes: 42 additions & 0 deletions src/proxywasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,33 @@ proxywasm_context *proxywasm_get_context(proxywasm *p)
return p->current_context;
}

void free_proxywasm(proxywasm *p)
{
if (p != NULL)
{
proxywasm_filter *f;
for (f = p->filters; f != NULL; f = f->next)
{
kfree(f);
}
free_proxywasm_context(p->root_context);
kfree(p);
}
}

void free_proxywasms(void)
{
int i;
for (i = 0; i < NR_CPUS; i++)
{
if (proxywasms[i] != NULL)
{
free_proxywasm(proxywasms[i]);
proxywasms[i] = NULL;
}
}
}

m3ApiRawFunction(proxy_log)
{
m3ApiReturnType(i32);
Expand Down Expand Up @@ -345,6 +372,20 @@ m3ApiRawFunction(proxy_set_buffer_bytes)
m3ApiReturn(set_buffer_bytes(filter->proxywasm->current_context, buffer_type, start, size, buffer_data, buffer_size));
}

m3ApiRawFunction(proxy_get_current_time_nanoseconds)
{
m3ApiReturnType(i32);
m3ApiGetArgMem(i64 *, result);

struct timespec64 ts;
ktime_get_real_ts64(&ts);

i64 current_time = ts.tv_sec * 1000000000 + ts.tv_nsec;
memcpy(result, &current_time, sizeof(i64));

m3ApiReturn(WasmResult_Ok);
}

static wasm_vm_result link_proxywasm_hostfunctions(proxywasm_filter *filter, wasm_vm_module *module)
{
M3Result result = m3Err_none;
Expand All @@ -357,6 +398,7 @@ static wasm_vm_result link_proxywasm_hostfunctions(proxywasm_filter *filter, was
_(SuppressLookupFailure(m3_LinkRawFunctionEx(module, env, "proxy_set_property", "i(*i*i)", proxy_set_property, filter)));
_(SuppressLookupFailure(m3_LinkRawFunctionEx(module, env, "proxy_get_buffer_bytes", "i(iii**)", proxy_get_buffer_bytes, filter)));
_(SuppressLookupFailure(m3_LinkRawFunctionEx(module, env, "proxy_set_buffer_bytes", "i(iii**)", proxy_set_buffer_bytes, filter)));
_(SuppressLookupFailure(m3_LinkRawFunctionEx(module, env, "proxy_get_current_time_nanoseconds", "i(i)", proxy_get_current_time_nanoseconds, filter)));

_catch:
return (wasm_vm_result){.err = result};
Expand Down
1 change: 1 addition & 0 deletions src/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -2325,6 +2325,7 @@ void socket_exit(void)

free_augmentation_cache();
free_cert_cache();
free_proxywasms();

pr_info("socket support unloaded");
}
1 change: 1 addition & 0 deletions src/wasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ wasm_vm_result wasm_vm_compile_module(wasm_vm_module *module)
M3Result result = m3_CompileModule(module);
if (result)
{
pr_err("wasm_vm_compile_module: %s", wasm_vm_last_error(module));
return (wasm_vm_result){.err = result};
}
return wasm_vm_ok;
Expand Down

0 comments on commit 6282288

Please sign in to comment.