Skip to content

Commit

Permalink
Merge pull request aldelaro5#109 from cristian64/lint_github_action
Browse files Browse the repository at this point in the history
Add Clang-Format check in GitHub Action.
  • Loading branch information
dreamsyntax authored Mar 8, 2024
2 parents 4789ff6 + a6ee202 commit aa5c167
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 41 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: 🔦 Lint

on: [push, pull_request]

jobs:
clang-format-check:
runs-on: ubuntu-22.04
name: Clang-Format Check
steps:
- uses: actions/checkout@v4
- uses: RafikFarhad/clang-format-github-action@v4
with:
style: "file"
sources: "Source/**/*.h,Source/**/*.cpp"
16 changes: 7 additions & 9 deletions Source/Common/CommonUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@
#elif _WIN32
#include <stdlib.h>
#elif __APPLE__
#define bswap_16(value) \
((((value) & 0xff) << 8) | ((value) >> 8))
#define bswap_16(value) ((((value)&0xff) << 8) | ((value) >> 8))

#define bswap_32(value) \
(((uint32_t)bswap_16((uint16_t)((value) & 0xffff)) << 16) | \
(uint32_t)bswap_16((uint16_t)((value) >> 16)))
#define bswap_32(value) \
(((uint32_t)bswap_16((uint16_t)((value)&0xffff)) << 16) | \
(uint32_t)bswap_16((uint16_t)((value) >> 16)))

#define bswap_64(value) \
(((uint64_t)bswap_32((uint32_t)((value) & 0xffffffff)) \
<< 32) | \
(uint64_t)bswap_32((uint32_t)((value) >> 32)))
#define bswap_64(value) \
(((uint64_t)bswap_32((uint32_t)((value)&0xffffffff)) << 32) | \
(uint64_t)bswap_32((uint32_t)((value) >> 32)))
#endif

#include "CommonTypes.h"
Expand Down
46 changes: 27 additions & 19 deletions Source/DolphinProcess/Mac/MacDolphinProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@
#include "../../Common/MemoryCommon.h"

#include <cstdlib>
#include <mach/mach_vm.h>
#include <memory>
#include <string_view>
#include <sys/sysctl.h>
#include <mach/mach_vm.h>

namespace DolphinComm
{
bool MacDolphinProcess::findPID()
{
static const int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0 };
static const int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0};

size_t procSize = 0;
if(sysctl((int*) mib, 4, NULL, &procSize, NULL, 0) == -1)
if (sysctl((int*)mib, 4, NULL, &procSize, NULL, 0) == -1)
return false;

auto procs = std::make_unique<kinfo_proc[]>(procSize / sizeof(kinfo_proc));
if(sysctl((int*) mib, 4, procs.get(), &procSize, NULL, 0) == -1)
if (sysctl((int*)mib, 4, procs.get(), &procSize, NULL, 0) == -1)
return false;

static const char* const s_dolphinProcessName{std::getenv("DME_DOLPHIN_PROCESS_NAME")};

m_PID = -1;
for(int i = 0; i < procSize / sizeof(kinfo_proc); i++)
for (int i = 0; i < procSize / sizeof(kinfo_proc); i++)
{
const std::string_view name{procs[i].kp_proc.p_comm};
const bool match{s_dolphinProcessName ? name == s_dolphinProcessName :
Expand All @@ -47,7 +47,7 @@ bool MacDolphinProcess::obtainEmuRAMInformations()
{
m_currentTask = current_task();
kern_return_t error = task_for_pid(m_currentTask, m_PID, &m_task);
if(error != KERN_SUCCESS)
if (error != KERN_SUCCESS)
return false;

mach_vm_address_t regionAddr = 0;
Expand All @@ -59,24 +59,29 @@ bool MacDolphinProcess::obtainEmuRAMInformations()
mach_port_t obj;
bool MEM1Found = false;
unsigned int MEM1Obj = 0;
while(mach_vm_region(m_task, &regionAddr, &size, VM_REGION_EXTENDED_INFO, (int*)&regInfo, &cnt, &obj) == KERN_SUCCESS)
while (mach_vm_region(m_task, &regionAddr, &size, VM_REGION_EXTENDED_INFO, (int*)&regInfo, &cnt,
&obj) == KERN_SUCCESS)
{
cnt = VM_REGION_BASIC_INFO_COUNT_64;
if(mach_vm_region(m_task, &regionAddr, &size, VM_REGION_BASIC_INFO_64, (int*)&basInfo, &cnt, &obj) != KERN_SUCCESS)
break;
if (mach_vm_region(m_task, &regionAddr, &size, VM_REGION_BASIC_INFO_64, (int*)&basInfo, &cnt,
&obj) != KERN_SUCCESS)
break;
cnt = VM_REGION_TOP_INFO_COUNT;
if(mach_vm_region(m_task, &regionAddr, &size, VM_REGION_TOP_INFO, (int*)&topInfo, &cnt, &obj) != 0)
break;
if (mach_vm_region(m_task, &regionAddr, &size, VM_REGION_TOP_INFO, (int*)&topInfo, &cnt,
&obj) != 0)
break;

if (!m_MEM2Present && size == Common::GetMEM2Size() && basInfo.offset == Common::GetMEM1Size() + 0x40000)
if (!m_MEM2Present && size == Common::GetMEM2Size() &&
basInfo.offset == Common::GetMEM1Size() + 0x40000)
{
m_MEM2Present = true;
m_MEM2AddressStart = regionAddr;
}

// if these are true, then it is very likely the correct region, but we cannot guarantee
if((!MEM1Found || (MEM1Found && MEM1Obj == topInfo.obj_id)) && size == Common::GetMEM1Size() && regInfo.share_mode == SM_TRUESHARED &&
basInfo.max_protection == (VM_PROT_READ | VM_PROT_WRITE))
if ((!MEM1Found || (MEM1Found && MEM1Obj == topInfo.obj_id)) && size == Common::GetMEM1Size() &&
regInfo.share_mode == SM_TRUESHARED &&
basInfo.max_protection == (VM_PROT_READ | VM_PROT_WRITE))
{
if (basInfo.offset == 0x0)
{
Expand Down Expand Up @@ -110,7 +115,8 @@ bool MacDolphinProcess::obtainEmuRAMInformations()
return false;
}

bool MacDolphinProcess::readFromRAM(const u32 offset, char* buffer, size_t size, const bool withBSwap)
bool MacDolphinProcess::readFromRAM(const u32 offset, char* buffer, size_t size,
const bool withBSwap)
{
vm_size_t nread;
u64 RAMAddress = 0;
Expand All @@ -130,7 +136,8 @@ bool MacDolphinProcess::readFromRAM(const u32 offset, char* buffer, size_t size,
RAMAddress = m_emuRAMAddressStart + offset;
}

if(vm_read_overwrite(m_task, RAMAddress, size, reinterpret_cast<vm_address_t>(buffer), &nread) != KERN_SUCCESS)
if (vm_read_overwrite(m_task, RAMAddress, size, reinterpret_cast<vm_address_t>(buffer), &nread) !=
KERN_SUCCESS)
return false;
if (nread != size)
return false;
Expand Down Expand Up @@ -169,7 +176,8 @@ bool MacDolphinProcess::readFromRAM(const u32 offset, char* buffer, size_t size,
return true;
}

bool MacDolphinProcess::writeToRAM(const u32 offset, const char* buffer, const size_t size, const bool withBSwap)
bool MacDolphinProcess::writeToRAM(const u32 offset, const char* buffer, const size_t size,
const bool withBSwap)
{
u64 RAMAddress = 0;
if (m_ARAMAccessible)
Expand Down Expand Up @@ -222,7 +230,7 @@ bool MacDolphinProcess::writeToRAM(const u32 offset, const char* buffer, const s
}
}

if(vm_write(m_task, RAMAddress, reinterpret_cast<vm_offset_t>(bufferCopy), size) != KERN_SUCCESS)
if (vm_write(m_task, RAMAddress, reinterpret_cast<vm_offset_t>(bufferCopy), size) != KERN_SUCCESS)
{
delete[] bufferCopy;
return false;
Expand All @@ -231,5 +239,5 @@ bool MacDolphinProcess::writeToRAM(const u32 offset, const char* buffer, const s
delete[] bufferCopy;
return true;
}
} // namespace DolphinComm
} // namespace DolphinComm
#endif
9 changes: 4 additions & 5 deletions Source/DolphinProcess/Mac/MacDolphinProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,24 @@

#pragma once

#include "../IDolphinProcess.h"
#include <mach/mach.h>
#include "../IDolphinProcess.h"

namespace DolphinComm
{
class MacDolphinProcess : public IDolphinProcess
{
public:
MacDolphinProcess()
{
}
MacDolphinProcess() {}
bool findPID() override;
bool obtainEmuRAMInformations() override;
bool readFromRAM(const u32 offset, char* buffer, size_t size, const bool withBSwap) override;
bool writeToRAM(const u32 offset, const char* buffer, const size_t size,
const bool withBSwap) override;

private:
task_t m_task;
task_t m_currentTask;
};
} // namespace DolphinComm
} // namespace DolphinComm
#endif
2 changes: 1 addition & 1 deletion Source/GUI/MemViewer/MemViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

#include <QApplication>
#include <QClipboard>
#include <QFontDatabase>
#include <QInputDialog>
#include <QMenu>
#include <QMessageBox>
#include <QMouseEvent>
#include <QPainter>
#include <QRegularExpression>
#include <QScrollBar>
#include <QFontDatabase>

#include "../../Common/CommonUtils.h"
#include "../../DolphinProcess/DolphinAccessor.h"
Expand Down
8 changes: 5 additions & 3 deletions Source/GUI/MemWatcher/Dialogs/DlgAddWatchEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,12 @@ void DlgAddWatchEntry::accept()
{
QString errorMsg = tr("The address you entered is invalid, make sure it is an "
"hexadecimal number between 0x%1 and 0x%2")
.arg(Common::MEM1_START, 8, 16).arg(Common::GetMEM1End() - 1, 8, 16);
.arg(Common::MEM1_START, 8, 16)
.arg(Common::GetMEM1End() - 1, 8, 16);
if (DolphinComm::DolphinAccessor::isMEM2Present())
errorMsg.append(
tr(" or between 0x%1 and 0x%2").arg(Common::MEM2_START, 8, 16).arg(Common::GetMEM2End() - 1, 8, 16));
errorMsg.append(tr(" or between 0x%1 and 0x%2")
.arg(Common::MEM2_START, 8, 16)
.arg(Common::GetMEM2End() - 1, 8, 16));
QMessageBox* errorBox = new QMessageBox(QMessageBox::Critical, tr("Invalid address"), errorMsg,
QMessageBox::Ok, this);
errorBox->exec();
Expand Down
3 changes: 2 additions & 1 deletion Source/GUI/MemWatcher/MemWatchWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,8 @@ void MemWatchWidget::onDataEdited(const QModelIndex& index, const QVariant& valu
if (selectedIndex.column() != MemWatchModel::WATCH_COL_VALUE)
continue;

MemWatchTreeNode* const selectedNode{static_cast<MemWatchTreeNode*>(selectedIndex.internalPointer())};
MemWatchTreeNode* const selectedNode{
static_cast<MemWatchTreeNode*>(selectedIndex.internalPointer())};
if (selectedNode->isGroup())
continue;
MemWatchEntry* const selectedEntry{selectedNode->getEntry()};
Expand Down
6 changes: 3 additions & 3 deletions Source/MemoryWatch/MemWatchEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ Common::MemOperationReturnCode MemWatchEntry::readMemoryFromRAM()
m_isValidPointer = true;
}

if(!DolphinComm::DolphinAccessor::isValidConsoleAddress(realConsoleAddress))
if (!DolphinComm::DolphinAccessor::isValidConsoleAddress(realConsoleAddress))
return Common::MemOperationReturnCode::OK;

if (DolphinComm::DolphinAccessor::readFromRAM(
Expand Down Expand Up @@ -306,7 +306,7 @@ Common::MemOperationReturnCode MemWatchEntry::writeMemoryToRAM(const char* memor
m_isValidPointer = true;
}

if(!DolphinComm::DolphinAccessor::isValidConsoleAddress(realConsoleAddress))
if (!DolphinComm::DolphinAccessor::isValidConsoleAddress(realConsoleAddress))
return Common::MemOperationReturnCode::OK;

if (DolphinComm::DolphinAccessor::writeToRAM(
Expand All @@ -320,7 +320,7 @@ Common::MemOperationReturnCode MemWatchEntry::writeMemoryToRAM(const char* memor
std::string MemWatchEntry::getStringFromMemory() const
{
if ((m_boundToPointer && !m_isValidPointer) ||
!DolphinComm::DolphinAccessor::isValidConsoleAddress(m_consoleAddress))
!DolphinComm::DolphinAccessor::isValidConsoleAddress(m_consoleAddress))
return "???";
return Common::formatMemoryToString(m_memory, m_type, m_length, m_base, m_isUnsigned);
}
Expand Down

0 comments on commit aa5c167

Please sign in to comment.