2015-05-15 05:44:48 +08:00
|
|
|
/*
|
|
|
|
|
2017-10-18 20:27:34 +08:00
|
|
|
nsjail - common macros
|
2015-05-15 05:44:48 +08:00
|
|
|
-----------------------------------------
|
|
|
|
|
|
|
|
Copyright 2014 Google Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2016-03-11 09:45:43 +08:00
|
|
|
#ifndef NS_COMMON_H
|
|
|
|
#define NS_COMMON_H
|
2015-05-15 05:44:48 +08:00
|
|
|
|
2018-02-10 12:25:55 +08:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#if !defined(TEMP_FAILURE_RETRY)
|
|
|
|
#define TEMP_FAILURE_RETRY(expression) \
|
|
|
|
(__extension__({ \
|
|
|
|
long int __result; \
|
2020-08-26 22:09:55 +08:00
|
|
|
do __result = (long int)(expression); \
|
2018-02-10 12:25:55 +08:00
|
|
|
while (__result == -1L && errno == EINTR); \
|
|
|
|
__result; \
|
|
|
|
}))
|
|
|
|
#endif /* !defined(TEMP_FAILURE_RETRY) */
|
|
|
|
|
2018-02-13 23:53:45 +08:00
|
|
|
#if !defined(ARR_SZ)
|
|
|
|
#define ARR_SZ(array) (sizeof(array) / sizeof(*array))
|
|
|
|
#endif /* !defined(ARR_SZ) */
|
2017-02-08 07:36:32 +08:00
|
|
|
#define UNUSED __attribute__((unused))
|
2015-05-15 05:44:48 +08:00
|
|
|
|
2017-10-09 05:00:45 +08:00
|
|
|
#if 0 /* Works, but needs -fblocks and libBlocksRuntime with clang */
|
2016-03-11 05:56:26 +08:00
|
|
|
/* Go-style defer implementation */
|
2016-03-09 05:40:29 +08:00
|
|
|
#define __STRMERGE(a, b) a##b
|
|
|
|
#define _STRMERGE(a, b) __STRMERGE(a, b)
|
2016-03-09 01:22:50 +08:00
|
|
|
|
|
|
|
#ifdef __clang__
|
2016-04-23 10:22:31 +08:00
|
|
|
static void __attribute__ ((unused)) __clang_cleanup_func(void (^*dfunc) (void))
|
2016-03-09 01:23:26 +08:00
|
|
|
{
|
2016-03-11 09:45:43 +08:00
|
|
|
(*dfunc) ();
|
2016-03-09 01:23:26 +08:00
|
|
|
}
|
|
|
|
|
2017-10-26 06:26:02 +08:00
|
|
|
#define defer \
|
|
|
|
void (^_STRMERGE(__defer_f_, __COUNTER__))(void) \
|
|
|
|
__attribute__((cleanup(__clang_cleanup_func))) __attribute__((unused)) = ^
|
2016-03-09 01:22:50 +08:00
|
|
|
#else
|
2016-03-09 01:23:26 +08:00
|
|
|
#define __block
|
2017-10-26 06:26:02 +08:00
|
|
|
#define _DEFER(a, count) \
|
|
|
|
auto void _STRMERGE(__defer_f_, count)(void* _defer_arg __attribute__((unused))); \
|
|
|
|
int _STRMERGE(__defer_var_, count) __attribute__((cleanup(_STRMERGE(__defer_f_, count)))) \
|
2021-02-02 06:22:43 +08:00
|
|
|
__attribute__((unused)); \
|
2017-10-09 05:00:45 +08:00
|
|
|
void _STRMERGE(__defer_f_, count)(void* _defer_arg __attribute__((unused)))
|
2016-04-23 10:22:31 +08:00
|
|
|
#define defer _DEFER(a, __COUNTER__)
|
2016-03-09 01:22:50 +08:00
|
|
|
#endif
|
2016-07-29 21:38:22 +08:00
|
|
|
#endif
|
2016-03-09 01:22:50 +08:00
|
|
|
|
2017-10-26 06:26:02 +08:00
|
|
|
#define NS_VALSTR_STRUCT(x) \
|
|
|
|
{ x, #x }
|
2017-10-09 05:06:40 +08:00
|
|
|
|
2017-10-09 05:00:45 +08:00
|
|
|
#endif /* NS_COMMON_H */
|