@@ -65,16 +65,22 @@ Pairs toPairs(std::string_view buffer) {
65
65
if (buffer.size () < sizeof (uint32_t )) {
66
66
return {};
67
67
}
68
- auto size = wasmtoh (*reinterpret_cast <const uint32_t *>(b));
68
+ bool reverse = " null" != contextOrEffectiveContext ()->wasmVm ()->getEngineName ();
69
+ auto size = reverse ? wasmtoh (*reinterpret_cast <const uint32_t *>(b))
70
+ : *reinterpret_cast <const uint32_t *>(b);
69
71
b += sizeof (uint32_t );
70
72
if (sizeof (uint32_t ) + size * 2 * sizeof (uint32_t ) > buffer.size ()) {
71
73
return {};
72
74
}
73
75
result.resize (size);
74
76
for (uint32_t i = 0 ; i < size; i++) {
75
- result[i].first = std::string_view (nullptr , wasmtoh (*reinterpret_cast <const uint32_t *>(b)));
77
+ result[i].first =
78
+ std::string_view (nullptr , reverse ? wasmtoh (*reinterpret_cast <const uint32_t *>(b))
79
+ : *reinterpret_cast <const uint32_t *>(b));
76
80
b += sizeof (uint32_t );
77
- result[i].second = std::string_view (nullptr , wasmtoh (*reinterpret_cast <const uint32_t *>(b)));
81
+ result[i].second =
82
+ std::string_view (nullptr , reverse ? wasmtoh (*reinterpret_cast <const uint32_t *>(b))
83
+ : *reinterpret_cast <const uint32_t *>(b));
78
84
b += sizeof (uint32_t );
79
85
}
80
86
for (auto &p : result) {
@@ -691,6 +697,7 @@ Word wasi_unstable_fd_prestat_dir_name(Word /*fd*/, Word /*path_ptr*/, Word /*pa
691
697
// logs.
692
698
Word writevImpl (Word fd, Word iovs, Word iovs_len, Word *nwritten_ptr) {
693
699
auto *context = contextOrEffectiveContext ();
700
+ bool reverse = " null" != context->wasmVm ()->getEngineName ();
694
701
695
702
// Read syscall args.
696
703
uint64_t log_level;
@@ -714,8 +721,9 @@ Word writevImpl(Word fd, Word iovs, Word iovs_len, Word *nwritten_ptr) {
714
721
}
715
722
const auto *iovec = reinterpret_cast <const uint32_t *>(memslice.value ().data ());
716
723
if (iovec[1 ] != 0U /* buf_len */ ) {
717
- memslice = context->wasmVm ()->getMemory (wasmtoh (iovec[0 ]) /* buf */ ,
718
- wasmtoh (iovec[1 ]) /* buf_len */ );
724
+ auto iovec0 = reverse ? wasmtoh (iovec[0 ]) : iovec[0 ];
725
+ auto iovec1 = reverse ? wasmtoh (iovec[1 ]) : iovec[1 ];
726
+ memslice = context->wasmVm ()->getMemory (iovec0 /* buf */ , iovec1 /* buf_len */ );
719
727
if (!memslice) {
720
728
return 21 ; // __WASI_EFAULT
721
729
}
0 commit comments