PX4 Firmware
PX4 Autopilot Software http://px4.io
visibility.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (C) 2012-2019 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 
34 /**
35  * @file visibility.h
36  *
37  * Definitions controlling symbol naming and visibility.
38  *
39  * This file is normally included automatically by the build system.
40  */
41 
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 
63 
64 
65 
66 /* exit() is used on NuttX to exit a task. However on Posix, it will exit the
67  * whole application, so we prevent its use there. There are cases where it
68  * still needs to be used, thus we remap system_exit to exit.
69  */
70 #define system_exit exit
71 #if !defined(__PX4_NUTTX)
72 #include <stdlib.h>
73 #ifdef __cplusplus
74 #include <cstdlib>
75 #endif
76 /* We should include cstdlib or stdlib.h but this doesn't
77  * compile because many C++ files include stdlib.h and would
78  * need to get changed. */
79 #pragma GCC poison exit
80 #endif // !defined(__PX4_NUTTX)
81 
82 
83 /* For SITL lockstep we fake the clock, sleeping, and timedwaits
84  * Therefore, we prefix these syscalls with system_. */
85 #include <time.h>
86 #define system_clock_gettime clock_gettime
87 #define system_clock_settime clock_settime
88 /* We can't poison clock_settime/clock_gettime because they are
89  * used in DriverFramework. */
90 
91 #if !defined(__PX4_NUTTX)
92 #include <pthread.h>
93 // We can't include this for NuttX otherwise we get conflicts for read/write
94 // symbols in cannode.
95 #endif // !defined(__PX4_NUTTX)
96 #define system_pthread_cond_timedwait pthread_cond_timedwait
97 /* We can't poison pthread_cond_timedwait because it seems to be used in the
98  * <string> include. */
99 
100 
101 /* We don't poison usleep and sleep because it is used in dependencies
102  * like uavcan and DriverFramework. */
103 #if !defined(__PX4_NUTTX)
104 #include <unistd.h>
105 // We can't include this for NuttX otherwise we get conflicts for read/write
106 // symbols in cannode.
107 #endif // !defined(__PX4_NUTTX)
108 #define system_usleep usleep
109 #define system_sleep sleep
110 
111 
112 /* On NuttX we call clearenv() so we cannot use getenv() and others (see
113  * px4_task_spawn_cmd() in px4_nuttx_tasks.c).
114  * We need to include the headers declaring getenv() before the pragma,
115  * otherwise it will trigger a poison error. */
116 #if defined(__PX4_NUTTX)
117 #include <stdlib.h>
118 #ifdef __cplusplus
119 #include <cstdlib>
120 #endif
121 /* We should include cstdlib or stdlib.h but this doesn't
122  * compile because many C++ files include stdlib.h and would
123  * need to get changed. */
124 #pragma GCC poison getenv setenv putenv
125 #endif // defined(__PX4_NUTTX)