mirror of
https://gitea.osmocom.org/sim-card/simtrace2.git
synced 2026-08-15 11:17:13 +03:00
firmware: Add talloc_report_buf() encode the allocation by bits
First byte encodes the amount of blocks. The following bytes encode a block as a single bit. Change-Id: I3a8ddbe4100f342db2c59ad1fb9aa0014efc62b8
This commit is contained in:
@@ -77,6 +77,30 @@ int _talloc_free(void *ptr, const char *location)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Report the talloc usages and return of used bytes */
|
||||
unsigned int talloc_report_buf(uint8_t *buf, unsigned int buf_len)
|
||||
{
|
||||
unsigned int i, bitoff = 0, bitpos;
|
||||
|
||||
osmo_static_assert(ARRAY_SIZE(msgb_inuse) < 256, msgb_inuse_too_ig);
|
||||
|
||||
memset(buf, 0, buf_len);
|
||||
buf[bitoff] = ARRAY_SIZE(msgb_inuse);
|
||||
bitoff++;
|
||||
|
||||
for (i = 0, bitpos = 7; i < ARRAY_SIZE(msgb_inuse) && bitoff < buf_len; i++, bitpos--) {
|
||||
if (msgb_inuse[i])
|
||||
buf[bitoff] |= (1 << bitpos);
|
||||
|
||||
if (bitpos == 0) {
|
||||
bitpos = 7;
|
||||
bitoff++;
|
||||
}
|
||||
}
|
||||
|
||||
return bitoff + 1;
|
||||
}
|
||||
|
||||
void talloc_report(const void *ptr, FILE *f)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
Reference in New Issue
Block a user