Skip to content

Commit 02d655c

Browse files
mkokryashkinigormunkin
authored andcommitted
sysprof: disable proto and trace dumps in default
There is no need to dump proto or trace information for sysprof in the default mode. Moreover, attempts to do so will lead to segmentation fault due to uninitialized buffer. This commit disables proto and trace dumps in the default mode. Resolves tarantool/tarantool#7264
1 parent 36b4b80 commit 02d655c

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

src/lj_sysprof.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ void lj_sysprof_add_proto(const struct GCproto *pt)
524524
{
525525
struct sysprof *sp = &sysprof;
526526

527-
if (sp->state != SPS_PROFILE)
527+
if (sp->state != SPS_PROFILE || sp->opt.mode == LUAM_SYSPROF_DEFAULT)
528528
return;
529529

530530
/*
@@ -543,7 +543,7 @@ void lj_sysprof_add_trace(const struct GCtrace *tr)
543543
{
544544
struct sysprof *sp = &sysprof;
545545

546-
if (sp->state != SPS_PROFILE)
546+
if (sp->state != SPS_PROFILE || sp->opt.mode == LUAM_SYSPROF_DEFAULT)
547547
return;
548548

549549
/* See the comment about the sysprof state above. */
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
-- Sysprof is implemented for x86 and x64 architectures only.
2+
require('utils').skipcond(
3+
jit.arch ~= 'x86' and jit.arch ~= 'x64' or jit.os ~= 'Linux'
4+
or require('ffi').abi('gc64'),
5+
jit.arch..' architecture or '..jit.os..
6+
' OS is NIY for sysprof'
7+
)
8+
9+
local tap = require('tap')
10+
local test = tap.test('gh-7264-add-proto-trace-sysprof-default.test.lua')
11+
test:plan(2)
12+
13+
local chunk = [[
14+
return function()
15+
local a = 'teststring'
16+
end
17+
]]
18+
19+
local function allocate()
20+
local a = {}
21+
for _ = 1, 3 do
22+
table.insert(a, 'teststring')
23+
end
24+
return a
25+
end
26+
27+
-- Proto creation during the sysprof runtime.
28+
jit.off()
29+
30+
assert(misc.sysprof.start({ mode = 'D' }))
31+
-- The first call yields the anonymous function created by loading
32+
-- <chunk> proto. As a result the child proto function is yielded.
33+
-- The second call invokes the child proto function to trigger
34+
-- <lj_sysprof_add_proto> call.
35+
assert(load(chunk))()()
36+
test:ok(misc.sysprof.stop(), 'new proto in sysprof runtime')
37+
38+
-- Trace creation during the sysprof runtime.
39+
jit.flush()
40+
jit.opt.start('hotloop=1')
41+
jit.on()
42+
43+
assert(misc.sysprof.start({ mode = 'D' }))
44+
-- Run <allocate> function to record a new trace. As a result,
45+
-- <lj_sysprof_add_trace> is triggered to be invoked.
46+
allocate()
47+
test:ok(misc.sysprof.stop(), 'trace record in sysprof runtime')
48+
49+
os.exit(test:check() and 0 or 1)

0 commit comments

Comments
 (0)