Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit f11f3d7

Browse files
brianrobvancem
authored andcommitted
EventPipe: Prepend variable length field sizes (#11600)
* Write the size in bytes of the stack before the stack contents. * Specify the size of the metadata payload explicitly in the file.
1 parent c4db3ea commit f11f3d7

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/vm/eventpipeconfiguration.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ EventPipeEventInstance* EventPipeConfiguration::BuildEventMetadataEvent(EventPip
336336
const GUID &providerID = sourceEvent.GetProvider()->GetProviderID();
337337
unsigned int eventID = sourceEvent.GetEventID();
338338
unsigned int eventVersion = sourceEvent.GetEventVersion();
339-
unsigned int instancePayloadSize = sizeof(providerID) + sizeof(eventID) + sizeof(eventVersion) + payloadLength;
339+
unsigned int instancePayloadSize = sizeof(providerID) + sizeof(eventID) + sizeof(eventVersion) + sizeof(payloadLength) + payloadLength;
340340

341341
// Allocate the payload.
342342
BYTE *pInstancePayload = new BYTE[instancePayloadSize];
@@ -356,6 +356,10 @@ EventPipeEventInstance* EventPipeConfiguration::BuildEventMetadataEvent(EventPip
356356
memcpy(currentPtr, &eventVersion, sizeof(eventVersion));
357357
currentPtr += sizeof(eventVersion);
358358

359+
// Write the size of the metadata.
360+
memcpy(currentPtr, &payloadLength, sizeof(payloadLength));
361+
currentPtr += sizeof(payloadLength);
362+
359363
// Write the incoming payload data.
360364
memcpy(currentPtr, pPayloadData, payloadLength);
361365

src/vm/eventpipeeventinstance.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ void EventPipeEventInstance::FastSerialize(FastSerializer *pSerializer, StreamLa
101101
sizeof(m_threadID) + // Thread ID
102102
sizeof(m_timeStamp) + // TimeStamp
103103
m_dataLength + // Event payload data length
104+
sizeof(unsigned int) + // Prepended stack payload size in bytes
104105
m_stackContents.GetSize(); // Stack payload size
105106

106107
// Write the size of the event to the file.
@@ -121,10 +122,14 @@ void EventPipeEventInstance::FastSerialize(FastSerializer *pSerializer, StreamLa
121122
pSerializer->WriteBuffer(m_pData, m_dataLength);
122123
}
123124

125+
// Write the size of the stack in bytes.
126+
unsigned int stackSize = m_stackContents.GetSize();
127+
pSerializer->WriteBuffer((BYTE*)&stackSize, sizeof(stackSize));
128+
124129
// Write the stack if present.
125-
if(m_stackContents.GetSize() > 0)
130+
if(stackSize > 0)
126131
{
127-
pSerializer->WriteBuffer(m_stackContents.GetPointer(), m_stackContents.GetSize());
132+
pSerializer->WriteBuffer(m_stackContents.GetPointer(), stackSize);
128133
}
129134
}
130135

0 commit comments

Comments
 (0)