Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cheri-build] Add conditionals for building with CHERI. #1

Open
wants to merge 1 commit into
base: 10.4.132.20_cheri_codegen
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/base/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
#include "src/base/compiler-specific.h"
#include "src/base/logging.h"
#include "src/base/platform/wrappers.h"
#if defined(__CHERI_PURE_CAPABILITY__)
#include "src/common/cheri.h"
#endif // defined(__CHERI_PURE_CAPABILITY__)

// No-op macro which is used to work around MSVC's funky VA_ARGS support.
#define EXPAND(x) x
Expand Down
6 changes: 3 additions & 3 deletions src/builtins/arm64/builtins-arm64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2469,9 +2469,9 @@ static void Generate_InterpreterEnterBytecode(MacroAssembler* masm) {
#else // defined(__CHERI_PURE_CAPABILITY__)
__ Ldr(x1, MemOperand(fp, StandardFrameConstants::kFunctionOffset));
__ LoadTaggedPointerField(
x1, FieldMemOperand(c1, JSFunction::kSharedFunctionInfoOffset));
x1, FieldMemOperand(x1, JSFunction::kSharedFunctionInfoOffset));
__ LoadTaggedPointerField(
x1, FieldMemOperand(c1, SharedFunctionInfo::kFunctionDataOffset));
x1, FieldMemOperand(x1, SharedFunctionInfo::kFunctionDataOffset));
__ CompareObjectType(x1, kInterpreterDispatchTableRegister,
kInterpreterDispatchTableRegister,
#endif // defined(__CHERI_PURE_CAPABILITY__)
Expand Down Expand Up @@ -2828,7 +2828,7 @@ void OnStackReplacement(MacroAssembler* masm, OsrSourceTier source,
#if defined(__CHERI_PURE_CAPABILITY__)
c1, FieldMemOperand(x1, FixedArray::OffsetOfElementAt(
#else // defined(__CHERI_PURE_CAPABILITY__)
c1, FieldMemOperand(x1, FixedArray::OffsetOfElementAt(
x1, FieldMemOperand(x1, FixedArray::OffsetOfElementAt(
#endif // defined(__CHERI_PURE_CAPABILITY__)
DeoptimizationData::kOsrPcOffsetIndex)));

Expand Down
4 changes: 4 additions & 0 deletions src/codegen/arm64/instructions-arm64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ bool Instruction::IsLoad() const {

bool Instruction::IsStore() const {
if (Mask(LoadStoreAnyFMask) == LoadStoreAnyFixed) {
#if defined(__CHERI_PURE_CAPABILITY__)
LoadStoreOp op = static_cast<LoadStoreOp>(Mask(LoadStoreCapMask));
#else
LoadStoreOp op = static_cast<LoadStoreOp>(Mask(LoadStoreMask));
#endif // __CHERI_PURE_CAPABILITY__
switch (op) {
case STRB_w:
case STRH_w:
Expand Down
16 changes: 16 additions & 0 deletions src/codegen/arm64/macro-assembler-arm64-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,17 @@ void TurboAssembler::Add(const Register& rd, const Register& rn,
DCHECK(allow_macro_instructions());
if (operand.IsImmediate() && (operand.ImmediateValue() < 0) &&
IsImmAddSub(-operand.ImmediateValue())) {
#if defined(__CHERI_PURE_CAPABILITY__)
AddSubMacro(rd, rn, -operand.ImmediateValue(), LeaveFlags, SubOpFor(rd));
#else
AddSubMacro(rd, rn, -operand.ImmediateValue(), LeaveFlags, SUB);
#endif // defined(__CHERI_PURE_CAPABILITY__)
} else {
#if defined(__CHERI_PURE_CAPABILITY__)
AddSubMacro(rd, rn, operand, LeaveFlags, AddOpFor(rd));
#else
AddSubMacro(rd, rn, operand, LeaveFlags, ADD);
#endif // defined(__CHERI_PURE_CAPABILITY__)
}
}

Expand Down Expand Up @@ -290,9 +298,17 @@ void TurboAssembler::Sub(const Register& rd, const Register& rn,
DCHECK(allow_macro_instructions());
if (operand.IsImmediate() && (operand.ImmediateValue() < 0) &&
IsImmAddSub(-operand.ImmediateValue())) {
#if defined(__CHERI_PURE_CAPABILITY__)
AddSubMacro(rd, rn, -operand.ImmediateValue(), LeaveFlags, AddOpFor(rd));
#else
AddSubMacro(rd, rn, -operand.ImmediateValue(), LeaveFlags, ADD);
#endif // __CHERI_PURE_CAPABILITY__
} else {
#if defined(__CHERI_PURE_CAPABILITY__)
AddSubMacro(rd, rn, operand, LeaveFlags, SubOpFor(rd));
#else
AddSubMacro(rd, rn, operand, LeaveFlags, SUB);
#endif // __CHERI_PURE_CAPABILITY__
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/common/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ constexpr size_t kMaxWasmCodeMemory = kMaxWasmCodeMB * MB;
#if defined(V8_HOST_CHERI_PURE_CAPABILITY)
constexpr int kSystemPointerSizeLog2 = 4;
#else
constexpr int kPtrAddrSizeLog2 = 3;
constexpr int kSystemPointerSizeLog2 = 3;
#endif
constexpr int kSystemPointerAddrSizeLog2 = 3;
constexpr int kPtrAddrSizeLog2 = 3;
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/machine-operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ class StoreRepresentation final {
public:
StoreRepresentation(MachineRepresentation representation,
WriteBarrierKind write_barrier_kind)
#if defined(__CHERI_PURE_CAPABILITY__)
: machine_type_(MachineType(representation, MachineSemantic::kCapability)),
#else
: machine_type_(MachineType(representation, MachineSemantic::kAny)),
#endif // defined(__CHERI_PURE_CAPABILITY__)
write_barrier_kind_(write_barrier_kind) {}

StoreRepresentation(MachineType machine_type,
Expand Down
8 changes: 8 additions & 0 deletions src/sandbox/external-pointer-table.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,21 @@ class V8_EXPORT_PRIVATE ExternalPointerTable {

// Atomically loads the value at the given index.
inline Address load_atomic(uint32_t index) const {
#if defined(__CHERI_PURE_CAPABILITY__)
auto addr = reinterpret_cast<base::AtomicIntPtr*>(entry_address(index));
#else
auto addr = reinterpret_cast<base::Atomic64*>(entry_address(index));
#endif // defined(__CHERI_PURE_CAPABILITY__)
return base::Relaxed_Load(addr);
}

// Atomically stores the provided value at the given index.
inline void store_atomic(uint32_t index, Address value) {
#if defined(__CHERI_PURE_CAPABILITY__)
auto addr = reinterpret_cast<base::AtomicIntPtr*>(entry_address(index));
#else
auto addr = reinterpret_cast<base::Atomic64*>(entry_address(index));
#endif // defined(__CHERI_PURE_CAPABILITY__)
base::Relaxed_Store(addr, value);
}

Expand Down
4 changes: 4 additions & 0 deletions src/tracing/trace-event.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ enum CategoryGroupEnabledFlags {

// Defines atomic operations used internally by the tracing system.
// Acquire/release barriers are important here: crbug.com/1330114#c8.
#if defined(__CHERI_PURE_CAPABILITY__)
#define TRACE_EVENT_API_ATOMIC_WORD v8::base::AtomicIntPtr
#else
#define TRACE_EVENT_API_ATOMIC_WORD v8::base::AtomicWord
#endif // defined(__CHERI_PURE_CAPABILITY__)
#define TRACE_EVENT_API_ATOMIC_LOAD(var) v8::base::Acquire_Load(&(var))
#define TRACE_EVENT_API_ATOMIC_STORE(var, value) \
v8::base::Release_Store(&(var), (value))
Expand Down