Skip to content

Commit 9983149

Browse files
authored
Merge pull request #1434 from nicolasnoble/asan
First pass at resolving various asan issues.
2 parents be4a4e8 + 26f6310 commit 9983149

File tree

16 files changed

+92
-43
lines changed

16 files changed

+92
-43
lines changed

.github/workflows/linux-asan.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Linux CI asan
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
asan:
11+
runs-on: ubuntu-latest
12+
container:
13+
image: ghcr.io/grumpycoders/pcsx-redux-build:latest
14+
env:
15+
TEST_RESULTS: /tmp/test-results
16+
BUILD: asan
17+
steps:
18+
- uses: actions/checkout@v3
19+
with:
20+
submodules: recursive
21+
set-safe-directory: true
22+
- uses: n1hility/cancel-previous-runs@v2
23+
with:
24+
token: ${{ secrets.GITHUB_TOKEN }}
25+
- run: |
26+
make -j 2 all pcsx-redux-tests
27+
make -C src/mips/openbios -j 2 BUILD=Release
28+
cp src/mips/openbios/openbios.bin .
29+
make -C src/mips/openbios clean
30+
make -C src/mips/tests -j 2 PCSX_TESTS=true BUILD=Release
31+
cp ./openbios.bin src/mips/openbios/
32+
- name: Test
33+
run: |
34+
xvfb-run ./pcsx-redux-tests

src/cdrom/cdriso-cue.cc

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ bool PCSX::CDRIso::parsecue(const char *isofileString) {
8181
file->opaque = fi;
8282
file->destroy = [](CueFile *file) {
8383
File *fi = reinterpret_cast<File *>(file->opaque);
84+
fi->close();
8485
delete fi;
8586
file->opaque = nullptr;
8687
};
@@ -140,16 +141,26 @@ bool PCSX::CDRIso::parsecue(const char *isofileString) {
140141
});
141142

142143
Scheduler_run(&scheduler);
143-
CueParser_destroy(&parser);
144+
CueParser_close(&parser, &scheduler, [](CueParser *parser, CueScheduler *scheduler, const char *error) {
145+
Context *context = reinterpret_cast<Context *>(scheduler->opaque);
146+
if (error) {
147+
context->failed = true;
148+
PCSX::g_system->printf("Error closing cue parser: %s", error);
149+
}
150+
CueParser_destroy(parser);
151+
});
152+
Scheduler_run(&scheduler);
144153

145154
File_schedule_close(&cue, &scheduler, [](CueFile *file, CueScheduler *scheduler) { file->destroy(file); });
146155
if (context.failed) {
147156
for (unsigned i = 1; i <= disc.trackCount; i++) {
148157
CueTrack *track = &disc.tracks[i];
149158
if (track->file) {
150159
if (track->file->references == 1) {
151-
File_schedule_close(track->file, &scheduler,
152-
[](CueFile *file, CueScheduler *scheduler) { file->destroy(file); });
160+
File_schedule_close(track->file, &scheduler, [](CueFile *file, CueScheduler *scheduler) {
161+
file->destroy(file);
162+
free(file);
163+
});
153164
} else {
154165
track->file->references--;
155166
}
@@ -172,6 +183,12 @@ bool PCSX::CDRIso::parsecue(const char *isofileString) {
172183
m_ti[i].start = IEC60908b::MSF(track->indices[1] + 150);
173184
m_ti[i].pregap = IEC60908b::MSF(track->indices[1] - track->indices[0]);
174185
m_ti[i].length = IEC60908b::MSF(track->size);
186+
if (track->file->references == 1) {
187+
free(track->file);
188+
} else {
189+
track->file->references--;
190+
}
191+
track->file = nullptr;
175192
}
176193

177194
m_numtracks = disc.trackCount;

src/cdrom/cdriso-sbi.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@
2020
#include "cdrom/cdriso.h"
2121

2222
bool PCSX::CDRIso::LoadSBI(const char *filename) {
23-
IO<File> sbihandle;
23+
IO<File> sbihandle(new UvFile(filename));
2424
char buffer[16];
2525

26-
sbihandle.setFile(new UvFile(filename));
26+
if (sbihandle->failed()) return false;
2727
if (g_emulator->settings.get<Emulator::SettingFullCaching>()) {
2828
sbihandle.asA<UvFile>()->startCaching();
2929
}
30-
if (sbihandle->failed()) return false;
3130

3231
// init
3332
sbicount = 0;

src/core/callstacks.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class CallStacks {
7474
m_currentSP = 0;
7575
});
7676
}
77+
~CallStacks() { m_callstacks.destroyAll(); }
7778
void setSP(uint32_t oldSP, uint32_t newSP);
7879
void offsetSP(uint32_t oldSP, int32_t offset);
7980
void storeRA(uint32_t sp, uint32_t ra);

src/core/pad.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class Pads {
3434
public:
3535
enum class Port { Port1 = 0, Port2 };
3636

37+
virtual ~Pads() = default;
38+
3739
virtual void init() = 0;
3840
virtual void shutdown() = 0;
3941
virtual uint8_t startPoll(Port port) = 0;

src/core/pio-cart.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ void PCSX::PIOCart::setLuts() {
4242
m_readLUT[0x1f05] = &m_exp1[1 << 16];
4343
m_pal.reset();
4444
} else {
45-
memset(&m_readLUT[0x1f00], NULL, 0x6 * sizeof(void *));
45+
memset(&m_readLUT[0x1f00], 0, 0x6 * sizeof(void *));
4646
}
4747

48-
// NULL by default, wipe to ensure writes are properly intercepted
49-
memset(&m_writeLUT[0x1f00], NULL, 0x6 * sizeof(void *));
50-
memset(&m_writeLUT[0x9f00], NULL, 0x6 * sizeof(void *));
51-
memset(&m_writeLUT[0xbf00], NULL, 0x6 * sizeof(void *));
48+
// nullptr by default, wipe to ensure writes are properly intercepted
49+
memset(&m_writeLUT[0x1f00], 0, 0x6 * sizeof(void *));
50+
memset(&m_writeLUT[0x9f00], 0, 0x6 * sizeof(void *));
51+
memset(&m_writeLUT[0xbf00], 0, 0x6 * sizeof(void *));
5252

5353
memcpy(&m_readLUT[0x9f00], &m_readLUT[0x1f00], 0x6 * sizeof(void *));
5454
memcpy(&m_readLUT[0xbf00], &m_readLUT[0x1f00], 0x6 * sizeof(void *));
@@ -133,7 +133,7 @@ void PCSX::PIOCart::PAL::setLUTFlashBank(uint8_t bank) {
133133
const auto &m_readLUT = g_emulator->m_mem->m_readLUT;
134134
const auto &m_exp1 = g_emulator->m_mem->m_exp1;
135135

136-
if (m_readLUT == NULL || m_exp1 == NULL) return;
136+
if (m_readLUT == nullptr || m_exp1 == nullptr) return;
137137

138138
switch (bank) {
139139
case 0:

src/core/pio-cart.h

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,7 @@ namespace PCSX {
3232
class PIOCart {
3333
public:
3434
PIOCart() : m_pal(this) {
35-
m_detachedMemory = static_cast<uint8_t *>(calloc(64 * 1024, 1));
36-
if (m_detachedMemory == NULL) {
37-
g_system->message("%s", _("Error allocating memory!"));
38-
} else {
39-
memset(m_detachedMemory, 0xff, static_cast<size_t>(64 * 1024));
40-
}
35+
memset(m_detachedMemory, 0xff, sizeof(m_detachedMemory));
4136
}
4237

4338
void setLuts();
@@ -80,7 +75,7 @@ class PIOCart {
8075

8176
private:
8277
bool m_switchOn = true;
83-
uint8_t *m_detachedMemory = NULL;
78+
uint8_t m_detachedMemory[64 * 1024];
8479

8580
class PAL {
8681
public:
@@ -101,14 +96,9 @@ class PIOCart {
10196
class FlashMemory {
10297
public:
10398
FlashMemory(PAL *parent) : m_pal(parent) {
104-
m_softwareID = static_cast<uint8_t *>(calloc(64 * 1024, 1));
105-
if (m_softwareID == NULL) {
106-
g_system->message("%s", _("Error allocating memory!"));
107-
} else {
108-
for (int i = 0; i < (64 * 1024) - 1; i += 2) {
109-
m_softwareID[i] = 0xbf;
110-
m_softwareID[i + 1] = 0x10;
111-
}
99+
for (int i = 0; i < (64 * 1024) - 1; i += 2) {
100+
m_softwareID[i] = 0xbf;
101+
m_softwareID[i + 1] = 0x10;
112102
}
113103
}
114104

@@ -158,7 +148,7 @@ class PIOCart {
158148
uint8_t m_commandBuffer[m_bufferSize] = {0};
159149
uint8_t m_busCycle = 0;
160150

161-
uint8_t *m_softwareID = NULL;
151+
uint8_t m_softwareID[64 * 1024];
162152

163153
bool m_dataProtectEnabled = true;
164154
bool m_pageWriteEnabled = false;

src/core/system.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ class System {
259259
protected:
260260
std::filesystem::path m_binDir;
261261
PCSX::VersionInfo m_version;
262-
bool m_emergencyExit = true;
262+
bool m_emergencyExit = false;
263263
};
264264

265265
extern System *g_system;

src/gui/resources-unix.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ void PCSX::Resources::loadIcon(std::function<void(const uint8_t*, uint32_t)> pro
4949
info[i].offset = ico->read<uint32_t>();
5050
}
5151
for (unsigned i = 0; i < count; i++) {
52-
ico->rSeek(info[i].offset, SEEK_SET);
53-
auto slice = ico->read(info[i].size);
52+
auto slice = ico->readAt(info[i].size, info[i].offset);
5453
process(reinterpret_cast<const uint8_t*>(slice.data()), slice.size());
5554
}
5655
}

src/main/main.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,9 @@ int pcsxMain(int argc, char **argv) {
359359
emulator->m_spu->close();
360360
emulator->m_cdrom->clearIso();
361361

362-
emulator->m_cpu->psxShutdown();
363362
emulator->m_spu->shutdown();
364363
emulator->m_gpu->shutdown();
364+
emulator->shutdown();
365365
s_ui->close();
366366
delete s_ui;
367367

0 commit comments

Comments
 (0)