diff options
author | YU Jincheng <shana@zju.edu.cn> | 2021-10-10 02:19:51 +0800 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-10-09 22:30:45 +0200 |
commit | 5156b245536ce0f07165793f07c63fd9fa5dd3b7 (patch) | |
tree | 3b73b7ea8ed1830d9cc13cbce1da6918926553e2 /include | |
parent | 04ad683bf99333c2a6c6fd6549faa67978ad9a98 (diff) | |
download | busybox-w32-5156b245536ce0f07165793f07c63fd9fa5dd3b7.tar.gz busybox-w32-5156b245536ce0f07165793f07c63fd9fa5dd3b7.tar.bz2 busybox-w32-5156b245536ce0f07165793f07c63fd9fa5dd3b7.zip |
Make const ptr assign as function call in clang
- This can act as memory barrier in clang to avoid
read before assign of a const ptr
Signed-off-by: LoveSy <shana@zju.edu.cn>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/libbb.h | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/include/libbb.h b/include/libbb.h index 296417dae..a340f27d2 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -2280,6 +2280,7 @@ extern const char bb_PATH_root_path[] ALIGN1; /* BB_PATH_ROOT_PATH */ | |||
2280 | extern const int const_int_0; | 2280 | extern const int const_int_0; |
2281 | //extern const int const_int_1; | 2281 | //extern const int const_int_1; |
2282 | 2282 | ||
2283 | |||
2283 | /* This struct is deliberately not defined. */ | 2284 | /* This struct is deliberately not defined. */ |
2284 | /* See docs/keep_data_small.txt */ | 2285 | /* See docs/keep_data_small.txt */ |
2285 | struct globals; | 2286 | struct globals; |
@@ -2304,23 +2305,31 @@ static ALWAYS_INLINE void* not_const_pp(const void *p) | |||
2304 | ); | 2305 | ); |
2305 | return pp; | 2306 | return pp; |
2306 | } | 2307 | } |
2308 | # define ASSIGN_CONST_PTR(pptr, v) do { \ | ||
2309 | *(void**)not_const_pp(pptr) = (void*)(v); \ | ||
2310 | barrier(); \ | ||
2311 | } while (0) | ||
2312 | /* XZALLOC_CONST_PTR() is an out-of-line function to prevent | ||
2313 | * clang from reading pointer before it is assigned. | ||
2314 | */ | ||
2315 | void XZALLOC_CONST_PTR(const void *pptr, size_t size) FAST_FUNC; | ||
2307 | #else | 2316 | #else |
2308 | static ALWAYS_INLINE void* not_const_pp(const void *p) { return (void*)p; } | 2317 | # define ASSIGN_CONST_PTR(pptr, v) do { \ |
2309 | #endif | 2318 | *(void**)(pptr) = (void*)(v); \ |
2310 | |||
2311 | #define ASSIGN_CONST_PTR(p, v) do { \ | ||
2312 | *(void**)not_const_pp(&p) = (void*)(v); \ | ||
2313 | /* At least gcc 3.4.6 on mipsel needs optimization barrier */ \ | 2319 | /* At least gcc 3.4.6 on mipsel needs optimization barrier */ \ |
2314 | barrier(); \ | 2320 | barrier(); \ |
2315 | } while (0) | 2321 | } while (0) |
2322 | # define XZALLOC_CONST_PTR(pptr, size) ASSIGN_CONST_PTR(pptr, xzalloc(size)) | ||
2323 | #endif | ||
2316 | 2324 | ||
2317 | #define SET_PTR_TO_GLOBALS(x) ASSIGN_CONST_PTR(ptr_to_globals, x) | 2325 | #define SET_PTR_TO_GLOBALS(x) ASSIGN_CONST_PTR(&ptr_to_globals, x) |
2318 | #define FREE_PTR_TO_GLOBALS() do { \ | 2326 | #define FREE_PTR_TO_GLOBALS() do { \ |
2319 | if (ENABLE_FEATURE_CLEAN_UP) { \ | 2327 | if (ENABLE_FEATURE_CLEAN_UP) { \ |
2320 | free(ptr_to_globals); \ | 2328 | free(ptr_to_globals); \ |
2321 | } \ | 2329 | } \ |
2322 | } while (0) | 2330 | } while (0) |
2323 | 2331 | ||
2332 | |||
2324 | /* You can change LIBBB_DEFAULT_LOGIN_SHELL, but don't use it, | 2333 | /* You can change LIBBB_DEFAULT_LOGIN_SHELL, but don't use it, |
2325 | * use bb_default_login_shell and following defines. | 2334 | * use bb_default_login_shell and following defines. |
2326 | * If you change LIBBB_DEFAULT_LOGIN_SHELL, | 2335 | * If you change LIBBB_DEFAULT_LOGIN_SHELL, |