mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
capture: do 24 bit counter identifier checks
Max uint was more than we allow, since we steal the top 8 bits for some other data. This instead checks for 24-bit and warns if the user tries to store a counter value that was not registered.
This commit is contained in:
@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
#define DEFAULT_BUFFER_SIZE (getpagesize() * 64L)
|
#define DEFAULT_BUFFER_SIZE (getpagesize() * 64L)
|
||||||
#define INVALID_ADDRESS (G_GUINT64_CONSTANT(0))
|
#define INVALID_ADDRESS (G_GUINT64_CONSTANT(0))
|
||||||
|
#define MAX_COUNTERS ((1 << 24) - 1)
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
@ -1079,7 +1080,15 @@ sp_capture_writer_define_counters (SpCaptureWriter *self,
|
|||||||
def->n_counters = n_counters;
|
def->n_counters = n_counters;
|
||||||
|
|
||||||
for (i = 0; i < n_counters; i++)
|
for (i = 0; i < n_counters; i++)
|
||||||
def->counters[i] = counters[i];
|
{
|
||||||
|
if (counters[i].id >= self->next_counter_id)
|
||||||
|
{
|
||||||
|
g_warning ("Counter %u has not been registered.", counters[i].id);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
def->counters[i] = counters[i];
|
||||||
|
}
|
||||||
|
|
||||||
self->stat.frame_count[SP_CAPTURE_FRAME_CTRDEF]++;
|
self->stat.frame_count[SP_CAPTURE_FRAME_CTRDEF]++;
|
||||||
|
|
||||||
@ -1171,7 +1180,7 @@ sp_capture_writer_request_counter (SpCaptureWriter *self,
|
|||||||
|
|
||||||
g_assert (self != NULL);
|
g_assert (self != NULL);
|
||||||
|
|
||||||
if (G_MAXUINT - n_counters < self->next_counter_id)
|
if (MAX_COUNTERS - n_counters < self->next_counter_id)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ret = self->next_counter_id;
|
ret = self->next_counter_id;
|
||||||
|
|||||||
Reference in New Issue
Block a user