@@ -858,11 +858,11 @@ wasm_runtime_set_default_running_mode(RunningMode running_mode)
858858PackageType
859859get_package_type (const uint8 * buf , uint32 size )
860860{
861+ if (buf && size >= 4 ) {
861862#if (WASM_ENABLE_WORD_ALIGN_READ != 0 )
862- uint32 buf32 = * (uint32 * )buf ;
863- buf = (const uint8 * )& buf32 ;
863+ uint32 buf32 = * (uint32 * )buf ;
864+ buf = (const uint8 * )& buf32 ;
864865#endif
865- if (buf && size >= 4 ) {
866866 if (buf [0 ] == '\0' && buf [1 ] == 'a' && buf [2 ] == 's' && buf [3 ] == 'm' )
867867 return Wasm_Module_Bytecode ;
868868 if (buf [0 ] == '\0' && buf [1 ] == 'a' && buf [2 ] == 'o' && buf [3 ] == 't' )
@@ -887,6 +887,62 @@ wasm_runtime_get_module_package_type(WASMModuleCommon *module)
887887 return module -> module_type ;
888888}
889889
890+ uint32
891+ wasm_runtime_get_file_package_version (const uint8 * buf , uint32 size )
892+ {
893+ if (buf && size >= 8 ) {
894+ uint32 version ;
895+ #if (WASM_ENABLE_WORD_ALIGN_READ != 0 )
896+ uint32 buf32 = * (uint32 * )(buf + sizeof (uint32 ));
897+ buf = (const uint8 * )& buf32 ;
898+ version = buf [0 ] | buf [1 ] << 8 | buf [2 ] << 16 | buf [3 ] << 24 ;
899+ #else
900+ version = buf [4 ] | buf [5 ] << 8 | buf [6 ] << 16 | buf [7 ] << 24 ;
901+ #endif
902+ return version ;
903+ }
904+
905+ return 0 ;
906+ }
907+
908+ uint32
909+ wasm_runtime_get_module_package_version (WASMModuleCommon * module )
910+ {
911+ if (!module ) {
912+ return 0 ;
913+ }
914+
915+ #if WASM_ENABLE_INTERP != 0
916+ if (module -> module_type == Wasm_Module_Bytecode ) {
917+ WASMModule * wasm_module = (WASMModule * )module ;
918+ return wasm_module -> package_version ;
919+ }
920+ #endif
921+
922+ #if WASM_ENABLE_AOT != 0
923+ if (module -> module_type == Wasm_Module_AoT ) {
924+ AOTModule * aot_module = (AOTModule * )module ;
925+ return aot_module -> package_version ;
926+ }
927+ #endif
928+
929+ return 0 ;
930+ }
931+
932+ uint32
933+ wasm_runtime_get_current_package_version (package_type_t package_type )
934+ {
935+ switch (package_type ) {
936+ case Wasm_Module_Bytecode :
937+ return WASM_CURRENT_VERSION ;
938+ case Wasm_Module_AoT :
939+ return AOT_CURRENT_VERSION ;
940+ case Package_Type_Unknown :
941+ default :
942+ return 0 ;
943+ }
944+ }
945+
890946#if WASM_ENABLE_AOT != 0
891947static uint8 *
892948align_ptr (const uint8 * p , uint32 b )
0 commit comments