@@ -712,7 +712,13 @@ Word writevImpl(Word fd, Word iovs, Word iovs_len, Word *nwritten_ptr) {
712
712
}
713
713
const uint32_t *iovec = reinterpret_cast <const uint32_t *>(memslice.value ().data ());
714
714
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
715
720
memslice = context->wasmVm ()->getMemory (iovec[0 ] /* buf */ , iovec[1 ] /* buf_len */ );
721
+ #endif
716
722
if (!memslice) {
717
723
return 21 ; // __WASI_EFAULT
718
724
}
@@ -744,7 +750,12 @@ Word wasi_unstable_fd_write(Word fd, Word iovs, Word iovs_len, Word nwritten_ptr
744
750
if (result != 0 ) { // __WASI_ESUCCESS
745
751
return result;
746
752
}
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
747
757
if (!context->wasmVm ()->setWord (nwritten_ptr, Word (nwritten))) {
758
+ #endif
748
759
return 21 ; // __WASI_EFAULT
749
760
}
750
761
return 0 ; // __WASI_ESUCCESS
@@ -798,7 +809,12 @@ Word wasi_unstable_environ_get(Word environ_array_ptr, Word environ_buf) {
798
809
auto word_size = context->wasmVm ()->getWordSize ();
799
810
auto &envs = context->wasm ()->envs ();
800
811
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
801
816
if (!context->wasmVm ()->setWord (environ_array_ptr, environ_buf)) {
817
+ #endif
802
818
return 21 ; // __WASI_EFAULT
803
819
}
804
820
@@ -823,7 +839,12 @@ Word wasi_unstable_environ_get(Word environ_array_ptr, Word environ_buf) {
823
839
Word wasi_unstable_environ_sizes_get (Word count_ptr, Word buf_size_ptr) {
824
840
auto context = contextOrEffectiveContext ();
825
841
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
826
846
if (!context->wasmVm ()->setWord (count_ptr, Word (envs.size ()))) {
847
+ #endif
827
848
return 21 ; // __WASI_EFAULT
828
849
}
829
850
@@ -832,7 +853,12 @@ Word wasi_unstable_environ_sizes_get(Word count_ptr, Word buf_size_ptr) {
832
853
// len(key) + len(value) + 1('=') + 1(null terminator)
833
854
size += e.first .size () + e.second .size () + 2 ;
834
855
}
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
835
860
if (!context->wasmVm ()->setWord (buf_size_ptr, Word (size))) {
861
+ #endif
836
862
return 21 ; // __WASI_EFAULT
837
863
}
838
864
return 0 ; // __WASI_ESUCCESS
0 commit comments