diff options
author | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2014-12-03 13:58:40 +0000 |
---|---|---|
committer | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2014-12-03 13:58:40 +0000 |
commit | 434a3e4dee2031afbb10c68a0f944071d131840e (patch) | |
tree | e84df970340820eb2d06bf4f60e8f084af0252fa /lib/msan/msan.cc | |
parent | 948698a1c629005cc27de7ca5497504a2f6159e9 (diff) |
[msan] Change the way origin ids are built.
Previously, all origin ids were "chained" origins, i.e values of
ChainedOriginDepot. This added a level of indirection for simple
stack and heap allocation, which were represented as chains of
length 1. This costs both RAM and CPU, but provides a joined 2**29
origin id space. It also made function (any instrumented function)
entry non-async-signal-safe, but that does not really matter because
memory stores in track-origins=2 mode are not async-signal-safe anyway.
With this change, the type of the origin is encoded in origin id.
See comment in msan_origin.h for more details. This reduces chained and stack
origin id range to 2**28 each, but leaves extra 2**31 for heap origins.
This change should not have any user-visible effects.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@223233 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/msan/msan.cc')
-rw-r--r-- | lib/msan/msan.cc | 37 |
1 files changed, 7 insertions, 30 deletions
diff --git a/lib/msan/msan.cc b/lib/msan/msan.cc index 523bf9465..af42176c2 100644 --- a/lib/msan/msan.cc +++ b/lib/msan/msan.cc @@ -205,10 +205,10 @@ void PrintWarningWithOrigin(uptr pc, uptr bp, u32 origin) { GET_FATAL_STACK_TRACE_PC_BP(pc, bp); u32 report_origin = - (__msan_get_track_origins() && Origin(origin).isValid()) ? origin : 0; + (__msan_get_track_origins() && Origin::isValidId(origin)) ? origin : 0; ReportUMR(&stack, report_origin); - if (__msan_get_track_origins() && !Origin(origin).isValid()) { + if (__msan_get_track_origins() && !Origin::isValidId(origin)) { Printf( " ORIGIN: invalid (%x). Might be a bug in MemorySanitizer origin " "tracking.\n This could still be a bug in your code, too!\n", @@ -258,32 +258,9 @@ u32 ChainOrigin(u32 id, StackTrace *stack) { if (t && t->InSignalHandler()) return id; - Origin o(id); - int depth = o.depth(); - // 0 means unlimited depth. - if (flags()->origin_history_size > 0 && depth > 0) { - if (depth >= flags()->origin_history_size) { - return id; - } else { - ++depth; - } - } - - StackDepotHandle h = StackDepotPut_WithHandle(*stack); - if (!h.valid()) return id; - - if (flags()->origin_history_per_stack_limit > 0) { - int use_count = h.use_count(); - if (use_count > flags()->origin_history_per_stack_limit) return id; - } - - u32 chained_id; - bool inserted = ChainedOriginDepotPut(h.id(), o.id(), &chained_id); - - if (inserted && flags()->origin_history_per_stack_limit > 0) - h.inc_use_count_unsafe(); - - return Origin(chained_id, depth).raw_id(); + Origin o = Origin::FromRawId(id); + Origin chained = Origin::CreateChainedOrigin(o, stack); + return chained.raw_id(); } } // namespace __msan @@ -542,14 +519,14 @@ void __msan_set_alloca_origin4(void *a, uptr size, char *descr, uptr pc) { CHECK_LT(idx, kNumStackOriginDescrs); StackOriginDescr[idx] = descr + 4; StackOriginPC[idx] = pc; - ChainedOriginDepotPut(idx, Origin::kStackRoot, &id); + id = Origin::CreateStackOrigin(idx).raw_id(); *id_ptr = id; if (print) Printf("First time: idx=%d id=%d %s %p \n", idx, id, descr + 4, pc); } if (print) Printf("__msan_set_alloca_origin: descr=%s id=%x\n", descr + 4, id); - __msan_set_origin(a, size, Origin(id, 1).raw_id()); + __msan_set_origin(a, size, id); } u32 __msan_chain_origin(u32 id) { |