diff options
Diffstat (limited to 'drivers/gator/gator_cookies.c')
-rw-r--r-- | drivers/gator/gator_cookies.c | 67 |
1 files changed, 38 insertions, 29 deletions
diff --git a/drivers/gator/gator_cookies.c b/drivers/gator/gator_cookies.c index 5c7d842070e0..c43cce815226 100644 --- a/drivers/gator/gator_cookies.c +++ b/drivers/gator/gator_cookies.c @@ -7,8 +7,10 @@ * */ -#define COOKIEMAP_ENTRIES 1024 /* must be power of 2 */ -#define TRANSLATE_BUFFER_SIZE 512 // must be a power of 2 - 512/4 = 128 entries +/* must be power of 2 */ +#define COOKIEMAP_ENTRIES 1024 +/* must be a power of 2 - 512/4 = 128 entries */ +#define TRANSLATE_BUFFER_SIZE 512 #define TRANSLATE_TEXT_SIZE 256 #define MAX_COLLISIONS 2 @@ -38,6 +40,7 @@ static uint32_t cookiemap_code(uint64_t value64) { uint32_t value = (uint32_t)((value64 >> 32) + value64); uint32_t cookiecode = (value >> 24) & 0xff; + cookiecode = cookiecode * 31 + ((value >> 16) & 0xff); cookiecode = cookiecode * 31 + ((value >> 8) & 0xff); cookiecode = cookiecode * 31 + ((value >> 0) & 0xff); @@ -52,9 +55,8 @@ static uint32_t gator_chksum_crc32(const char *data) int i, length = strlen(data); crc = 0xFFFFFFFF; - for (i = 0; i < length; i++) { + for (i = 0; i < length; i++) crc = ((crc >> 8) & 0x00FFFFFF) ^ gator_crc32_table[(crc ^ *block++) & 0xFF]; - } return (crc ^ 0xFFFFFFFF); } @@ -72,11 +74,12 @@ static uint32_t cookiemap_exists(uint64_t key) uint64_t *keys = &(per_cpu(cookie_keys, cpu)[cookiecode]); uint32_t *values = &(per_cpu(cookie_values, cpu)[cookiecode]); - // Can be called from interrupt handler or from work queue + /* Can be called from interrupt handler or from work queue */ local_irq_save(flags); for (x = 0; x < MAX_COLLISIONS; x++) { if (keys[x] == key) { uint32_t value = values[x]; + for (; x > 0; x--) { keys[x] = keys[x - 1]; values[x] = values[x - 1]; @@ -126,7 +129,7 @@ static void translate_buffer_write_args(int cpu, struct task_struct *task, const write = per_cpu(translate_buffer_write, cpu); next_write = (write + 1) & translate_buffer_mask; - // At least one entry must always remain available as when read == write, the queue is empty not full + /* At least one entry must always remain available as when read == write, the queue is empty not full */ if (next_write != per_cpu(translate_buffer_read, cpu)) { args = &per_cpu(translate_buffer, cpu)[write]; args->task = task; @@ -178,11 +181,11 @@ static void wq_cookie_handler(struct work_struct *unused) static void app_process_wake_up_handler(unsigned long unused_data) { - // had to delay scheduling work as attempting to schedule work during the context switch is illegal in kernel versions 3.5 and greater + /* had to delay scheduling work as attempting to schedule work during the context switch is illegal in kernel versions 3.5 and greater */ schedule_work(&cookie_work); } -// Retrieve full name from proc/pid/cmdline for java processes on Android +/* Retrieve full name from proc/pid/cmdline for java processes on Android */ static int translate_app_process(const char **text, int cpu, struct task_struct *task, bool from_wq) { void *maddr; @@ -195,12 +198,16 @@ static int translate_app_process(const char **text, int cpu, struct task_struct char *buf = per_cpu(translate_text, cpu); #ifndef CONFIG_PREEMPT_RT_FULL - // Push work into a work queue if in atomic context as the kernel functions below might sleep - // Rely on the in_interrupt variable rather than in_irq() or in_interrupt() kernel functions, as the value of these functions seems - // inconsistent during a context switch between android/linux versions + /* Push work into a work queue if in atomic context as the kernel + * functions below might sleep. Rely on the in_interrupt variable + * rather than in_irq() or in_interrupt() kernel functions, as the + * value of these functions seems inconsistent during a context + * switch between android/linux versions + */ if (!from_wq) { - // Check if already in buffer + /* Check if already in buffer */ int pos = per_cpu(translate_buffer_read, cpu); + while (pos != per_cpu(translate_buffer_write, cpu)) { if (per_cpu(translate_buffer, cpu)[pos].task == task) goto out; @@ -209,7 +216,7 @@ static int translate_app_process(const char **text, int cpu, struct task_struct translate_buffer_write_args(cpu, task, *text); - // Not safe to call in RT-Preempt full in schedule switch context + /* Not safe to call in RT-Preempt full in schedule switch context */ mod_timer(&app_process_wake_up_timer, jiffies + 1); goto out; } @@ -239,7 +246,8 @@ static int translate_app_process(const char **text, int cpu, struct task_struct copy_from_user_page(page_vma, page, addr, buf, maddr + offset, bytes); - kunmap(page); // release page allocated by get_user_pages() + /* release page allocated by get_user_pages() */ + kunmap(page); page_cache_release(page); len -= bytes; @@ -250,7 +258,7 @@ static int translate_app_process(const char **text, int cpu, struct task_struct retval = 1; } - // On app_process startup, /proc/pid/cmdline is initially "zygote" then "<pre-initialized>" but changes after an initial startup period + /* On app_process startup, /proc/pid/cmdline is initially "zygote" then "<pre-initialized>" but changes after an initial startup period */ if (strcmp(*text, "zygote") == 0 || strcmp(*text, "<pre-initialized>") == 0) retval = 0; @@ -262,6 +270,8 @@ out: return retval; } +static const char APP_PROCESS[] = "app_process"; + static uint32_t get_cookie(int cpu, struct task_struct *task, const char *text, bool from_wq) { unsigned long flags, cookie; @@ -271,16 +281,16 @@ static uint32_t get_cookie(int cpu, struct task_struct *task, const char *text, key = (key << 32) | (uint32_t)task->tgid; cookie = cookiemap_exists(key); - if (cookie) { + if (cookie) return cookie; - } - if (strcmp(text, "app_process") == 0) { + /* On 64-bit android app_process can be app_process32 or app_process64 */ + if (strncmp(text, APP_PROCESS, sizeof(APP_PROCESS) - 1) == 0) { if (!translate_app_process(&text, cpu, task, from_wq)) return UNRESOLVED_COOKIE; } - // Can be called from interrupt handler or from work queue or from scheduler trace + /* Can be called from interrupt handler or from work queue or from scheduler trace */ local_irq_save(flags); cookie = UNRESOLVED_COOKIE; @@ -300,7 +310,7 @@ static int get_exec_cookie(int cpu, struct task_struct *task) struct mm_struct *mm = task->mm; const char *text; - // kernel threads have no address space + /* kernel threads have no address space */ if (!mm) return NO_COOKIE; @@ -355,7 +365,7 @@ static int cookies_initialize(void) per_cpu(cookie_next_key, cpu) = nr_cpu_ids + cpu; size = COOKIEMAP_ENTRIES * MAX_COLLISIONS * sizeof(uint64_t); - per_cpu(cookie_keys, cpu) = (uint64_t *)kmalloc(size, GFP_KERNEL); + per_cpu(cookie_keys, cpu) = kmalloc(size, GFP_KERNEL); if (!per_cpu(cookie_keys, cpu)) { err = -ENOMEM; goto cookie_setup_error; @@ -363,14 +373,14 @@ static int cookies_initialize(void) memset(per_cpu(cookie_keys, cpu), 0, size); size = COOKIEMAP_ENTRIES * MAX_COLLISIONS * sizeof(uint32_t); - per_cpu(cookie_values, cpu) = (uint32_t *)kmalloc(size, GFP_KERNEL); + per_cpu(cookie_values, cpu) = kmalloc(size, GFP_KERNEL); if (!per_cpu(cookie_values, cpu)) { err = -ENOMEM; goto cookie_setup_error; } memset(per_cpu(cookie_values, cpu), 0, size); - per_cpu(translate_buffer, cpu) = (struct cookie_args *)kmalloc(TRANSLATE_BUFFER_SIZE, GFP_KERNEL); + per_cpu(translate_buffer, cpu) = kmalloc(TRANSLATE_BUFFER_SIZE, GFP_KERNEL); if (!per_cpu(translate_buffer, cpu)) { err = -ENOMEM; goto cookie_setup_error; @@ -379,16 +389,16 @@ static int cookies_initialize(void) per_cpu(translate_buffer_write, cpu) = 0; per_cpu(translate_buffer_read, cpu) = 0; - per_cpu(translate_text, cpu) = (char *)kmalloc(TRANSLATE_TEXT_SIZE, GFP_KERNEL); + per_cpu(translate_text, cpu) = kmalloc(TRANSLATE_TEXT_SIZE, GFP_KERNEL); if (!per_cpu(translate_text, cpu)) { err = -ENOMEM; goto cookie_setup_error; } } - // build CRC32 table + /* build CRC32 table */ poly = 0x04c11db7; - gator_crc32_table = (uint32_t *)kmalloc(256 * sizeof(uint32_t), GFP_KERNEL); + gator_crc32_table = kmalloc(256 * sizeof(*gator_crc32_table), GFP_KERNEL); if (!gator_crc32_table) { err = -ENOMEM; goto cookie_setup_error; @@ -396,11 +406,10 @@ static int cookies_initialize(void) for (i = 0; i < 256; i++) { crc = i; for (j = 8; j > 0; j--) { - if (crc & 1) { + if (crc & 1) crc = (crc >> 1) ^ poly; - } else { + else crc >>= 1; - } } gator_crc32_table[i] = crc; } |