File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -228,12 +228,22 @@ function getMemoryPatched(
228228 const libName = libPath . split ( '/' ) . at ( - 1 ) ! ;
229229 // 1. Is it loaded in the snapshot? Replay the memory base.
230230 {
231- const { soMemoryBases } = LOADED_SNAPSHOT_META ?? { } ;
231+ const { soMemoryBases, soTableBases } = LOADED_SNAPSHOT_META ?? { } ;
232232 // If we loaded this library before taking the snapshot, we already allocated the memory and the
233233 // allocator remembers because its state is in the linear memory. We just have to look it up.
234- const base = soMemoryBases ?. [ libPath ] ?? soMemoryBases ?. [ libName ] ;
235- if ( base ) {
236- return base ;
234+ const tableBase = Module . wasmTable . length ;
235+ const expectedTableBase =
236+ soTableBases ?. [ libPath ] ?? soTableBases ?. [ libName ] ;
237+ if ( expectedTableBase && tableBase !== expectedTableBase ) {
238+ // If this happens, we will segfault if we ever try to use this dynamic library.
239+ // Save ourselves some debugging pain by crashing early.
240+ throw new PythonRuntimeError (
241+ `Error loading ${ libName } : Expected table base ${ expectedTableBase } but got table base ${ tableBase } `
242+ ) ;
243+ }
244+ const memoryBase = soMemoryBases ?. [ libPath ] ?? soMemoryBases ?. [ libName ] ;
245+ if ( memoryBase ) {
246+ return memoryBase ;
237247 }
238248 }
239249 // 2. It's not loaded in the snapshot. Record
You can’t perform that action at this time.
0 commit comments