35 void *(*Alloc)(
unsigned int);
48 static int storage_registration_closed = 0;
70 memset(&storage_max_id, 0x00,
sizeof(storage_max_id));
73 storage_registration_closed = 0;
81 if (storage_map[i] != NULL) {
83 storage_map[i] = NULL;
102 if (storage_registration_closed)
106 size == 0 || (size !=
sizeof(
void *) && Alloc == NULL) || Free == NULL)
113 "name \"%s\" already registered",
114 StoragePrintType(
type), name);
133 entry->
id = storage_max_id[
type]++;
134 entry->
next = storage_list;
135 storage_list = entry;
145 storage_registration_closed = 1;
148 if (storage_max_id[i] > 0)
155 if (
unlikely(storage_map == NULL)) {
161 if (storage_max_id[i] > 0) {
163 if (storage_map[i] == NULL)
165 memset(storage_map[i], 0x00,
sizeof(
StorageMapping) * storage_max_id[i]);
171 if (storage_map[entry->
map.
type] != NULL) {
187 if (storage_map[i] == NULL)
191 for (j = 0; j < storage_max_id[i]; j++) {
193 SCLogDebug(
"type \"%s\" name \"%s\" size \"%"PRIuMAX
"\"",
194 StoragePrintType(
m->type),
m->name, (uintmax_t)
m->size);
203 return storage_max_id[
type];
214 return storage_max_id[
type] *
sizeof(
void *);
220 BUG_ON(!storage_registration_closed);
231 BUG_ON(!storage_registration_closed);
243 BUG_ON(!storage_registration_closed);
248 if (storage[
id] == NULL &&
map->
Alloc != NULL) {
250 if (storage[
id] == NULL) {
261 BUG_ON(!storage_registration_closed);
269 store =
SCMalloc(
sizeof(
void *) * storage_max_id[
type]);
272 memset(store, 0x00,
sizeof(
void *) * storage_max_id[
type]);
276 if (store[
id] == NULL &&
map->
Alloc != NULL) {
278 if (store[
id] == NULL) {
292 BUG_ON(!storage_registration_closed);
295 if (storage_map == NULL)
303 if (store[
id] != NULL) {
316 BUG_ON(!storage_registration_closed);
319 if (storage_map == NULL)
325 for (i = 0; i < storage_max_id[
type]; i++) {
326 if (store[i] != NULL) {
336 if (*storage == NULL)
340 BUG_ON(!storage_registration_closed);
343 if (storage_map == NULL)
349 for (i = 0; i < storage_max_id[
type]; i++) {
350 if (store[i] != NULL) {
362 static void *StorageTestAlloc(
unsigned int size)
367 static void StorageTestFree(
void *x)
373 static int StorageTest01(
void)
401 static void *StorageTest02Init(
unsigned int size)
409 static int StorageTest02(
void)
417 printf(
"StorageRegister failed (2): ");
422 printf(
"StorageRegister failed (2): ");
427 printf(
"StorageFinalize failed: ");
434 printf(
"StorageAllocById failed, data == NULL, storage %p: ", storage);
438 if (test->
abc != 1234) {
439 printf(
"setup failed, test->abc != 1234, but %d (1):", test->
abc);
446 printf(
"StorageAllocById failed, data == NULL, storage %p: ", storage);
450 if (test->
abc != 1234) {
451 printf(
"setup failed, test->abc != 1234, but %d (2):", test->
abc);
457 printf(
"StorageAllocById failed, data == NULL, storage %p: ", storage);
461 if (test->
abc != 4321) {
462 printf(
"setup failed, test->abc != 4321, but %d (3):", test->
abc);
478 static int StorageTest03(
void)
487 printf(
"duplicate registration should have failed: ");
493 printf(
"duplicate registration should have failed (2): ");
499 printf(
"duplicate registration should have failed (3): ");
505 printf(
"duplicate registration should have failed (4): ");
511 printf(
"duplicate registration should have failed (5): ");
517 printf(
"duplicate registration should have failed (6): ");
523 printf(
"duplicate registration should have failed (7): ");
527 id =
StorageRegister(38,
"test5", 8, StorageTestAlloc, StorageTestFree);
529 printf(
"duplicate registration should have failed (8): ");
533 id =
StorageRegister(-1,
"test6", 8, StorageTestAlloc, StorageTestFree);
535 printf(
"duplicate registration should have failed (9): ");