mirror of
https://gitea.osmocom.org/sim-card/simtrace2.git
synced 2026-03-16 21:28:33 +03:00
We now generalize the USB communiction and abandon the 'req_ctx' structure inherited from openpcd. Instead we use the libosmocore 'msgb' structure to handle incoming and outgoing USB tranfers. We also use linuxlist-based msgb-queues for each endpoint.
70 lines
1.4 KiB
C
70 lines
1.4 KiB
C
#include <stdint.h>
|
|
|
|
#include "talloc.h"
|
|
#include "trace.h"
|
|
#include "osmocom/core/utils.h"
|
|
|
|
#define NUM_RCTX_SMALL 10
|
|
#define RCTX_SIZE_SMALL 348
|
|
|
|
static uint8_t msgb_data[NUM_RCTX_SMALL][RCTX_SIZE_SMALL] __attribute__((aligned(sizeof(long))));
|
|
static uint8_t msgb_inuse[NUM_RCTX_SMALL];
|
|
|
|
void *_talloc_zero(const void *ctx, size_t size, const char *name)
|
|
{
|
|
unsigned int i;
|
|
|
|
if (size > RCTX_SIZE_SMALL) {
|
|
TRACE_ERROR("%s() request too large(%d > %d)\r\n", __func__, size, RCTX_SIZE_SMALL);
|
|
return NULL;
|
|
}
|
|
|
|
for (i = 0; i < ARRAY_SIZE(msgb_inuse); i++) {
|
|
if (!msgb_inuse[i]) {
|
|
uint8_t *out = msgb_data[i];
|
|
msgb_inuse[i] = 1;
|
|
memset(out, 0, size);
|
|
return out;
|
|
}
|
|
}
|
|
TRACE_ERROR("%s() out of memory!\r\n", __func__);
|
|
return NULL;
|
|
}
|
|
|
|
int _talloc_free(void *ptr, const char *location)
|
|
{
|
|
unsigned int i;
|
|
for (i = 0; i < ARRAY_SIZE(msgb_inuse); i++) {
|
|
if (ptr == msgb_data[i]) {
|
|
if (!msgb_inuse[i]) {
|
|
TRACE_ERROR("%s: double_free by \r\n", __func__, location);
|
|
} else {
|
|
msgb_inuse[i] = 0;
|
|
}
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
TRACE_ERROR("%s: invalid pointer %p from %s\r\n", __func__, ptr, location);
|
|
return -1;
|
|
}
|
|
|
|
void talloc_set_name_const(const void *ptr, const char *name)
|
|
{
|
|
/* do nothing */
|
|
}
|
|
|
|
#if 0
|
|
void *talloc_named_const(const void *context, size_t size, const char *name)
|
|
{
|
|
if (size)
|
|
TRACE_ERROR("%s: called with size!=0 from %s\r\n", __func__, name);
|
|
return NULL;
|
|
}
|
|
|
|
void *talloc_pool(const void *context, size_t size)
|
|
{
|
|
}
|
|
#endif
|
|
|