Skip to content

Commit 178b34d

Browse files
committed
Integration patch 1.0.6
1 parent b28325a commit 178b34d

File tree

7 files changed

+441
-31
lines changed

7 files changed

+441
-31
lines changed

crates/c_api/CMakeLists.txt

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ option(BUILD_SHARED_LIBS "Build using shared libraries" OFF)
66
option(WASMI_ALWAYS_BUILD "If cmake should always invoke cargo to build Wasmi" ON)
77
set(WASMI_TARGET "" CACHE STRING "Rust target to build for")
88

9+
add_compile_definitions(COMPILING_WASM_RUNTIME_API=1)
10+
911
if(NOT WASMI_TARGET)
1012
execute_process(
1113
COMMAND rustc -vV
@@ -43,6 +45,10 @@ endif()
4345
list(TRANSFORM WASMI_SHARED_FILES PREPEND ${WASMI_TARGET_DIR}/)
4446
list(TRANSFORM WASMI_STATIC_FILES PREPEND ${WASMI_TARGET_DIR}/)
4547

48+
if(NOT BUILD_SHARED_LIBS)
49+
set(WASMI_SHARED_FILES)
50+
endif()
51+
4652
# Instructions on how to build and install the Wasmi Rust crate.
4753
find_program(WASMI_CARGO_BINARY cargo REQUIRED)
4854
include(ExternalProject)
@@ -79,7 +85,6 @@ else()
7985
target_link_libraries(wasmi INTERFACE ${WASMI_STATIC_FILES})
8086

8187
if(WASMI_TARGET MATCHES "windows")
82-
target_compile_options(wasmi INTERFACE -DWASM_API_EXTERN= -DWASI_API_EXTERN=)
8388
target_link_libraries(wasmi INTERFACE ws2_32 advapi32 userenv ntdll shell32 ole32 bcrypt)
8489
elseif(NOT WASMI_TARGET MATCHES "darwin")
8590
target_link_libraries(wasmi INTERFACE pthread dl m)
@@ -112,6 +117,7 @@ install(
112117
DESTINATION ${CMAKE_INSTALL_LIBDIR}
113118
)
114119

120+
if(BUILD_SHARED_LIBS)
115121
if(WASMI_TARGET MATCHES "darwin")
116122
set(INSTALLED_LIB "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/libwasmi.dylib")
117123
install(
@@ -131,6 +137,7 @@ if(WASMI_TARGET MATCHES "darwin")
131137
install(CODE "execute_process(COMMAND ${install_name_tool_cmd})")
132138
endif()
133139
endif()
140+
endif()
134141

135142
# Documentation Generation via Doxygen:
136143
set(DOXYGEN_CONF_IN ${CMAKE_CURRENT_SOURCE_DIR}/doxygen.conf.in)
@@ -141,19 +148,3 @@ add_custom_target(doc
141148
DEPENDS ${WASMI_GENERATED_CONF_H} ${DOXYGEN_CONF_OUT}
142149
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
143150
)
144-
145-
# C-Header Formatting via clang-format:
146-
find_program(CLANG_FORMAT clang-format REQUIRED)
147-
file(GLOB_RECURSE HEADER_FILES
148-
${CMAKE_CURRENT_SOURCE_DIR}/include/wasmi.h
149-
${CMAKE_CURRENT_SOURCE_DIR}/include/wasmi/*.h
150-
${CMAKE_CURRENT_SOURCE_DIR}/include/wasmi/*.hh
151-
)
152-
add_custom_target(check-format
153-
COMMAND ${CLANG_FORMAT} -style=llvm -Werror --dry-run ${HEADER_FILES}
154-
COMMENT "clang-format: Check formatting for Wasmi C-API header files"
155-
)
156-
add_custom_target(format
157-
COMMAND ${CLANG_FORMAT} -style=llvm -i ${HEADER_FILES}
158-
COMMENT "clang-format: Apply formatting rules for Wasmi C-API header files"
159-
)

crates/c_api/include/wasm.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,17 @@
1313
#include <assert.h>
1414

1515
#ifndef WASM_API_EXTERN
16-
#if defined(_WIN32) && !defined(__MINGW32__) && !defined(LIBWASM_STATIC)
16+
#if defined(_MSC_BUILD)
17+
#if defined(COMPILING_WASM_RUNTIME_API)
18+
#define WASM_API_EXTERN __declspec(dllexport)
19+
#elif defined(_DLL)
1720
#define WASM_API_EXTERN __declspec(dllimport)
1821
#else
1922
#define WASM_API_EXTERN
2023
#endif
24+
#else
25+
#define WASM_API_EXTERN
26+
#endif
2127
#endif
2228

2329
#ifdef __cplusplus
@@ -145,7 +151,13 @@ WASM_API_EXTERN own wasm_engine_t* wasm_engine_new_with_config(own wasm_config_t
145151
WASM_DECLARE_OWN(store)
146152

147153
WASM_API_EXTERN own wasm_store_t* wasm_store_new(wasm_engine_t*);
154+
WASM_API_EXTERN own wasm_store_t* wasm_store_new_with_memory_max_pages(wasm_engine_t*, uint32_t max_pages);
155+
156+
// Store fuel functions (forward declarations)
157+
struct wasmi_error;
148158

159+
WASM_API_EXTERN struct wasmi_error* wasm_store_get_fuel(const wasm_store_t*, uint64_t* fuel);
160+
WASM_API_EXTERN struct wasmi_error* wasm_store_set_fuel(wasm_store_t*, uint64_t fuel);
149161

150162
///////////////////////////////////////////////////////////////////////////////
151163
// Type Representations

crates/c_api/include/wasmi.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@
1010
/**
1111
* \brief Wasmi version string.
1212
*/
13-
#define WASMI_VERSION "0.35.0"
13+
#define WASMI_VERSION "1.0.6"
1414
/**
1515
* \brief Wasmi major version number.
1616
*/
17-
#define WASMI_VERSION_MAJOR 0
17+
#define WASMI_VERSION_MAJOR 1
1818
/**
1919
* \brief Wasmi minor version number.
2020
*/
21-
#define WASMI_VERSION_MINOR 35
21+
#define WASMI_VERSION_MINOR 0
2222
/**
2323
* \brief Wasmi patch version number.
2424
*/
25-
#define WASMI_VERSION_PATCH 0
25+
#define WASMI_VERSION_PATCH 6
2626

2727
#endif // WASMI_H

crates/c_api/include/wasmi/config.h

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,40 @@ WASMI_CONFIG_PROP(void, consume_fuel, bool)
3535
*/
3636
WASMI_CONFIG_PROP(void, ignore_custom_sections, bool)
3737

38+
/**
39+
* \brief Sets the maximum recursion depth of the engine's stack during execution.
40+
*
41+
* An execution traps if it exceeds this limit.
42+
*/
43+
WASMI_CONFIG_PROP(void, set_max_recursion_depth, size_t)
44+
45+
/**
46+
* \brief Sets the minimum (or initial) height of the engine's value stack in bytes.
47+
*
48+
* Lower initial heights may improve memory consumption.
49+
* Higher initial heights may improve cold start times.
50+
*
51+
* Note: Panics if value is greater than the current maximum height of the value stack.
52+
*/
53+
WASMI_CONFIG_PROP(void, set_min_stack_height, size_t)
54+
55+
/**
56+
* \brief Sets the maximum height of the engine's value stack in bytes.
57+
*
58+
* An execution traps if it exceeds this limit.
59+
*
60+
* Note: Panics if value is less than the current minimum height of the value stack.
61+
*/
62+
WASMI_CONFIG_PROP(void, set_max_stack_height, size_t)
63+
64+
/**
65+
* \brief Sets the maximum number of cached stacks for reuse.
66+
*
67+
* A higher value may improve execution performance.
68+
* A lower value may improve memory consumption.
69+
*/
70+
WASMI_CONFIG_PROP(void, set_max_cached_stacks, size_t)
71+
3872
/**
3973
* \brief Whether or not to Wasm mutable-globals proposal is enabled.
4074
*
@@ -92,6 +126,52 @@ WASMI_CONFIG_PROP(void, wasm_tail_call, bool)
92126
*/
93127
WASMI_CONFIG_PROP(void, wasm_extended_const, bool)
94128

129+
/**
130+
* \brief Whether or not to Wasm multi-memory proposal is enabled.
131+
*
132+
* Default value: `true`
133+
*/
134+
WASMI_CONFIG_PROP(void, wasm_multi_memory, bool)
135+
136+
/**
137+
* \brief Whether or not to Wasm custom-page-sizes proposal is enabled.
138+
*
139+
* Default value: `false`
140+
*/
141+
WASMI_CONFIG_PROP(void, wasm_custom_page_sizes, bool)
142+
143+
/**
144+
* \brief Whether or not to Wasm memory64 proposal is enabled.
145+
*
146+
* Default value: `true`
147+
*/
148+
WASMI_CONFIG_PROP(void, wasm_memory64, bool)
149+
150+
/**
151+
* \brief Whether or not to Wasm wide-arithmetic proposal is enabled.
152+
*
153+
* Default value: `false`
154+
*/
155+
WASMI_CONFIG_PROP(void, wasm_wide_arithmetic, bool)
156+
157+
/**
158+
* \brief Whether or not to Wasm simd proposal is enabled.
159+
*
160+
* Only available when compiled with the `simd` feature.
161+
*
162+
* Default value: `true` (when feature enabled)
163+
*/
164+
WASMI_CONFIG_PROP(void, wasm_simd, bool)
165+
166+
/**
167+
* \brief Whether or not to Wasm relaxed-simd proposal is enabled.
168+
*
169+
* Only available when compiled with the `simd` feature.
170+
*
171+
* Default value: `true` (when feature enabled)
172+
*/
173+
WASMI_CONFIG_PROP(void, wasm_relaxed_simd, bool)
174+
95175
/**
96176
* \brief Whether or not to floating Wasm point types and operations are
97177
* enabled.
@@ -125,6 +205,58 @@ WASMI_CONFIG_PROP(void, compilation_mode, enum wasmi_compilation_mode_enum)
125205

126206
#undef WASMI_CONFIG_PROP
127207

208+
/**
209+
* \brief Enforced limits for Wasm module parsing and compilation.
210+
*
211+
* Opaque type representing limits that can be enforced on Wasm modules.
212+
*/
213+
typedef struct wasmi_enforced_limits_t wasmi_enforced_limits_t;
214+
215+
/**
216+
* \brief Creates a new enforced limits object with strict preset values.
217+
*
218+
* This set of strict enforced rules can be used to safeguard against
219+
* malicious actors trying to attack the Wasmi compilation procedures.
220+
*
221+
* The strict limits are:
222+
* - max_globals: 1000
223+
* - max_functions: 10,000
224+
* - max_tables: 100
225+
* - max_element_segments: 1000
226+
* - max_memories: 1
227+
* - max_data_segments: 1000
228+
* - max_params: 32
229+
* - max_results: 32
230+
* - min_avg_bytes_per_function: 40 (enforced at 1000+ total bytes)
231+
*
232+
* The returned object must be freed using wasmi_enforced_limits_delete().
233+
*
234+
* \return A new enforced limits object with strict preset values
235+
*/
236+
WASM_API_EXTERN wasmi_enforced_limits_t* wasmi_enforced_limits_strict();
237+
238+
/**
239+
* \brief Deletes an enforced limits object.
240+
*
241+
* \param limits The enforced limits object to delete
242+
*/
243+
WASM_API_EXTERN void wasmi_enforced_limits_delete(wasmi_enforced_limits_t* limits);
244+
245+
/**
246+
* \brief Sets the enforced limits for the configuration.
247+
*
248+
* By default no limits are enforced. Use this function to apply a set of
249+
* enforced limits (such as those created by wasmi_enforced_limits_strict())
250+
* to the configuration.
251+
*
252+
* \param config The configuration to modify
253+
* \param limits The enforced limits to apply
254+
*/
255+
WASM_API_EXTERN void wasmi_config_enforced_limits_set(
256+
wasm_config_t* config,
257+
const wasmi_enforced_limits_t* limits
258+
);
259+
128260
#ifdef __cplusplus
129261
} // extern "C"
130262
#endif

0 commit comments

Comments
 (0)