2023-08-19 12:49:23 +00:00
|
|
|
/************************************************************/ /**
|
2023-05-09 16:44:23 +00:00
|
|
|
*
|
2023-08-09 11:06:32 +00:00
|
|
|
* @file: runtime_io.c
|
2023-05-09 16:44:23 +00:00
|
|
|
* @author: Martin Fouilleul
|
|
|
|
* @date: 09/05/2023
|
|
|
|
*
|
|
|
|
*****************************************************************/
|
2023-08-19 12:49:23 +00:00
|
|
|
#include "platform/platform_io_internal.h"
|
|
|
|
#include "runtime.h"
|
2023-05-09 16:44:23 +00:00
|
|
|
|
2023-08-14 08:26:11 +00:00
|
|
|
oc_io_cmp oc_runtime_io_wait_single_req(oc_io_req* wasmReq)
|
2023-05-11 16:09:26 +00:00
|
|
|
{
|
2023-08-19 12:49:23 +00:00
|
|
|
oc_runtime* orca = oc_runtime_get();
|
|
|
|
oc_arena* scratch = oc_scratch();
|
2023-05-11 16:09:26 +00:00
|
|
|
|
2023-08-19 12:49:23 +00:00
|
|
|
oc_io_cmp cmp = { 0 };
|
|
|
|
oc_io_req req = *wasmReq;
|
|
|
|
//NOTE: convert the req->buffer wasm pointer to a native pointer
|
|
|
|
// for some reason, wasm3 memory doesn't start at the beginning of the block we give it.
|
|
|
|
u64 bufferIndex = (u64)req.buffer & 0xffffffff;
|
|
|
|
u32 memSize = 0;
|
|
|
|
char* memory = (char*)m3_GetMemory(orca->runtime.m3Runtime, &memSize, 0);
|
2023-05-09 16:44:23 +00:00
|
|
|
|
2023-08-19 12:49:23 +00:00
|
|
|
if(bufferIndex + req.size > memSize)
|
|
|
|
{
|
|
|
|
cmp.error = OC_IO_ERR_ARG;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
req.buffer = memory + bufferIndex;
|
2023-05-09 16:44:23 +00:00
|
|
|
|
2023-08-19 12:49:23 +00:00
|
|
|
if(req.op == OC_IO_OPEN_AT)
|
|
|
|
{
|
|
|
|
if(req.handle.h == 0)
|
|
|
|
{
|
|
|
|
//NOTE: change root to app local folder
|
|
|
|
req.handle = orca->rootDir;
|
|
|
|
req.open.flags |= OC_FILE_OPEN_RESTRICT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cmp = oc_io_wait_single_req_with_table(&req, &orca->fileTable);
|
|
|
|
}
|
|
|
|
return (cmp);
|
2023-05-09 16:44:23 +00:00
|
|
|
}
|