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-06-11 16:21:04 +00:00
|
|
|
#include"platform/platform_io_internal.h"
|
2023-08-09 11:06:32 +00:00
|
|
|
#include"runtime.h"
|
2023-05-09 16:44:23 +00:00
|
|
|
|
2023-06-09 15:28:33 +00:00
|
|
|
io_cmp orca_io_wait_single_req(io_req* wasmReq)
|
2023-05-11 16:09:26 +00:00
|
|
|
{
|
2023-06-11 16:21:04 +00:00
|
|
|
orca_app* orca = orca_app_get();
|
2023-05-11 16:09:26 +00:00
|
|
|
mem_arena* scratch = mem_scratch();
|
|
|
|
|
2023-05-09 16:44:23 +00:00
|
|
|
io_cmp cmp = {0};
|
2023-06-09 15:28:33 +00:00
|
|
|
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;
|
2023-05-09 16:44:23 +00:00
|
|
|
u32 memSize = 0;
|
2023-06-11 16:21:04 +00:00
|
|
|
char* memory = (char*)m3_GetMemory(orca->runtime.m3Runtime, &memSize, 0);
|
2023-05-09 16:44:23 +00:00
|
|
|
|
2023-06-09 15:28:33 +00:00
|
|
|
if(bufferIndex + req.size > memSize)
|
2023-05-09 16:44:23 +00:00
|
|
|
{
|
2023-05-10 16:41:30 +00:00
|
|
|
cmp.error = IO_ERR_ARG;
|
2023-05-09 16:44:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-09 15:28:33 +00:00
|
|
|
req.buffer = memory + bufferIndex;
|
2023-05-09 16:44:23 +00:00
|
|
|
|
2023-06-09 15:28:33 +00:00
|
|
|
if(req.op == IO_OP_OPEN_AT)
|
2023-05-10 16:41:30 +00:00
|
|
|
{
|
2023-06-11 16:21:04 +00:00
|
|
|
if(req.handle.h == 0)
|
|
|
|
{
|
|
|
|
//NOTE: change root to app local folder
|
|
|
|
req.handle = orca->rootDir;
|
2023-06-16 18:07:26 +00:00
|
|
|
req.open.flags |= FILE_OPEN_RESTRICT;
|
2023-06-11 16:21:04 +00:00
|
|
|
}
|
2023-06-09 15:28:33 +00:00
|
|
|
}
|
2023-06-11 16:21:04 +00:00
|
|
|
cmp = io_wait_single_req_with_table(&req, &orca->fileTable);
|
2023-05-09 16:44:23 +00:00
|
|
|
}
|
|
|
|
return(cmp);
|
|
|
|
}
|