#define ZLOGGER_BLOCK_COUNT (ZLOGGER_BUFFER_SIZE / ZLOGGER_BLOCK_SIZE)
#define ZLOGGER_BITMAP_SIZE (ZLOGGER_BLOCK_COUNT / 8)
#define ZLOGGER_DATA_MAX (ZLOGGER_BLOCK_SIZE - sizeof(struct zlogger_header))
-#define ZLOGGER_BLOCK_NUMBER 8192
+#define ZLOGGER_INITIAL_BLOCK_NUMBER 8192
#define ZLOGGER_TAG_MAX (32)
#define ZLOGGER_MSG_MAX (140)
static struct miscdevice zlogger_dump_device;
static int g_init;
-static char *g_shm_ptr[ZLOGGER_BLOCK_NUMBER];
+static char **g_shm_ptr;
+static uint32_t g_shm_ptr_size;
static struct thread_table *g_thread_table;
static struct mutex g_block_mutex;
return 0;
}
+static long zlogger_resize(unsigned long arg)
+{
+ // save blocks if shrinking, avoid ruining everything via realloc if expanding
+ g_shm_ptr_size = arg;
+ return 0;
+}
+
static long zlogger_dump_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
switch (cmd) {
case ZLOGGER_IOCTL_COMMAND_CLEAR:
return zlogger_clear();
+ case ZLOGGER_IOCTL_COMMAND_RESIZE:
+ return zlogger_resize(arg);
+
case ZLOGGER_IOCTL_COMMAND_GET_BITMAP:
return zlogger_get_bitmap(filp, arg);
int g_shm_ptr_i = 0;
int r = 0;
- unsigned int target_size = 32 * 1024 * 1024; // 32mb
unsigned int page_size = 4 * 1024; // 4kb
- unsigned int iterations = target_size / page_size;
- if (target_size % page_size != 0) {
- iterations++;
- }
-
if (!g_zlog_enable) {
pr_info("zlog is disable\n");
return 0;
return -ENOMEM;
hash_init(g_thread_table->data);
- for (g_shm_ptr_i = 0; g_shm_ptr_i < iterations; g_shm_ptr_i++) {
+ g_shm_ptr = kzalloc(ZLOGGER_INITIAL_BLOCK_NUMBER * sizeof *g_shm_ptr, GFP_KERNEL);
+ if (g_shm_ptr == NULL) {
+ kfree(g_thread_table);
+ g_thread_table = NULL;
+ return -ENOMEM;
+ }
+ g_shm_ptr_size = ZLOGGER_INITIAL_BLOCK_NUMBER;
+
+ for (g_shm_ptr_i = 0; g_shm_ptr_i < g_shm_ptr_size; g_shm_ptr_i++) {
g_shm_ptr[g_shm_ptr_i] = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, get_order(page_size));
if (g_shm_ptr[g_shm_ptr_i] == NULL) {
r = -ENOMEM;
g_shm_ptr[i] = NULL;
}
+ kfree(g_shm_ptr);
+ g_shm_ptr = NULL;
+
kfree(g_thread_table);
g_thread_table = NULL;
kfree(g_thread_table);
g_thread_table = NULL;
- for (i = 0; i < ZLOGGER_DEVICE_COUNT; i++) {
+ for (i = 0; i < g_shm_ptr_size; i++) {
free_pages((unsigned long)g_shm_ptr[i], MAP_ORDER);
g_shm_ptr[i] = NULL;
}
+ kfree(g_shm_ptr);
+ g_shm_ptr = NULL;
+
g_init = 0;
}