From 544446c8d390ecf2b130ce52ace00d4cca0a4ce9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20RIVIERE?= Date: Tue, 8 Jul 2025 13:43:58 +0200 Subject: [PATCH 1/4] add OOME during clinit in troubleshooting section --- .../managedc/troubleshooting.rst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ApplicationDeveloperGuide/managedc/troubleshooting.rst b/ApplicationDeveloperGuide/managedc/troubleshooting.rst index 48f9fa9d4..2119c618a 100644 --- a/ApplicationDeveloperGuide/managedc/troubleshooting.rst +++ b/ApplicationDeveloperGuide/managedc/troubleshooting.rst @@ -96,6 +96,22 @@ Running code containing Managed C in a simulation will prompt an error similar t Runtime Errors ~~~~~~~~~~~~~~ +-------------------------- +java.lang.OutOfMemoryError +-------------------------- + +If you encounter a stack trace like the following, there is insufficient space in the Managed Heap to allocate a Wasm module linear memory. +Increase the :ref:`Managed Heap size ` or :ref:`reduce the linear memory size ` of the Wasm module. + +.. code:: console + + java.lang.OutOfMemoryErrorM:0x808d2c8:0x808d2d3@ + at com.mycompany.MyApplication.(Unknown Source) + at java.lang.Thread.execClinit(Unknown Source) + at java.lang.Thread.clinitWrapper(Thread.java:484) + at java.lang.Thread.callWrapper(Thread.java:450) + + ----------------------------- java.lang.AssertionError ----------------------------- From 1c2f08219256e7c8c9759d16560df2a0a042a33f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20RIVIERE?= Date: Tue, 8 Jul 2025 13:55:04 +0200 Subject: [PATCH 2/4] fix WASI example according to feedbacks --- ApplicationDeveloperGuide/managedc/wasi.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ApplicationDeveloperGuide/managedc/wasi.rst b/ApplicationDeveloperGuide/managedc/wasi.rst index 70791601a..73ef764df 100644 --- a/ApplicationDeveloperGuide/managedc/wasi.rst +++ b/ApplicationDeveloperGuide/managedc/wasi.rst @@ -47,7 +47,7 @@ Here is an example: void print_time() { struct timespec ts; clock_gettime(CLOCK_REALTIME, &ts); - printf("%lld.%.9ld", (long long)ts.tv_sec, ts.tv_nsec); + printf("%lld.%.9ld\n", (long long)ts.tv_sec, ts.tv_nsec); } @@ -72,7 +72,7 @@ Here is an example: public static void main(String[] args) throws IOException { // Initialize WASI with the memory of my_app module and no preopened directories - Wasi.init(Memory, null); + Wasi.init(Memory); // Call and the "print_time" Wasm function printTime(); From 48e77f62b72251c7f10a5a7670b8b154a9b8c4f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20RIVIERE?= Date: Tue, 8 Jul 2025 13:55:28 +0200 Subject: [PATCH 3/4] reword the one module restriction note --- ApplicationDeveloperGuide/managedc/wasi.rst | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/ApplicationDeveloperGuide/managedc/wasi.rst b/ApplicationDeveloperGuide/managedc/wasi.rst index 73ef764df..2cc9f55b1 100644 --- a/ApplicationDeveloperGuide/managedc/wasi.rst +++ b/ApplicationDeveloperGuide/managedc/wasi.rst @@ -87,11 +87,8 @@ In this example, the implementation of The POSIX-compliant C functions ``clock_g .. note:: - WASI cannot be used in more than one Wasm module in a `Standalone Application `; otherwise calls to WASI methods will result in undefined behavior. - - In a `Sandboxed Application `, WASI methods must not be exposed in the `Kernel API ` and each Application and the Kernel can use WASI in only one module. - - Using WASI in multiple modules within an Application or the Kernel will result in undefined behavior. + WASI cannot be used by more than one Wasm module within a single Application. Otherwise, calls to WASI methods may result in undefined behavior. + In particular, in Multi-Sandbox mode, WASI APIs must not be exposed as :ref:`Kernel APIs `. This restriction allows each Application and the Kernel to use WASI independently, while still limiting usage to a single Wasm module per context. WASI APIs From b2df869d608181aa89a277ddfbe8f9ec01ca0014 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20RIVIERE?= Date: Tue, 8 Jul 2025 15:04:03 +0200 Subject: [PATCH 4/4] improve the introduction of managed c memory --- ApplicationDeveloperGuide/managedc/binding.rst | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/ApplicationDeveloperGuide/managedc/binding.rst b/ApplicationDeveloperGuide/managedc/binding.rst index 98600eb3f..a7279540a 100644 --- a/ApplicationDeveloperGuide/managedc/binding.rst +++ b/ApplicationDeveloperGuide/managedc/binding.rst @@ -416,14 +416,13 @@ SOAR will trigger an error if Managed C function parameter(s) and return types d .. _managedc.communication.managedc_memory: -Manipulate Managed C Memory from Java -------------------------------------- - -The Core Engine allows to expose Managed C memory to Java code. A Managed C module contains -at most one memory. This Managed C module memory is automatically generated by the C compiler -according to C source code and C compiler options. On Java side, Managed C module memory can be seen by -using ``@WasmMemory`` annotation on a Java static byte array field declaration (mapping automatically -done by the :ref:`soar`). +Access Managed C Memory from Java +--------------------------------- + +The Managed C memory is composed of all static arrays, structures, globals declared in C files, thread stacks and optional heap for dynamic allocations. +All these elements are :ref:`linked ` to the :ref:`Wasm module linear memory `. + +On Java side, the Wasm module linear memory can be bound to a Java static byte array field declaration using the ``@WasmMemory`` annotation. .. note:: A SOAR error will occurred if ``@WasmMemory`` is not strictly followed by a Java static byte array declaration (see :ref:`managedc.troubleshooting`).