Skip to content
Snippets Groups Projects
Commit 0e0f41c0 authored by Ben Gamari's avatar Ben Gamari Committed by Marge Bot
Browse files

rts/eventlog: Avoid truncating event sizes

Previously ensureRoomForVariableEvent would truncate the desired size to
16-bits, resulting in #24197.

Fixes #24197.
parent a10f9b9b
No related branches found
No related tags found
No related merge requests found
...@@ -136,12 +136,12 @@ static void postBlockMarker(EventsBuf *eb); ...@@ -136,12 +136,12 @@ static void postBlockMarker(EventsBuf *eb);
static void closeBlockMarker(EventsBuf *ebuf); static void closeBlockMarker(EventsBuf *ebuf);
static StgBool hasRoomForEvent(EventsBuf *eb, EventTypeNum eNum); static StgBool hasRoomForEvent(EventsBuf *eb, EventTypeNum eNum);
static StgBool hasRoomForVariableEvent(EventsBuf *eb, uint32_t payload_bytes); static StgBool hasRoomForVariableEvent(EventsBuf *eb, StgWord payload_bytes);
static void freeEventLoggingBuffer(void); static void freeEventLoggingBuffer(void);
static void ensureRoomForEvent(EventsBuf *eb, EventTypeNum tag); static void ensureRoomForEvent(EventsBuf *eb, EventTypeNum tag);
static int ensureRoomForVariableEvent(EventsBuf *eb, StgWord16 size); static int ensureRoomForVariableEvent(EventsBuf *eb, StgWord size);
static inline void postWord8(EventsBuf *eb, StgWord8 i) static inline void postWord8(EventsBuf *eb, StgWord8 i)
{ {
...@@ -1509,9 +1509,9 @@ StgBool hasRoomForEvent(EventsBuf *eb, EventTypeNum eNum) ...@@ -1509,9 +1509,9 @@ StgBool hasRoomForEvent(EventsBuf *eb, EventTypeNum eNum)
} }
STG_WARN_UNUSED_RESULT STG_WARN_UNUSED_RESULT
StgBool hasRoomForVariableEvent(EventsBuf *eb, uint32_t payload_bytes) StgBool hasRoomForVariableEvent(EventsBuf *eb, StgWord payload_bytes)
{ {
uint32_t size = sizeof(EventTypeNum) + sizeof(EventTimestamp) + StgWord size = sizeof(EventTypeNum) + sizeof(EventTimestamp) +
sizeof(EventPayloadSize) + payload_bytes; sizeof(EventPayloadSize) + payload_bytes;
if (eb->pos + size > eb->begin + eb->size) { if (eb->pos + size > eb->begin + eb->size) {
...@@ -1526,17 +1526,19 @@ void ensureRoomForEvent(EventsBuf *eb, EventTypeNum tag) ...@@ -1526,17 +1526,19 @@ void ensureRoomForEvent(EventsBuf *eb, EventTypeNum tag)
if (!hasRoomForEvent(eb, tag)) { if (!hasRoomForEvent(eb, tag)) {
// Flush event buffer to make room for new event. // Flush event buffer to make room for new event.
printAndClearEventBuf(eb); printAndClearEventBuf(eb);
ASSERT(hasRoomForEvent(eb, tag));
} }
} }
STG_WARN_UNUSED_RESULT STG_WARN_UNUSED_RESULT
int ensureRoomForVariableEvent(EventsBuf *eb, StgWord16 size) int ensureRoomForVariableEvent(EventsBuf *eb, StgWord size)
{ {
if (!hasRoomForVariableEvent(eb, size)) { if (!hasRoomForVariableEvent(eb, size)) {
// Flush event buffer to make room for new event. // Flush event buffer to make room for new event.
printAndClearEventBuf(eb); printAndClearEventBuf(eb);
if (!hasRoomForVariableEvent(eb, size)) if (!hasRoomForVariableEvent(eb, size)) {
return 1; // Not enough space return 1; // Not enough space
}
} }
return 0; return 0;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment