feat: extend wasm backend entrypoints

This commit is contained in:
root
2026-06-13 21:50:19 +00:00
parent fe83c52411
commit d6421cb8f3
14 changed files with 315 additions and 83 deletions
+2 -2
View File
@@ -30,7 +30,7 @@ String join(StringList l, String delim = "\n");
String nibble(String& haystack, String delim);
void json_consume_space(String s, u32& i);
String to_string(StringList l) {
inline String to_string(StringList l) {
String result;
u32 i = 0;
for(auto& s : l)
@@ -43,7 +43,7 @@ String to_string(StringList l) {
return(result);
}
String to_string(SharedUnit* u) {
inline String to_string(SharedUnit* u) {
String result;
result += String("SharedUnit( \n")+
+6 -6
View File
@@ -39,7 +39,7 @@ struct MySQL {
};
MySQL* mysql_connect(String host = "localhost", String username = "root", String password = "")
inline MySQL* mysql_connect(String host = "localhost", String username = "root", String password = "")
{
MySQL* m = new MySQL();
m->request_cleanup_delete = true;
@@ -47,7 +47,7 @@ MySQL* mysql_connect(String host = "localhost", String username = "root", String
return(m);
}
void mysql_disconnect(MySQL* m)
inline void mysql_disconnect(MySQL* m)
{
if(!m)
return;
@@ -55,24 +55,24 @@ void mysql_disconnect(MySQL* m)
delete m;
}
String mysql_error(MySQL* m)
inline String mysql_error(MySQL* m)
{
return(m->error());
}
String mysql_escape(String raw, char quote_char);
DValue mysql_query(MySQL* m, String q)
inline DValue mysql_query(MySQL* m, String q)
{
return(m->query(q));
}
DValue mysql_query(MySQL* m, String q, StringMap params)
inline DValue mysql_query(MySQL* m, String q, StringMap params)
{
return(m->query(q, params));
}
u64 mysql_insert_id(MySQL* m)
inline u64 mysql_insert_id(MySQL* m)
{
return(m->insert_id);
}
+4
View File
@@ -318,6 +318,10 @@ StringMap default_config()
#include "sys.h"
#include "hash.h"
// Single definitions for the native split build (declared extern in sys.h).
pid_t parent_pid = 0;
pid_t my_pid = 0;
namespace {
constexpr f64 FILE_LOCK_WAIT_TIMEOUT_SECONDS = 3.0;
+7
View File
@@ -100,8 +100,15 @@ bool memcache_delete(u64 connection, String key);
String memcache_get(u64 connection, String key, String default_value = "");
StringMap memcache_get_multiple(u64 connection, StringList keys);
// Defined once in sys.cpp for the native split build (core/wasm/main); the wasm
// core/unit builds keep the in-place definition (single TU / loader-resolved).
#if defined(__UCE_WASM_CORE__) || defined(__UCE_WASM_UNIT__)
pid_t parent_pid = 0;
pid_t my_pid = 0;
#else
extern pid_t parent_pid;
extern pid_t my_pid;
#endif
void on_segfault(int sig);
int task_kill(pid_t pid, int sig = 0);
+26
View File
@@ -16,6 +16,32 @@
#include "types.h"
// Single definition of context for the native split build (the wasm core/unit
// builds keep the in-place definition from types.h — see the guard there).
#if !defined(__UCE_WASM_CORE__) && !defined(__UCE_WASM_UNIT__)
Request* context = 0;
#endif
#ifndef __UCE_WASM_UNIT__
void * operator new(decltype(sizeof(0)) n) noexcept(false)
{
void* ptr = malloc(n);
if(context)
{
context->stats.mem_alloc += n;
if(context->stats.mem_alloc > context->stats.mem_high)
context->stats.mem_high = context->stats.mem_alloc;
}
return(ptr);
}
void operator delete(void * p) throw()
{
//TO DO: track deallocations
free(p);
}
#endif
namespace {
String http_status_reason(s32 code)
+20 -26
View File
@@ -22,27 +22,29 @@ typedef long long s64;
typedef std::string String;
String operator+(String lhs, u64 rhs) {
// inline: this header is included by every runtime object (core/wasm/main); a
// non-inline definition here would be a duplicate symbol across them.
inline String operator+(String lhs, u64 rhs) {
return(lhs + std::to_string(rhs));
}
String operator+(String lhs, u32 rhs) {
inline String operator+(String lhs, u32 rhs) {
return(lhs + std::to_string(rhs));
}
String operator+(String lhs, s64 rhs) {
inline String operator+(String lhs, s64 rhs) {
return(lhs + std::to_string(rhs));
}
String operator+(String lhs, s32 rhs) {
inline String operator+(String lhs, s32 rhs) {
return(lhs + std::to_string(rhs));
}
String operator+(String lhs, f64 rhs) {
inline String operator+(String lhs, f64 rhs) {
return(lhs + std::to_string(rhs));
}
String operator+(String lhs, f32 rhs) {
inline String operator+(String lhs, f32 rhs) {
return(lhs + std::to_string(rhs));
}
@@ -59,7 +61,7 @@ typedef void (*request_ref_handler)(Request& request);
typedef DValue* (*dv_call_handler)(DValue* call_param);
typedef void (*request_handler)(Request* request);
String to_string(s64 v) { return(std::to_string(v)); }
inline String to_string(s64 v) { return(std::to_string(v)); }
struct SharedUnit {
@@ -242,7 +244,15 @@ struct Request {
typedef Request FastCGIRequest;
// Native runtime is split across objects (core/wasm/main), so context is
// declared here and defined once in types.cpp. The wasm core is a single TU and
// wasm units resolve context through the loader's GOT, so both keep the
// in-place definition (unchanged ABI).
#if defined(__UCE_WASM_CORE__) || defined(__UCE_WASM_UNIT__)
Request* context;
#else
extern Request* context;
#endif
#include <iostream>
@@ -268,22 +278,6 @@ inline String concat(Ts... args)
return(out.str());
}
#ifndef __UCE_WASM_UNIT__
void * operator new(decltype(sizeof(0)) n) noexcept(false)
{
void* ptr = malloc(n);
if(context)
{
context->stats.mem_alloc += n;
if(context->stats.mem_alloc > context->stats.mem_high)
context->stats.mem_high = context->stats.mem_alloc;
}
return(ptr);
}
void operator delete(void * p) throw()
{
//TO DO: track deallocations
free(p);
}
#endif
// The global allocator override (request memory accounting) is defined once in
// types.cpp so it lives in a single runtime object; a header definition would
// duplicate it across core/wasm/main. Units (__UCE_WASM_UNIT__) import it.