capture: make structs more cross-platform

There were some GCC'isms here that don't port well to mingw
(and likely other win32 compilers). Of note are the removal
of #pragma pack to instead use the GCC attributes or MSVC
declarations. Also we cannot be so liberal in our use of
bitflags, we need to use common types from neighbors.
This commit is contained in:
Christian Hergert
2019-05-06 20:01:25 -07:00
parent b6d24dafcf
commit 191754e505

View File

@ -32,6 +32,14 @@ G_BEGIN_DECLS
#define SP_CAPTURE_MAGIC (GUINT32_TO_LE(0xFDCA975E)) #define SP_CAPTURE_MAGIC (GUINT32_TO_LE(0xFDCA975E))
#define SP_CAPTURE_ALIGN (sizeof(SpCaptureAddress)) #define SP_CAPTURE_ALIGN (sizeof(SpCaptureAddress))
#if defined(_MSC_VER)
# define SP_ALIGNED_BEGIN(_N) __declspec(align (_N))
# define SP_ALIGNED_END(_N)
#else
# define SP_ALIGNED_BEGIN(_N)
# define SP_ALIGNED_END(_N) __attribute__((aligned ((_N))))
#endif
#if GLIB_SIZEOF_VOID_P == 8 #if GLIB_SIZEOF_VOID_P == 8
# define SP_CAPTURE_JITMAP_MARK G_GUINT64_CONSTANT(0xE000000000000000) # define SP_CAPTURE_JITMAP_MARK G_GUINT64_CONSTANT(0xE000000000000000)
# define SP_CAPTURE_ADDRESS_FORMAT "0x%016lx" # define SP_CAPTURE_ADDRESS_FORMAT "0x%016lx"
@ -73,32 +81,35 @@ typedef enum
SP_CAPTURE_FRAME_MARK = 10, SP_CAPTURE_FRAME_MARK = 10,
} SpCaptureFrameType; } SpCaptureFrameType;
#pragma pack(push, 1) SP_ALIGNED_BEGIN(1)
typedef struct typedef struct
{ {
guint32 magic; guint32 magic;
guint8 version; guint32 version : 8;
guint32 little_endian : 1; guint32 little_endian : 1;
guint32 padding : 23; guint32 padding : 23;
gchar capture_time[64]; gchar capture_time[64];
gint64 time; gint64 time;
gint64 end_time; gint64 end_time;
gchar suffix[168]; gchar suffix[168];
} SpCaptureFileHeader; } SpCaptureFileHeader
SP_ALIGNED_END(1);
SP_ALIGNED_BEGIN(1)
typedef struct typedef struct
{ {
guint16 len; guint16 len;
gint16 cpu; gint16 cpu;
gint32 pid; gint32 pid;
gint64 time; gint64 time;
guint8 type; guint32 type : 8;
guint32 padding1; guint32 padding1 : 24;
guint32 padding2 : 24; guint32 padding2;
guint8 data[0]; guint8 data[0];
} SpCaptureFrame; } SpCaptureFrame
SP_ALIGNED_END(1);
SP_ALIGNED_BEGIN(1)
typedef struct typedef struct
{ {
SpCaptureFrame frame; SpCaptureFrame frame;
@ -107,65 +118,83 @@ typedef struct
guint64 offset; guint64 offset;
guint64 inode; guint64 inode;
gchar filename[0]; gchar filename[0];
} SpCaptureMap; } SpCaptureMap
SP_ALIGNED_END(1);
SP_ALIGNED_BEGIN(1)
typedef struct typedef struct
{ {
SpCaptureFrame frame; SpCaptureFrame frame;
guint32 n_jitmaps; guint32 n_jitmaps;
guint8 data[0]; guint8 data[0];
} SpCaptureJitmap; } SpCaptureJitmap
SP_ALIGNED_END(1);
SP_ALIGNED_BEGIN(1)
typedef struct typedef struct
{ {
SpCaptureFrame frame; SpCaptureFrame frame;
gchar cmdline[0]; gchar cmdline[0];
} SpCaptureProcess; } SpCaptureProcess
SP_ALIGNED_END(1);
SP_ALIGNED_BEGIN(1)
typedef struct typedef struct
{ {
SpCaptureFrame frame; SpCaptureFrame frame;
guint16 n_addrs; guint32 n_addrs : 16;
guint32 padding1; guint32 padding1 : 16;
guint32 padding2 : 16; guint32 padding2;
SpCaptureAddress addrs[0]; SpCaptureAddress addrs[0];
} SpCaptureSample; } SpCaptureSample
SP_ALIGNED_END(1);
SP_ALIGNED_BEGIN(1)
typedef struct typedef struct
{ {
SpCaptureFrame frame; SpCaptureFrame frame;
GPid child_pid; gint32 child_pid;
} SpCaptureFork; } SpCaptureFork
SP_ALIGNED_END(1);
SP_ALIGNED_BEGIN(1)
typedef struct typedef struct
{ {
SpCaptureFrame frame; SpCaptureFrame frame;
} SpCaptureExit; } SpCaptureExit
SP_ALIGNED_END(1);
SP_ALIGNED_BEGIN(1)
typedef struct typedef struct
{ {
SpCaptureFrame frame; SpCaptureFrame frame;
} SpCaptureTimestamp; } SpCaptureTimestamp
SP_ALIGNED_END(1);
SP_ALIGNED_BEGIN(1)
typedef struct typedef struct
{ {
gchar category[32]; gchar category[32];
gchar name[32]; gchar name[32];
gchar description[52]; gchar description[52];
guint32 id : 24; guint32 id : 24;
guint8 type; guint32 type : 8;
SpCaptureCounterValue value; SpCaptureCounterValue value;
} SpCaptureCounter; } SpCaptureCounter
SP_ALIGNED_END(1);
SP_ALIGNED_BEGIN(1)
typedef struct typedef struct
{ {
SpCaptureFrame frame; SpCaptureFrame frame;
guint16 n_counters; guint32 n_counters : 16;
guint32 padding1; guint32 padding1 : 16;
guint32 padding2 : 16; guint32 padding2;
SpCaptureCounter counters[0]; SpCaptureCounter counters[0];
} SpCaptureFrameCounterDefine; } SpCaptureFrameCounterDefine
SP_ALIGNED_END(1);
SP_ALIGNED_BEGIN(1)
typedef struct typedef struct
{ {
/* /*
@ -175,17 +204,21 @@ typedef struct
*/ */
guint32 ids[8]; guint32 ids[8];
SpCaptureCounterValue values[8]; SpCaptureCounterValue values[8];
} SpCaptureCounterValues; } SpCaptureCounterValues
SP_ALIGNED_END(1);
SP_ALIGNED_BEGIN(1)
typedef struct typedef struct
{ {
SpCaptureFrame frame; SpCaptureFrame frame;
guint16 n_values; guint32 n_values : 16;
guint32 padding1; guint32 padding1 : 16;
guint32 padding2 : 16; guint32 padding2;
SpCaptureCounterValues values[0]; SpCaptureCounterValues values[0];
} SpCaptureFrameCounterSet; } SpCaptureFrameCounterSet
SP_ALIGNED_END(1);
SP_ALIGNED_BEGIN(1)
typedef struct typedef struct
{ {
SpCaptureFrame frame; SpCaptureFrame frame;
@ -193,9 +226,8 @@ typedef struct
gchar group[24]; gchar group[24];
gchar name[40]; gchar name[40];
gchar message[0]; gchar message[0];
} SpCaptureMark; } SpCaptureMark
SP_ALIGNED_END(1);
#pragma pack(pop)
G_STATIC_ASSERT (sizeof (SpCaptureFileHeader) == 256); G_STATIC_ASSERT (sizeof (SpCaptureFileHeader) == 256);
G_STATIC_ASSERT (sizeof (SpCaptureFrame) == 24); G_STATIC_ASSERT (sizeof (SpCaptureFrame) == 24);