2023-05-09 16:44:23 +00:00
|
|
|
/************************************************************//**
|
|
|
|
*
|
|
|
|
* @file: io_impl.c
|
|
|
|
* @author: Martin Fouilleul
|
|
|
|
* @date: 09/05/2023
|
|
|
|
*
|
|
|
|
*****************************************************************/
|
2023-06-09 15:28:33 +00:00
|
|
|
#include"platform/platform_io.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
|
|
|
{
|
|
|
|
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;
|
|
|
|
char* memory = (char*)m3_GetMemory(__orcaApp.runtime.m3Runtime, &memSize, 0);
|
|
|
|
|
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
|
|
|
//TODO: do some further ownership/rights checking here, and make sure we modify flags to avoid walking out the app folder
|
2023-05-10 14:25:51 +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-09 15:28:33 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
//TODO: should change root to app local folder
|
|
|
|
// - if file handle is null, set it to pre-opened handle to app local folder
|
|
|
|
// - if file handle is not null, check that it is valid
|
|
|
|
// --> this means we probably need a second indirection: from wasm file handle to native file handle
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
}
|
2023-05-10 16:41:30 +00:00
|
|
|
|
2023-06-09 15:28:33 +00:00
|
|
|
cmp = io_wait_single_req(&req);
|
2023-05-10 16:41:30 +00:00
|
|
|
|
2023-05-09 16:44:23 +00:00
|
|
|
}
|
|
|
|
return(cmp);
|
|
|
|
}
|