nlib
Config_linux.h
1 
2 #pragma once
3 #ifndef INCLUDE_NN_NLIB_CONFIG_LINUX_H_
4 #define INCLUDE_NN_NLIB_CONFIG_LINUX_H_
5 #ifndef INCLUDE_NN_NLIB_CONFIG_H_
6 # error do not include directly
7 #endif
8 
9 #include <cxxabi.h>
10 
11 #if defined(__linux__)
12 # if defined(__clang__)
13 # include "nn/nlib/Config_clang.h"
14 # elif defined(__GNUC__)
15 # include "nn/nlib/Config_gcc.h"
16 # else
17 # error
18 # endif
19 # define NLIB_HAS_VIRTUALMEMORY
20 #endif
21 
22 #define NLIB_PATHMAPPER_FORSAMPLE \
23  extern "C" ssize_t readlink(const char *path, char *buf, size_t bufsiz); \
24  extern "C" char *getcwd(char *buf, size_t size); \
25  nlib_ns::NativePathMapper g_PathMapper; \
26  inline void InitPathMapperForSample() { \
27  char dir[1024]; \
28  ssize_t cnt = readlink("/proc/self/exe", dir, 1024); \
29  if (cnt == -1) { \
30  char* cwd = getcwd(dir, 1024); \
31  if (cwd) { \
32  g_PathMapper.AddMap(cwd, "nlibpath:
33  g_PathMapper.AddMap(cwd, "nlibpath:
34  } \
35  } else { \
36  dir[cnt] = '\0'; \
37  *const_cast<char*>(nlib_strrchr(dir, '/')) = '\0'; \
38  g_PathMapper.AddMap(dir, "nlibpath:
39  g_PathMapper.AddMap(dir, "nlibpath:
40  } \
41  }
42 
43 #define NLIB_MAINFUNC int main(int argc, char** argv) { \
44  bool result = SampleMain(argc, argv); nlib_printf(result ? "OK\n" : "NG\n"); \
45  return result ? 0 : 1; }
46 
47 #ifdef NLIB_ALPINE
48 #define NLIB_THREAD_EXIT_CPP_THROW_NLIB_EXCEPTION
49 #endif
50 
51 #ifndef NLIB_THREAD_EXIT_CPP_THROW_NLIB_EXCEPTION
52 # define NLIB_RETHROW_UNWIND catch (abi::__forced_unwind&)
53 #else
54 #ifdef NLIB_EXCEPTION_ENABLED
55 #undef nlib_thread_cleanup_push
56 #undef nlib_thread_cleanup_pop
57 #define nlib_thread_cleanup_push(fn, arg) pthread_cleanup_push(fn, arg); try {
58 #define nlib_thread_cleanup_pop(exec) } catch(...) { { pthread_cleanup_pop(1) throw; } \
59  pthread_cleanup_pop(exec)
60 #endif
61 #endif
62 
63 #endif // INCLUDE_NN_NLIB_CONFIG_LINUX_H_