Extend os_mmap to support map file from fd (#2763)

Add an extra argument `os_file_handle file` for `os_mmap` to support
mapping file from a file fd, and remove `os_get_invalid_handle` from
`posix_file.c` and `win_file.c`, instead, add it in the `platform_internal.h`
files to remove the dependency on libc-wasi.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
This commit is contained in:
Huang Qi
2023-11-16 08:28:54 +08:00
committed by GitHub
parent 0b8a904193
commit 24aa1cb408
35 changed files with 127 additions and 45 deletions

View File

@ -73,6 +73,12 @@ typedef int os_file_handle;
typedef DIR *os_dir_stream;
typedef int os_raw_file_handle;
static inline os_file_handle
os_get_invalid_handle()
{
return -1;
}
#ifdef __cplusplus
}
#endif

View File

@ -120,13 +120,20 @@ strcpy(char *dest, const char *src)
}
void *
os_mmap(void *hint, size_t size, int prot, int flags)
os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file)
{
int mprot = 0;
uint64 aligned_size, page_size;
void *ret = NULL;
sgx_status_t st = 0;
if (os_is_handle_valid(&file)) {
os_printf("os_mmap(size=%u, prot=0x%x, file=%x) failed: file is not "
"supported.\n",
size, prot, file);
return NULL;
}
page_size = getpagesize();
aligned_size = (size + page_size - 1) & ~(page_size - 1);
@ -198,4 +205,4 @@ os_dcache_flush(void)
void
os_icache_flush(void *start, size_t len)
{}
{}