smolstuf
This commit is contained in:
+44
-24
@@ -225,8 +225,12 @@ static bool wasm_read_file(const String& path, std::vector<u8>& out)
|
||||
return(false);
|
||||
in.seekg(0, std::ios::end);
|
||||
std::streamoff n = in.tellg();
|
||||
if(n < 0)
|
||||
return(false);
|
||||
in.seekg(0, std::ios::beg);
|
||||
out.resize((size_t)n);
|
||||
if(n == 0)
|
||||
return(true);
|
||||
in.read((char*)out.data(), n);
|
||||
return((bool)in);
|
||||
}
|
||||
@@ -473,6 +477,8 @@ public:
|
||||
if(!staged_hostcall_input.empty() && input == staged_hostcall_input)
|
||||
{
|
||||
out = staged_hostcall_result;
|
||||
staged_hostcall_input = "";
|
||||
staged_hostcall_result = "";
|
||||
return(true);
|
||||
}
|
||||
return(false);
|
||||
@@ -1322,14 +1328,16 @@ private:
|
||||
return(add([self](Caller caller, Span<const Val> args, Span<Val> results) -> Result<std::monostate, Trap> {
|
||||
String cmd;
|
||||
self->hostcall_read(args[0].i32(), args[1].i32(), cmd);
|
||||
String out;
|
||||
if(!self->hostcall_staged("shell:" + cmd, out))
|
||||
{
|
||||
out = ::shell_exec(cmd);
|
||||
self->hostcall_stage("shell:" + cmd, out);
|
||||
}
|
||||
u32 cap = (u32)args[3].i32();
|
||||
int32_t buf = args[2].i32();
|
||||
String out;
|
||||
String stage_key = "shell:" + cmd;
|
||||
if(!self->hostcall_staged(stage_key, out))
|
||||
{
|
||||
out = ::shell_exec(cmd);
|
||||
if(buf == 0)
|
||||
self->hostcall_stage(stage_key, out);
|
||||
}
|
||||
if(buf != 0 && cap >= out.size())
|
||||
self->hostcall_write(buf, out);
|
||||
caller.context().set_epoch_deadline(self->worker.cfg.epoch_deadline_ticks);
|
||||
@@ -1427,10 +1435,14 @@ private:
|
||||
}));
|
||||
if(mod == "env" && name == "uce_host_file_open_locked")
|
||||
return(add([self](Caller, Span<const Val> args, Span<Val> results) -> Result<std::monostate, Trap> {
|
||||
String path, purpose;
|
||||
String path, purpose, current;
|
||||
self->hostcall_read(args[0].i32(), args[1].i32(), path);
|
||||
self->hostcall_read(args[6].i32(), args[7].i32(), purpose);
|
||||
int fd = ::file_open_locked(path, args[2].i32(), args[3].i32(), args[4].i32(), args[5].f64(), purpose);
|
||||
self->hostcall_read(args[8].i32(), args[9].i32(), current);
|
||||
int open_flags = args[2].i32();
|
||||
bool may_write = (open_flags & (O_WRONLY | O_RDWR | O_CREAT | O_TRUNC | O_APPEND)) != 0;
|
||||
String resolved = may_write ? self->resolve_guest_write(path, current) : self->resolve_guest_file(path, current);
|
||||
int fd = resolved != "" ? ::file_open_locked(resolved, open_flags, args[3].i32(), args[4].i32(), args[5].f64(), purpose) : -1;
|
||||
int handle = -1;
|
||||
if(fd >= 0)
|
||||
{
|
||||
@@ -1578,8 +1590,11 @@ private:
|
||||
return(add([self](Caller, Span<const Val> args, Span<Val> results) -> Result<std::monostate, Trap> {
|
||||
String encoded;
|
||||
self->hostcall_read(args[0].i32(), args[1].i32(), encoded);
|
||||
u32 cap = (u32)args[3].i32();
|
||||
int32_t buf = args[2].i32();
|
||||
String out;
|
||||
if(!self->hostcall_staged(encoded, out))
|
||||
String stage_key = "zip:" + encoded;
|
||||
if(!self->hostcall_staged(stage_key, out))
|
||||
{
|
||||
DValue request, response;
|
||||
String decode_error;
|
||||
@@ -1625,10 +1640,9 @@ private:
|
||||
response["error"] = e.what();
|
||||
}
|
||||
out = ucb_encode(response);
|
||||
self->hostcall_stage(encoded, out);
|
||||
if(buf == 0)
|
||||
self->hostcall_stage(stage_key, out);
|
||||
}
|
||||
u32 cap = (u32)args[3].i32();
|
||||
int32_t buf = args[2].i32();
|
||||
if(buf != 0 && cap >= out.size())
|
||||
self->hostcall_write(buf, out);
|
||||
results[0] = Val((int32_t)out.size());
|
||||
@@ -1638,8 +1652,11 @@ private:
|
||||
return(add([self](Caller caller, Span<const Val> args, Span<Val> results) -> Result<std::monostate, Trap> {
|
||||
String encoded;
|
||||
self->hostcall_read(args[0].i32(), args[1].i32(), encoded);
|
||||
u32 cap = (u32)args[3].i32();
|
||||
int32_t buf = args[2].i32();
|
||||
String out;
|
||||
if(!self->hostcall_staged(encoded, out))
|
||||
String stage_key = "units:" + encoded;
|
||||
if(!self->hostcall_staged(stage_key, out))
|
||||
{
|
||||
DValue request, response;
|
||||
String decode_error;
|
||||
@@ -1678,10 +1695,9 @@ private:
|
||||
response["error"] = e.what();
|
||||
}
|
||||
out = ucb_encode(response);
|
||||
self->hostcall_stage(encoded, out);
|
||||
if(buf == 0)
|
||||
self->hostcall_stage(stage_key, out);
|
||||
}
|
||||
u32 cap = (u32)args[3].i32();
|
||||
int32_t buf = args[2].i32();
|
||||
if(buf != 0 && cap >= out.size())
|
||||
self->hostcall_write(buf, out);
|
||||
caller.context().set_epoch_deadline(self->worker.cfg.epoch_deadline_ticks);
|
||||
@@ -1696,9 +1712,12 @@ private:
|
||||
// handle table (handle = 1-based index).
|
||||
String encoded;
|
||||
self->hostcall_read(args[0].i32(), args[1].i32(), encoded);
|
||||
u32 cap = (u32)args[3].i32();
|
||||
int32_t buf = args[2].i32();
|
||||
String out;
|
||||
String stage_key = "sqlite:" + encoded;
|
||||
// run the op once across the length-query + fetch pair
|
||||
if(!self->hostcall_staged(encoded, out))
|
||||
if(!self->hostcall_staged(stage_key, out))
|
||||
{
|
||||
DValue request, response;
|
||||
String decode_error;
|
||||
@@ -1746,10 +1765,9 @@ private:
|
||||
}
|
||||
}
|
||||
out = ucb_encode(response);
|
||||
self->hostcall_stage(encoded, out);
|
||||
if(buf == 0)
|
||||
self->hostcall_stage(stage_key, out);
|
||||
}
|
||||
u32 cap = (u32)args[3].i32();
|
||||
int32_t buf = args[2].i32();
|
||||
if(buf != 0 && cap >= out.size())
|
||||
self->hostcall_write(buf, out);
|
||||
results[0] = Val((int32_t)out.size());
|
||||
@@ -1789,8 +1807,11 @@ private:
|
||||
return(add([self](Caller, Span<const Val> args, Span<Val> results) -> Result<std::monostate, Trap> {
|
||||
String encoded;
|
||||
self->hostcall_read(args[0].i32(), args[1].i32(), encoded);
|
||||
u32 cap = (u32)args[3].i32();
|
||||
int32_t buf = args[2].i32();
|
||||
String out;
|
||||
if(!self->hostcall_staged(encoded, out))
|
||||
String stage_key = "mysql:" + encoded;
|
||||
if(!self->hostcall_staged(stage_key, out))
|
||||
{
|
||||
DValue request, response;
|
||||
String decode_error;
|
||||
@@ -1839,10 +1860,9 @@ private:
|
||||
}
|
||||
}
|
||||
out = ucb_encode(response);
|
||||
self->hostcall_stage(encoded, out);
|
||||
if(buf == 0)
|
||||
self->hostcall_stage(stage_key, out);
|
||||
}
|
||||
u32 cap = (u32)args[3].i32();
|
||||
int32_t buf = args[2].i32();
|
||||
if(buf != 0 && cap >= out.size())
|
||||
self->hostcall_write(buf, out);
|
||||
results[0] = Val((int32_t)out.size());
|
||||
|
||||
Reference in New Issue
Block a user