bonefish+mmlr:
* Introduce TracingMetaData::IsInBuffer() to validate that a certain memory range is within the valid tracing buffer limits. * Use that when validating in tracing_is_entry_valid() before trying to access the entry, resolving a TODO. * Validate the candidate time against the handed in time (if specified) as an additional check. * Tiny unrelated text cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@43116 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -265,7 +265,8 @@ TraceOutput::Print(const char* format,...)
|
|||||||
|
|
||||||
int dump_tracing(int argc, char** argv, WrapperTraceFilter* wrapperFilter);
|
int dump_tracing(int argc, char** argv, WrapperTraceFilter* wrapperFilter);
|
||||||
|
|
||||||
bool tracing_is_entry_valid(TraceEntry* entry, bigtime_t entryTime);
|
bool tracing_is_entry_valid(AbstractTraceEntry* entry,
|
||||||
|
bigtime_t entryTime = -1);
|
||||||
|
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
|
|
||||||
|
|||||||
@@ -100,6 +100,8 @@ public:
|
|||||||
|
|
||||||
trace_entry* AllocateEntry(size_t size, uint16 flags);
|
trace_entry* AllocateEntry(size_t size, uint16 flags);
|
||||||
|
|
||||||
|
bool IsInBuffer(void* address, size_t size);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _FreeFirstEntry();
|
bool _FreeFirstEntry();
|
||||||
bool _MakeSpace(size_t needed);
|
bool _MakeSpace(size_t needed);
|
||||||
@@ -285,6 +287,25 @@ TracingMetaData::AllocateEntry(size_t size, uint16 flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
TracingMetaData::IsInBuffer(void* address, size_t size)
|
||||||
|
{
|
||||||
|
if (fEntries == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
addr_t start = (addr_t)address;
|
||||||
|
addr_t end = start + size;
|
||||||
|
|
||||||
|
if (start < (addr_t)fBuffer || end > (addr_t)(fBuffer + kBufferSize))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (fFirstEntry > fAfterLastEntry)
|
||||||
|
return start >= (addr_t)fFirstEntry || end <= (addr_t)fAfterLastEntry;
|
||||||
|
|
||||||
|
return start >= (addr_t)fFirstEntry && end <= (addr_t)fAfterLastEntry;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
TracingMetaData::_FreeFirstEntry()
|
TracingMetaData::_FreeFirstEntry()
|
||||||
{
|
{
|
||||||
@@ -495,8 +516,8 @@ bool
|
|||||||
TracingMetaData::_InitPreviousTracingData()
|
TracingMetaData::_InitPreviousTracingData()
|
||||||
{
|
{
|
||||||
// TODO: ATM re-attaching the previous tracing buffer doesn't work very
|
// TODO: ATM re-attaching the previous tracing buffer doesn't work very
|
||||||
// well. The entries should checked more thoroughly for validity -- e.g. the
|
// well. The entries should be checked more thoroughly for validity -- e.g.
|
||||||
// pointers to the entries' vtable pointers could be invalid, which can
|
// the pointers to the entries' vtable pointers could be invalid, which can
|
||||||
// make the "traced" command quite unusable. The validity of the entries
|
// make the "traced" command quite unusable. The validity of the entries
|
||||||
// could be checked in a safe environment (i.e. with a fault handler) with
|
// could be checked in a safe environment (i.e. with a fault handler) with
|
||||||
// typeid() and call of a virtual function.
|
// typeid() and call of a virtual function.
|
||||||
@@ -1696,18 +1717,25 @@ dump_tracing(int argc, char** argv, WrapperTraceFilter* wrapperFilter)
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
tracing_is_entry_valid(TraceEntry* candidate, bigtime_t entryTime)
|
tracing_is_entry_valid(AbstractTraceEntry* candidate, bigtime_t entryTime)
|
||||||
{
|
{
|
||||||
#if ENABLE_TRACING
|
#if ENABLE_TRACING
|
||||||
|
if (!sTracingMetaData->IsInBuffer(candidate, sizeof(*candidate)))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (entryTime < 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
TraceEntryIterator iterator;
|
TraceEntryIterator iterator;
|
||||||
while (TraceEntry* entry = iterator.Next()) {
|
while (TraceEntry* entry = iterator.Next()) {
|
||||||
AbstractTraceEntry* abstract = dynamic_cast<AbstractTraceEntry*>(entry);
|
AbstractTraceEntry* abstract = dynamic_cast<AbstractTraceEntry*>(entry);
|
||||||
if (abstract == NULL)
|
if (abstract == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// TODO: This could be better by additionally checking if the
|
if (abstract != candidate && abstract->Time() > entryTime)
|
||||||
// candidate entry address falls within the valid entry range.
|
return false;
|
||||||
return abstract == candidate || abstract->Time() < entryTime;
|
|
||||||
|
return candidate->Time() == entryTime;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user