@@ -712,7 +712,13 @@ Word writevImpl(Word fd, Word iovs, Word iovs_len, Word *nwritten_ptr) {
712712 }
713713 const uint32_t *iovec = reinterpret_cast <const uint32_t *>(memslice.value ().data ());
714714 if (iovec[1 ] /* buf_len */ ) {
715+ #if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \
716+ __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
717+ memslice = context->wasmVm ()->getMemory (__builtin_bswap32 (iovec[0 ]) /* buf */ ,
718+ __builtin_bswap32 (iovec[1 ]) /* buf_len */ );
719+ #else
715720 memslice = context->wasmVm ()->getMemory (iovec[0 ] /* buf */ , iovec[1 ] /* buf_len */ );
721+ #endif
716722 if (!memslice) {
717723 return 21 ; // __WASI_EFAULT
718724 }
@@ -744,7 +750,12 @@ Word wasi_unstable_fd_write(Word fd, Word iovs, Word iovs_len, Word nwritten_ptr
744750 if (result != 0 ) { // __WASI_ESUCCESS
745751 return result;
746752 }
753+ #if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \
754+ __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
755+ if (!context->wasmVm ()->setWord (nwritten_ptr, Word (__builtin_bswap32 (nwritten)))) {
756+ #else
747757 if (!context->wasmVm ()->setWord (nwritten_ptr, Word (nwritten))) {
758+ #endif
748759 return 21 ; // __WASI_EFAULT
749760 }
750761 return 0 ; // __WASI_ESUCCESS
@@ -798,7 +809,12 @@ Word wasi_unstable_environ_get(Word environ_array_ptr, Word environ_buf) {
798809 auto word_size = context->wasmVm ()->getWordSize ();
799810 auto &envs = context->wasm ()->envs ();
800811 for (auto e : envs) {
812+ #if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \
813+ __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
814+ if (!context->wasmVm ()->setWord (environ_array_ptr, __builtin_bswap32 (environ_buf))) {
815+ #else
801816 if (!context->wasmVm ()->setWord (environ_array_ptr, environ_buf)) {
817+ #endif
802818 return 21 ; // __WASI_EFAULT
803819 }
804820
@@ -823,7 +839,12 @@ Word wasi_unstable_environ_get(Word environ_array_ptr, Word environ_buf) {
823839Word wasi_unstable_environ_sizes_get (Word count_ptr, Word buf_size_ptr) {
824840 auto context = contextOrEffectiveContext ();
825841 auto &envs = context->wasm ()->envs ();
842+ #if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \
843+ __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
844+ if (!context->wasmVm ()->setWord (count_ptr, Word (__builtin_bswap32 (envs.size ())))) {
845+ #else
826846 if (!context->wasmVm ()->setWord (count_ptr, Word (envs.size ()))) {
847+ #endif
827848 return 21 ; // __WASI_EFAULT
828849 }
829850
@@ -832,7 +853,12 @@ Word wasi_unstable_environ_sizes_get(Word count_ptr, Word buf_size_ptr) {
832853 // len(key) + len(value) + 1('=') + 1(null terminator)
833854 size += e.first .size () + e.second .size () + 2 ;
834855 }
856+ #if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \
857+ __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
858+ if (!context->wasmVm ()->setWord (buf_size_ptr, Word (__builtin_bswap32 (size)))) {
859+ #else
835860 if (!context->wasmVm ()->setWord (buf_size_ptr, Word (size))) {
861+ #endif
836862 return 21 ; // __WASI_EFAULT
837863 }
838864 return 0 ; // __WASI_ESUCCESS
0 commit comments