1 /*
2 * Copyright 2012, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef _PORTABILITY_H_
18 #define _PORTABILITY_H_
19
20 #include <stdint.h>
21 #include "asm-generic/portability.h"
22 /*
23 * Common portability helper routines
24 */
25
26 /*
27 * Check a portable pointer before we access it
28 * Well behaved programs should not be passing bad pointers
29 * to the kernel but this routine can be used to check a pointer
30 * if we need to use it before calling the kernel
31 *
32 * It does not catch every possible case but it is sufficient for LTP
33 */
invalid_pointer(void * p)34 inline static int invalid_pointer(void *p)
35 {
36 return p == 0
37 || p == (void *)-1
38 #ifdef __mips__
39 || (intptr_t)p < 0
40 #endif
41 ;
42 }
43
44 /*
45 * Hidden functions are exposed while linking the libportable shared object
46 * but are not exposed thereafter.
47 */
48 #define __hidden __attribute__((visibility("hidden")))
49
50 #endif /* _PORTABILITY_H_ */
51