1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
/* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
* only version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <linux/module.h>
#include <linux/cpu.h>
#include <linux/slab.h>
#include <linux/notifier.h>
#include <asm/app_api.h>
#define MAX_LEN 100
static char *lib_names[MAX_ENTRIES];
static unsigned int count;
static struct mutex mutex;
static char lib_str[MAX_LEN] = "";
static struct kparam_string kps = {
.string = lib_str,
.maxlen = MAX_LEN,
};
static int set_name(const char *str, struct kernel_param *kp);
module_param_call(lib_name, set_name, param_get_string, &kps, S_IWUSR);
bool use_app_setting = true;
module_param(use_app_setting, bool, 0644);
MODULE_PARM_DESC(use_app_setting, "control use of app specific settings");
bool use_32bit_app_setting = true;
module_param(use_32bit_app_setting, bool, 0644);
MODULE_PARM_DESC(use_32bit_app_setting, "control use of 32 bit app specific settings");
bool use_32bit_app_setting_pro;
module_param(use_32bit_app_setting_pro, bool, 0644);
MODULE_PARM_DESC(use_32bit_app_setting_pro, "control use of 32 bit app specific settings");
static int set_name(const char *str, struct kernel_param *kp)
{
int len = strlen(str);
char *name;
if (len >= MAX_LEN) {
pr_err("app_setting: name string too long\n");
return -ENOSPC;
}
/*
* echo adds '\n' which we need to chop off later
*/
name = kzalloc(len + 1, GFP_KERNEL);
if (!name)
return -ENOMEM;
strlcpy(name, str, len + 1);
if (name[len - 1] == '\n')
name[len - 1] = '\0';
mutex_lock(&mutex);
if (count < MAX_ENTRIES) {
lib_names[count] = name;
/*
* mb to ensure that the new lib_names entry is present
* before updating the view presented by get_lib_names
*/
mb();
count++;
} else {
pr_err("app_setting: set name failed. Max entries reached\n");
kfree(name);
mutex_unlock(&mutex);
return -EPERM;
}
mutex_unlock(&mutex);
return 0;
}
void switch_app_setting_bit(struct task_struct *prev, struct task_struct *next)
{
if (prev->mm && unlikely(prev->mm->app_setting))
clear_app_setting_bit(APP_SETTING_BIT);
if (next->mm && unlikely(next->mm->app_setting))
set_app_setting_bit(APP_SETTING_BIT);
}
EXPORT_SYMBOL(switch_app_setting_bit);
void switch_32bit_app_setting_bit(struct task_struct *prev,
struct task_struct *next)
{
if (prev->mm && unlikely(is_compat_thread(task_thread_info(prev))))
clear_app_setting_bit_for_32bit_apps();
if (next->mm && unlikely(is_compat_thread(task_thread_info(next))))
set_app_setting_bit_for_32bit_apps();
}
EXPORT_SYMBOL(switch_32bit_app_setting_bit);
void apply_app_setting_bit(struct file *file)
{
bool found = false;
int i;
if (file && file->f_path.dentry) {
const char *name = file->f_path.dentry->d_name.name;
for (i = 0; i < count; i++) {
if (unlikely(!strcmp(name, lib_names[i]))) {
found = true;
break;
}
}
if (found) {
preempt_disable();
set_app_setting_bit(APP_SETTING_BIT);
/* This will take care of child processes as well */
current->mm->app_setting = 1;
preempt_enable();
}
}
}
EXPORT_SYMBOL(apply_app_setting_bit);
static int __init app_setting_init(void)
{
mutex_init(&mutex);
return 0;
}
module_init(app_setting_init);
|