Skip to content

Commit dec6b94

Browse files
committed
Do not reverse bytes for nullvm
- use buf and buf_len variables for readability - added back word.h include - hardcoded usesWasmByteOrder() to true Fixes #294 Signed-off-by: Konstantin Maksimov <konstantin.maksimov@ibm.com>
1 parent ad11d07 commit dec6b94

File tree

6 files changed

+12
-11
lines changed

6 files changed

+12
-11
lines changed

src/exports.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -693,9 +693,9 @@ Word writevImpl(Word fd, Word iovs, Word iovs_len, Word *nwritten_ptr) {
693693
}
694694
const auto *iovec = reinterpret_cast<const uint32_t *>(memslice.value().data());
695695
if (iovec[1] != 0U /* buf_len */) {
696-
memslice = context->wasmVm()->getMemory(
697-
wasmtoh(iovec[0], context->wasmVm()->usesWasmByteOrder()) /* buf */,
698-
wasmtoh(iovec[1], context->wasmVm()->usesWasmByteOrder()) /* buf_len */);
696+
const auto buf = wasmtoh(iovec[0], context->wasmVm()->usesWasmByteOrder());
697+
const auto buf_len = wasmtoh(iovec[1], context->wasmVm()->usesWasmByteOrder());
698+
memslice = context->wasmVm()->getMemory(buf, buf_len);
699699
if (!memslice) {
700700
return 21; // __WASI_EFAULT
701701
}

src/pairs_util.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include "include/proxy-wasm/exports.h"
2323
#include "include/proxy-wasm/limits.h"
24+
#include "include/proxy-wasm/word.h"
2425

2526
namespace proxy_wasm {
2627

src/v8/v8.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ bool V8::getWord(uint64_t pointer, Word *word) {
504504
}
505505
uint32_t word32;
506506
::memcpy(&word32, memory_->data() + pointer, size);
507-
word->u64_ = wasmtoh(word32, usesWasmByteOrder());
507+
word->u64_ = wasmtoh(word32, true);
508508
return true;
509509
}
510510

@@ -517,7 +517,7 @@ bool V8::setWord(uint64_t pointer, Word word) {
517517
if (pointer + size > memory_->data_size()) {
518518
return false;
519519
}
520-
uint32_t word32 = htowasm(word.u32(), usesWasmByteOrder());
520+
uint32_t word32 = htowasm(word.u32(), true);
521521
::memcpy(memory_->data() + pointer, &word32, size);
522522
return true;
523523
}

src/wamr/wamr.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ bool Wamr::getWord(uint64_t pointer, Word *word) {
369369

370370
uint32_t word32;
371371
::memcpy(&word32, wasm_memory_data(memory_.get()) + pointer, size);
372-
word->u64_ = wasmtoh(word32, usesWasmByteOrder());
372+
word->u64_ = wasmtoh(word32, true);
373373
return true;
374374
}
375375

@@ -378,7 +378,7 @@ bool Wamr::setWord(uint64_t pointer, Word word) {
378378
if (pointer + size > wasm_memory_data_size(memory_.get())) {
379379
return false;
380380
}
381-
uint32_t word32 = htowasm(word.u32(), usesWasmByteOrder());
381+
uint32_t word32 = htowasm(word.u32(), true);
382382
::memcpy(wasm_memory_data(memory_.get()) + pointer, &word32, size);
383383
return true;
384384
}

src/wasmtime/wasmtime.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ bool Wasmtime::getWord(uint64_t pointer, Word *word) {
395395

396396
uint32_t word32;
397397
::memcpy(&word32, wasm_memory_data(memory_.get()) + pointer, size);
398-
word->u64_ = wasmtoh(word32, usesWasmByteOrder());
398+
word->u64_ = wasmtoh(word32, true);
399399
return true;
400400
}
401401

@@ -404,7 +404,7 @@ bool Wasmtime::setWord(uint64_t pointer, Word word) {
404404
if (pointer + size > wasm_memory_data_size(memory_.get())) {
405405
return false;
406406
}
407-
uint32_t word32 = htowasm(word.u32(), usesWasmByteOrder());
407+
uint32_t word32 = htowasm(word.u32(), true);
408408
::memcpy(wasm_memory_data(memory_.get()) + pointer, &word32, size);
409409
return true;
410410
}

src/wavm/wavm.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,12 +390,12 @@ bool Wavm::getWord(uint64_t pointer, Word *data) {
390390
auto *p = reinterpret_cast<char *>(memory_base_ + pointer);
391391
uint32_t data32;
392392
memcpy(&data32, p, sizeof(uint32_t));
393-
data->u64_ = wasmtoh(data32, usesWasmByteOrder());
393+
data->u64_ = wasmtoh(data32, true);
394394
return true;
395395
}
396396

397397
bool Wavm::setWord(uint64_t pointer, Word data) {
398-
uint32_t data32 = htowasm(data.u32(), usesWasmByteOrder());
398+
uint32_t data32 = htowasm(data.u32(), true);
399399
return setMemory(pointer, sizeof(uint32_t), &data32);
400400
}
401401

0 commit comments

Comments
 (0)