11package org .extism .sdk .chicory ;
22
3+ import com .dylibso .chicory .runtime .ByteArrayMemory ;
34import com .dylibso .chicory .runtime .ExportFunction ;
45import com .dylibso .chicory .runtime .HostFunction ;
56import com .dylibso .chicory .runtime .Instance ;
67import com .dylibso .chicory .runtime .Machine ;
78import com .dylibso .chicory .wasm .Parser ;
89import com .dylibso .chicory .wasm .WasmModule ;
910import com .dylibso .chicory .wasm .types .FunctionType ;
11+ import com .dylibso .chicory .wasm .types .MemoryLimits ;
1012import com .dylibso .chicory .wasm .types .ValType ;
1113
1214import java .util .List ;
@@ -38,11 +40,11 @@ public class Kernel {
3840 final ExportFunction memoryBytes ;
3941
4042 public Kernel () {
41- this (null );
43+ this (null , null );
4244 }
4345
44- Kernel (Function <Instance , Machine > machineFactory ) {
45- Instance kernel = instance (machineFactory );
46+ Kernel (Function <Instance , Machine > machineFactory , MemoryLimits memoryLimits ) {
47+ Instance kernel = instance (machineFactory , memoryLimits );
4648 instanceMemory = kernel .memory ();
4749 alloc = kernel .export ("alloc" );
4850 free = kernel .export ("free" );
@@ -66,13 +68,17 @@ public Kernel() {
6668 memoryBytes = kernel .export ("memory_bytes" );
6769 }
6870
69- private static Instance instance (Function <Instance , Machine > machineFactory ) {
71+ private static Instance instance (Function <Instance , Machine > machineFactory , MemoryLimits memoryLimits ) {
7072 var kernelStream = Kernel .class .getClassLoader ().getResourceAsStream ("extism-runtime.wasm" );
7173 WasmModule module = Parser .parse (kernelStream );
7274 if (machineFactory != null && machineFactory instanceof CachedAotMachineFactory ) {
7375 ((CachedAotMachineFactory ) machineFactory ).compile (module );
7476 }
75- return Instance .builder (module ).withMachineFactory (machineFactory ).build ();
77+ var builder = Instance .builder (module ).withMachineFactory (machineFactory );
78+ if (memoryLimits != null ) {
79+ builder .withMemoryFactory (ByteArrayMemory ::new ).withMemoryLimits (memoryLimits );
80+ }
81+ return builder .build ();
7682 }
7783
7884 public void setInput (byte [] input ) {
0 commit comments