[Codestyle] More clang-tidy fixes after codestyle

Issue: #I8RW9U

Testing: ninja all tests

Signed-off-by: Petrov Igor <petrov.826961@huawei.com>
This commit is contained in:
Petrov Igor 2024-01-12 06:47:53 +03:00
parent 29a051c51f
commit 6268e5b411
29 changed files with 400 additions and 398 deletions

View File

@ -2731,7 +2731,7 @@ void Aarch64Encoder::LoadStoreRegisters(RegMask registers, bool isFp, int32_t sl
template <bool IS_STORE>
void Aarch64Encoder::LoadStoreRegistersLoop(RegMask registers, ssize_t slot, size_t startReg, bool isFp,
const vixl::aarch64::Register &base_reg)
const vixl::aarch64::Register &baseReg)
{
size_t i = 0;
const auto getNextReg = [&registers, &i, isFp]() {
@ -2750,19 +2750,19 @@ void Aarch64Encoder::LoadStoreRegistersLoop(RegMask registers, ssize_t slot, siz
if (nextReg.IsValid() && (nextReg.GetCode() - 1 == currReg.GetCode())) {
if constexpr (IS_STORE) { // NOLINT
GetMasm()->Stp(currReg, nextReg,
MemOperand(base_reg, (slot + currReg.GetCode() - startReg) * DOUBLE_WORD_SIZE_BYTES));
MemOperand(baseReg, (slot + currReg.GetCode() - startReg) * DOUBLE_WORD_SIZE_BYTES));
} else { // NOLINT
GetMasm()->Ldp(currReg, nextReg,
MemOperand(base_reg, (slot + currReg.GetCode() - startReg) * DOUBLE_WORD_SIZE_BYTES));
MemOperand(baseReg, (slot + currReg.GetCode() - startReg) * DOUBLE_WORD_SIZE_BYTES));
}
nextReg = getNextReg();
} else {
if constexpr (IS_STORE) { // NOLINT
GetMasm()->Str(currReg,
MemOperand(base_reg, (slot + currReg.GetCode() - startReg) * DOUBLE_WORD_SIZE_BYTES));
MemOperand(baseReg, (slot + currReg.GetCode() - startReg) * DOUBLE_WORD_SIZE_BYTES));
} else { // NOLINT
GetMasm()->Ldr(currReg,
MemOperand(base_reg, (slot + currReg.GetCode() - startReg) * DOUBLE_WORD_SIZE_BYTES));
MemOperand(baseReg, (slot + currReg.GetCode() - startReg) * DOUBLE_WORD_SIZE_BYTES));
}
}
}

View File

@ -82,10 +82,10 @@ void InstBuilder::BuildCall(const BytecodeInstruction *bcInst, bool isRange, boo
}
}
template void InstBuilder::BuildCall<Opcode::CallLaunchStatic>(const BytecodeInstruction *bc_inst, bool is_range,
bool acc_read, Inst *additional_input);
template void InstBuilder::BuildCall<Opcode::CallLaunchVirtual>(const BytecodeInstruction *bc_inst, bool is_range,
bool acc_read, Inst *additional_input);
template void InstBuilder::BuildCall<Opcode::CallLaunchStatic>(const BytecodeInstruction *bcInst, bool isRange,
bool accRead, Inst *additionalInput);
template void InstBuilder::BuildCall<Opcode::CallLaunchVirtual>(const BytecodeInstruction *bcInst, bool isRange,
bool accRead, Inst *additionalInput);
// NOLINTNEXTLINE(misc-definitions-in-headers)
template <typename T>
@ -319,8 +319,7 @@ BinaryOperation *CreateBinaryOperation<Opcode::Mod>(Graph *graph, DataType::Type
return graph->CreateInstMod(returnType, pc);
}
template void InstBuilder::BuildBinaryOperationIntrinsic<Opcode::Mod>(const BytecodeInstruction *bc_inst,
bool acc_read);
template void InstBuilder::BuildBinaryOperationIntrinsic<Opcode::Mod>(const BytecodeInstruction *bcInst, bool accRead);
template <Opcode OPCODE>
void InstBuilder::BuildBinaryOperationIntrinsic(const BytecodeInstruction *bcInst, bool accRead)
@ -593,48 +592,48 @@ void InstBuilder::BuildDefaultIntrinsic(bool isVirtual, const BytecodeInstructio
// do not specify reason for tidy suppression because comment does not fit single line
// NOLINTNEXTLINE
void InstBuilder::BuildStaticCallIntrinsic(const BytecodeInstruction *bc_inst, bool is_range, bool acc_read)
void InstBuilder::BuildStaticCallIntrinsic(const BytecodeInstruction *bcInst, bool isRange, bool accRead)
{
auto methodIndex = bc_inst->GetId(0).AsIndex();
auto methodIndex = bcInst->GetId(0).AsIndex();
auto methodId = GetRuntime()->ResolveMethodIndex(GetMethod(), methodIndex);
auto method = GetRuntime()->GetMethodById(GetMethod(), methodId);
auto intrinsicId = GetRuntime()->GetIntrinsicId(method);
switch (intrinsicId) {
case RuntimeInterface::IntrinsicId::INTRINSIC_OBJECT_MONITOR_ENTER:
case RuntimeInterface::IntrinsicId::INTRINSIC_OBJECT_MONITOR_EXIT: {
BuildMonitorIntrinsic(bc_inst, intrinsicId == RuntimeInterface::IntrinsicId::INTRINSIC_OBJECT_MONITOR_ENTER,
acc_read);
BuildMonitorIntrinsic(bcInst, intrinsicId == RuntimeInterface::IntrinsicId::INTRINSIC_OBJECT_MONITOR_ENTER,
accRead);
break;
}
case RuntimeInterface::IntrinsicId::INTRINSIC_MATH_ABS_I32:
case RuntimeInterface::IntrinsicId::INTRINSIC_MATH_ABS_I64:
case RuntimeInterface::IntrinsicId::INTRINSIC_MATH_ABS_F32:
case RuntimeInterface::IntrinsicId::INTRINSIC_MATH_ABS_F64: {
BuildAbsIntrinsic(bc_inst, acc_read);
BuildAbsIntrinsic(bcInst, accRead);
break;
}
case RuntimeInterface::IntrinsicId::INTRINSIC_MATH_SQRT_F32:
case RuntimeInterface::IntrinsicId::INTRINSIC_MATH_SQRT_F64: {
BuildSqrtIntrinsic(bc_inst, acc_read);
BuildSqrtIntrinsic(bcInst, accRead);
break;
}
case RuntimeInterface::IntrinsicId::INTRINSIC_MATH_MIN_I32:
case RuntimeInterface::IntrinsicId::INTRINSIC_MATH_MIN_I64:
case RuntimeInterface::IntrinsicId::INTRINSIC_MATH_MIN_F32:
case RuntimeInterface::IntrinsicId::INTRINSIC_MATH_MIN_F64: {
BuildBinaryOperationIntrinsic<Opcode::Min>(bc_inst, acc_read);
BuildBinaryOperationIntrinsic<Opcode::Min>(bcInst, accRead);
break;
}
case RuntimeInterface::IntrinsicId::INTRINSIC_MATH_MAX_I32:
case RuntimeInterface::IntrinsicId::INTRINSIC_MATH_MAX_I64:
case RuntimeInterface::IntrinsicId::INTRINSIC_MATH_MAX_F32:
case RuntimeInterface::IntrinsicId::INTRINSIC_MATH_MAX_F64: {
BuildBinaryOperationIntrinsic<Opcode::Max>(bc_inst, acc_read);
BuildBinaryOperationIntrinsic<Opcode::Max>(bcInst, accRead);
break;
}
#include "intrinsics_ir_build_static_call.inl"
default: {
BuildDefaultStaticIntrinsic(bc_inst, is_range, acc_read);
BuildDefaultStaticIntrinsic(bcInst, isRange, accRead);
}
}
}

View File

@ -41,9 +41,9 @@ Graph* GenerateIntrinsicOperation(Inst* inst) {
ASSERT(graph->GetVectorBlocks().size() > 2);
auto block = graph->GetVectorBlocks()[2];
if (inst->RequireState()) {
auto save_state = graph->CreateInstSaveState();
block->AppendInst(save_state);
inst->AppendInput(save_state);
auto saveState = graph->CreateInstSaveState();
block->AppendInst(saveState);
inst->AppendInput(saveState);
inst->CastToIntrinsic()->AddInputType(DataType::NO_TYPE);
}
block->AppendInst(inst);

View File

@ -1,5 +1,5 @@
/**
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -17,7 +17,7 @@
template<>
// NOLINTNEXTLINE(readability-function-size)
std::vector<Inst*>& InstGenerator::GenerateOperations<IntrinsicInst>([[maybe_unused]] Opcode op_code) {
std::vector<Inst*>& InstGenerator::GenerateOperations<IntrinsicInst>([[maybe_unused]] Opcode opCode) {
% Compiler::intrinsics.select(&:has_impl?).each do |intrinsic|
% # dynamic intrinsics doesn't support in inst_generator
% next if intrinsic.is_dynamic?

View File

@ -39,18 +39,18 @@ os::unique_fd::UniqueFd CreateUnixServerSocket(int backlog)
return os::unique_fd::UniqueFd();
}
struct sockaddr_un server_addr {};
if (memset_s(&server_addr, sizeof(server_addr), 0, sizeof(server_addr)) != EOK) {
struct sockaddr_un serverAddr {};
if (memset_s(&serverAddr, sizeof(serverAddr), 0, sizeof(serverAddr)) != EOK) {
PLOG(ERROR, DPROF) << "CreateUnixServerSocket memset_s failed";
UNREACHABLE();
}
server_addr.sun_family = AF_UNIX;
if (memcpy_s(server_addr.sun_path, sizeof(SOCKET_NAME), SOCKET_NAME, sizeof(SOCKET_NAME)) != EOK) {
serverAddr.sun_family = AF_UNIX;
if (memcpy_s(serverAddr.sun_path, sizeof(SOCKET_NAME), SOCKET_NAME, sizeof(SOCKET_NAME)) != EOK) {
PLOG(ERROR, DPROF) << "CreateUnixServerSocket memcpy_s failed";
UNREACHABLE();
}
if (PANDA_FAILURE_RETRY(
::bind(sock.Get(), reinterpret_cast<struct sockaddr *>(&server_addr), sizeof(server_addr))) == -1) {
if (PANDA_FAILURE_RETRY(::bind(sock.Get(), reinterpret_cast<struct sockaddr *>(&serverAddr), sizeof(serverAddr))) ==
-1) {
PLOG(ERROR, DPROF) << "bind() failed";
return os::unique_fd::UniqueFd();
}
@ -71,18 +71,18 @@ os::unique_fd::UniqueFd CreateUnixClientSocket()
return os::unique_fd::UniqueFd();
}
struct sockaddr_un server_addr {};
if (memset_s(&server_addr, sizeof(server_addr), 0, sizeof(server_addr)) != EOK) {
struct sockaddr_un serverAddr {};
if (memset_s(&serverAddr, sizeof(serverAddr), 0, sizeof(serverAddr)) != EOK) {
PLOG(ERROR, DPROF) << "CreateUnixClientSocket memset_s failed";
UNREACHABLE();
}
server_addr.sun_family = AF_UNIX;
if (memcpy_s(server_addr.sun_path, sizeof(SOCKET_NAME), SOCKET_NAME, sizeof(SOCKET_NAME)) != EOK) {
serverAddr.sun_family = AF_UNIX;
if (memcpy_s(serverAddr.sun_path, sizeof(SOCKET_NAME), SOCKET_NAME, sizeof(SOCKET_NAME)) != EOK) {
PLOG(ERROR, DPROF) << "CreateUnixClientSocket memcpy_s failed";
UNREACHABLE();
}
if (PANDA_FAILURE_RETRY(
::connect(sock.Get(), reinterpret_cast<struct sockaddr *>(&server_addr), sizeof(server_addr))) == -1) {
::connect(sock.Get(), reinterpret_cast<struct sockaddr *>(&serverAddr), sizeof(serverAddr))) == -1) {
PLOG(ERROR, DPROF) << "connect() failed";
return os::unique_fd::UniqueFd();
}
@ -107,13 +107,13 @@ bool SendAll(int fd, const void *buf, int len)
return true;
}
bool WaitDataTimeout(int fd, int timeout_ms)
bool WaitDataTimeout(int fd, int timeoutMs)
{
struct pollfd pfd {};
pfd.fd = fd;
pfd.events = POLLIN;
int rc = PANDA_FAILURE_RETRY(::poll(&pfd, 1, timeout_ms));
int rc = PANDA_FAILURE_RETRY(::poll(&pfd, 1, timeoutMs));
if (rc == 1) {
// Success
return true;
@ -133,9 +133,9 @@ bool WaitDataTimeout(int fd, int timeout_ms)
return false;
}
int RecvTimeout(int fd, void *buf, int len, int timeout_ms)
int RecvTimeout(int fd, void *buf, int len, int timeoutMs)
{
if (!WaitDataTimeout(fd, timeout_ms)) {
if (!WaitDataTimeout(fd, timeoutMs)) {
LOG(ERROR, DPROF) << "Cannot get access to data";
return -1;
}

View File

@ -33,9 +33,9 @@ class UsedRegistersCollector : public vixl::aarch64::Disassembler {
public:
explicit UsedRegistersCollector(panda::ArenaAllocator *allocator) : Disassembler(allocator) {}
RegMask &GetUsedRegs(bool is_fp)
RegMask &GetUsedRegs(bool isFp)
{
return is_fp ? vreg_mask_ : reg_mask_;
return isFp ? vregMask_ : regMask_;
}
static UsedRegisters CollectForCode(ArenaAllocator *allocator, Span<const uint8_t> code)
@ -44,12 +44,12 @@ public:
ASSERT(!code.Empty());
vixl::aarch64::Decoder decoder(allocator);
UsedRegistersCollector used_regs_collector(allocator);
decoder.AppendVisitor(&used_regs_collector);
UsedRegistersCollector usedRegsCollector(allocator);
decoder.AppendVisitor(&usedRegsCollector);
bool skipping = false;
auto start_instr = reinterpret_cast<const vixl::aarch64::Instruction *>(code.data());
auto end_instr = reinterpret_cast<const vixl::aarch64::Instruction *>(&(*code.end()));
auto startInstr = reinterpret_cast<const vixl::aarch64::Instruction *>(code.data());
auto endInstr = reinterpret_cast<const vixl::aarch64::Instruction *>(&(*code.end()));
// To determine real registers usage we check each assembly instruction which has
// destination register(s). There is a problem with handlers with `return` cause
// there is an epilogue part with registers restoring. We need to separate both register
@ -65,23 +65,23 @@ public:
// instructions (assuming they are related to epilogue part) but without adding their
// registers into the result set. If we meet another kind of intruction we unset
// the `skipping` flag.
for (auto instr = used_regs_collector.GetPrevInstruction(end_instr); instr >= start_instr;
instr = used_regs_collector.GetPrevInstruction(instr)) {
for (auto instr = usedRegsCollector.GetPrevInstruction(endInstr); instr >= startInstr;
instr = usedRegsCollector.GetPrevInstruction(instr)) {
if (instr->Mask(vixl::aarch64::UnconditionalBranchToRegisterMask) == vixl::aarch64::RET) {
skipping = true;
continue;
}
if (skipping && (instr->IsLoad() || used_regs_collector.CheckSPAdd(instr))) {
if (skipping && (instr->IsLoad() || usedRegsCollector.CheckSPAdd(instr))) {
continue;
}
skipping = false;
decoder.Decode(instr);
}
UsedRegisters used_registers;
used_registers.gpr |= used_regs_collector.GetUsedRegs(false);
used_registers.fp |= used_regs_collector.GetUsedRegs(true);
return used_registers;
UsedRegisters usedRegisters;
usedRegisters.gpr |= usedRegsCollector.GetUsedRegs(false);
usedRegisters.fp |= usedRegsCollector.GetUsedRegs(true);
return usedRegisters;
}
protected:
@ -106,24 +106,24 @@ protected:
}
uint32_t code = reg.GetCode();
// We need to account for both registers in case of a pair load
bool is_pair = instr->Mask(vixl::aarch64::LoadStorePairAnyFMask) == vixl::aarch64::LoadStorePairAnyFixed;
bool isPair = instr->Mask(vixl::aarch64::LoadStorePairAnyFMask) == vixl::aarch64::LoadStorePairAnyFixed;
if (!(code == static_cast<uint32_t>(instr->GetRd()) ||
(is_pair && code == static_cast<uint32_t>(instr->GetRt2())))) {
(isPair && code == static_cast<uint32_t>(instr->GetRt2())))) {
return;
}
if (reg.IsRegister()) {
if (!reg.IsZero()) {
reg_mask_.Set(code);
regMask_.Set(code);
}
} else {
ASSERT(reg.IsVRegister());
vreg_mask_.Set(code);
vregMask_.Set(code);
}
}
private:
RegMask reg_mask_;
VRegMask vreg_mask_;
RegMask regMask_;
VRegMask vregMask_;
};
#endif // ifdef LLVM_INTERPRETER_CHECK_REGS_MASK

View File

@ -18,6 +18,7 @@ llvm::FunctionType *GetEntrypointDeclaration(llvm::LLVMContext &ctx, llvm::Modul
{
constexpr auto GC_SPACE = panda::llvmbackend::LLVMArkInterface::GC_ADDR_SPACE;
// We hope that ARK will not use segmentated memory and size_t will have the same width as uintptr_t
// NOLINTNEXTLINE(readability-identifier-naming)
auto size_type = llvm::Type::getIntNTy(ctx, module->getDataLayout().getPointerSizeInBits(0));
switch (id) {
% Compiler::entrypoints.each do |entrypoint|

View File

@ -53,7 +53,7 @@ public:
static InlinePrepare Create(LLVMArkInterface *arkInterface, const panda::llvmbackend::LLVMCompilerOptions *options);
// NOLINTNEXTLINE(readability-identifier-naming)
llvm::PreservedAnalyses run(llvm::Module &module, llvm::ModuleAnalysisManager &module_am);
llvm::PreservedAnalyses run(llvm::Module &module, llvm::ModuleAnalysisManager &moduleAm);
};
} // namespace panda::llvmbackend::passes

View File

@ -36,7 +36,7 @@ public:
}
// NOLINTNEXTLINE(readability-identifier-naming)
llvm::PreservedAnalyses run(llvm::Function &function, llvm::FunctionAnalysisManager &analysis_manager);
llvm::PreservedAnalyses run(llvm::Function &function, llvm::FunctionAnalysisManager &analysisManager);
private:
bool InsertAddrSpaceCast(llvm::Instruction *atomicInstruction);

View File

@ -122,26 +122,26 @@ bool IterateDieRanges([[maybe_unused]] F func, [[maybe_unused]] Dwarf_Attribute
{
#ifdef HAVE_DWARF_RNGLISTS_API
Dwarf_Rnglists_Head rnglhead = nullptr;
Dwarf_Unsigned count_rnglists_entries = 0;
if (dwarf_rnglists_get_rle_head(attr, form, offset, &rnglhead, &count_rnglists_entries, nullptr, nullptr) ==
Dwarf_Unsigned countRnglistsEntries = 0;
if (dwarf_rnglists_get_rle_head(attr, form, offset, &rnglhead, &countRnglistsEntries, nullptr, nullptr) ==
DW_DLV_OK) {
AtReturn r([rnglhead]() { dwarf_dealloc_rnglists_head(rnglhead); });
for (Dwarf_Unsigned i = 0; i < count_rnglists_entries; i++) {
unsigned rle_code = 0;
Dwarf_Bool no_debug_addr_available = false;
for (Dwarf_Unsigned i = 0; i < countRnglistsEntries; i++) {
unsigned rleCode = 0;
Dwarf_Bool noDebugAddrAvailable = false;
Dwarf_Unsigned cooked1 = 0;
Dwarf_Unsigned cooked2 = 0;
if (dwarf_get_rnglists_entry_fields_a(rnglhead, i, nullptr, &rle_code, nullptr, nullptr,
&no_debug_addr_available, &cooked1, &cooked2, nullptr) != DW_DLV_OK) {
if (dwarf_get_rnglists_entry_fields_a(rnglhead, i, nullptr, &rleCode, nullptr, nullptr,
&noDebugAddrAvailable, &cooked1, &cooked2, nullptr) != DW_DLV_OK) {
return false;
}
if (rle_code == DW_RLE_base_addressx || rle_code == DW_RLE_base_address || no_debug_addr_available) {
if (rleCode == DW_RLE_base_addressx || rleCode == DW_RLE_base_address || noDebugAddrAvailable) {
continue;
}
if (rle_code == DW_RLE_end_of_list) {
if (rleCode == DW_RLE_end_of_list) {
break;
}

View File

@ -44,12 +44,12 @@ DfxOptionHandler::DfxOption DfxOptionHandler::DfxOptionFromString(const std::str
}
/* static */
std::string DfxOptionHandler::StringFromDfxOption(DfxOptionHandler::DfxOption dfx_option)
std::string DfxOptionHandler::StringFromDfxOption(DfxOptionHandler::DfxOption dfxOption)
{
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define D(e, v, str) \
if (dfx_option == DfxOptionHandler::DfxOption::e) { \
return (str); \
#define D(e, v, str) \
if (dfxOption == DfxOptionHandler::DfxOption::e) { \
return (str); \
}
DFX_OPTION_LIST(D)
#undef D

View File

@ -17,15 +17,15 @@
namespace panda::os::native_stack {
#if !defined(PANDA_TARGET_UNIX)
void DumpUnattachedThread::AddTid([[maybe_unused]] pid_t tid_thread) {}
void DumpUnattachedThread::AddTid([[maybe_unused]] pid_t tidThread) {}
bool DumpUnattachedThread::InitKernelTidLists()
{
return true;
}
void DumpUnattachedThread::Dump([[maybe_unused]] std::ostream &os, [[maybe_unused]] bool dump_native_crash,
[[maybe_unused]] FuncUnwindstack call_unwindstack)
void DumpUnattachedThread::Dump([[maybe_unused]] std::ostream &os, [[maybe_unused]] bool dumpNativeCrash,
[[maybe_unused]] FuncUnwindstack callUnwindstack)
{
}
void DumpKernelStack([[maybe_unused]] std::ostream &os, [[maybe_unused]] pid_t tid, [[maybe_unused]] const char *tag,

View File

@ -42,13 +42,13 @@ const auto ChangeJaveStackFormat = // NOLIN
using FuncUnwindstack = bool (*)(pid_t, std::ostream &, int);
class DumpUnattachedThread {
public:
void AddTid(pid_t tid_thread);
void AddTid(pid_t tidThread);
bool InitKernelTidLists();
void Dump(std::ostream &os, bool dump_native_crash, FuncUnwindstack call_unwindstack);
void Dump(std::ostream &os, bool dumpNativeCrash, FuncUnwindstack callUnwindstack);
private:
std::set<pid_t> kernel_tid_;
std::set<pid_t> thread_manager_tids_;
std::set<pid_t> kernelTid_;
std::set<pid_t> threadManagerTids_;
};
void DumpKernelStack(std::ostream &os, pid_t tid, const char *tag, bool count);
std::string GetNativeThreadNameForFile(pid_t tid);

View File

@ -66,9 +66,9 @@ Logger::ComponentMask Logger::ComponentMaskFromString(std::string_view s)
}
/* static */
std::string Logger::StringfromDfxComponent(LogDfxComponent dfx_component)
std::string Logger::StringfromDfxComponent(LogDfxComponent dfxComponent)
{
switch (dfx_component) {
switch (dfxComponent) {
% LoggerData.dfx_components.each do |c|
case Logger::LogDfxComponent::<%= c.enum %>:
return "<%= c.name %>";

View File

@ -38,19 +38,19 @@ protected:
void SetUp() override
{
os::unix::SignalCtl::GetCurrent(signal_ctl_);
sig_action_count_ = 0;
os::unix::SignalCtl::GetCurrent(signalCtl_);
sigActionCount_ = 0;
}
void TearDown() override
{
os::unix::SignalCtl signal_ctl;
os::unix::SignalCtl::GetCurrent(signal_ctl);
os::unix::SignalCtl signalCtl;
os::unix::SignalCtl::GetCurrent(signalCtl);
}
static void SigAction(int sig, UnixSignal *self)
{
self->sig_action_count_ += sig;
self->sigActionCount_ += sig;
}
static void Delay()
@ -60,27 +60,27 @@ protected:
void CheckSignalsInsideCycle(int signals)
{
uint32_t timeout_counter = 0;
uint32_t timeoutCounter = 0;
while (true) {
if (sig_action_count_ == signals) {
if (sigActionCount_ == signals) {
break;
}
++timeout_counter;
++timeoutCounter;
Delay();
ASSERT_NE(timeout_counter, max_timeout_counter_wait_) << "Timeout error: Signals not got in time";
ASSERT_NE(timeoutCounter, maxTimeoutCounterWait_) << "Timeout error: Signals not got in time";
}
}
static const uint32_t TIME_TO_WAIT = 100U * 1000U; // 0.1 second
// NOLINTNEXTLINE(misc-non-private-member-variables-in-classes)
const uint32_t max_timeout_counter_wait_ = 5U * 60U * 1000U * 1000U / TIME_TO_WAIT; // 5 minutes
const uint32_t maxTimeoutCounterWait_ = 5U * 60U * 1000U * 1000U / TIME_TO_WAIT; // 5 minutes
// NOLINTNEXTLINE(misc-non-private-member-variables-in-classes)
os::unix::SignalCtl signal_ctl_ {};
os::unix::SignalCtl signalCtl_ {};
// NOLINTNEXTLINE(misc-non-private-member-variables-in-classes)
std::atomic_int sig_action_count_ {0U};
std::atomic_int sigActionCount_ {0U};
};
TEST_F(UnixSignal, CheckRestoringSigSet)
@ -95,34 +95,34 @@ TEST_F(UnixSignal, CheckRestoringSigSet2)
sigaddset(&sigset, SIGUSR1);
pthread_sigmask(SIG_BLOCK, &sigset, nullptr);
os::unix::SignalCtl signal_ctl;
os::unix::SignalCtl::GetCurrent(signal_ctl);
ASSERT_NE(signal_ctl_, signal_ctl);
os::unix::SignalCtl signalCtl;
os::unix::SignalCtl::GetCurrent(signalCtl);
ASSERT_NE(signalCtl_, signalCtl);
pthread_sigmask(SIG_UNBLOCK, &sigset, nullptr);
}
TEST_F(UnixSignal, StartStopThread)
{
os::unix::SignalCatcherThread catcher_thread;
os::unix::SignalCatcherThread catcherThread;
catcher_thread.StartThread(&UnixSignal::SigAction, this);
catcher_thread.StopThread();
catcherThread.StartThread(&UnixSignal::SigAction, this);
catcherThread.StopThread();
}
TEST_F(UnixSignal, StartStopThreadCatchOnlyCatcherThread)
{
os::unix::SignalCatcherThread catcher_thread;
catcher_thread.CatchOnlyCatcherThread();
os::unix::SignalCatcherThread catcherThread;
catcherThread.CatchOnlyCatcherThread();
catcher_thread.StartThread(&UnixSignal::SigAction, this);
catcher_thread.StopThread();
catcherThread.StartThread(&UnixSignal::SigAction, this);
catcherThread.StopThread();
}
TEST_F(UnixSignal, SendSignalsToMainThread)
{
os::unix::SignalCatcherThread catcher_thread({SIGUSR1, SIGUSR2});
catcher_thread.StartThread(&UnixSignal::SigAction, this);
os::unix::SignalCatcherThread catcherThread({SIGUSR1, SIGUSR2});
catcherThread.StartThread(&UnixSignal::SigAction, this);
// Send signals to main thread
kill(getpid(), SIGUSR1);
@ -130,9 +130,9 @@ TEST_F(UnixSignal, SendSignalsToMainThread)
// Wait for the signals inside the cycle
CheckSignalsInsideCycle(SIGUSR1 + SIGUSR2);
catcher_thread.StopThread();
catcherThread.StopThread();
ASSERT_EQ(sig_action_count_, SIGUSR1 + SIGUSR2);
ASSERT_EQ(sigActionCount_, SIGUSR1 + SIGUSR2);
}
// The test fails on WSL
@ -141,19 +141,19 @@ TEST_F(UnixSignal, SendSignalsToMainThread2)
{
EXPECT_DEATH(
{
os::unix::SignalCatcherThread catcher_thread({SIGUSR1});
catcher_thread.CatchOnlyCatcherThread();
os::unix::SignalCatcherThread catcherThread({SIGUSR1});
catcherThread.CatchOnlyCatcherThread();
catcher_thread.StartThread(&UnixSignal::SigAction, this);
catcherThread.StartThread(&UnixSignal::SigAction, this);
// Send signals to main thread
catcher_thread.SendSignal(SIGUSR1);
catcherThread.SendSignal(SIGUSR1);
CheckSignalsInsideCycle(SIGUSR1);
// After kill process must die
kill(getpid(), SIGUSR1);
CheckSignalsInsideCycle(SIGUSR1 + SIGUSR1);
catcher_thread.StopThread();
catcherThread.StopThread();
ASSERT_EQ(true, false) << "Error: Thread must die before this assert";
},
@ -163,118 +163,118 @@ TEST_F(UnixSignal, SendSignalsToMainThread2)
TEST_F(UnixSignal, SendSignalsToCatcherThread)
{
os::unix::SignalCatcherThread catcher_thread({SIGUSR1, SIGUSR2});
catcher_thread.CatchOnlyCatcherThread();
os::unix::SignalCatcherThread catcherThread({SIGUSR1, SIGUSR2});
catcherThread.CatchOnlyCatcherThread();
catcher_thread.StartThread(&UnixSignal::SigAction, this);
catcherThread.StartThread(&UnixSignal::SigAction, this);
// Send signals to catcher thread
catcher_thread.SendSignal(SIGUSR1);
catcher_thread.SendSignal(SIGUSR2);
catcherThread.SendSignal(SIGUSR1);
catcherThread.SendSignal(SIGUSR2);
// Wait for the signals inside the cycle
CheckSignalsInsideCycle(SIGUSR1 + SIGUSR2);
catcher_thread.StopThread();
catcherThread.StopThread();
ASSERT_EQ(sig_action_count_, SIGUSR1 + SIGUSR2);
ASSERT_EQ(sigActionCount_, SIGUSR1 + SIGUSR2);
}
TEST_F(UnixSignal, SendUnhandledSignal)
{
EXPECT_DEATH(
{
os::unix::SignalCatcherThread catcher_thread({SIGUSR1});
catcher_thread.StartThread(&UnixSignal::SigAction, this);
os::unix::SignalCatcherThread catcherThread({SIGUSR1});
catcherThread.StartThread(&UnixSignal::SigAction, this);
// Send signals to catcher thread
catcher_thread.SendSignal(SIGUSR1);
catcher_thread.SendSignal(SIGUSR2);
catcherThread.SendSignal(SIGUSR1);
catcherThread.SendSignal(SIGUSR2);
// Wait for the signals inside the cycle
CheckSignalsInsideCycle(SIGUSR1 + SIGUSR2);
catcher_thread.StopThread();
catcherThread.StopThread();
ASSERT_EQ(sig_action_count_, SIGUSR1 + SIGUSR2);
ASSERT_EQ(sigActionCount_, SIGUSR1 + SIGUSR2);
},
"");
}
TEST_F(UnixSignal, SendSomeSignalsToCatcherThread)
{
os::unix::SignalCatcherThread catcher_thread({SIGQUIT, SIGUSR1, SIGUSR2});
catcher_thread.CatchOnlyCatcherThread();
os::unix::SignalCatcherThread catcherThread({SIGQUIT, SIGUSR1, SIGUSR2});
catcherThread.CatchOnlyCatcherThread();
catcher_thread.StartThread(&UnixSignal::SigAction, this);
catcherThread.StartThread(&UnixSignal::SigAction, this);
// Send signals to catcher thread
catcher_thread.SendSignal(SIGQUIT);
catcher_thread.SendSignal(SIGUSR1);
catcher_thread.SendSignal(SIGUSR2);
catcherThread.SendSignal(SIGQUIT);
catcherThread.SendSignal(SIGUSR1);
catcherThread.SendSignal(SIGUSR2);
// Wait for the signals inside the cycle
CheckSignalsInsideCycle(SIGQUIT + SIGUSR1 + SIGUSR2);
catcher_thread.StopThread();
catcherThread.StopThread();
ASSERT_EQ(sig_action_count_, SIGQUIT + SIGUSR1 + SIGUSR2);
ASSERT_EQ(sigActionCount_, SIGQUIT + SIGUSR1 + SIGUSR2);
}
TEST_F(UnixSignal, AfterThreadStartCallback)
{
os::unix::SignalCatcherThread catcher_thread({SIGQUIT});
os::unix::SignalCatcherThread catcherThread({SIGQUIT});
// NOLINTNEXTLINE(readability-magic-numbers)
catcher_thread.SetupCallbacks([this]() { sig_action_count_ += 1000U; }, nullptr);
catcherThread.SetupCallbacks([this]() { sigActionCount_ += 1000U; }, nullptr);
catcher_thread.StartThread(&UnixSignal::SigAction, this);
catcherThread.StartThread(&UnixSignal::SigAction, this);
// Send signals to catcher thread
catcher_thread.SendSignal(SIGQUIT);
catcherThread.SendSignal(SIGQUIT);
// Wait for the signals inside the cycle
// NOLINTNEXTLINE(readability-magic-numbers)
CheckSignalsInsideCycle(SIGQUIT + 1000U);
catcher_thread.StopThread();
catcherThread.StopThread();
ASSERT_EQ(sig_action_count_, SIGQUIT + 1000U);
ASSERT_EQ(sigActionCount_, SIGQUIT + 1000U);
}
TEST_F(UnixSignal, BeforeThreadStopCallback)
{
os::unix::SignalCatcherThread catcher_thread({SIGQUIT});
os::unix::SignalCatcherThread catcherThread({SIGQUIT});
// NOLINTNEXTLINE(readability-magic-numbers)
catcher_thread.SetupCallbacks(nullptr, [this]() { sig_action_count_ += 2000U; });
catcherThread.SetupCallbacks(nullptr, [this]() { sigActionCount_ += 2000U; });
catcher_thread.StartThread(&UnixSignal::SigAction, this);
catcherThread.StartThread(&UnixSignal::SigAction, this);
// Send signals to catcher thread
catcher_thread.SendSignal(SIGQUIT);
catcherThread.SendSignal(SIGQUIT);
// Wait for the signals inside the cycle
CheckSignalsInsideCycle(SIGQUIT);
catcher_thread.StopThread();
catcherThread.StopThread();
ASSERT_EQ(sig_action_count_, SIGQUIT + 2000U);
ASSERT_EQ(sigActionCount_, SIGQUIT + 2000U);
}
TEST_F(UnixSignal, ThreadCallbacks)
{
os::unix::SignalCatcherThread catcher_thread({SIGQUIT});
os::unix::SignalCatcherThread catcherThread({SIGQUIT});
// NOLINTNEXTLINE(readability-magic-numbers)
catcher_thread.SetupCallbacks([this]() { sig_action_count_ += 1000U; }, [this]() { sig_action_count_ += 2000U; });
catcherThread.SetupCallbacks([this]() { sigActionCount_ += 1000U; }, [this]() { sigActionCount_ += 2000U; });
catcher_thread.StartThread(&UnixSignal::SigAction, this);
catcherThread.StartThread(&UnixSignal::SigAction, this);
// Send signals to catcher thread
catcher_thread.SendSignal(SIGQUIT);
catcherThread.SendSignal(SIGQUIT);
// Wait for the signals inside the cycle
// NOLINTNEXTLINE(readability-magic-numbers)
CheckSignalsInsideCycle(1000U + SIGQUIT);
catcher_thread.StopThread();
catcherThread.StopThread();
ASSERT_EQ(sig_action_count_, 1000U + SIGQUIT + 2000U);
ASSERT_EQ(sigActionCount_, 1000U + SIGQUIT + 2000U);
}
} // namespace panda::test

View File

@ -33,7 +33,7 @@ namespace ark::os::unix::memory::futex {
// This field is set to false in case of deadlock with daemon threads (only daemon threads
// are not finished and they have state IS_BLOCKED). In this case we should terminate
// those threads ignoring failures on lock structures destructors.
static ATOMIC(bool) DEADLOCK_FLAG = false;
static ATOMIC(bool) g_deadlockFlag = false;
#ifdef MC_ON
// GenMC does not support syscalls(futex)
@ -63,12 +63,12 @@ static inline void FutexWake(void)
bool MutexDoNotCheckOnTerminationLoop()
{
return DEADLOCK_FLAG;
return g_deadlockFlag;
}
void MutexIgnoreChecksOnTerminationLoop()
{
DEADLOCK_FLAG = true;
g_deadlockFlag = true;
}
int *GetStateAddr(struct fmutex *const m)
@ -106,8 +106,8 @@ static void BackOff(uint32_t i)
static constexpr uint32_t SPIN_MAX = 10;
if (i <= SPIN_MAX) {
volatile uint32_t x = 0; // Volatile to make sure loop is not optimized out.
const uint32_t spin_count = 10 * i;
for (uint32_t spin = 0; spin < spin_count; spin++) {
const uint32_t spinCount = 10 * i;
for (uint32_t spin = 0; spin < spinCount; spin++) {
++x;
}
} else {
@ -242,8 +242,8 @@ bool MutexLock(struct fmutex *const m, bool trylock)
bool MutexTryLockWithSpinning(struct fmutex *const m)
{
const int max_iter = 10;
for (int i = 0; i < max_iter; i++) {
const int maxIter = 10;
for (int i = 0; i < maxIter; i++) {
if (MutexLock(m, true)) {
return true;
}

View File

@ -201,9 +201,9 @@ bool RWLock::TryReadLock()
auto curState = state_.load(std::memory_order_relaxed);
while (!done) {
if (curState >= UNLOCKED) {
auto new_state = curState + READ_INCREMENT;
auto newState = curState + READ_INCREMENT;
// curState should be updated with fetched value on fail
done = state_.compare_exchange_weak(curState, new_state, std::memory_order_acquire);
done = state_.compare_exchange_weak(curState, newState, std::memory_order_acquire);
} else {
// RWLock is Write held, trylock failed.
return false;

View File

@ -34,8 +34,8 @@ int FindLibDwarfCodeRegion(dl_phdr_info *info, [[maybe_unused]] size_t size, voi
{
auto arange = reinterpret_cast<PandaHooks::AddrRange *>(data);
if (std::string_view(info->dlpi_name).find("libdwarf.so") != std::string_view::npos) {
Span<const ElfW(Phdr)> phdr_list(info->dlpi_phdr, info->dlpi_phnum);
for (ElfW(Phdr) phdr : phdr_list) {
Span<const ElfW(Phdr)> phdrList(info->dlpi_phdr, info->dlpi_phnum);
for (ElfW(Phdr) phdr : phdrList) {
// NOLINTNEXTLINE(hicpp-signed-bitwise)
if (phdr.p_type == PT_LOAD && (phdr.p_flags & PF_X) != 0) {
*arange = PandaHooks::AddrRange(info->dlpi_addr + phdr.p_vaddr, phdr.p_memsz);

View File

@ -29,9 +29,9 @@ static constexpr int FIND_TID = 10; // decimal number
std::string GetNativeThreadNameForFile(pid_t tid)
{
std::string result;
std::ostringstream comm_file;
comm_file << "/proc/self/task/" << tid << "/comm";
if (native_stack::ReadOsFile(comm_file.str(), &result)) {
std::ostringstream commFile;
commFile << "/proc/self/task/" << tid << "/comm";
if (native_stack::ReadOsFile(commFile.str(), &result)) {
result.resize(result.size() - 1);
} else {
result = "<unknown>";
@ -57,32 +57,32 @@ void DumpKernelStack(std::ostream &os, pid_t tid, const char *tag, bool count)
if (tid == static_cast<pid_t>(thread::GetCurrentThreadId())) {
return;
}
std::string kernel_stack;
std::ostringstream stack_file;
stack_file << "/proc/self/task/" << tid << "/stack";
if (!native_stack::ReadOsFile(stack_file.str(), &kernel_stack)) {
os << tag << "(couldn't read " << stack_file.str() << ")\n";
std::string kernelStack;
std::ostringstream stackFile;
stackFile << "/proc/self/task/" << tid << "/stack";
if (!native_stack::ReadOsFile(stackFile.str(), &kernelStack)) {
os << tag << "(couldn't read " << stackFile.str() << ")\n";
return;
}
std::regex split("\n");
std::vector<std::string> kernel_stack_frames(
std::sregex_token_iterator(kernel_stack.begin(), kernel_stack.end(), split, -1), std::sregex_token_iterator());
std::vector<std::string> kernelStackFrames(
std::sregex_token_iterator(kernelStack.begin(), kernelStack.end(), split, -1), std::sregex_token_iterator());
if (!kernel_stack_frames.empty()) {
kernel_stack_frames.pop_back();
if (!kernelStackFrames.empty()) {
kernelStackFrames.pop_back();
}
for (size_t i = 0; i < kernel_stack_frames.size(); ++i) {
const char *kernel_stack_build = kernel_stack_frames[i].c_str();
for (size_t i = 0; i < kernelStackFrames.size(); ++i) {
const char *kernelStackBuild = kernelStackFrames[i].c_str();
// change the stack string, case:
// kernel stack in linux file is : "[<0>] do_syscall_64+0x73/0x130"
// kernel stack in Application Not Responding file is : "do_syscall_64+0x73/0x130"
const char *remove_bracket = strchr(kernel_stack_build, ']');
const char *removeBracket = strchr(kernelStackBuild, ']');
if (remove_bracket != nullptr) {
kernel_stack_build = remove_bracket + MOVE_2; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
if (removeBracket != nullptr) {
kernelStackBuild = removeBracket + MOVE_2; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
}
// if need count, case: "do_syscall_64+0x73/0x130" --> "#00 do_syscall_64+0x73/0x130"
@ -90,13 +90,13 @@ void DumpKernelStack(std::ostream &os, pid_t tid, const char *tag, bool count)
if (count) {
os << BuildNumber(static_cast<int>(i));
}
os << kernel_stack_build << std::endl;
os << kernelStackBuild << std::endl;
}
}
void DumpUnattachedThread::AddTid(pid_t tid_thread)
void DumpUnattachedThread::AddTid(pid_t tidThread)
{
threadManagerTids_.insert(tid_thread);
threadManagerTids_.insert(tidThread);
}
bool DumpUnattachedThread::InitKernelTidLists()
@ -109,9 +109,9 @@ bool DumpUnattachedThread::InitKernelTidLists()
}
dirent *dir = nullptr;
while ((dir = readdir(task)) != nullptr) {
char *dir_end = nullptr;
auto tid = static_cast<pid_t>(strtol(dir->d_name, &dir_end, FIND_TID));
if (*dir_end == 0) {
char *dirEnd = nullptr;
auto tid = static_cast<pid_t>(strtol(dir->d_name, &dirEnd, FIND_TID));
if (*dirEnd == 0) {
kernelTid_.insert(tid);
}
}
@ -177,15 +177,15 @@ std::string ChangeJaveStackFormat(const char *descriptor)
LOG(ERROR, RUNTIME) << "Invalid descriptor: no scln at end";
return "";
}
std::string java_name = str.substr(1, end - 1); // Remove 'L' and ';'
std::replace(java_name.begin(), java_name.end(), '/', '.');
return java_name;
std::string javaName = str.substr(1, end - 1); // Remove 'L' and ';'
std::replace(javaName.begin(), javaName.end(), '/', '.');
return javaName;
}
if (descriptor[0] == '[') { // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
std::string java_name(descriptor);
std::replace(java_name.begin(), java_name.end(), '/', '.');
return java_name;
std::string javaName(descriptor);
std::replace(javaName.begin(), javaName.end(), '/', '.');
return javaName;
}
const char *primitiveName = "";

View File

@ -36,31 +36,31 @@
namespace panda {
static decltype(&sigaction) REAL_SIGACTION;
static decltype(&sigprocmask) REAL_SIGPROCMASK;
static bool IS_INIT_REALLY {false};
static bool IS_INIT_KEY_CREATE {false};
static decltype(&sigaction) g_realSigaction;
static decltype(&sigprocmask) g_realSigProcMask;
static bool g_isInitReally {false};
static bool g_isInitKeyCreate {false};
// NOLINTNEXTLINE(fuchsia-statically-constructed-objects)
#if PANDA_TARGET_MACOS
__attribute__((init_priority(101))) static os::memory::Mutex REAL_LOCK;
__attribute__((init_priority(101))) static os::memory::Mutex g_realLock;
#else
// NOLINTNEXTLINE(fuchsia-statically-constructed-objects)
static os::memory::Mutex REAL_LOCK;
static os::memory::Mutex g_realLock;
#endif
// NOLINTNEXTLINE(fuchsia-statically-constructed-objects)
static os::memory::Mutex KEY_CREATE_LOCK;
static os::memory::Mutex g_keyCreateLock;
static os::memory::PandaThreadKey GetHandlingSignalKey()
{
static os::memory::PandaThreadKey key;
{
os::memory::LockHolder lock(KEY_CREATE_LOCK);
if (!IS_INIT_KEY_CREATE) {
os::memory::LockHolder lock(g_keyCreateLock);
if (!g_isInitKeyCreate) {
int rc = os::memory::PandaThreadKeyCreate(&key, nullptr);
if (rc != 0) {
LOG(FATAL, RUNTIME) << "failed to create sigchain thread key: " << os::Error(rc).ToString();
}
IS_INIT_KEY_CREATE = true;
g_isInitKeyCreate = true;
}
}
return key;
@ -101,19 +101,19 @@ public:
void RegisterAction(int signo)
{
struct sigaction handler_action = {};
sigfillset(&handler_action.sa_mask);
struct sigaction handlerAction = {};
sigfillset(&handlerAction.sa_mask);
// SIGSEGV from signal handler must be handled as well
sigdelset(&handler_action.sa_mask, SIGSEGV);
sigdelset(&handlerAction.sa_mask, SIGSEGV);
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
handler_action.sa_sigaction = SignalHook::Handler;
handlerAction.sa_sigaction = SignalHook::Handler;
// SA_NODEFER+: do not block signals from the signal handler
// SA_ONSTACK-: call signal handler on the same stack
// NOLINTNEXTLINE(hicpp-signed-bitwise)
handler_action.sa_flags = SA_RESTART | SA_SIGINFO | SA_NODEFER;
REAL_SIGACTION(signo, nullptr, &oldAction_);
REAL_SIGACTION(signo, &handler_action, &userAction_);
handlerAction.sa_flags = SA_RESTART | SA_SIGINFO | SA_NODEFER;
g_realSigaction(signo, nullptr, &oldAction_);
g_realSigaction(signo, &handlerAction, &userAction_);
}
void RegisterHookAction(const SighookAction *sa)
@ -202,48 +202,48 @@ private:
bool userActionRegister_ {false};
};
static std::array<SignalHook, _NSIG + 1> SIGNAL_HOOKS;
static std::array<SignalHook, _NSIG + 1> g_signalHooks;
void SignalHook::CallOldAction(int signo, siginfo_t *siginfo, void *ucontextRaw)
{
auto handlerFlags = static_cast<size_t>(SIGNAL_HOOKS[signo].oldAction_.sa_flags);
sigset_t mask = SIGNAL_HOOKS[signo].oldAction_.sa_mask;
REAL_SIGPROCMASK(SIG_SETMASK, &mask, nullptr);
auto handlerFlags = static_cast<size_t>(g_signalHooks[signo].oldAction_.sa_flags);
sigset_t mask = g_signalHooks[signo].oldAction_.sa_mask;
g_realSigProcMask(SIG_SETMASK, &mask, nullptr);
if ((handlerFlags & SA_SIGINFO)) { // NOLINT
SIGNAL_HOOKS[signo].oldAction_.sa_sigaction(signo, siginfo, ucontextRaw); // NOLINT
if ((handlerFlags & SA_SIGINFO)) { // NOLINT
g_signalHooks[signo].oldAction_.sa_sigaction(signo, siginfo, ucontextRaw); // NOLINT
} else {
if (SIGNAL_HOOKS[signo].oldAction_.sa_handler == nullptr) { // NOLINT
REAL_SIGACTION(signo, &SIGNAL_HOOKS[signo].oldAction_, nullptr);
if (g_signalHooks[signo].oldAction_.sa_handler == nullptr) { // NOLINT
g_realSigaction(signo, &g_signalHooks[signo].oldAction_, nullptr);
kill(getpid(), signo); // send signal again
return;
}
SIGNAL_HOOKS[signo].oldAction_.sa_handler(signo); // NOLINT
g_signalHooks[signo].oldAction_.sa_handler(signo); // NOLINT
}
}
bool SignalHook::SetHandlingSignal(int signo, siginfo_t *siginfo, void *ucontextRaw)
{
for (const auto &handler : SIGNAL_HOOKS[signo].hookActionHandlers_) {
for (const auto &handler : g_signalHooks[signo].hookActionHandlers_) {
if (handler.scSigaction == nullptr) {
break;
}
bool handler_noreturn = ((handler.scFlags & SIGHOOK_ALLOW_NORETURN) != 0);
bool handlerNoreturn = ((handler.scFlags & SIGHOOK_ALLOW_NORETURN) != 0);
sigset_t previousMask;
REAL_SIGPROCMASK(SIG_SETMASK, &handler.scMask, &previousMask);
g_realSigProcMask(SIG_SETMASK, &handler.scMask, &previousMask);
bool old_handle_key = GetHandlingSignal();
if (!handler_noreturn) {
bool oldHandleKey = GetHandlingSignal();
if (!handlerNoreturn) {
::panda::SetHandlingSignal(true);
}
if (handler.scSigaction(signo, siginfo, ucontextRaw)) {
::panda::SetHandlingSignal(old_handle_key);
::panda::SetHandlingSignal(oldHandleKey);
return false;
}
REAL_SIGPROCMASK(SIG_SETMASK, &previousMask, nullptr);
::panda::SetHandlingSignal(old_handle_key);
g_realSigProcMask(SIG_SETMASK, &previousMask, nullptr);
::panda::SetHandlingSignal(oldHandleKey);
}
return true;
@ -258,20 +258,20 @@ void SignalHook::Handler(int signo, siginfo_t *siginfo, void *ucontextRaw)
}
// if not set user handler,call linker handler
if (!SIGNAL_HOOKS[signo].IsUserActionRegister()) {
if (!g_signalHooks[signo].IsUserActionRegister()) {
CallOldAction(signo, siginfo, ucontextRaw);
return;
}
// call user handler
auto handlerFlags = static_cast<size_t>(SIGNAL_HOOKS[signo].userAction_.sa_flags);
auto handlerFlags = static_cast<size_t>(g_signalHooks[signo].userAction_.sa_flags);
auto *ucontext = static_cast<ucontext_t *>(ucontextRaw);
sigset_t mask;
sigemptyset(&mask);
constexpr int N = sizeof(sigset_t) * 2;
for (int i = 0; i < N; ++i) {
if (sigismember(&ucontext->uc_sigmask, i) == 1 ||
sigismember(&SIGNAL_HOOKS[signo].userAction_.sa_mask, i) == 1) {
sigismember(&g_signalHooks[signo].userAction_.sa_mask, i) == 1) {
sigaddset(&mask, i);
}
}
@ -279,13 +279,13 @@ void SignalHook::Handler(int signo, siginfo_t *siginfo, void *ucontextRaw)
if ((handlerFlags & SA_NODEFER) == 0) { // NOLINT
sigaddset(&mask, signo);
}
REAL_SIGPROCMASK(SIG_SETMASK, &mask, nullptr);
g_realSigProcMask(SIG_SETMASK, &mask, nullptr);
if ((handlerFlags & SA_SIGINFO)) { // NOLINT
SIGNAL_HOOKS[signo].userAction_.sa_sigaction(signo, siginfo, ucontextRaw); // NOLINT
if ((handlerFlags & SA_SIGINFO)) { // NOLINT
g_signalHooks[signo].userAction_.sa_sigaction(signo, siginfo, ucontextRaw); // NOLINT
} else {
auto handler = SIGNAL_HOOKS[signo].userAction_.sa_handler; // NOLINT
if (handler == SIG_IGN) { // NOLINT
auto handler = g_signalHooks[signo].userAction_.sa_handler; // NOLINT
if (handler == SIG_IGN) { // NOLINT
return;
}
if (handler == SIG_DFL) { // NOLINT
@ -324,13 +324,13 @@ __attribute__((constructor)) static bool InitRealSignalFun()
#endif
{
{
os::memory::LockHolder lock(REAL_LOCK);
if (!IS_INIT_REALLY) {
os::memory::LockHolder lock(g_realLock);
if (!g_isInitReally) {
bool isError = true;
isError = isError && FindRealSignal(&REAL_SIGACTION, sigaction, "sigaction");
isError = isError && FindRealSignal(&REAL_SIGPROCMASK, sigprocmask, "sigprocmask");
isError = isError && FindRealSignal(&g_realSigaction, sigaction, "sigaction");
isError = isError && FindRealSignal(&g_realSigProcMask, sigprocmask, "sigprocmask");
if (isError) {
IS_INIT_REALLY = true;
g_isInitReally = true;
}
return isError;
}
@ -348,10 +348,10 @@ static int RegisterUserHandler(int signal, const struct sigaction *newAction, st
return -1;
}
if (SIGNAL_HOOKS[signal].IsHook()) {
auto userAction = SIGNAL_HOOKS[signal].SignalHook::GetUserAction();
if (g_signalHooks[signal].IsHook()) {
auto userAction = g_signalHooks[signal].SignalHook::GetUserAction();
if (newAction != nullptr) {
SIGNAL_HOOKS[signal].RegisterUserAction(newAction);
g_signalHooks[signal].RegisterUserAction(newAction);
}
if (oldAction != nullptr) {
*oldAction = userAction;
@ -376,7 +376,7 @@ int RegisterUserMask(int how, const sigset_t *newSet, sigset_t *oldSet,
sigset_t buildSigset = *newSet;
if (how == SIG_BLOCK || how == SIG_SETMASK) {
for (int i = 1; i < _NSIG; ++i) {
if (SIGNAL_HOOKS[i].IsHook() && (sigismember(&buildSigset, i) != 0)) {
if (g_signalHooks[i].IsHook() && (sigismember(&buildSigset, i) != 0)) {
sigdelset(&buildSigset, i);
}
}
@ -395,7 +395,7 @@ extern "C" int sigaction([[maybe_unused]] int __sig, [[maybe_unused]] const stru
if (!InitRealSignalFun()) {
return -1;
}
return RegisterUserHandler(__sig, __act, __oact, REAL_SIGACTION);
return RegisterUserHandler(__sig, __act, __oact, g_realSigaction);
}
#else
// NOLINTNEXTLINE(readability-identifier-naming)
@ -405,7 +405,7 @@ extern "C" int sigactionStub([[maybe_unused]] int __sig, [[maybe_unused]] const
if (!InitRealSignalFun()) {
return -1;
}
return RegisterUserHandler(__sig, __act, __oact, REAL_SIGACTION);
return RegisterUserHandler(__sig, __act, __oact, g_realSigaction);
}
#endif // USE_ADDRESS_SANITIZER
@ -415,7 +415,7 @@ extern "C" int sigprocmask(int how, const sigset_t *newSet, sigset_t *oldSet) /
if (!InitRealSignalFun()) {
return -1;
}
return RegisterUserMask(how, newSet, oldSet, REAL_SIGPROCMASK);
return RegisterUserMask(how, newSet, oldSet, g_realSigProcMask);
}
extern "C" void RegisterHookHandler(int signal, const SighookAction *sa)
@ -428,8 +428,8 @@ extern "C" void RegisterHookHandler(int signal, const SighookAction *sa)
LOG(FATAL, RUNTIME) << "illegal signal " << signal;
}
SIGNAL_HOOKS[signal].RegisterHookAction(sa);
SIGNAL_HOOKS[signal].HookSig(signal);
g_signalHooks[signal].RegisterHookAction(sa);
g_signalHooks[signal].HookSig(signal);
}
extern "C" void RemoveHookHandler(int signal, bool (*action)(int, siginfo_t *, void *))
@ -442,7 +442,7 @@ extern "C" void RemoveHookHandler(int signal, bool (*action)(int, siginfo_t *, v
LOG(FATAL, RUNTIME) << "illegal signal " << signal;
}
SIGNAL_HOOKS[signal].RemoveHookAction(action);
g_signalHooks[signal].RemoveHookAction(action);
}
extern "C" void CheckOldHookHandler(int signal)
@ -457,12 +457,12 @@ extern "C" void CheckOldHookHandler(int signal)
// get old action
struct sigaction oldAction {};
REAL_SIGACTION(signal, nullptr, &oldAction);
g_realSigaction(signal, nullptr, &oldAction);
if (oldAction.sa_sigaction != SignalHook::Handler) { // NOLINT
LOG(ERROR, RUNTIME) << "error: Check old hook handler found unexpected action "
<< (oldAction.sa_sigaction != nullptr); // NOLINT
SIGNAL_HOOKS[signal].RegisterAction(signal);
g_signalHooks[signal].RegisterAction(signal);
}
}
@ -486,10 +486,10 @@ extern "C" void EnsureFrontOfChain(int signal)
void ClearSignalHooksHandlersArray()
{
IS_INIT_REALLY = false;
IS_INIT_KEY_CREATE = false;
g_isInitReally = false;
g_isInitKeyCreate = false;
for (int i = 1; i < _NSIG; i++) {
SIGNAL_HOOKS[i].ClearHookActionHandlers();
g_signalHooks[i].ClearHookActionHandlers();
}
}

View File

@ -15,7 +15,7 @@
case RuntimeInterface::IntrinsicId::INTRINSIC_STD_DOUBLE_IS_NAN:
case RuntimeInterface::IntrinsicId::INTRINSIC_STD_FLOAT_IS_NAN: {
BuildIsNanIntrinsic(bc_inst, acc_read);
BuildIsNanIntrinsic(bcInst, accRead);
break;
}
@ -26,15 +26,15 @@ case RuntimeInterface::IntrinsicId::INTRINSIC_STD_FLOAT_IS_FINITE: {
* deal with 64-bits data (double type), so, for for 32-bit archs
* (e.g. ARM32) it is just better to use c++ implementation */
if(Is64BitsArch(GetGraph()->GetArch())) {
BuildIsFiniteIntrinsic(bc_inst, acc_read);
BuildIsFiniteIntrinsic(bcInst, accRead);
} else {
BuildDefaultStaticIntrinsic(bc_inst, false, acc_read);
BuildDefaultStaticIntrinsic(bcInst, false, accRead);
}
break;
}
case RuntimeInterface::IntrinsicId::INTRINSIC_STD_MATH_ABS: {
BuildAbsIntrinsic(bc_inst, acc_read);
BuildAbsIntrinsic(bcInst, accRead);
break;
}
@ -42,7 +42,7 @@ case RuntimeInterface::IntrinsicId::INTRINSIC_STD_MATH_MAX_I32:
case RuntimeInterface::IntrinsicId::INTRINSIC_STD_MATH_MAX_I64:
case RuntimeInterface::IntrinsicId::INTRINSIC_STD_MATH_MAX_F32:
case RuntimeInterface::IntrinsicId::INTRINSIC_STD_MATH_MAX_F64: {
BuildBinaryOperationIntrinsic<Opcode::Max>(bc_inst, acc_read);
BuildBinaryOperationIntrinsic<Opcode::Max>(bcInst, accRead);
break;
}
@ -50,28 +50,28 @@ case RuntimeInterface::IntrinsicId::INTRINSIC_STD_MATH_MIN_I32:
case RuntimeInterface::IntrinsicId::INTRINSIC_STD_MATH_MIN_I64:
case RuntimeInterface::IntrinsicId::INTRINSIC_STD_MATH_MIN_F32:
case RuntimeInterface::IntrinsicId::INTRINSIC_STD_MATH_MIN_F64: {
BuildBinaryOperationIntrinsic<Opcode::Min>(bc_inst, acc_read);
BuildBinaryOperationIntrinsic<Opcode::Min>(bcInst, accRead);
break;
}
case RuntimeInterface::IntrinsicId::INTRINSIC_STD_MATH_MOD: {
BuildBinaryOperationIntrinsic<Opcode::Mod>(bc_inst, acc_read);
BuildBinaryOperationIntrinsic<Opcode::Mod>(bcInst, accRead);
break;
}
case RuntimeInterface::IntrinsicId::INTRINSIC_STD_CORE_CHAR_IS_UPPER_CASE: {
BuildCharIsUpperCaseIntrinsic(bc_inst, acc_read);
BuildCharIsUpperCaseIntrinsic(bcInst, accRead);
break;
}
case RuntimeInterface::IntrinsicId::INTRINSIC_STD_CORE_CHAR_TO_UPPER_CASE: {
BuildCharToUpperCaseIntrinsic(bc_inst, acc_read);
BuildCharToUpperCaseIntrinsic(bcInst, accRead);
break;
}
case RuntimeInterface::IntrinsicId::INTRINSIC_STD_CORE_CHAR_IS_LOWER_CASE: {
BuildCharIsLowerCaseIntrinsic(bc_inst, acc_read);
BuildCharIsLowerCaseIntrinsic(bcInst, accRead);
break;
}
case RuntimeInterface::IntrinsicId::INTRINSIC_STD_CORE_CHAR_TO_LOWER_CASE: {
BuildCharToLowerCaseIntrinsic(bc_inst, acc_read);
BuildCharToLowerCaseIntrinsic(bcInst, accRead);
break;
}

View File

@ -480,9 +480,9 @@ extern "C" {
#define ETS_IMPORT
#define ETS_CALL
ets_int ETS_GetDefaultVMInitArgs(EtsVMInitArgs *vm_args);
ets_int ETS_GetCreatedVMs(EtsVM **vm_buf, ets_size buf_len, ets_size *n_vms);
ets_int ETS_CreateVM(EtsVM **p_vm, EtsEnv **p_env, EtsVMInitArgs *vm_args);
ets_int ETS_GetDefaultVMInitArgs(EtsVMInitArgs *vmArgs);
ets_int ETS_GetCreatedVMs(EtsVM **vmBuf, ets_size bufLen, ets_size *nVms);
ets_int ETS_CreateVM(EtsVM **pVm, EtsEnv **pEnv, EtsVMInitArgs *vmArgs);
#ifdef __cplusplus
}
@ -490,7 +490,7 @@ ets_int ETS_CreateVM(EtsVM **p_vm, EtsEnv **p_env, EtsVMInitArgs *vm_args);
struct ETS_InvokeInterface {
ets_int (*DestroyEtsVM)(EtsVM *vm);
ets_int (*GetEnv)(EtsVM *vm, EtsEnv **p_env, ets_int version);
ets_int (*GetEnv)(EtsVM *vm, EtsEnv **pEnv, ets_int version);
};
struct __EtsVM {
@ -503,9 +503,9 @@ struct __EtsVM {
return invoke_interface->DestroyEtsVM(this);
}
ets_int GetEnv(EtsEnv **p_env, ets_int version)
ets_int GetEnv(EtsEnv **pEnv, ets_int version)
{
return invoke_interface->GetEnv(this, p_env, version);
return invoke_interface->GetEnv(this, pEnv, version);
}
#endif
};

View File

@ -64,8 +64,8 @@ TEST_F(AccessingObjectsFieldsTest, DISABLED_GetBaseFieldID2)
ets_class cls = env_->FindClass("F_sub");
ASSERT_NE(cls, nullptr);
ets_field member_id = env_->Getp_field(cls, "member4", "I");
ASSERT_NE(member_id, nullptr);
ets_field memberId = env_->Getp_field(cls, "member4", "I");
ASSERT_NE(memberId, nullptr);
}
TEST_F(AccessingObjectsFieldsTest, GetTypeField)
@ -361,41 +361,41 @@ TEST_F(AccessingObjectsFieldsTest, DISABLED_GetStaticTypeFieldBase)
ets_class cls = env_->FindClass("F_static_sub");
ASSERT_NE(cls, nullptr);
ets_field member0_id = env_->GetStaticp_field(cls, "member0", "Z");
ASSERT_NE(member0_id, nullptr);
ets_field member1_id = env_->GetStaticp_field(cls, "member1", "B");
ASSERT_NE(member1_id, nullptr);
ets_field member2_id = env_->GetStaticp_field(cls, "member2", "C");
ASSERT_NE(member2_id, nullptr);
ets_field member3_id = env_->GetStaticp_field(cls, "member3", "S");
ASSERT_NE(member3_id, nullptr);
ets_field member4_id = env_->GetStaticp_field(cls, "member4", "I");
ASSERT_NE(member4_id, nullptr);
ets_field member5_id = env_->GetStaticp_field(cls, "member5", "J");
ASSERT_NE(member5_id, nullptr);
ets_field member6_id = env_->GetStaticp_field(cls, "member6", "F");
ASSERT_NE(member6_id, nullptr);
ets_field member7_id = env_->GetStaticp_field(cls, "member7", "D");
ASSERT_NE(member7_id, nullptr);
ets_field member8_id = env_->GetStaticp_field(cls, "member8", "LA;");
ASSERT_NE(member8_id, nullptr);
ets_field member0Id = env_->GetStaticp_field(cls, "member0", "Z");
ASSERT_NE(member0Id, nullptr);
ets_field member1Id = env_->GetStaticp_field(cls, "member1", "B");
ASSERT_NE(member1Id, nullptr);
ets_field member2Id = env_->GetStaticp_field(cls, "member2", "C");
ASSERT_NE(member2Id, nullptr);
ets_field member3Id = env_->GetStaticp_field(cls, "member3", "S");
ASSERT_NE(member3Id, nullptr);
ets_field member4Id = env_->GetStaticp_field(cls, "member4", "I");
ASSERT_NE(member4Id, nullptr);
ets_field member5Id = env_->GetStaticp_field(cls, "member5", "J");
ASSERT_NE(member5Id, nullptr);
ets_field member6Id = env_->GetStaticp_field(cls, "member6", "F");
ASSERT_NE(member6Id, nullptr);
ets_field member7Id = env_->GetStaticp_field(cls, "member7", "D");
ASSERT_NE(member7Id, nullptr);
ets_field member8Id = env_->GetStaticp_field(cls, "member8", "LA;");
ASSERT_NE(member8Id, nullptr);
EXPECT_EQ(env_->GetStaticBooleanField(cls, member0_id), static_cast<ets_boolean>(1));
EXPECT_EQ(env_->GetStaticByteField(cls, member1_id), static_cast<ets_byte>(2_I));
EXPECT_EQ(env_->GetStaticCharField(cls, member2_id), static_cast<ets_char>(3U));
EXPECT_EQ(env_->GetStaticShortField(cls, member3_id), static_cast<ets_short>(4_I));
EXPECT_EQ(env_->GetStaticIntField(cls, member4_id), static_cast<ets_int>(5_I));
EXPECT_EQ(env_->GetStaticLongField(cls, member5_id), static_cast<ets_long>(6L));
EXPECT_FLOAT_EQ(env_->GetStaticFloatField(cls, member6_id), static_cast<ets_float>(7.0F));
EXPECT_DOUBLE_EQ(env_->GetStaticDoubleField(cls, member7_id), static_cast<ets_double>(8.0_D));
EXPECT_EQ(env_->GetStaticBooleanField(cls, member0Id), static_cast<ets_boolean>(1));
EXPECT_EQ(env_->GetStaticByteField(cls, member1Id), static_cast<ets_byte>(2_I));
EXPECT_EQ(env_->GetStaticCharField(cls, member2Id), static_cast<ets_char>(3U));
EXPECT_EQ(env_->GetStaticShortField(cls, member3Id), static_cast<ets_short>(4_I));
EXPECT_EQ(env_->GetStaticIntField(cls, member4Id), static_cast<ets_int>(5_I));
EXPECT_EQ(env_->GetStaticLongField(cls, member5Id), static_cast<ets_long>(6L));
EXPECT_FLOAT_EQ(env_->GetStaticFloatField(cls, member6Id), static_cast<ets_float>(7.0F));
EXPECT_DOUBLE_EQ(env_->GetStaticDoubleField(cls, member7Id), static_cast<ets_double>(8.0_D));
ets_class a_cls = env_->FindClass("A");
ASSERT_NE(a_cls, nullptr);
ets_field a_member_id = env_->Getp_field(a_cls, "member", "I");
ASSERT_NE(a_member_id, nullptr);
ets_object a_obj = env_->GetStaticObjectField(cls, member8_id);
ASSERT_NE(a_obj, nullptr);
EXPECT_EQ(env_->GetIntField(a_obj, a_member_id), static_cast<ets_int>(1));
ets_class aCls = env_->FindClass("A");
ASSERT_NE(aCls, nullptr);
ets_field aMemberId = env_->Getp_field(aCls, "member", "I");
ASSERT_NE(aMemberId, nullptr);
ets_object aObj = env_->GetStaticObjectField(cls, member8Id);
ASSERT_NE(aObj, nullptr);
EXPECT_EQ(env_->GetIntField(aObj, aMemberId), static_cast<ets_int>(1));
}
TEST_F(AccessingObjectsFieldsTestDeath, SetStaticTypeFieldDeathTests)
@ -445,57 +445,57 @@ TEST_F(AccessingObjectsFieldsTest, DISABLED_SetStaticFieldBase)
ets_class cls = env_->FindClass("F_static_sub");
ASSERT_NE(cls, nullptr);
ets_field member0_id = env_->GetStaticp_field(cls, "member0", "Z");
ASSERT_NE(member0_id, nullptr);
ets_field member1_id = env_->GetStaticp_field(cls, "member1", "B");
ASSERT_NE(member1_id, nullptr);
ets_field member2_id = env_->GetStaticp_field(cls, "member2", "C");
ASSERT_NE(member2_id, nullptr);
ets_field member3_id = env_->GetStaticp_field(cls, "member3", "S");
ASSERT_NE(member3_id, nullptr);
ets_field member4_id = env_->GetStaticp_field(cls, "member4", "I");
ASSERT_NE(member4_id, nullptr);
ets_field member5_id = env_->GetStaticp_field(cls, "member5", "J");
ASSERT_NE(member5_id, nullptr);
ets_field member6_id = env_->GetStaticp_field(cls, "member6", "F");
ASSERT_NE(member6_id, nullptr);
ets_field member7_id = env_->GetStaticp_field(cls, "member7", "D");
ASSERT_NE(member7_id, nullptr);
ets_field member8_id = env_->GetStaticp_field(cls, "member8", "LA;");
ASSERT_NE(member8_id, nullptr);
ets_field member0Id = env_->GetStaticp_field(cls, "member0", "Z");
ASSERT_NE(member0Id, nullptr);
ets_field member1Id = env_->GetStaticp_field(cls, "member1", "B");
ASSERT_NE(member1Id, nullptr);
ets_field member2Id = env_->GetStaticp_field(cls, "member2", "C");
ASSERT_NE(member2Id, nullptr);
ets_field member3Id = env_->GetStaticp_field(cls, "member3", "S");
ASSERT_NE(member3Id, nullptr);
ets_field member4Id = env_->GetStaticp_field(cls, "member4", "I");
ASSERT_NE(member4Id, nullptr);
ets_field member5Id = env_->GetStaticp_field(cls, "member5", "J");
ASSERT_NE(member5Id, nullptr);
ets_field member6Id = env_->GetStaticp_field(cls, "member6", "F");
ASSERT_NE(member6Id, nullptr);
ets_field member7Id = env_->GetStaticp_field(cls, "member7", "D");
ASSERT_NE(member7Id, nullptr);
ets_field member8Id = env_->GetStaticp_field(cls, "member8", "LA;");
ASSERT_NE(member8Id, nullptr);
ets_class a_cls = env_->FindClass("A");
ASSERT_NE(a_cls, nullptr);
ets_field a_member_id = env_->Getp_field(a_cls, "member", "I");
ASSERT_NE(a_member_id, nullptr);
ets_object a_obj = env_->GetStaticObjectField(cls, member8_id);
ASSERT_NE(a_obj, nullptr);
ets_class aCls = env_->FindClass("A");
ASSERT_NE(aCls, nullptr);
ets_field aMemberId = env_->Getp_field(aCls, "member", "I");
ASSERT_NE(aMemberId, nullptr);
ets_object aObj = env_->GetStaticObjectField(cls, member8Id);
ASSERT_NE(aObj, nullptr);
env_->SetIntField(a_obj, a_member_id, static_cast<ets_int>(5_I));
env_->SetIntField(aObj, aMemberId, static_cast<ets_int>(5_I));
env_->SetStaticBooleanField(cls, member0_id, static_cast<ets_boolean>(1));
env_->SetStaticByteField(cls, member1_id, static_cast<ets_byte>(10_I));
env_->SetStaticCharField(cls, member2_id, static_cast<ets_char>(20U));
env_->SetStaticShortField(cls, member3_id, static_cast<ets_short>(30_I));
env_->SetStaticIntField(cls, member4_id, static_cast<ets_int>(40_I));
env_->SetStaticLongField(cls, member5_id, static_cast<ets_long>(50L));
env_->SetStaticFloatField(cls, member6_id, static_cast<ets_float>(60.0F));
env_->SetStaticDoubleField(cls, member7_id, static_cast<ets_double>(70.0F));
env_->SetStaticObjectField(cls, member8_id, a_obj);
env_->SetStaticBooleanField(cls, member0Id, static_cast<ets_boolean>(1));
env_->SetStaticByteField(cls, member1Id, static_cast<ets_byte>(10_I));
env_->SetStaticCharField(cls, member2Id, static_cast<ets_char>(20U));
env_->SetStaticShortField(cls, member3Id, static_cast<ets_short>(30_I));
env_->SetStaticIntField(cls, member4Id, static_cast<ets_int>(40_I));
env_->SetStaticLongField(cls, member5Id, static_cast<ets_long>(50L));
env_->SetStaticFloatField(cls, member6Id, static_cast<ets_float>(60.0F));
env_->SetStaticDoubleField(cls, member7Id, static_cast<ets_double>(70.0F));
env_->SetStaticObjectField(cls, member8Id, aObj);
EXPECT_EQ(env_->GetStaticBooleanField(cls, member0_id), static_cast<ets_boolean>(1));
EXPECT_EQ(env_->GetStaticByteField(cls, member1_id), static_cast<ets_byte>(10_I));
EXPECT_EQ(env_->GetStaticCharField(cls, member2_id), static_cast<ets_char>(20U));
EXPECT_EQ(env_->GetStaticShortField(cls, member3_id), static_cast<ets_short>(30_I));
EXPECT_EQ(env_->GetStaticIntField(cls, member4_id), static_cast<ets_int>(40_I));
EXPECT_EQ(env_->GetStaticLongField(cls, member5_id), static_cast<ets_long>(50L));
EXPECT_FLOAT_EQ(env_->GetStaticFloatField(cls, member6_id), static_cast<ets_float>(60.0F));
EXPECT_DOUBLE_EQ(env_->GetStaticDoubleField(cls, member7_id), static_cast<ets_double>(70.0F));
EXPECT_EQ(env_->GetStaticBooleanField(cls, member0Id), static_cast<ets_boolean>(1));
EXPECT_EQ(env_->GetStaticByteField(cls, member1Id), static_cast<ets_byte>(10_I));
EXPECT_EQ(env_->GetStaticCharField(cls, member2Id), static_cast<ets_char>(20U));
EXPECT_EQ(env_->GetStaticShortField(cls, member3Id), static_cast<ets_short>(30_I));
EXPECT_EQ(env_->GetStaticIntField(cls, member4Id), static_cast<ets_int>(40_I));
EXPECT_EQ(env_->GetStaticLongField(cls, member5Id), static_cast<ets_long>(50L));
EXPECT_FLOAT_EQ(env_->GetStaticFloatField(cls, member6Id), static_cast<ets_float>(60.0F));
EXPECT_DOUBLE_EQ(env_->GetStaticDoubleField(cls, member7Id), static_cast<ets_double>(70.0F));
ets_object set_a_obj = env_->GetStaticObjectField(cls, member8_id);
ASSERT_NE(set_a_obj, nullptr);
EXPECT_EQ(env_->IsInstanceOf(set_a_obj, a_cls), ETS_TRUE);
EXPECT_EQ(env_->GetIntField(set_a_obj, a_member_id), static_cast<ets_int>(5_I));
ets_object setAObj = env_->GetStaticObjectField(cls, member8Id);
ASSERT_NE(setAObj, nullptr);
EXPECT_EQ(env_->IsInstanceOf(setAObj, aCls), ETS_TRUE);
EXPECT_EQ(env_->GetIntField(setAObj, aMemberId), static_cast<ets_int>(5_I));
}
} // namespace panda::ets::test

View File

@ -96,14 +96,14 @@ void ExecuteImpl(ManagedThread *thread, const uint8_t *pc, Frame *frame, bool ju
#endif
% if mode == :nodebug
static std::array<const void*, DISPATCH_TABLE_LEN> inst_dispatch_table {
static std::array<const void*, DISPATCH_TABLE_LEN> instDispatchTable {
% Panda::dispatch_table.handler_names.each do |name|
&&HANDLE_<%= name %>,
% end
&&EXCEPTION_HANDLER,
};
static std::array<const void*, DISPATCH_TABLE_LEN> debug_dispatch_table {
static std::array<const void*, DISPATCH_TABLE_LEN> debugDispatchTable {
% Panda::dispatch_table.handler_names.each do ||
&&HANDLE_DEBUG_SWITCH,
% end
@ -111,7 +111,7 @@ void ExecuteImpl(ManagedThread *thread, const uint8_t *pc, Frame *frame, bool ju
};
% else
static std::array<const void*, DISPATCH_TABLE_LEN> inst_dispatch_table {
static std::array<const void*, DISPATCH_TABLE_LEN> instDispatchTable {
% Panda::dispatch_table.handler_names.each do |name|
&&DEBUG_HANDLE_<%= name %>,
% end
@ -136,20 +136,20 @@ void ExecuteImpl(ManagedThread *thread, const uint8_t *pc, Frame *frame, bool ju
% end
#endif
default:
thread->SetCurrentDispatchTable<IS_DEBUG>(inst_dispatch_table.data());
thread->SetCurrentDispatchTable<IS_DEBUG>(instDispatchTable.data());
% if mode == :debug
thread->SetDebugDispatchTable(inst_dispatch_table.data());
thread->SetDebugDispatchTable(instDispatchTable.data());
% else
thread->SetDebugDispatchTable(debug_dispatch_table.data());
thread->SetDebugDispatchTable(debugDispatchTable.data());
% end
break;
}
} else {
thread->SetCurrentDispatchTable<IS_DEBUG>(inst_dispatch_table.data());
thread->SetCurrentDispatchTable<IS_DEBUG>(instDispatchTable.data());
% if mode == :debug
thread->SetDebugDispatchTable(inst_dispatch_table.data());
thread->SetDebugDispatchTable(instDispatchTable.data());
% else
thread->SetDebugDispatchTable(debug_dispatch_table.data());
thread->SetDebugDispatchTable(debugDispatchTable.data());
% end
}
@ -211,14 +211,14 @@ void ExecuteImpl(ManagedThread *thread, const uint8_t *pc, Frame *frame, bool ju
}
% Panda::prefixes.each do |p|
<%= prefix %><%= p.handler_name %>: {
const auto secondary_opcode = state.GetSecondaryOpcode();
const auto secondaryOpcode = state.GetSecondaryOpcode();
LOG(DEBUG, INTERPRETER) << "Prefix subdispatch: " << "<%= p.name %>, " << static_cast<int32_t>(secondary_opcode);
LOG(DEBUG, INTERPRETER) << "Prefix subdispatch: " << "<%= p.name %>, " << static_cast<int32_t>(secondaryOpcode);
ASSERT(secondary_opcode <= <%= Panda::dispatch_table.secondary_opcode_bound(p) %>);
const size_t dispatch_idx = <%= Panda::dispatch_table.secondary_opcode_offset(p) %> + secondary_opcode;
ASSERT(dispatch_idx < DISPATCH_TABLE_LEN);
DISPATCH(state.GetDispatchTable(), dispatch_idx);
ASSERT(secondaryOpcode <= <%= Panda::dispatch_table.secondary_opcode_bound(p) %>);
const size_t dispatchIdx = <%= Panda::dispatch_table.secondary_opcode_offset(p) %> + secondaryOpcode;
ASSERT(dispatchIdx < DISPATCH_TABLE_LEN);
DISPATCH(state.GetDispatchTable(), dispatchIdx);
}
% end
@ -277,13 +277,13 @@ EXCEPTION_HANDLER: {
ASSERT(thread->HasPendingException());
InstructionHandler<RuntimeIfaceT, IS_DYNAMIC, IS_DEBUG> handler(&state);
uint32_t pc_offset = panda_file::INVALID_OFFSET;
uint32_t pcOffset = panda_file::INVALID_OFFSET;
% if mode == :debug
RuntimeIfaceT::GetNotificationManager()->ExceptionThrowEvent(thread, handler.GetFrame()->GetMethod(), thread->GetException(), pc_offset);
RuntimeIfaceT::GetNotificationManager()->ExceptionThrowEvent(thread, handler.GetFrame()->GetMethod(), thread->GetException(), pcOffset);
% end
pc_offset = handler.FindCatchBlockStackless();
if (pc_offset == panda_file::INVALID_OFFSET) {
pcOffset = handler.FindCatchBlockStackless();
if (pcOffset == panda_file::INVALID_OFFSET) {
if constexpr (RUNTIME_ARCH == Arch::AARCH64 || RUNTIME_ARCH == Arch::AARCH32 || RUNTIME_ARCH == Arch::X86_64) {
return FindCatchBlockInCallStack(thread);
} else {
@ -294,15 +294,15 @@ EXCEPTION_HANDLER: {
auto *method = handler.GetFrame()->GetMethod();
ASSERT(method != nullptr);
LanguageContext ctx = RuntimeIfaceT::GetLanguageContext(*method);
ObjectHeader *exception_object = thread->GetException();
ctx.SetExceptionToVReg(handler.GetFrame()->GetAcc(), exception_object);
ObjectHeader *exceptionObject = thread->GetException();
ctx.SetExceptionToVReg(handler.GetFrame()->GetAcc(), exceptionObject);
thread->ClearException();
% if mode == :debug
RuntimeIfaceT::GetNotificationManager()->ExceptionCatchEvent(thread, handler.GetFrame()->GetMethod(), exception_object, pc_offset);
RuntimeIfaceT::GetNotificationManager()->ExceptionCatchEvent(thread, handler.GetFrame()->GetMethod(), exceptionObject, pcOffset);
% end
Span<const uint8_t> sp(handler.GetFrame()->GetMethod()->GetInstructions(), pc_offset);
Span<const uint8_t> sp(handler.GetFrame()->GetMethod()->GetInstructions(), pcOffset);
state = InstructionHandlerState(thread, sp.cend(), handler.GetFrame(), handler.GetDispatchTable());
ASSERT(frame->GetMethod()->GetPandaFile()->GetHeader()->quickenedFlag || state.IsPrimaryOpcodeValid());

View File

@ -26,7 +26,7 @@
namespace panda {
os::memory::Mutex g_traceLock;
os::memory::Mutex g_traceLock; // NOLINT(fuchsia-statically-constructed-objects)
Trace *volatile Trace::singletonTrace_ = nullptr;
bool Trace::isTracing_ = false;
// NOLINTNEXTLINE(fuchsia-statically-constructed-objects)

View File

@ -32,6 +32,7 @@ namespace panda {
namespace object_header_traits {
// NOLINTNEXTLINE(fuchsia-statically-constructed-objects)
std::atomic<uint32_t> g_hashSeed = std::atomic<uint32_t>(LINEAR_SEED + std::time(nullptr));
} // namespace object_header_traits

View File

@ -33,22 +33,22 @@ if (lang == <%= plugin_opts["lang_enum"] %>)
}
% end
static CoreLanguageContext core_ctx;
return &core_ctx;
static CoreLanguageContext coreCtx;
return &coreCtx;
}
panda_file::SourceLang RuntimeTypeToLang(const std::string &runtime_type) {
if (runtime_type == "core") {
panda_file::SourceLang RuntimeTypeToLang(const std::string &runtimeType) {
if (runtimeType == "core") {
return panda_file::SourceLang::PANDA_ASSEMBLY;
}
% Common::plugins.each do |plugin_lang, plugin_opts|
if (runtime_type == "<%= plugin_lang.downcase %>") {
if (runtimeType == "<%= plugin_lang.downcase %>") {
return <%= plugin_opts["lang_enum"] %>;
}
% end
LOG(FATAL, RUNTIME) << "Incorrect runtime_type: " << runtime_type;
LOG(FATAL, RUNTIME) << "Incorrect runtime_type: " << runtimeType;
UNREACHABLE();
return panda::panda_file::SourceLang::PANDA_ASSEMBLY;
}
@ -69,13 +69,13 @@ std::string_view LangToRuntimeType(panda_file::SourceLang lang) {
return "core";
}
bool HasRuntime(const std::string &runtime_type) {
if (runtime_type == "core") {
bool HasRuntime(const std::string &runtimeType) {
if (runtimeType == "core") {
return true; // NOLINT(readability-simplify-boolean-expr)
}
% Common::plugins.each_key do |plugin_lang|
if (runtime_type == "<%= plugin_lang.downcase %>") {
if (runtimeType == "<%= plugin_lang.downcase %>") {
return true; // NOLINT(readability-simplify-boolean-expr)
}
% end

View File

@ -278,7 +278,8 @@ TEST_F(FreeListAllocatorTest, AllocateTheWholePoolFreeAndAllocateAgainTest)
if ((FREELIST_ALLOCATOR_MIN_SIZE & (FREELIST_ALLOCATOR_MIN_SIZE - 1)) == 0U) {
minSizePowerOfTwo = panda::helpers::math::GetIntLog2(FREELIST_ALLOCATOR_MIN_SIZE);
} else {
minSizePowerOfTwo = ceil(std::log(FREELIST_ALLOCATOR_MIN_SIZE) / std::log(2.0F));
minSizePowerOfTwo =
ceil(std::log(FREELIST_ALLOCATOR_MIN_SIZE) / std::log(2.0F)); // NOLINT(readability-magic-numbers)
}
if (((1U << minSizePowerOfTwo) - sizeof(freelist::MemoryBlockHeader)) < FREELIST_ALLOCATOR_MIN_SIZE) {
minSizePowerOfTwo++;

View File

@ -42,7 +42,7 @@ inline bool Job::ResolveIdentifiers() {
LOG(DEBUG, VERIFIER) << "JOBFILL: Filling Job cache for method '" << method_->GetFullName() << "'";
constexpr std::size_t DISPATCH_TABLE_HANDLER_NAMES_SIZE = <%= Panda::dispatch_table.handler_names.size %>;
std::array<const void*, DISPATCH_TABLE_HANDLER_NAMES_SIZE> dispatch_table{
std::array<const void*, DISPATCH_TABLE_HANDLER_NAMES_SIZE> dispatchTable{
% Panda::dispatch_table.handler_names.each do |name|
&&HANDLE_<%= name %>,
% end
@ -64,7 +64,7 @@ std::array<const void*, DISPATCH_TABLE_HANDLER_NAMES_SIZE> dispatch_table{
LOG(ERROR, VERIFIER) << "Incorrect opcode";
return false;
}
goto* dispatch_table[inst.GetPrimaryOpcode()];
goto* dispatchTable[inst.GetPrimaryOpcode()];
% dt_non_prefixed_min_minus = (Panda::dispatch_table.invalid_non_prefixed_interval.min - 1).to_s
% dt_non_prefixed_max_plus = (Panda::dispatch_table.invalid_non_prefixed_interval.max + 1).to_s
@ -190,7 +190,7 @@ std::array<const void*, DISPATCH_TABLE_HANDLER_NAMES_SIZE> dispatch_table{
% Method *calledMethod = pf->GetPandaCache()->GetMethodFromCache(methodId);
% // Special case for array constructors, which are fake methods that other
% // Panda code treats in a special way
% bool is_array_constructor_call = false;
% bool isArrayConstructorCall = false;
% if (calledMethod == nullptr) {
% panda_file::MethodDataAccessor const mda(*pf, methodId);
% Class * cls = classLinker_->GetClass(*method_, mda.GetClassId());
@ -200,7 +200,7 @@ std::array<const void*, DISPATCH_TABLE_HANDLER_NAMES_SIZE> dispatch_table{
% opcode == BytecodeInstructionSafe::Opcode::INITOBJ_V4_V4_V4_V4_ID16 ||
% opcode == BytecodeInstructionSafe::Opcode::INITOBJ_RANGE_V8_ID16) &&
% cls != nullptr && cls->IsArrayClass())) {
% is_array_constructor_call = true;
% isArrayConstructorCall = true;
% Type tp = Type {cls};
% AddType(inst.GetOffset(), &tp);
% } else {
@ -211,7 +211,7 @@ std::array<const void*, DISPATCH_TABLE_HANDLER_NAMES_SIZE> dispatch_table{
% AddMethod(inst.GetOffset(), calledMethod);
% auto classType = Type {calledMethod->GetClass()};
% AddType(inst.GetOffset(), &classType);
% } else if (!is_array_constructor_call) {
% } else if (!isArrayConstructorCall) {
% LOG(DEBUG, VERIFIER) << "JOBFILL: Cannot resolve method with id " << id << " in method "
% << method_->GetFullName();
% }
@ -230,9 +230,9 @@ std::array<const void*, DISPATCH_TABLE_HANDLER_NAMES_SIZE> dispatch_table{
% }
% }),
% "TypeId_" => %({
% auto class_idx = method_->GetClass()->ResolveClassIndex(id.AsIndex());
% auto classIdx = method_->GetClass()->ResolveClassIndex(id.AsIndex());
% ScopedChangeThreadStatus st(ManagedThread::GetCurrent(), ThreadStatus::RUNNING);
% auto *cachedClass = classLinker_->GetClass(*method_, class_idx, &errorHandler);
% auto *cachedClass = classLinker_->GetClass(*method_, classIdx, &errorHandler);
% if (cachedClass != nullptr) {
% auto classType = Type {cachedClass};
% AddType(inst.GetOffset(), &classType);
@ -256,8 +256,8 @@ std::array<const void*, DISPATCH_TABLE_HANDLER_NAMES_SIZE> dispatch_table{
% // We are in lda.type bytecode handler. acc type is going to be java.lang.Class
% auto cachedClassClass = classLinker_->GetClass(langContext_.GetClassClassDescriptor(), false, classLinkerCtx_, &errorHandler);
% if (cachedClassClass != nullptr) {
% auto cachedClass_type = Type {cachedClassClass};
% AddType(inst.GetOffset(), &cachedClass_type);
% auto cachedClassType = Type {cachedClassClass};
% AddType(inst.GetOffset(), &cachedClassType);
% } else {
% LOG(ERROR, VERIFIER) << "JOBFILL: Cannot resolve Class class in method " << method_->GetFullName();
% }
@ -284,7 +284,7 @@ std::array<const void*, DISPATCH_TABLE_HANDLER_NAMES_SIZE> dispatch_table{
% }
% inst = nextInst;
% }
% goto* dispatch_table[inst.GetPrimaryOpcode()];
% goto* dispatchTable[inst.GetPrimaryOpcode()];
% )
%}
%
@ -325,7 +325,7 @@ HANDLE_<%= p.handler_name %>:
}
// NOLINTNEXTLINE(readability-magic-numbers, cppcoreguidelines-avoid-goto)
goto *dispatch_table[<%= dt_sec_opcode_offset %> + secondaryOpcode];
goto *dispatchTable[<%= dt_sec_opcode_offset %> + secondaryOpcode];
% end