feat: extend wasm backend entrypoints
This commit is contained in:
+39
-12
@@ -1,5 +1,8 @@
|
||||
#include "lib/uce_lib.cpp"
|
||||
#include "wasm/backend.cpp"
|
||||
// The wasm backend is its own object (src/wasm/wasm_module.cpp → wasm.o); the
|
||||
// main object only needs its declarations, so editing the wasm runtime no
|
||||
// longer recompiles the whole native TU.
|
||||
#include "wasm/backend.h"
|
||||
#include <csetjmp>
|
||||
#include <deque>
|
||||
#include <errno.h>
|
||||
@@ -853,7 +856,13 @@ int handle_cli_complete(FastCGIRequest& request)
|
||||
request.params["SCRIPT_FILENAME"] = script_filename;
|
||||
prepare_request_body_maps(request);
|
||||
request.props = DValue();
|
||||
compiler_invoke_cli(&request, script_filename);
|
||||
// The CLI socket path installs no native fault handler, so the
|
||||
// wasm worker (whose traps are signal-based) can run directly.
|
||||
String cli_unit = compiler_normalize_unit_path(&request, script_filename);
|
||||
if(wasm_backend_should_handle(request, cli_unit))
|
||||
wasm_backend_serve(request, cli_unit, wasm_kind::CLI);
|
||||
else
|
||||
compiler_invoke_cli(&request, script_filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -937,18 +946,15 @@ int handle_complete(FastCGIRequest& request) {
|
||||
{
|
||||
prepare_request_body_maps(request);
|
||||
request.props = DValue();
|
||||
if(request.resources.is_cli)
|
||||
compiler_invoke_cli(&request, request.params["SCRIPT_FILENAME"]);
|
||||
else if(request.params["UCE_SERVE_HTTP"] == "1")
|
||||
compiler_invoke_serve_http(&request, request.params["SCRIPT_FILENAME"], request.params["UCE_SERVE_HTTP_FUNCTION"]);
|
||||
else if(wasm_backend_should_handle(request, compiler_normalize_unit_path(&request, request.params["SCRIPT_FILENAME"])))
|
||||
{
|
||||
// W4/W5: Wasmtime uses host signals internally to implement guest
|
||||
// traps. The native SIGSEGV/SIGILL request recovery handler must not
|
||||
// intercept those, or clean guest traps become native fatal signals.
|
||||
|
||||
// Suspend the native SIGSEGV/SIGILL request recovery handler around a
|
||||
// wasm invocation: Wasmtime uses host signals internally to implement
|
||||
// guest traps, and the native handler would otherwise turn a clean
|
||||
// guest trap into a native fatal signal. Sets failure_* on error.
|
||||
auto serve_via_wasm = [&](const String& entry_unit, int32_t kind, const String& handler_name = "") {
|
||||
request_fault_active = 0;
|
||||
restore_request_fault_handlers();
|
||||
String wasm_error = wasm_backend_serve(request, compiler_normalize_unit_path(&request, request.params["SCRIPT_FILENAME"]));
|
||||
String wasm_error = wasm_backend_serve(request, entry_unit, kind, handler_name);
|
||||
install_request_fault_handlers();
|
||||
request_fault_active = 1;
|
||||
if(wasm_error != "")
|
||||
@@ -957,7 +963,25 @@ int handle_complete(FastCGIRequest& request) {
|
||||
failure_details = "";
|
||||
failure_trace = wasm_error;
|
||||
}
|
||||
};
|
||||
|
||||
String entry_unit = compiler_normalize_unit_path(&request, request.params["SCRIPT_FILENAME"]);
|
||||
if(request.resources.is_cli)
|
||||
{
|
||||
if(wasm_backend_should_handle(request, entry_unit))
|
||||
serve_via_wasm(entry_unit, wasm_kind::CLI);
|
||||
else
|
||||
compiler_invoke_cli(&request, request.params["SCRIPT_FILENAME"]);
|
||||
}
|
||||
else if(request.params["UCE_SERVE_HTTP"] == "1")
|
||||
// W7c pending: the custom-server dispatcher is forked from a worker
|
||||
// that already holds a live Wasmtime engine, so re-creating an engine
|
||||
// in that child is unsafe (engine must not cross fork). The fix is to
|
||||
// have the broker forward to the worker pool rather than render in the
|
||||
// fork; until then serve_http renders natively.
|
||||
compiler_invoke_serve_http(&request, request.params["SCRIPT_FILENAME"], request.params["UCE_SERVE_HTTP_FUNCTION"]);
|
||||
else if(wasm_backend_should_handle(request, entry_unit))
|
||||
serve_via_wasm(entry_unit, wasm_kind::RENDER);
|
||||
else
|
||||
compiler_invoke(&request, request.params["SCRIPT_FILENAME"]);
|
||||
}
|
||||
@@ -1220,6 +1244,9 @@ void custom_server_http_dispatcher_loop(String key)
|
||||
custom_server_dispatcher_key = key;
|
||||
close_inherited_server_sockets();
|
||||
install_process_fault_handlers();
|
||||
// This broker is forked from a worker that may already hold a wasm engine;
|
||||
// drop the inherited (unusable post-fork) engine so it re-inits its own.
|
||||
wasm_backend_reset_after_fork();
|
||||
|
||||
StringMap cfg = custom_server_read_config(key);
|
||||
if(cfg["type"] != "http" || cfg["bind"] == "")
|
||||
|
||||
Reference in New Issue
Block a user