LINUX 5.6: define time_t and use timespec/timespec64
[openafs.git] / src / crypto / hcrypto / kernel / config.h
1 /*
2  * Copyright (c) 2010 Your File System Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  */
24
25 #include <afsconfig.h>
26 #include "afs/param.h"
27 #include "afs/opr.h"
28
29 #include "afs/stds.h"
30 #include "afs/sysincludes.h"
31 #include "afs/afsincludes.h"
32 #include "afs/afs_prototypes.h"
33
34 #if defined(assert)
35 #undef assert
36 #endif
37 #define assert osi_Assert
38
39 /* Linux's current.h defines current to get_current(), conflicing with
40  * heimdal's rand-fortuna.c's local variable. */
41 #if defined(current)
42 #undef current
43 #define current current
44 #endif
45
46 /* AIX and some Solaris (and others, presumably) still have a 'u' symbol for
47  * the user area.  rand-fortuna.c has a local variable of that name. */
48 #if defined(u)
49 #undef u
50 #define u u
51 #endif
52
53 /* hcrypto uses "static inline", which isn't supported by some of our
54  * compilers */
55 #if !defined(inline) && !defined(__GNUC__)
56 #define inline
57 #endif
58
59 /* We need wrappers for the various memory management functions */
60 #define calloc _afscrypto_calloc
61 void * _afscrypto_calloc(int, size_t);
62
63 #define malloc _afscrypto_malloc
64 void * _afscrypto_malloc(size_t);
65
66 #define free _afscrypto_free
67 void _afscrypto_free(void *);
68
69 #define strdup _afscrypto_strdup
70 char * _afscrypto_strdup(const char *);
71
72 #define realloc _afscrypto_realloc
73 void * _afscrypto_realloc(void *, size_t);
74
75 /* we may not have strcasecmp in the kernel */
76 #define strcasecmp afs_strcasecmp
77
78 /* osi_readRandom is also prototyped in afs_prototypes.h, but pulling that in
79  * here creates loads of additional dependencies */
80 extern int osi_readRandom(void *, afs_size_t);
81
82 #if defined(getpid)
83 /* On linux, getpid() is unfortunately declared in terms of current, which
84  * already gives us a namespace clash.  It was lousy entropy, anyway. */
85 #undef getpid
86 #define getpid()        1
87 #else
88 static_inline pid_t getpid(void) {return 1;};
89 #endif
90 static_inline int open(const char *path, int flags, ...) {return -1;}
91 static_inline void abort(void) {osi_Panic("hckernel aborting\n");}
92 static_inline void rk_cloexec(int fd) {}
93 static_inline ssize_t read(int d, void *buf, size_t nbytes) {return -1;}
94 static_inline int close(int d) {return -1;}
95 #if defined(HAVE_GETUID)
96 #undef HAVE_GETUID
97 #endif
98 #ifdef HAVE_ARC4RANDOM
99 # undef HAVE_ARC4RANDOM
100 #endif
101
102 #if !defined(AFS_LINUX26_ENV)
103 /*
104  * gettimeofday is only used in rand-fortuna.c, not built for Linux.
105  * Linux 5.6 removes the native struct timeval, so this stub would not build.
106  */
107 static_inline int gettimeofday(struct timeval *tp, void *tzp)
108     {if (tp == NULL) return -1; tp->tv_sec = osi_Time(); tp->tv_usec = 0; return 0;}
109 #endif
110
111 #if defined(KERNEL) && (defined(AFS_SUN5_ENV) || defined(AFS_ARM64_LINUX26_ENV))
112 /*
113  * Some functions such as RAND_add take a 'double' as an argument, but floating
114  * point code generally cannot be used in kernelspace. We never actually use
115  * that argument in kernel code, but just that it exists as an argument is
116  * enough to break the kernel code on Linux (on arm64) and Solaris (depending
117  * on the compiler version and flags). Change all instances of double to void*
118  * to avoid this; if someone does try to use that argument, hopefully the fact
119  * that it is now a void* will flag an error at compile time before it causes
120  * any further problems.
121  */
122 # define double void*
123 #endif