34 void *(*Alloc)(
unsigned int);
47 static int storage_registration_closed = 0;
69 memset(&storage_max_id, 0x00,
sizeof(storage_max_id));
72 storage_registration_closed = 0;
80 if (storage_map[i] != NULL) {
82 storage_map[i] = NULL;
101 if (storage_registration_closed)
105 size == 0 || (size !=
sizeof(
void *) && Alloc == NULL) || Free == NULL)
112 "name \"%s\" already registered", StoragePrintType(
type),
132 entry->
id = storage_max_id[
type]++;
133 entry->
next = storage_list;
134 storage_list = entry;
144 storage_registration_closed = 1;
147 if (storage_max_id[i] > 0)
154 if (
unlikely(storage_map == NULL)) {
160 if (storage_max_id[i] > 0) {
162 if (storage_map[i] == NULL)
164 memset(storage_map[i], 0x00,
sizeof(
StorageMapping) * storage_max_id[i]);
170 if (storage_map[entry->
map.
type] != NULL) {
186 if (storage_map[i] == NULL)
190 for (j = 0; j < storage_max_id[i]; j++) {
192 SCLogDebug(
"type \"%s\" name \"%s\" size \"%"PRIuMAX
"\"",
193 StoragePrintType(
m->type),
m->name, (uintmax_t)
m->size);
202 return storage_max_id[
type];
213 return storage_max_id[
type] *
sizeof(
void *);
219 BUG_ON(!storage_registration_closed);
230 BUG_ON(!storage_registration_closed);
242 BUG_ON(!storage_registration_closed);
247 if (storage[
id] == NULL &&
map->
Alloc != NULL) {
249 if (storage[
id] == NULL) {
260 BUG_ON(!storage_registration_closed);
268 store =
SCMalloc(
sizeof(
void *) * storage_max_id[
type]);
271 memset(store, 0x00,
sizeof(
void *) * storage_max_id[
type]);
275 if (store[
id] == NULL &&
map->
Alloc != NULL) {
277 if (store[
id] == NULL) {
291 BUG_ON(!storage_registration_closed);
294 if (storage_map == NULL)
302 if (store[
id] != NULL) {
315 BUG_ON(!storage_registration_closed);
318 if (storage_map == NULL)
324 for (i = 0; i < storage_max_id[
type]; i++) {
325 if (store[i] != NULL) {
335 if (*storage == NULL)
339 BUG_ON(!storage_registration_closed);
342 if (storage_map == NULL)
348 for (i = 0; i < storage_max_id[
type]; i++) {
349 if (store[i] != NULL) {
361 static void *StorageTestAlloc(
unsigned int size)
366 static void StorageTestFree(
void *x)
372 static int StorageTest01(
void)
400 static void *StorageTest02Init(
unsigned int size)
408 static int StorageTest02(
void)
416 printf(
"StorageRegister failed (2): ");
421 printf(
"StorageRegister failed (2): ");
426 printf(
"StorageFinalize failed: ");
433 printf(
"StorageAllocById failed, data == NULL, storage %p: ", storage);
437 if (test->
abc != 1234) {
438 printf(
"setup failed, test->abc != 1234, but %d (1):", test->
abc);
445 printf(
"StorageAllocById failed, data == NULL, storage %p: ", storage);
449 if (test->
abc != 1234) {
450 printf(
"setup failed, test->abc != 1234, but %d (2):", test->
abc);
456 printf(
"StorageAllocById failed, data == NULL, storage %p: ", storage);
460 if (test->
abc != 4321) {
461 printf(
"setup failed, test->abc != 4321, but %d (3):", test->
abc);
477 static int StorageTest03(
void)
486 printf(
"duplicate registration should have failed: ");
492 printf(
"duplicate registration should have failed (2): ");
498 printf(
"duplicate registration should have failed (3): ");
504 printf(
"duplicate registration should have failed (4): ");
510 printf(
"duplicate registration should have failed (5): ");
516 printf(
"duplicate registration should have failed (6): ");
522 printf(
"duplicate registration should have failed (7): ");
526 id =
StorageRegister(38,
"test5", 8, StorageTestAlloc, StorageTestFree);
528 printf(
"duplicate registration should have failed (8): ");
532 id =
StorageRegister(-1,
"test6", 8, StorageTestAlloc, StorageTestFree);
534 printf(
"duplicate registration should have failed (9): ");