@@ -253,13 +253,7 @@ pub unsafe trait InstanceAllocatorImpl {
253253 fn decrement_core_instance_count ( & self ) ;
254254
255255 /// Allocate a memory for an instance.
256- ///
257- /// # Unsafety
258- ///
259- /// The memory and its associated module must have already been validated by
260- /// `Self::validate_memory` (or transtively via
261- /// `Self::validate_{module,component}`) and passed that validation.
262- unsafe fn allocate_memory (
256+ fn allocate_memory (
263257 & self ,
264258 request : & mut InstanceAllocationRequest ,
265259 ty : & wasmtime_environ:: Memory ,
@@ -282,12 +276,7 @@ pub unsafe trait InstanceAllocatorImpl {
282276 ) ;
283277
284278 /// Allocate a table for an instance.
285- ///
286- /// # Unsafety
287- ///
288- /// The table and its associated module must have already been validated by
289- /// `Self::validate_module` and passed that validation.
290- unsafe fn allocate_table (
279+ fn allocate_table (
291280 & self ,
292281 req : & mut InstanceAllocationRequest ,
293282 table : & wasmtime_environ:: Table ,
@@ -409,10 +398,10 @@ pub trait InstanceAllocator: InstanceAllocatorImpl {
409398 /// Note that the returned instance must still have `.initialize(..)` called
410399 /// on it to complete the instantiation process.
411400 ///
412- /// # Unsafety
401+ /// # Safety
413402 ///
414- /// The request's associated module, memories, tables, and vmctx must have
415- /// already have been validated by `Self::validate_module` .
403+ /// The ` request` provided must be valid, e.g. the imports within are
404+ /// correctly sized/typed for the instance being created .
416405 unsafe fn allocate_module (
417406 & self ,
418407 mut request : InstanceAllocationRequest ,
@@ -432,15 +421,14 @@ pub trait InstanceAllocator: InstanceAllocatorImpl {
432421 let mut tables = PrimaryMap :: with_capacity ( num_defined_tables) ;
433422
434423 match ( || {
435- // SAFETY: validation of tables/memories is a contract of this
436- // function.
437- unsafe {
438- self . allocate_memories ( & mut request, & mut memories) ?;
439- self . allocate_tables ( & mut request, & mut tables) ?;
440- }
424+ self . allocate_memories ( & mut request, & mut memories) ?;
425+ self . allocate_tables ( & mut request, & mut tables) ?;
441426 Ok ( ( ) )
442427 } ) ( ) {
443- Ok ( _) => Ok ( Instance :: new ( request, memories, tables, & module. memories ) ) ,
428+ // SAFETY: memories/tables were just allocated from the store within
429+ // `request` and this function's own contract requires that the
430+ // imports are valid.
431+ Ok ( _) => unsafe { Ok ( Instance :: new ( request, memories, tables, & module. memories ) ) } ,
444432 Err ( e) => {
445433 // SAFETY: these were previously allocated by this allocator
446434 unsafe {
@@ -475,12 +463,7 @@ pub trait InstanceAllocator: InstanceAllocatorImpl {
475463
476464 /// Allocate the memories for the given instance allocation request, pushing
477465 /// them into `memories`.
478- ///
479- /// # Unsafety
480- ///
481- /// The request's associated module and memories must have previously been
482- /// validated by `Self::validate_module`.
483- unsafe fn allocate_memories (
466+ fn allocate_memories (
484467 & self ,
485468 request : & mut InstanceAllocationRequest ,
486469 memories : & mut PrimaryMap < DefinedMemoryIndex , ( MemoryAllocationIndex , Memory ) > ,
@@ -496,10 +479,7 @@ pub trait InstanceAllocator: InstanceAllocatorImpl {
496479 . defined_memory_index ( memory_index)
497480 . expect ( "should be a defined memory since we skipped imported ones" ) ;
498481
499- // SAFETY: validation of the memory from this allocator is itself a
500- // contract of this function.
501- let memory =
502- unsafe { self . allocate_memory ( request, ty, request. tunables , Some ( memory_index) ) ? } ;
482+ let memory = self . allocate_memory ( request, ty, request. tunables , Some ( memory_index) ) ?;
503483 memories. push ( memory) ;
504484 }
505485
@@ -533,12 +513,7 @@ pub trait InstanceAllocator: InstanceAllocatorImpl {
533513
534514 /// Allocate tables for the given instance allocation request, pushing them
535515 /// into `tables`.
536- ///
537- /// # Unsafety
538- ///
539- /// The request's associated module and tables must have previously been
540- /// validated by `Self::validate_module`.
541- unsafe fn allocate_tables (
516+ fn allocate_tables (
542517 & self ,
543518 request : & mut InstanceAllocationRequest ,
544519 tables : & mut PrimaryMap < DefinedTableIndex , ( TableAllocationIndex , Table ) > ,
@@ -554,10 +529,7 @@ pub trait InstanceAllocator: InstanceAllocatorImpl {
554529 . defined_table_index ( index)
555530 . expect ( "should be a defined table since we skipped imported ones" ) ;
556531
557- // SAFETY: the contract here is that the table has been validated by
558- // this allocator which is a contract of this function itself.
559- let table =
560- unsafe { self . allocate_table ( request, table, request. tunables , def_index) ? } ;
532+ let table = self . allocate_table ( request, table, request. tunables , def_index) ?;
561533 tables. push ( table) ;
562534 }
563535
0 commit comments