summaryrefslogtreecommitdiffstats
path: root/src/framework/include/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/framework/include/common')
-rw-r--r--src/framework/include/common/compile_config.h30
-rw-r--r--src/framework/include/common/compiling_check.h108
-rw-r--r--src/framework/include/common/dmm_fs.h31
-rw-r--r--src/framework/include/common/generic/dmm_atomic.h184
-rw-r--r--src/framework/include/common/generic/dmm_barrier.h25
-rw-r--r--src/framework/include/common/generic/dmm_common.h68
-rw-r--r--src/framework/include/common/generic/dmm_config.h52
-rw-r--r--src/framework/include/common/generic/dmm_pause.h30
-rw-r--r--src/framework/include/common/generic/dmm_rwlock.h72
-rw-r--r--src/framework/include/common/generic/dmm_spinlock.h119
-rw-r--r--src/framework/include/common/list.h179
-rw-r--r--src/framework/include/common/pid_common.h82
-rw-r--r--src/framework/include/common/pidinfo.h49
13 files changed, 1029 insertions, 0 deletions
diff --git a/src/framework/include/common/compile_config.h b/src/framework/include/common/compile_config.h
new file mode 100644
index 0000000..2ec5373
--- /dev/null
+++ b/src/framework/include/common/compile_config.h
@@ -0,0 +1,30 @@
+/*
+*
+* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at:
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#ifndef COMPILE_CONFIG_H
+#define COMPILE_CONFIG_H
+
+#ifndef NSTACK_STATIC
+#ifndef NSTACK_STATIC_CHECK
+#define NSTACK_STATIC static
+#else
+#define NSTACK_STATIC
+#endif
+#endif
+
+#include "compiling_check.h"
+
+#endif /*compile_config.h */
diff --git a/src/framework/include/common/compiling_check.h b/src/framework/include/common/compiling_check.h
new file mode 100644
index 0000000..41858b9
--- /dev/null
+++ b/src/framework/include/common/compiling_check.h
@@ -0,0 +1,108 @@
+/*
+*
+* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at:
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#ifndef COMPILING_CHECK_H
+#define COMPILING_CHECK_H
+
+/* protect the value of macro whose value impacts the version
+ * compatibility, can't be changed!!! */
+
+#define COMPAT_PROTECT_RETURN(name, value) \
+ \
+ static inline char value_of_##name##_equal_to() \
+ { \
+ char __dummy1[(name) - (value)]; \
+ char __dummy2[(value) - (name)]; \
+ return __dummy1[-1] + __dummy2[-1]; \
+ }
+
+/* check whether struct size is equal to a special value */
+#define SIZE_OF_TYPE_EQUAL_TO(type, size) \
+static inline char size_of_##type##_equal_to_##size() \
+{ \
+ char __dummy1[sizeof(type) - size]; \
+ char __dummy2[size - sizeof(type)]; \
+ return __dummy1[-1] + __dummy2[-1]; \
+}
+
+/* check whether struct size is not equal to a special value */
+#define SIZE_OF_TYPE_UNEQUAL_TO_RETURN(type, size) \
+static inline char size_of_##type##_unequal_to_##size() \
+{ \
+ char __dummy1[0==(10/(sizeof(type)-size))]; \
+ return __dummy1[-1]; \
+}
+
+/* check whether struct size is not larger than a special value */
+#define SIZE_OF_TYPE_NOT_LARGER_THAN_RETURN(type, size) \
+static inline char size_of_##type##_not_larger_than_##size() \
+{ \
+ char __dummy1[size - sizeof(type)]; \
+ return __dummy1[-1]; \
+}
+
+/* check whether struct size + sizeof(void*) is not larger than a special value */
+/* reserve 8 bytes for 64 bits pointers */
+#define SIZE_OF_TYPE_PLUS8_NOT_LARGER_THAN_RETURN(type, size) \
+static inline char size_of_##type##_not_larger_than_##size() \
+{ \
+ char __dummy1[size - sizeof(type) - sizeof(void*)]; \
+ return __dummy1[-1]; \
+}
+
+/* check whether struct size is not smaller than a special value */
+#define SIZE_OF_TYPE_NOT_SMALLER_THAN_RETURN(type, size) \
+static inline char size_of_##type##_not_smaller_than_##size() \
+{ \
+ char __dummy1[sizeof(type) - size]; \
+ return __dummy1[-1]; \
+}
+
+/* check whether struct size is smaller than a special value */
+#define SIZE_OF_TYPE_SMALLER_THAN(type, size) \
+ SIZE_OF_TYPE_NOT_LARGER_THAN_RETURN(type, size) \
+ SIZE_OF_TYPE_UNEQUAL_TO_RETURN(type, size)
+
+/* check whether struct size is larger than a special value */
+#define SIZE_OF_TYPE_LARGER_THAN(type, size) \
+ SIZE_OF_TYPE_NOT_SMALLER_THAN_RETURN(type, size) \
+ SIZE_OF_TYPE_UNEQUAL_TO_RETURN(type, size)
+
+/* check whether struct size is smaller than a special value, version 2 */
+#define SIZE_OF_TYPE_SMALLER_THAN2(type, size) \
+static inline char size_of_##type##_smaller_than2_##size() \
+{ \
+ char __dummy1[size - sizeof(type) - 1]; \
+ return __dummy1[-1]; \
+}
+
+/* check whether struct size is larger than a special value, version 2 */
+#define SIZE_OF_TYPE_LARGER_THAN2(type, size) \
+static inline char size_of_##type##_larger_than2_##size() \
+{ \
+ char __dummy1[sizeof(type) - size - 1]; \
+ return __dummy1[-1]; \
+}
+
+/* check whether struct size is equal to an integer multiple of a special value */
+#define SIZE_OF_TYPE_IS_MULTIPLE_OF(type, size) \
+static inline char size_of_##type##_is_multiple_of_##size() \
+{ \
+ char __dummy1[0 - (sizeof(type) % size)]; \
+ return __dummy1[-1]; \
+}
+
+#endif /*compiling_check.h */
diff --git a/src/framework/include/common/dmm_fs.h b/src/framework/include/common/dmm_fs.h
new file mode 100644
index 0000000..3a63550
--- /dev/null
+++ b/src/framework/include/common/dmm_fs.h
@@ -0,0 +1,31 @@
+/*
+*
+* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at:
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#ifndef _DMM_FS_H_
+#define _DMM_FS_H_
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+static inline size_t dmm_file_size(int fd)
+{
+ struct stat st;
+ if (fstat(fd, &st) < 0)
+ return 0;
+ return (size_t) st.st_size;
+}
+
+#endif /* _DMM_FS_H_ */
diff --git a/src/framework/include/common/generic/dmm_atomic.h b/src/framework/include/common/generic/dmm_atomic.h
new file mode 100644
index 0000000..0778e4a
--- /dev/null
+++ b/src/framework/include/common/generic/dmm_atomic.h
@@ -0,0 +1,184 @@
+/*
+*
+* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at:
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#ifndef _DMM_ATOMIC_H_
+#define _DMM_ATOMIC_H_
+
+/* atomic 32 bit operation */
+
+typedef struct
+{
+ volatile int cnt;
+} dmm_atomic_t;
+
+inline static void dmm_atomic_set(dmm_atomic_t * a, int n)
+{
+ a->cnt = n;
+}
+
+inline static int dmm_atomic_get(dmm_atomic_t * a)
+{
+ return a->cnt;
+}
+
+inline static int dmm_atomic_add(dmm_atomic_t * a, int n)
+{
+ return __sync_fetch_and_add(&a->cnt, n);
+}
+
+inline static int dmm_atomic_inc(dmm_atomic_t * a)
+{
+ return dmm_atomic_add(a, 1);
+}
+
+inline static int dmm_atomic_sub(dmm_atomic_t * a, int n)
+{
+ return __sync_fetch_and_sub(&a->cnt, n);
+}
+
+inline static int dmm_atomic_dec(dmm_atomic_t * a)
+{
+ return dmm_atomic_sub(a, 1);
+}
+
+inline static int dmm_atomic_and(dmm_atomic_t * a, int n)
+{
+ return __sync_fetch_and_and(&a->cnt, n);
+}
+
+inline static int dmm_atomic_or(dmm_atomic_t * a, int n)
+{
+ return __sync_fetch_and_or(&a->cnt, n);
+}
+
+inline static int dmm_atomic_xor(dmm_atomic_t * a, int n)
+{
+ return __sync_fetch_and_xor(&a->cnt, n);
+}
+
+inline static int dmm_atomic_swap(dmm_atomic_t * a, int o, int n)
+{
+ return __sync_bool_compare_and_swap(&a->cnt, o, n);
+}
+
+inline static int dmm_atomic_add_return(dmm_atomic_t * a, int n)
+{
+ return __sync_add_and_fetch(&a->cnt, n);
+}
+
+inline static int dmm_atomic_sub_return(dmm_atomic_t * a, int n)
+{
+ return __sync_sub_and_fetch(&a->cnt, n);
+}
+
+inline static int dmm_atomic_and_return(dmm_atomic_t * a, int n)
+{
+ return __sync_and_and_fetch(&a->cnt, n);
+}
+
+inline static int dmm_atomic_or_return(dmm_atomic_t * a, int n)
+{
+ return __sync_or_and_fetch(&a->cnt, n);
+}
+
+inline static int dmm_atomic_xor_return(dmm_atomic_t * a, int n)
+{
+ return __sync_xor_and_fetch(&a->cnt, n);
+}
+
+/* atomit 64bit operation */
+
+typedef struct
+{
+ volatile long long int cnt;
+} dmm_atomic64_t;
+
+inline static long long int dmm_atomic64_get(dmm_atomic64_t * a)
+{
+ return a->cnt;
+}
+
+inline static void dmm_atomic64_set(dmm_atomic64_t * a, int n)
+{
+ a->cnt = n;
+}
+
+inline static long long int dmm_atomic64_add(dmm_atomic64_t * a, int n)
+{
+ return __sync_fetch_and_add(&a->cnt, n);
+}
+
+inline static int dmm_atomic64_inc(dmm_atomic64_t * a)
+{
+ return dmm_atomic64_add(a, 1);
+}
+
+inline static long long int dmm_atomic64_sub(dmm_atomic64_t * a, int n)
+{
+ return __sync_fetch_and_sub(&a->cnt, n);
+}
+
+inline static int dmm_atomic64_dec(dmm_atomic64_t * a)
+{
+ return dmm_atomic64_sub(a, 1);
+}
+
+inline static long long int dmm_atomic64_and(dmm_atomic64_t * a, int n)
+{
+ return __sync_fetch_and_and(&a->cnt, n);
+}
+
+inline static long long int dmm_atomic64_or(dmm_atomic64_t * a, int n)
+{
+ return __sync_fetch_and_or(&a->cnt, n);
+}
+
+inline static long long int dmm_atomic64_xor(dmm_atomic64_t * a, int n)
+{
+ return __sync_fetch_and_xor(&a->cnt, n);
+}
+
+inline static long long int dmm_atomic64_swap(dmm_atomic_t * a, int o, int n)
+{
+ return __sync_bool_compare_and_swap(&a->cnt, o, n);
+}
+
+inline static long long int dmm_atomic64_add_return(dmm_atomic64_t * a, int n)
+{
+ return __sync_add_and_fetch(&a->cnt, n);
+}
+
+inline static long long int dmm_atomic64_sub_return(dmm_atomic64_t * a, int n)
+{
+ return __sync_sub_and_fetch(&a->cnt, n);
+}
+
+inline static long long int dmm_atomic64_and_return(dmm_atomic64_t * a, int n)
+{
+ return __sync_and_and_fetch(&a->cnt, n);
+}
+
+inline static long long int dmm_atomic64_or_return(dmm_atomic64_t * a, int n)
+{
+ return __sync_or_and_fetch(&a->cnt, n);
+}
+
+inline static long long int dmm_atomic64_xor_return(dmm_atomic64_t * a, int n)
+{
+ return __sync_xor_and_fetch(&a->cnt, n);
+}
+
+#endif /* #ifndef _DMM_ATOMIC_H_ */
diff --git a/src/framework/include/common/generic/dmm_barrier.h b/src/framework/include/common/generic/dmm_barrier.h
new file mode 100644
index 0000000..5076702
--- /dev/null
+++ b/src/framework/include/common/generic/dmm_barrier.h
@@ -0,0 +1,25 @@
+/*
+*
+* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at:
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#ifndef _DMM_BARRIER_H_
+#define _DMM_BARRIER_H_
+
+inline static void dmm_barrier(void)
+{
+ __sync_synchronize();
+}
+
+#endif /* #ifndef _DMM_BARRIER_H_ */
diff --git a/src/framework/include/common/generic/dmm_common.h b/src/framework/include/common/generic/dmm_common.h
new file mode 100644
index 0000000..344f47e
--- /dev/null
+++ b/src/framework/include/common/generic/dmm_common.h
@@ -0,0 +1,68 @@
+/*
+*
+* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at:
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#ifndef _DMM_COMMON_H_
+#define _DMM_COMMON_H_
+
+#include "dmm_config.h"
+
+#ifndef likely
+#define likely(x) __builtin_expect(!!(x), 1)
+#endif
+#ifndef unlikely
+#define unlikely(x) __builtin_expect(!!(x), 0)
+#endif
+
+#define _dmm_packed __attribute__((__packed__))
+#define _dmm_aliened(a) __attribute__((__aligned__(a)))
+#define _dmm_cache_aligned _dmm_aliened(DMM_CACHE_LINE_SIZE)
+
+#define DMM_ALIGN(x, a) (((x) + ((a) - 1)) / (a) * (a))
+#define dmm_align(x, a) ({ \
+ typeof(x) _a = (a); \
+ ((x) + (_a - 1)) / _a * _a; \
+})
+
+#ifndef offsetof
+#define offsetof(type, member) ((size_t)((type *)0)->member)
+#endif
+
+inline static unsigned int dmm_align32pow2(unsigned int v)
+{
+ v--;
+ v |= v >> 1;
+ v |= v >> 2;
+ v |= v >> 4;
+ v |= v >> 8;
+ v |= v >> 16;
+
+ return v + 1;
+}
+
+inline static unsigned long long dmm_align64pow2(unsigned long long v)
+{
+ v--;
+ v |= v >> 1;
+ v |= v >> 2;
+ v |= v >> 4;
+ v |= v >> 8;
+ v |= v >> 16;
+ v |= v >> 32;
+
+ return v + 1;
+}
+
+#endif
diff --git a/src/framework/include/common/generic/dmm_config.h b/src/framework/include/common/generic/dmm_config.h
new file mode 100644
index 0000000..657ecd8
--- /dev/null
+++ b/src/framework/include/common/generic/dmm_config.h
@@ -0,0 +1,52 @@
+/*
+*
+* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at:
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#ifndef _DMM_CONFIG_H_
+#define _DMM_CONFIG_H_
+
+#ifndef DMM_VAR_DIR
+#define DMM_VAR_DIR "/var/run"
+#endif
+
+#ifndef DMM_MAIN_SHARE_TYPE
+#define DMM_MAIN_SHARE_TYPE DMM_SHARE_FSHM
+#endif
+
+#ifndef DMM_MAIN_SHARE_SIZE
+#define DMM_MAIN_SHARE_SIZE 1024 /* Megabyte */
+#endif
+
+#ifndef DMM_MAIN_SHARE_BASE
+#define DMM_MAIN_SHARE_BASE 0x700080000000 /* fixed base address */
+#endif
+
+#ifndef DMM_SHARE_TYPE
+#define DMM_SHARE_TYPE DMM_SHARE_FSHM
+#endif
+
+#ifndef DMM_SHARE_SIZE
+#define DMM_SHARE_SIZE 8 /* Megabyte */
+#endif
+
+#ifndef DMM_HUGE_DIR
+#define DMM_HUGE_DIR "/mnt/nstackhuge"
+#endif
+
+#ifndef DMM_CACHE_LINE_SIZE
+#define DMM_CACHE_LINE_SIZE 64
+#endif
+
+#endif /* _DMM_CONFIG_H_ */
diff --git a/src/framework/include/common/generic/dmm_pause.h b/src/framework/include/common/generic/dmm_pause.h
new file mode 100644
index 0000000..65b60db
--- /dev/null
+++ b/src/framework/include/common/generic/dmm_pause.h
@@ -0,0 +1,30 @@
+/*
+*
+* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at:
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#ifndef _DMM_PAUSE_H_
+#define _DMM_PAUSE_H_
+
+#include <emmintrin.h>
+
+inline static void dmm_pause(void)
+{
+ _mm_pause();
+}
+
+#define DMM_PAUSE_WHILE(cond) do { dmm_pause(); } while (!!(cond))
+#define DMM_WHILE_PAUSE(cond) do { while (!!(cond)) dmm_pause(); } while (0)
+
+#endif /* #ifndef _DMM_PAUSE_H_ */
diff --git a/src/framework/include/common/generic/dmm_rwlock.h b/src/framework/include/common/generic/dmm_rwlock.h
new file mode 100644
index 0000000..2b9ec8b
--- /dev/null
+++ b/src/framework/include/common/generic/dmm_rwlock.h
@@ -0,0 +1,72 @@
+/*
+*
+* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at:
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#ifndef _DMM_RWLOCK_H_
+#define _DMM_RWLOCK_H_
+
+#include "dmm_pause.h"
+
+typedef struct
+{
+ volatile int lock;
+} dmm_rwlock_t;
+
+#define DMM_RWLOCK_INIT { 0 }
+
+inline static void dmm_rwlock_init(dmm_rwlock_t * rwlock)
+{
+ rwlock->lock = 0;
+}
+
+inline static void dmm_read_lock(dmm_rwlock_t * rwlock)
+{
+ int val;
+
+ do
+ {
+ if ((val = rwlock->lock) < 0)
+ {
+ dmm_pause();
+ continue;
+ }
+ }
+ while (!__sync_bool_compare_and_swap(&rwlock->lock, val, val + 1));
+}
+
+inline static void dmm_read_unlock(dmm_rwlock_t * rwlock)
+{
+ __sync_sub_and_fetch(&rwlock->lock, 1);
+}
+
+inline static void dmm_write_lock(dmm_rwlock_t * rwlock)
+{
+ do
+ {
+ if (rwlock->lock != 0)
+ {
+ dmm_pause();
+ continue;
+ }
+ }
+ while (!__sync_bool_compare_and_swap(&rwlock->lock, 0, -1));
+}
+
+inline static void dmm_write_unlock(dmm_rwlock_t * rwlock)
+{
+ rwlock->lock = 0;
+}
+
+#endif /* #ifndef _DMM_RWLOCK_H_ */
diff --git a/src/framework/include/common/generic/dmm_spinlock.h b/src/framework/include/common/generic/dmm_spinlock.h
new file mode 100644
index 0000000..5723ecf
--- /dev/null
+++ b/src/framework/include/common/generic/dmm_spinlock.h
@@ -0,0 +1,119 @@
+/*
+*
+* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at:
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#ifndef _DMM_SPINLOCK_H_
+#define _DMM_SPINLOCK_H_
+
+#include "dmm_pause.h"
+#include "pid_common.h"
+#include "nsfw_branch_prediction.h"
+#include "nstack_log.h"
+
+#define DMM_SPINLOCK_MALLOC(sys_sem,count) \
+{ \
+ dmm_spin_init(&(sys_sem)); \
+ /*not problem*/\
+ if (!(count)) \
+ /*not problem*/\
+ { \
+ dmm_spin_lock(&(sys_sem)); \
+ } \
+}
+
+typedef struct
+{
+ volatile int lock;
+} dmm_spinlock_t;
+
+inline static void dmm_spin_init(dmm_spinlock_t * spinlock)
+{
+ spinlock->lock = 0;
+}
+
+static inline int dmm_spin_trylock_with(dmm_spinlock_t * spinlock, int value)
+{
+ return __sync_bool_compare_and_swap(&spinlock->lock, 0, value);
+}
+
+static inline void dmm_spin_lock_with(dmm_spinlock_t * spinlock, int value)
+{
+ while (!dmm_spin_trylock_with(spinlock, value))
+ {
+ DMM_PAUSE_WHILE(spinlock->lock);
+ }
+}
+
+inline static void dmm_spin_lock(dmm_spinlock_t * spinlock)
+{
+ dmm_spin_lock_with(spinlock, 1);
+}
+
+inline static int dmm_spin_trylock(dmm_spinlock_t * spinlock)
+{
+ return dmm_spin_trylock_with(spinlock, 1);
+}
+
+//replace sys_sem_s_signal
+inline static void dmm_spin_unlock(dmm_spinlock_t * spinlock)
+{
+ __sync_lock_release(&spinlock->lock);
+}
+
+//replace sys_arch_trylock_with_pid
+static inline int dmm_spin_trylock_with_pid(dmm_spinlock_t * sem, int t_us)
+{
+ if (unlikely(SYS_HOST_INITIAL_PID == g_sys_host_pid))
+ (void) sys_get_hostpid_from_file(getpid());
+
+ if (dmm_spin_trylock_with(sem, g_sys_host_pid))
+ {
+ return 0;
+ }
+
+ while (t_us > 0)
+ {
+ --t_us;
+ sys_sleep_ns(0, 1000);
+ if (dmm_spin_trylock_with(sem, g_sys_host_pid))
+ {
+ return 0;
+ }
+ }
+
+ return -1;
+}
+
+//replace sys_arch_sem_trywait_s_v2
+static inline int dmm_spinlock_trylock(dmm_spinlock_t * sl)
+{
+ int lockval = 1;
+
+ asm volatile ("xchg %[locked], %[lockval]":[locked] "=m"(sl->lock),
+ [lockval] "=q"(lockval):"[lockval]"(lockval):"memory");
+
+ return lockval == 0;
+}
+
+static inline u32_t dmm_spin_lock_with_pid(dmm_spinlock_t * sem)
+{
+ if (SYS_HOST_INITIAL_PID == g_sys_host_pid)
+ {
+ (void) sys_get_hostpid_from_file(getpid());
+ }
+ dmm_spin_lock_with(sem, g_sys_host_pid);
+ return 0;
+}
+#endif /* #ifndef _DMM_SPINLOCK_H_ */
diff --git a/src/framework/include/common/list.h b/src/framework/include/common/list.h
new file mode 100644
index 0000000..06b558b
--- /dev/null
+++ b/src/framework/include/common/list.h
@@ -0,0 +1,179 @@
+/*
+*
+* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at:
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#ifndef LIST_H_
+#define LIST_H_
+
+#include <signal.h>
+#include <stdio.h>
+#include <pthread.h>
+#include <unistd.h>
+
+#include "types.h"
+
+#ifdef __cplusplus
+/* *INDENT-OFF* */
+extern "C" {
+/* *INDENT-ON* */
+#endif
+
+struct list_head
+{
+ union
+ {
+ struct list_head *next;
+ };
+
+ union
+ {
+ struct list_head *prev;
+ };
+};
+
+struct hlist_node
+{
+ /**
+ * @pprev: point the previous node's next pointer
+ */
+ union
+ {
+ struct hlist_node *next;
+ };
+
+ union
+ {
+ struct hlist_node **pprev;
+ };
+};
+
+struct hlist_head
+{
+ struct hlist_node *first;
+};
+
+#define list_entry(ptr, type, member) \
+ container_of(ptr, type, member)
+
+#define list_for_each_entry_type(tpos, typeof_tpos,pos, head, member) \
+ for (pos = ((head)->next); \
+ pos && pos != (head) && ({tpos = list_entry(pos, typeof_tpos, member); 1;}); \
+ pos = ((pos)->next))
+
+#define list_for_each_entry(tpos, pos, head, member) \
+ for (pos = ((head)->next); \
+ pos && pos != (head) && ({tpos = list_entry(pos, typeof(*tpos), member); 1;}); \
+ pos = ((pos)->next))
+
+#define list_for_each_entry_list_head(tpos, pos, head, member) \
+ for (pos = (struct list_head *)((head)->next); \
+ pos && pos != (struct list_head *)(head) && ({tpos = list_entry(pos, typeof(*tpos), member); 1;}); \
+ pos = (pos)->next)
+#define list_for_each_safe_entry(tpos, pos, n, head, member) \
+ for (pos = (head)->next,n = pos->next; \
+ pos && pos != (head) && ({tpos = list_entry(pos, typeof(*tpos), member); 1;}); \
+ pos = n,n = (pos)->next)
+
+#define INIT_LIST_HEAD(list) {(list)->next = (list); (list)->prev = (list);}
+
+/*
+ * @head: the list to test.
+ */
+inline void list_add(struct list_head *newp, struct list_head *head);
+inline void list_link(struct list_head *newhead, struct list_head *head);
+inline void list_add_tail(struct list_head *newp, struct list_head *head);
+inline int list_empty(const struct list_head *head);
+inline void list_del(struct list_head *entry);
+inline struct list_head *list_get_first(struct list_head *head);
+inline void hlist_del_init(struct hlist_node *n);
+
+struct hlist_tail
+{
+ struct hlist_node *end;
+};
+
+struct hlist_ctl
+{
+ struct hlist_head head;
+ struct hlist_tail tail;
+};
+#define INIT_HLIST_CTRL(ptr) {(ptr)->head.first = NULL; (ptr)->tail.end = NULL;}
+
+inline int hlist_empty(const struct hlist_head *h);
+inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h);
+
+#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
+#define INIT_HLIST_NODE(ptr) {(ptr)->next = NULL; (ptr)->pprev = NULL;}
+#define hlist_entry(ptr, type, member) \
+ container_of(ptr, type, member)
+
+/***
+ * hlist_for_each_entry - iterate over list of given type
+ * @member: the name of the hlist_node within the struct.
+ * @head: the head for your list.
+ * @pos: the &struct hlist_node to use as a loop cursor.
+ * @tpos: the type * to use as a loop cursor.
+ */
+#define hlist_for_each_entry(tpos, pos, head, member) \
+ for (pos = (head)->first; \
+ pos && ({tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
+ pos = pos->next)
+
+/**
+ * hlist_for_each_entry_type - iterate over list of given type
+ * @member: the name of the hlist_node within the struct.
+ * @head: the head for your list.
+ * @pos: the &struct hlist_node to use as a loop cursor.
+ * @tpos: the type * to use as a loop cursor.
+ */
+#define hlist_for_each_entry_type(tpos, typeof_tpos,pos, head, member) \
+ for (pos = (head)->first; \
+ pos && ({tpos = hlist_entry(pos, typeof_tpos, member); 1;}); \
+ pos = pos->next)
+
+inline void hlist_del_init(struct hlist_node *n);
+
+/**
+ * next must be != NULL
+ * add n node before next node
+ *
+ * @n: new node
+ * @next: node in the hlist
+ */
+inline void hlist_add_before(struct hlist_node *n, struct hlist_node *next);
+
+/**
+ * next must be != NULL
+ * add n node after next node
+ * actual behavior is add after n
+ * @n: node in the hlist
+ * @next: new node
+ */
+inline void hlist_add_after(struct hlist_node *n, struct hlist_node *next);
+
+/* add after the head */
+inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h);
+
+inline int hlist_unhashed(const struct hlist_node *h);
+
+inline int hlist_empty(const struct hlist_head *h);
+
+#ifdef __cplusplus
+/* *INDENT-OFF* */
+};
+/* *INDENT-ON* */
+#endif
+
+#endif /* HASH_H_ */
diff --git a/src/framework/include/common/pid_common.h b/src/framework/include/common/pid_common.h
new file mode 100644
index 0000000..a8f5572
--- /dev/null
+++ b/src/framework/include/common/pid_common.h
@@ -0,0 +1,82 @@
+/*
+*
+* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at:
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#ifndef _PIA_COMMON_H_
+#define _PIA_COMMON_H_
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <unistd.h>
+
+#ifdef __cplusplus
+/* *INDENT-OFF* */
+extern "C" {
+/* *INDENT-ON* */
+#endif
+
+#ifndef u32_t
+typedef uint32_t u32_t;
+#endif
+
+#define SYS_HOST_INITIAL_PID 1
+
+#define READ_FILE_BUFLEN 512
+#define BUF_SIZE_FILEPATH 256
+
+#define MAX_GET_PID_TIME 10
+
+extern volatile pid_t g_sys_host_pid;
+
+pid_t sys_get_hostpid_from_file(pid_t pid);
+pid_t get_hostpid_from_file(u32_t pid);
+pid_t get_hostpid_from_file_one_time(u32_t pid);
+void get_exec_name_by_pid(pid_t pid, char *task_name, int task_name_len);
+pid_t updata_sys_pid();
+
+static inline pid_t get_sys_pid()
+{
+ if (SYS_HOST_INITIAL_PID == g_sys_host_pid)
+ (void) sys_get_hostpid_from_file(getpid());
+ return g_sys_host_pid;
+}
+
+#ifndef u64
+typedef unsigned long long u64;
+#endif
+
+typedef struct nsfw_app_info
+{
+ int nsocket_fd;
+ int sbr_fd;
+
+ int hostpid;
+ int pid;
+ int ppid;
+ int tid;
+ u64 extend_member_bit;
+} nsfw_app_info_t;
+
+#define _dmm_packed __attribute__((__packed__))
+#define _dmm_aliened(a) __attribute__((__aligned__(a)))
+#define _dmm_cache_aligned _dmm_aliened(DMM_CACHE_LINE_SIZE)
+
+#ifdef __cplusplus
+/* *INDENT-OFF* */
+}
+/* *INDENT-ON* */
+#endif
+
+#endif
diff --git a/src/framework/include/common/pidinfo.h b/src/framework/include/common/pidinfo.h
new file mode 100644
index 0000000..d97fa1d
--- /dev/null
+++ b/src/framework/include/common/pidinfo.h
@@ -0,0 +1,49 @@
+/*
+*
+* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at:
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#ifndef _PIDINFO_H_
+#define _PIDINFO_H_
+
+#include "types.h"
+
+#ifdef __cplusplus
+/* *INDENT-OFF* */
+extern "C" {
+/* *INDENT-ON* */
+#endif
+
+#define NSFW_MAX_FORK_NUM 32
+
+typedef struct
+{
+ u32 used_size;
+ u32 apid[NSFW_MAX_FORK_NUM];
+} nsfw_pidinfo;
+
+inline i32 nsfw_pidinfo_init(nsfw_pidinfo * pidinfo);
+inline int nsfw_add_pid(nsfw_pidinfo * pidinfo, u32 pid);
+inline int nsfw_del_pid(nsfw_pidinfo * pidinfo, u32 pid);
+inline int nsfw_del_last_pid(nsfw_pidinfo * pidinfo, u32 pid);
+inline int nsfw_pid_exist(nsfw_pidinfo * pidinfo, u32 pid);
+inline int nsfw_pidinfo_empty(nsfw_pidinfo * pidinfo);
+
+#ifdef __cplusplus
+/* *INDENT-OFF* */
+};
+/* *INDENT-ON* */
+#endif
+
+#endif /* _PIDINFO_H_ */