Message ID | 151127332036.6888.3168353085464706816.stgit@Misha-PC.lan02.inno |
---|---|
State | New |
Headers | show |
Series | Windbg supporting | expand |
On Tue, Nov 21, 2017 at 3:08 PM, Mihail Abakumov <mikhail.abakumov@ispras.ru> wrote: > Defined useful sized data buffer. It contains pointer to data and size of this data. Also, defined some macros for init and free. > > Signed-off-by: Mihail Abakumov <mikhail.abakumov@ispras.ru> > Signed-off-by: Pavel Dovgalyuk <dovgaluk@ispras.ru> > Signed-off-by: Dmitriy Koltunov <koltunov@ispras.ru> > --- > include/exec/windbgstub-utils.h | 16 ++++++++++++++++ > 1 file changed, 16 insertions(+) > > diff --git a/include/exec/windbgstub-utils.h b/include/exec/windbgstub-utils.h > index 6ce870beb1..b729cd604e 100755 > --- a/include/exec/windbgstub-utils.h > +++ b/include/exec/windbgstub-utils.h > @@ -67,6 +67,22 @@ typedef struct PacketData { > uint16_t extra_size; > } PacketData; > > +typedef struct SizedBuf { > + uint8_t *data; > + size_t size; > +} SizedBuf; > + > +#define SBUF_INIT(buf, mem_ptr, len) do { \ > + buf.data = mem_ptr; \ > + buf.size = len; \ > +} while (false) > +#define SBUF_MALLOC(buf, size) SBUF_INIT(buf, g_malloc0(size), size) > +#define SBUF_FREE(buf) do { \ > + g_free(buf.data); \ > + buf.data = NULL; \ > + buf.size = 0; \ > +} while (false) > + I don't think that this is necessary. These macros are used for ~240 byte data structures and the points where they are allocated and freed are super close together. I'd just put them on the stack in the callers of kd_gen_exception_sc() and kd_gen_load_symbols_sc() (only one caller each) and remove this patch. > InitedAddr *windbg_get_KPCR(void); > InitedAddr *windbg_get_version(void); > >
diff --git a/include/exec/windbgstub-utils.h b/include/exec/windbgstub-utils.h index 6ce870beb1..b729cd604e 100755 --- a/include/exec/windbgstub-utils.h +++ b/include/exec/windbgstub-utils.h @@ -67,6 +67,22 @@ typedef struct PacketData { uint16_t extra_size; } PacketData; +typedef struct SizedBuf { + uint8_t *data; + size_t size; +} SizedBuf; + +#define SBUF_INIT(buf, mem_ptr, len) do { \ + buf.data = mem_ptr; \ + buf.size = len; \ +} while (false) +#define SBUF_MALLOC(buf, size) SBUF_INIT(buf, g_malloc0(size), size) +#define SBUF_FREE(buf) do { \ + g_free(buf.data); \ + buf.data = NULL; \ + buf.size = 0; \ +} while (false) + InitedAddr *windbg_get_KPCR(void); InitedAddr *windbg_get_version(void);