1#ifndef PROCPS_PROC_PROCPS_H
2#define PROCPS_PROC_PROCPS_H
3
4#ifdef  __cplusplus
5#define EXTERN_C_BEGIN extern "C" {
6#define EXTERN_C_END }
7#else
8#define EXTERN_C_BEGIN
9#define EXTERN_C_END
10#endif
11
12// Some ports make the mistake of running a 32-bit userspace
13// on a 64-bit kernel. Shame on them. It's not at all OK to
14// make everything "long long", since that causes unneeded
15// slowness on 32-bit hardware.
16//
17// SPARC: The 32-bit kernel was looking like an ex-penguin,
18// but it lives! ("I'm not dead yet.") So, 64-bit users will
19// just have to compile for 64-bit. Aw, the suffering.
20//
21// MIPS: Used 32-bit for embedded systems and obsolete hardware.
22// The 64-bit systems use an n32 format executable, defining
23// _ABIN32 to indicate this. Since n32 doesn't currently run on
24// any 32-bit system, nobody get hurt if it's bloated. Not that
25// this is sane of course, but it won't hurt the 32-bit users.
26// __mips_eabi means eabi, which comes in both sizes, but isn't used.
27//
28// PowerPC: Big ugly problem! 32-bit Macs are still popular. :-/
29//
30// x86-64: So far, nobody has been dumb enough to go 32-bit.
31//
32// Unknown: PA-RISC and zSeries
33//
34#if defined(k64test) || (defined(_ABIN32) && _MIPS_SIM == _ABIN32)
35#define KLONG long long    // not typedef; want "unsigned KLONG" to work
36#define KLF "L"
37#define STRTOUKL strtoull
38#else
39#define KLONG long
40#define KLF "l"
41#define STRTOUKL strtoul
42#endif
43
44// since gcc-2.5
45#define NORETURN __attribute__((__noreturn__))
46#define FUNCTION __attribute__((__const__))  // no access to global mem, even via ptr, and no side effect
47
48#if !defined(restrict) && __STDC_VERSION__ < 199901
49#if __GNUC__ > 2 || __GNUC_MINOR__ >= 92
50#define restrict __restrict__
51#else
52#warning No restrict keyword?
53#define restrict
54#endif
55#endif
56
57#if __GNUC__ > 2 || __GNUC_MINOR__ >= 96
58// won't alias anything, and aligned enough for anything
59#define MALLOC __attribute__ ((__malloc__))
60// no side effect, may read globals
61#define PURE __attribute__ ((__pure__))
62// tell gcc what to expect:   if(unlikely(err)) die(err);
63#define likely(x)       __builtin_expect(!!(x),1)
64#define unlikely(x)     __builtin_expect(!!(x),0)
65#define expected(x,y)   __builtin_expect((x),(y))
66#else
67#define MALLOC
68#define PURE
69#define likely(x)       (x)
70#define unlikely(x)     (x)
71#define expected(x,y)   (x)
72#endif
73
74#if SHARED==1 && (__GNUC__ > 2 || __GNUC_MINOR__ >= 96)
75#define LABEL_OFFSET
76#endif
77
78#define STRINGIFY_ARG(a)	#a
79#define STRINGIFY(a)		STRINGIFY_ARG(a)
80
81// marks old junk, to warn non-procps library users
82#if ( __GNUC__ == 3 && __GNUC_MINOR__ > 0 ) || __GNUC__ > 3
83#define OBSOLETE __attribute__((deprecated))
84#else
85#define OBSOLETE
86#endif
87
88#if ( __GNUC__ == 3 && __GNUC_MINOR__ > 1 ) || __GNUC__ > 3
89// Tells gcc that function is library-internal;
90// so no need to do dynamic linking at run-time.
91// This might work with slightly older compilers too.
92#define HIDDEN __attribute__((visibility("hidden")))
93// The opposite, in case -fvisibility=hidden used
94#define EXPORT __attribute__((visibility("default")))
95// Tell g++ that a function won't throw exceptions.
96#define NOTHROW __attribute__((__nothrow__))
97#else
98#define HIDDEN
99#define EXPORT
100#define NOTHROW
101#endif
102
103// Like HIDDEN, but for an alias that gets created.
104// In gcc-3.2 there is an alias+hidden conflict.
105// Many will have patched this bug, but oh well.
106#if ( __GNUC__ == 3 && __GNUC_MINOR__ > 2 ) || __GNUC__ > 3
107#define HIDDEN_ALIAS(x) extern __typeof(x) x##_direct __attribute__((alias(#x),visibility("hidden")))
108#else
109#define HIDDEN_ALIAS(x) extern __typeof(x) x##_direct __attribute__((alias(#x)))
110#endif
111
112#endif
113