Skip to content

Commit

Permalink
fix a series of type mismatching
Browse files Browse the repository at this point in the history
misc
* add compiler options
* atomic instruction computation

Signed-off-by: Lîm Tsú-thuàn <[email protected]>
  • Loading branch information
dannypsnl committed Nov 14, 2023
1 parent c28d9ea commit a7c4a28
Show file tree
Hide file tree
Showing 21 changed files with 372 additions and 357 deletions.
22 changes: 11 additions & 11 deletions include/api/wasmedge/wasmedge.h
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ WASMEDGE_CAPI_EXPORT extern bool WasmEdge_ConfigureHasHostRegistration(
/// \param Page the maximum page count.
WASMEDGE_CAPI_EXPORT extern void
WasmEdge_ConfigureSetMaxMemoryPage(WasmEdge_ConfigureContext *Cxt,
const uint32_t Page);
const uint64_t Page);

/// Get the setting of the page limit of memory instances.
///
Expand All @@ -776,7 +776,7 @@ WasmEdge_ConfigureSetMaxMemoryPage(WasmEdge_ConfigureContext *Cxt,
/// setting.
///
/// \returns the page count limitation value.
WASMEDGE_CAPI_EXPORT extern uint32_t
WASMEDGE_CAPI_EXPORT extern uint64_t
WasmEdge_ConfigureGetMaxMemoryPage(const WasmEdge_ConfigureContext *Cxt);

/// Set the force interpreter mode execution option.
Expand Down Expand Up @@ -2657,8 +2657,8 @@ WasmEdge_MemoryInstanceGetMemoryType(const WasmEdge_MemoryInstanceContext *Cxt);
/// message.
WASMEDGE_CAPI_EXPORT extern WasmEdge_Result
WasmEdge_MemoryInstanceGetData(const WasmEdge_MemoryInstanceContext *Cxt,
uint8_t *Data, const uint32_t Offset,
const uint32_t Length);
uint8_t *Data, const uint64_t Offset,
const uint64_t Length);

/// Copy the data into a memory instance from the input buffer.
///
Expand All @@ -2672,8 +2672,8 @@ WasmEdge_MemoryInstanceGetData(const WasmEdge_MemoryInstanceContext *Cxt,
/// message.
WASMEDGE_CAPI_EXPORT extern WasmEdge_Result
WasmEdge_MemoryInstanceSetData(WasmEdge_MemoryInstanceContext *Cxt,
const uint8_t *Data, const uint32_t Offset,
const uint32_t Length);
const uint8_t *Data, const uint64_t Offset,
const uint64_t Length);

/// Get the data pointer in a memory instance.
///
Expand All @@ -2685,7 +2685,7 @@ WasmEdge_MemoryInstanceSetData(WasmEdge_MemoryInstanceContext *Cxt,
/// \returns the pointer to data with the start offset. NULL if failed.
WASMEDGE_CAPI_EXPORT extern uint8_t *
WasmEdge_MemoryInstanceGetPointer(WasmEdge_MemoryInstanceContext *Cxt,
const uint32_t Offset, const uint32_t Length);
const uint64_t Offset, const uint64_t Length);

/// Get the const data pointer in a const memory instance.
///
Expand All @@ -2697,15 +2697,15 @@ WasmEdge_MemoryInstanceGetPointer(WasmEdge_MemoryInstanceContext *Cxt,
/// \returns the pointer to data with the start offset. NULL if failed.
WASMEDGE_CAPI_EXPORT extern const uint8_t *
WasmEdge_MemoryInstanceGetPointerConst(
const WasmEdge_MemoryInstanceContext *Cxt, const uint32_t Offset,
const uint32_t Length);
const WasmEdge_MemoryInstanceContext *Cxt, const uint64_t Offset,
const uint64_t Length);

/// Get the current page size (64 KiB of each page) of a memory instance.
///
/// \param Cxt the WasmEdge_MemoryInstanceContext.
///
/// \returns the page size of the memory instance.
WASMEDGE_CAPI_EXPORT extern uint32_t
WASMEDGE_CAPI_EXPORT extern uint64_t
WasmEdge_MemoryInstanceGetPageSize(const WasmEdge_MemoryInstanceContext *Cxt);

/// Grow a memory instance with a page size.
Expand All @@ -2717,7 +2717,7 @@ WasmEdge_MemoryInstanceGetPageSize(const WasmEdge_MemoryInstanceContext *Cxt);
/// message.
WASMEDGE_CAPI_EXPORT extern WasmEdge_Result
WasmEdge_MemoryInstanceGrowPage(WasmEdge_MemoryInstanceContext *Cxt,
const uint32_t Page);
const uint64_t Page);

/// Deletion of the WasmEdge_MemoryInstanceContext.
///
Expand Down
26 changes: 13 additions & 13 deletions include/common/errinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,13 @@ struct InfoInstanceBound {

struct InfoForbidIndex {
InfoForbidIndex() = delete;
InfoForbidIndex(const IndexCategory Cate, const uint32_t Idx,
const uint32_t Bound) noexcept
InfoForbidIndex(const IndexCategory Cate, const uint64_t Idx,
const uint64_t Bound) noexcept
: Category(Cate), Index(Idx), Boundary(Bound) {}

IndexCategory Category;
uint32_t Index, Boundary;
uint64_t Index;
uint64_t Boundary;
};

struct InfoExporting {
Expand All @@ -83,12 +84,12 @@ struct InfoExporting {

struct InfoLimit {
InfoLimit() = delete;
InfoLimit(const bool HasMax, const uint32_t Min,
const uint32_t Max = 0) noexcept
InfoLimit(const bool HasMax, const uint64_t Min,
const uint64_t Max = 0) noexcept
: LimHasMax(HasMax), LimMin(Min), LimMax(Max) {}

bool LimHasMax;
uint32_t LimMin, LimMax;
uint64_t LimMin, LimMax;
};

struct InfoRegistering {
Expand Down Expand Up @@ -155,7 +156,6 @@ struct InfoMismatch {
const std::vector<ValType> &GotR) noexcept
: Category(MismatchCategory::FunctionType), ExpParams(ExpP),
GotParams(GotP), ExpReturns(ExpR), GotReturns(GotR) {}

/// Case 7: unexpected table types
InfoMismatch(const ValType &ExpRType,
// Expected reference type
Expand All @@ -174,11 +174,11 @@ struct InfoMismatch {
GotLimMax(GotMax) {}

/// Case 8: unexpected memory limits
InfoMismatch(const bool ExpHasMax, const uint32_t ExpMin,
const uint32_t ExpMax,
InfoMismatch(const bool ExpHasMax, const uint64_t ExpMin,
const uint64_t ExpMax,
// Expect Limit
const bool GotHasMax, const uint32_t GotMin,
const uint32_t GotMax
const bool GotHasMax, const uint64_t GotMin,
const uint64_t GotMax
// Got limit
) noexcept
: Category(MismatchCategory::Memory), ExpLimHasMax(ExpHasMax),
Expand Down Expand Up @@ -220,8 +220,8 @@ struct InfoMismatch {
ValMut ExpValMut, GotValMut;
/// Case 7 & 8: unexpected table or memory type: limit
bool ExpLimHasMax, GotLimHasMax;
uint32_t ExpLimMin, GotLimMin;
uint32_t ExpLimMax, GotLimMax;
uint64_t ExpLimMin, GotLimMin;
uint64_t ExpLimMax, GotLimMax;

/// Case 10: unexpected version
uint32_t ExpVersion, GotVersion;
Expand Down
3 changes: 3 additions & 0 deletions include/driver/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ struct DriverCompilerOptions {
PropTailCall(PO::Description("Enable Tail-call proposal"sv)),
PropExtendConst(PO::Description("Enable Extended-const proposal"sv)),
PropThreads(PO::Description("Enable Threads proposal"sv)),
PropMemory64(PO::Description("Enable Memory64 proposal"sv)),
PropAll(PO::Description("Enable all features"sv)),
PropOptimizationLevel(
PO::Description("Optimization level, one of 0, 1, 2, 3, s, z."sv),
Expand All @@ -78,6 +79,7 @@ struct DriverCompilerOptions {
PO::Option<PO::Toggle> PropTailCall;
PO::Option<PO::Toggle> PropExtendConst;
PO::Option<PO::Toggle> PropThreads;
PO::Option<PO::Toggle> PropMemory64;
PO::Option<PO::Toggle> PropAll;
PO::Option<std::string> PropOptimizationLevel;

Expand All @@ -102,6 +104,7 @@ struct DriverCompilerOptions {
.add_option("enable-tail-call"sv, PropTailCall)
.add_option("enable-extended-const"sv, PropExtendConst)
.add_option("enable-threads"sv, PropThreads)
.add_option("enable-memory64"sv, PropMemory64)
.add_option("enable-all"sv, PropAll)
.add_option("optimize"sv, PropOptimizationLevel);
}
Expand Down
66 changes: 30 additions & 36 deletions include/executor/executor.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2019-2022 Second State INC
// SPDX-FileCopyrightText: 2019-2023 Second State INC

//===-- wasmedge/executor/executor.h - Executor class definition ----------===//
//
Expand All @@ -20,7 +20,9 @@
#include "common/defines.h"
#include "common/errcode.h"
#include "common/statistics.h"
#include "executor/executor.h"
#include "runtime/callingframe.h"
#include "runtime/instance/memory.h"
#include "runtime/instance/module.h"
#include "runtime/stackmgr.h"
#include "runtime/storemgr.h"
Expand Down Expand Up @@ -292,7 +294,7 @@ class Executor {

/// Helper function for get memory instance by index.
Runtime::Instance::MemoryInstance *
getMemInstByIdx(Runtime::StackManager &StackMgr, const uint32_t Idx) const;
getMemInstByIdx(Runtime::StackManager &StackMgr, const uint64_t Idx) const;

/// Helper function for get global instance by index.
Runtime::Instance::GlobalInstance *
Expand All @@ -304,7 +306,7 @@ class Executor {

/// Helper function for get data instance by index.
Runtime::Instance::DataInstance *
getDataInstByIdx(Runtime::StackManager &StackMgr, const uint32_t Idx) const;
getDataInstByIdx(Runtime::StackManager &StackMgr, const uint64_t Idx) const;
/// @}

/// \name Run instructions functions
Expand Down Expand Up @@ -636,23 +638,23 @@ class Executor {
const uint32_t TableIdx, const uint32_t FuncTypeIdx,
const uint32_t FuncIdx, const ValVariant *Args,
ValVariant *Rets) noexcept;
Expect<uint32_t> memGrow(Runtime::StackManager &StackMgr,
const uint32_t MemIdx,
const uint32_t NewSize) noexcept;
Expect<uint32_t> memSize(Runtime::StackManager &StackMgr,
const uint32_t MemIdx) noexcept;
Expect<uint64_t> memGrow(Runtime::StackManager &StackMgr,
const uint64_t MemIdx,
const uint64_t NewSize) noexcept;
Expect<uint64_t> memSize(Runtime::StackManager &StackMgr,
const uint64_t MemIdx) noexcept;
Expect<void> memCopy(Runtime::StackManager &StackMgr,
const uint32_t DstMemIdx, const uint32_t SrcMemIdx,
const uint32_t DstOff, const uint32_t SrcOff,
const uint32_t Len) noexcept;
Expect<void> memFill(Runtime::StackManager &StackMgr, const uint32_t MemIdx,
const uint32_t Off, const uint8_t Val,
const uint32_t Len) noexcept;
Expect<void> memInit(Runtime::StackManager &StackMgr, const uint32_t MemIdx,
const uint32_t DataIdx, const uint32_t DstOff,
const uint32_t SrcOff, const uint32_t Len) noexcept;
const uint64_t DstMemIdx, const uint64_t SrcMemIdx,
const uint64_t DstOff, const uint64_t SrcOff,
const uint64_t Len) noexcept;
Expect<void> memFill(Runtime::StackManager &StackMgr, const uint64_t MemIdx,
const uint64_t Off, const uint8_t Val,
const uint64_t Len) noexcept;
Expect<void> memInit(Runtime::StackManager &StackMgr, const uint64_t MemIdx,
const uint64_t DataIdx, const uint64_t DstOff,
const uint64_t SrcOff, const uint64_t Len) noexcept;
Expect<void> dataDrop(Runtime::StackManager &StackMgr,
const uint32_t DataIdx) noexcept;
const uint64_t DataIdx) noexcept;

Expect<RefVariant> tableGet(Runtime::StackManager &StackMgr,
const uint32_t TableIdx,
Expand Down Expand Up @@ -684,13 +686,13 @@ class Executor {
const uint32_t TableIdx,
const uint32_t FuncTypeIdx,
const uint32_t FuncIdx) noexcept;
Expect<uint32_t> memoryAtomicNotify(Runtime::StackManager &StackMgr,
const uint32_t MemIdx,
const uint32_t Offset,
const uint32_t Count) noexcept;
Expect<uint32_t>
memoryAtomicWait(Runtime::StackManager &StackMgr, const uint32_t MemIdx,
const uint32_t Offset, const uint64_t Expected,
Expect<uint64_t> memoryAtomicNotify(Runtime::StackManager &StackMgr,
const uint64_t MemIdx,
const uint64_t Offset,
const uint64_t Count) noexcept;
Expect<uint64_t>
memoryAtomicWait(Runtime::StackManager &StackMgr, const uint64_t MemIdx,
const uint64_t Offset, const uint64_t Expected,
const int64_t Timeout, const uint32_t BitWidth) noexcept;
Expect<void> callRef(Runtime::StackManager &StackMgr, const RefVariant Ref,
const ValVariant *Args, ValVariant *Rets) noexcept;
Expand All @@ -707,8 +709,8 @@ class Executor {
Expect<uint64_t> atomicWait(Runtime::Instance::MemoryInstance &MemInst,
uint64_t Address, T Expected,
int64_t Timeout) noexcept;
Expect<uint32_t> atomicNotify(Runtime::Instance::MemoryInstance &MemInst,
uint64_t Address, uint32_t Count) noexcept;
Expect<uint64_t> atomicNotify(Runtime::Instance::MemoryInstance &MemInst,
uint64_t Address, uint64_t Count) noexcept;
void atomicNotifyAll() noexcept;

struct Waiter {
Expand All @@ -718,7 +720,7 @@ class Executor {
Waiter(Runtime::Instance::MemoryInstance *Inst) noexcept : MemInst(Inst) {}
};
std::mutex WaiterMapMutex;
std::unordered_multimap<uint32_t, Waiter> WaiterMap;
std::unordered_multimap<uint64_t, Waiter> WaiterMap;

private:
/// Prepare execution context
Expand Down Expand Up @@ -767,14 +769,6 @@ class Executor {
HostFuncHandler HostFuncHelper = {};
};

// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2019-2022 Second State INC

#include "executor/executor.h"
#include "runtime/instance/memory.h"

#include <cstdint>

// If `memoryOffset + instruction Value` is overflow, it's an out of bound
// access, trap.
template <uint32_t BitWidth>
Expand Down
6 changes: 3 additions & 3 deletions include/runtime/instance/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ namespace Instance {
class DataInstance {
public:
DataInstance() = delete;
DataInstance(const uint32_t Offset, Span<const Byte> Init) noexcept
DataInstance(const uint64_t Offset, Span<const Byte> Init) noexcept
: Off(Offset), Data(Init.begin(), Init.end()) {}

/// Get offset in data instance.
uint32_t getOffset() const noexcept { return Off; }
uint64_t getOffset() const noexcept { return Off; }

/// Get data in data instance.
Span<const Byte> getData() const noexcept { return Data; }
Expand All @@ -40,7 +40,7 @@ class DataInstance {
private:
/// \name Data of data instance.
/// @{
const uint32_t Off;
const uint64_t Off;
std::vector<Byte> Data;
/// @}
};
Expand Down
4 changes: 2 additions & 2 deletions include/runtime/instance/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ class MemoryInstance {

/// Get array of object at specific offset of memory.
template <typename T>
Span<T> getSpan(uint64_t Offset, uint32_t Size) const noexcept {
uint32_t ByteSize = static_cast<uint32_t>(sizeof(T) * Size);
Span<T> getSpan(uint64_t Offset, uint64_t Size) const noexcept {
uint64_t ByteSize = sizeof(T) * Size;
if (unlikely(!checkAccessBound(Offset, ByteSize))) {
return Span<T>();
}
Expand Down
4 changes: 2 additions & 2 deletions include/runtime/instance/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ class ModuleInstance {
}
return unsafeGetMemory(Idx);
}
MemoryInstance *unsafeGetMemory(uint32_t Idx) const noexcept {
MemoryInstance *unsafeGetMemory(uint64_t Idx) const noexcept {
return MemInsts[Idx];
}
Expect<GlobalInstance *> getGlobal(uint32_t Idx) const noexcept {
Expand Down Expand Up @@ -324,7 +324,7 @@ class ModuleInstance {
}
return unsafeGetData(Idx);
}
DataInstance *unsafeGetData(uint32_t Idx) const noexcept {
DataInstance *unsafeGetData(uint64_t Idx) const noexcept {
return DataInsts[Idx];
}

Expand Down

0 comments on commit a7c4a28

Please sign in to comment.