Firmware
visibility.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (C) 2012-2018 PX4 Development Team. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
42 #pragma once
43 
44 #ifdef __EXPORT
45 # undef __EXPORT
46 #endif
47 #define __EXPORT __attribute__ ((visibility ("default")))
48 
49 #ifdef __PRIVATE
50 # undef __PRIVATE
51 #endif
52 #define __PRIVATE __attribute__ ((visibility ("hidden")))
53 
54 #ifdef __cplusplus
55 # define __BEGIN_DECLS extern "C" {
56 # define __END_DECLS }
57 #else
58 # define __BEGIN_DECLS
59 # define __END_DECLS
60 #endif
61 
62 /* exit() is used on NuttX to exit a task. However on Posix, it will exit the
63  * whole application, so we prevent its use there. There are cases where it
64  * still needs to be used, thus we remap system_exit to exit.
65  */
66 #define system_exit exit
67 
68 #if defined(ENABLE_LOCKSTEP_SCHEDULER)
69 
70 #include <stdlib.h>
71 #include <unistd.h>
72 
73 #define system_usleep usleep
74 #pragma GCC poison usleep
75 #define system_sleep sleep
76 #pragma GCC poison sleep
77 
78 #define system_clock_gettime clock_gettime
79 #define system_clock_settime clock_settime
80 
81 #include <pthread.h>
82 #define system_pthread_cond_timedwait pthread_cond_timedwait
83 // We can't poison pthread_cond_timedwait because it seems to be used in the
84 // <string> include.
85 
86 #ifdef __cplusplus
87 #include <cstdlib>
88 #endif
89 #pragma GCC poison exit
90 
91 #include <stdlib.h>
92 
93 #ifdef __cplusplus
94 #include <cstdlib>
95 #endif
96 
97 // We don't poison usleep and sleep on NuttX because it is used in dependencies
98 // like uavcan and we don't need to fake time on the real system.
99 #include <unistd.h>
100 #include <time.h>
101 
102 #else // defined(ENABLE_LOCKSTEP_SCHEDULER)
103 
104 #define system_usleep usleep
105 #define system_sleep sleep
106 #define system_clock_gettime clock_gettime
107 #define system_clock_settime clock_settime
108 #define system_pthread_cond_timedwait pthread_cond_timedwait
109 
110 #endif
111 
112 
113 #if defined(__PX4_NUTTX)
114 /* On NuttX we call clearenv() so we cannot use getenv() and others (see
115  * px4_task_spawn_cmd() in px4_nuttx_tasks.c).
116  * We need to include the headers declaring getenv() before the pragma,
117  * otherwise it will trigger a poison error. */
118 #include <stdlib.h>
119 #ifdef __cplusplus
120 #include <cstdlib>
121 #endif
122 #pragma GCC poison getenv setenv putenv
123 #endif // defined(__PX4_NUTTX)