Skip to content

Commit 0f590b7

Browse files
committed
arm arch; remove valgrind annotations
1 parent 26767e1 commit 0f590b7

File tree

5 files changed

+30
-117
lines changed

5 files changed

+30
-117
lines changed

.github/workflows/tests.yml

Lines changed: 6 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ jobs:
6767
6868
Ubuntu:
6969
name: ubuntu-${{ matrix.os-version }}-${{ matrix.build-config }}-${{ matrix.compiler.cc }}
70-
runs-on: ubuntu-${{ matrix.os-version }}.04
70+
runs-on: ubuntu-${{ matrix.os-version }}
7171
env:
7272
CC: ${{ matrix.compiler.cc }}
7373
CXX: ${{ matrix.compiler.cxx }}
7474
strategy:
7575
fail-fast: false
7676
matrix:
77-
os-version: [22, 24]
77+
os-version: [22.04, 24.04, 24.04-arm]
7878
build-config: [debug, release]
7979
compiler:
8080
- {
@@ -98,16 +98,16 @@ jobs:
9898
install: clang-18
9999
}
100100
exclude:
101-
- os-version: 24
101+
- os-version: 24.04
102102
compiler:
103103
cc: gcc-12
104-
- os-version: 22
104+
- os-version: 22.04
105105
compiler:
106106
cc: gcc-13
107-
- os-version: 24
107+
- os-version: 24.04
108108
compiler:
109109
cc: clang-15
110-
- os-version: 22
110+
- os-version: 22.04
111111
compiler:
112112
cc: clang-18
113113

@@ -266,53 +266,3 @@ jobs:
266266
run: |
267267
cd build/result/${{ matrix.build-config }}
268268
./cage-test-core
269-
270-
271-
Valgrind:
272-
name: valgrind-${{ matrix.options.tool }}
273-
needs: Ubuntu
274-
runs-on: ubuntu-24.04
275-
env:
276-
CC: gcc
277-
CXX: g++
278-
strategy:
279-
fail-fast: false
280-
matrix:
281-
options:
282-
- {
283-
tool: memcheck,
284-
flags: --exit-on-first-error=yes --error-exitcode=1
285-
}
286-
- {
287-
tool: helgrind,
288-
flags: # helgrind produces some false-positives so lets not fail on them
289-
}
290-
291-
steps:
292-
- name: Install packages
293-
run: |
294-
sudo apt-get update
295-
sudo apt-get install -y xorg-dev libwayland-dev libxkbcommon-dev libpulse-dev libasound2-dev nasm libssl-dev
296-
sudo apt-get install -y valgrind
297-
298-
- uses: actions/checkout@v4
299-
with:
300-
submodules: recursive
301-
302-
- name: Configure
303-
run: |
304-
mkdir build
305-
cd build
306-
# WAMR_DISABLE_WRITE_GS_BASE: avoid valgrind crashing on an instruction it does not understand
307-
cmake -DWAMR_DISABLE_WRITE_GS_BASE=1 -DCMAKE_BUILD_TYPE=RELWITHDEBINFO ..
308-
309-
- name: Build
310-
run: |
311-
cd build
312-
cmake --build . --target cage-test-core -- -j$(( `nproc` + 1 ))
313-
314-
- name: Tests
315-
run: |
316-
cd build/result/relwithdebinfo
317-
valgrind ${{ matrix.options.flags }} --tool=${{ matrix.options.tool }} ./cage-test-core
318-

sources/libcore/concurrent/concurrent.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,6 @@
2121
#include <dispatch/dispatch.h>
2222
#endif
2323

24-
#if __has_include(<valgrind/helgrind.h>)
25-
// https://github.com/fredericgermain/valgrind/blob/master/helgrind/tests/annotate_rwlock.c
26-
#include <valgrind/helgrind.h>
27-
#else
28-
#define ANNOTATE_RWLOCK_CREATE(ADDR)
29-
#define ANNOTATE_RWLOCK_DESTROY(ADDR)
30-
#define ANNOTATE_RWLOCK_ACQUIRED(ADDR, WRT)
31-
#define ANNOTATE_RWLOCK_RELEASED(ADDR, WRT)
32-
#endif
33-
3424
#include <cage-core/concurrent.h>
3525
#include <cage-core/debug.h>
3626

@@ -123,10 +113,6 @@ namespace cage
123113
std::atomic<uint32> v = 0;
124114
static constexpr uint32 YieldAfter = 50;
125115
static constexpr uint32 Writer = m;
126-
127-
RwMutexImpl() { ANNOTATE_RWLOCK_CREATE(this); }
128-
129-
~RwMutexImpl() { ANNOTATE_RWLOCK_DESTROY(this); }
130116
};
131117
}
132118

@@ -140,10 +126,7 @@ namespace cage
140126
if (p == 0)
141127
{
142128
if (impl->v.compare_exchange_weak(p, RwMutexImpl::Writer))
143-
{
144-
ANNOTATE_RWLOCK_ACQUIRED(impl, 1);
145129
return;
146-
}
147130
}
148131
if (++attempt >= RwMutexImpl::YieldAfter)
149132
{
@@ -163,10 +146,7 @@ namespace cage
163146
if (p != RwMutexImpl::Writer)
164147
{
165148
if (impl->v.compare_exchange_weak(p, p + 1))
166-
{
167-
ANNOTATE_RWLOCK_ACQUIRED(impl, 0);
168149
return;
169-
}
170150
}
171151
if (++attempt >= RwMutexImpl::YieldAfter)
172152
{
@@ -181,15 +161,9 @@ namespace cage
181161
RwMutexImpl *impl = (RwMutexImpl *)this;
182162
uint32 p = impl->v;
183163
if (p == RwMutexImpl::Writer)
184-
{
185164
impl->v = 0;
186-
ANNOTATE_RWLOCK_RELEASED(impl, 1);
187-
}
188165
else
189-
{
190166
impl->v--;
191-
ANNOTATE_RWLOCK_RELEASED(impl, 0);
192-
}
193167
}
194168

195169
Holder<RwMutex> newRwMutex()

sources/libcore/debug.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ namespace cage
154154
__debugbreak();
155155
#elif defined(__clang__)
156156
__builtin_debugtrap();
157+
#elif defined(__aarch64__)
158+
__asm__ volatile("brk #0");
159+
#elif defined(__ARM_ARCH)
160+
__asm__ volatile("bkpt #0");
157161
#else
158162
__asm__ volatile("int $0x03");
159163
#endif

sources/libcore/memory/utils.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,6 @@
88
#include <unistd.h>
99
#endif
1010

11-
#if __has_include(<valgrind/helgrind.h>)
12-
// see https://valgrind.org/docs/manual/hg-manual.html
13-
#include <valgrind/helgrind.h>
14-
#else
15-
#define ANNOTATE_HAPPENS_AFTER(XXX)
16-
#define ANNOTATE_HAPPENS_BEFORE_FORGET_ALL(XXX)
17-
#define ANNOTATE_HAPPENS_BEFORE(XXX)
18-
#endif
19-
2011
#include <cage-core/memoryUtils.h>
2112

2213
namespace cage
@@ -58,15 +49,7 @@ namespace cage
5849
CAGE_ASSERT(val != m);
5950

6051
if (val == 0)
61-
{
62-
ANNOTATE_HAPPENS_AFTER(&counter);
63-
ANNOTATE_HAPPENS_BEFORE_FORGET_ALL(&counter);
6452
deleter(deletee);
65-
}
66-
else
67-
{
68-
ANNOTATE_HAPPENS_BEFORE(&counter);
69-
}
7053
}
7154
}
7255

sources/libcore/string.cpp

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,10 @@ namespace cage
153153
return std::binary_search(data, data + current, what);
154154
}
155155

156-
uint32 encodeUrlBase(char *pStart, const char *pSrc, uint32 length)
156+
uint32 encodeUrlBase(uint8 *pStart, const uint8 *pSrc, uint32 length)
157157
{
158-
static constexpr bool SAFE[256] = { /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
158+
static constexpr bool SAFE[256] = { //
159+
/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
159160
/* 0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
160161
/* 1 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
161162
/* 2 */ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, // (, ), +, -, .
@@ -176,26 +177,27 @@ namespace cage
176177
/* E */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
177178
/* F */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
178179
};
179-
static constexpr char DEC2HEX[16 + 1] = "0123456789ABCDEF";
180-
char *pEnd = pStart;
181-
const char *const SRC_END = pSrc + length;
180+
static constexpr uint8 DEC2HEX[16 + 1] = "0123456789ABCDEF";
181+
uint8 *pEnd = pStart;
182+
const uint8 *const SRC_END = pSrc + length;
182183
for (; pSrc < SRC_END; ++pSrc)
183184
{
184-
if (SAFE[(unsigned char)*pSrc])
185+
if (SAFE[*pSrc])
185186
*pEnd++ = *pSrc;
186187
else
187188
{
188189
*pEnd++ = '%';
189-
*pEnd++ = DEC2HEX[((unsigned char)*pSrc) >> 4];
190-
*pEnd++ = DEC2HEX[((unsigned char)*pSrc) & 0x0F];
190+
*pEnd++ = DEC2HEX[(*pSrc) >> 4];
191+
*pEnd++ = DEC2HEX[(*pSrc) & 0x0F];
191192
}
192193
}
193194
return numeric_cast<uint32>(pEnd - pStart);
194195
}
195196

196-
uint32 decodeUrlBase(char *pStart, const char *pSrc, uint32 length)
197+
uint32 decodeUrlBase(uint8 *pStart, const uint8 *pSrc, uint32 length)
197198
{
198-
static constexpr char HEX2DEC[256] = { /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
199+
static constexpr sint8 HEX2DEC[256] = { //
200+
/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
199201
/* 0 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
200202
/* 1 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
201203
/* 2 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
@@ -216,15 +218,15 @@ namespace cage
216218
/* E */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
217219
/* F */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
218220
};
219-
const char *const SRC_END = pSrc + length;
220-
const char *const SRC_LAST_DEC = SRC_END - 2;
221-
char *pEnd = pStart;
221+
const uint8 *const SRC_END = pSrc + length;
222+
const uint8 *const SRC_LAST_DEC = SRC_END - 2;
223+
uint8 *pEnd = pStart;
222224
while (pSrc < SRC_LAST_DEC)
223225
{
224226
if (*pSrc == '%')
225227
{
226-
char dec1, dec2;
227-
if (-1 != (dec1 = HEX2DEC[(unsigned char)*(pSrc + 1)]) && -1 != (dec2 = HEX2DEC[(unsigned char)*(pSrc + 2)]))
228+
uint8 dec1, dec2;
229+
if (-1 != (dec1 = HEX2DEC[*(pSrc + 1)]) && -1 != (dec2 = HEX2DEC[*(pSrc + 2)]))
228230
{
229231
*pEnd++ = (dec1 << 4) + dec2;
230232
pSrc += 3;
@@ -468,8 +470,8 @@ namespace cage
468470
void stringEncodeUrl(char *data, uint32 &current, uint32 maxLength, PointerRange<const char> what)
469471
{
470472
// todo this can buffer overflow
471-
char tmp[4096];
472-
const uint32 len = encodeUrlBase(tmp, what.data(), numeric_cast<uint32>(what.size()));
473+
uint8 tmp[4096];
474+
const uint32 len = encodeUrlBase(tmp, (uint8 *)what.data(), numeric_cast<uint32>(what.size()));
473475
if (len > maxLength)
474476
CAGE_THROW_ERROR(Exception, "string truncation");
475477
std::memcpy(data, tmp, len);
@@ -480,7 +482,7 @@ namespace cage
480482
void stringDecodeUrl(char *data, uint32 &current, uint32 maxLength, PointerRange<const char> what)
481483
{
482484
CAGE_ASSERT(maxLength >= what.size());
483-
current = decodeUrlBase(data, what.data(), numeric_cast<uint32>(what.size()));
485+
current = decodeUrlBase((uint8 *)data, (const uint8 *)what.data(), numeric_cast<uint32>(what.size()));
484486
data[current] = 0;
485487
}
486488

0 commit comments

Comments
 (0)