Skip to content

Commit 91eafa1

Browse files
authored
Make a workaround for EGO when fstat returns NOT_SUPPORT (#1970)
The problem was found by a `Golang + WAMR (as CGO)` wrapped by EGO in SGX Enclave. `fstat()` in EGO returns dummy values: - EGO uses a `mount` configuration to define the mount points that apply the host file system presented to the Encalve. - EGO has a different programming model: the entire application runs inside the enclave. Manual ECALLs/OCALLs by application code are neither required nor possible. Add platform ego and add macro control for the return value checking of `fd_determine_type_rights` in libc-wasi to resolve the issue.
1 parent 37b09d0 commit 91eafa1

File tree

5 files changed

+56
-8
lines changed

5 files changed

+56
-8
lines changed

CMakeLists.txt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ project (iwasm)
77

88
set (CMAKE_VERBOSE_MAKEFILE OFF)
99

10-
string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM)
10+
if (NOT DEFINED WAMR_BUILD_PLATFORM)
11+
string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM)
12+
endif ()
1113

1214
# Reset default linker flags
1315
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
@@ -135,23 +137,26 @@ include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
135137

136138
# STATIC LIBRARY
137139
add_library(iwasm_static STATIC ${WAMR_RUNTIME_LIB_SOURCE})
140+
set_target_properties (iwasm_static PROPERTIES OUTPUT_NAME vmlib)
141+
target_include_directories(iwasm_static INTERFACE ${WAMR_ROOT_DIR}/core/iwasm/include)
142+
target_link_libraries (iwasm_static INTERFACE ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -lpthread)
138143
if (WAMR_BUILD_WASM_CACHE EQUAL 1)
139-
target_link_libraries(iwasm_static PUBLIC boringssl_crypto)
144+
target_link_libraries(iwasm_static INTERFACE boringssl_crypto)
140145
endif ()
141-
set_target_properties (iwasm_static PROPERTIES OUTPUT_NAME vmlib)
142146

143147
install (TARGETS iwasm_static ARCHIVE DESTINATION lib)
144148

145149
# SHARED LIBRARY
146150
add_library (iwasm_shared SHARED ${WAMR_RUNTIME_LIB_SOURCE})
147151
set_target_properties (iwasm_shared PROPERTIES OUTPUT_NAME iwasm)
148-
target_link_libraries (iwasm_shared ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -lpthread)
152+
target_include_directories(iwasm_shared INTERFACE ${WAMR_ROOT_DIR}/core/iwasm/include)
153+
target_link_libraries (iwasm_shared INTERFACE ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -lpthread)
149154
if (WAMR_BUILD_WASM_CACHE EQUAL 1)
150-
target_link_libraries(iwasm_shared boringssl_crypto)
155+
target_link_libraries(iwasm_shared INTERFACE boringssl_crypto)
151156
endif ()
152157

153158
if (MINGW)
154-
target_link_libraries (iwasm_shared -lWs2_32)
159+
target_link_libraries (iwasm_shared -lWs2_32)
155160
endif ()
156161

157162
install (TARGETS iwasm_shared LIBRARY DESTINATION lib)

core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -685,9 +685,20 @@ fd_table_insert_existing(struct fd_table *ft, __wasi_fd_t in, int out)
685685
struct fd_object *fo;
686686
__wasi_errno_t error;
687687

688-
if (fd_determine_type_rights(out, &type, &rights_base, &rights_inheriting)
689-
!= 0)
688+
error =
689+
fd_determine_type_rights(out, &type, &rights_base, &rights_inheriting);
690+
if (error != 0) {
691+
#ifdef BH_PLATFORM_EGO
692+
/**
693+
* since it is an already opened file and we can assume the opened file
694+
* has all necessary rights no matter how to get
695+
*/
696+
if (error != __WASI_ENOTSUP)
697+
return false;
698+
#else
690699
return false;
700+
#endif
701+
}
691702

692703
error = fd_object_new(type, &fo);
693704
if (error != 0)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*
2+
* Copyright (C) 2019 Intel Corporation. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
*/
5+
6+
#include "../linux/platform_init.c"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*
2+
* Copyright (C) 2019 Intel Corporation. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
*/
5+
6+
#include "../linux/platform_internal.h"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright (C) 2019 Intel Corporation. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
set (PLATFORM_SHARED_DIR ${CMAKE_CURRENT_LIST_DIR})
5+
6+
add_definitions(-DBH_PLATFORM_EGO)
7+
8+
include_directories(${PLATFORM_SHARED_DIR})
9+
include_directories(${PLATFORM_SHARED_DIR}/../include)
10+
11+
include (${CMAKE_CURRENT_LIST_DIR}/../common/posix/platform_api_posix.cmake)
12+
13+
set (PLATFORM_SHARED_SOURCE
14+
${PLATFORM_COMMON_POSIX_SOURCE}
15+
${CMAKE_CURRENT_LIST_DIR}/platform_init.c
16+
)
17+
18+
LIST (APPEND RUNTIME_LIB_HEADER_LIST
19+
${CMAKE_CURRENT_LIST_DIR}/platform_internal.h
20+
)

0 commit comments

Comments
 (0)