4 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the License);
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 #ifndef __CORE_COMMON_H__
21 #define __CORE_COMMON_H__
28 #define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0]))
31 * One byte digit has 3 position in decimal representation
35 * >8 - compile time error
36 * plus 1 null termination byte
37 * plus 1 for negative prefix
39 #define MAX_DEC_SIZE(type) \
40 (2 + (sizeof(type) <= 1 ? 3 : \
41 sizeof(type) <= 2 ? 5 : \
42 sizeof(type) <= 4 ? 10 : \
43 sizeof(type) <= 8 ? 20 : \
44 sizeof(int[-2*(sizeof(type) > 8)])))
46 #ifndef __CONSTRUCTOR__
47 #define __CONSTRUCTOR__ __attribute__ ((constructor))
50 #ifndef __DESTRUCTOR__
51 #define __DESTRUCTOR__ __attribute__ ((destructor))
55 #define __WEAK__ __attribute__ ((weak))
77 #define clamp(x, low, high) \
80 typeof(low) _low = (low); \
81 typeof(high) _high = (high); \
82 ((_x > _high) ? _high : ((_x < _low) ? _low : _x)); \
87 #define SEC_TO_MSEC(x) ((x)*1000)
90 #define NSEC_TO_MSEC(x) ((double)x/1000000)
93 #define USEC_TO_MSEC(x) ((double)x/1000)
96 FILE * open_proc_oom_score_adj_file(int pid, const char *mode);
97 int get_exec_pid(const char *execpath);
98 int get_cmdline_name(pid_t pid, char *cmdline, size_t cmdline_size);
100 int run_child(int argc, const char *argv[]);
101 int remove_dir(const char *path, int del_dir);
102 int sys_get_int(char *fname, int *val);
103 int sys_set_int(char *fname, int val);
104 int terminate_process(char* partition, bool force);
105 int mount_check(const char* path);
107 #endif /* __CORE_COMMON_H__ */