FBSD: Handle malloc/free changes in FBSD 12
[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 #ifdef malloc
64 # undef malloc
65 #endif
66 #define malloc _afscrypto_malloc
67 void * _afscrypto_malloc(size_t);
68
69 #define free _afscrypto_free
70 void _afscrypto_free(void *);
71
72 #define strdup _afscrypto_strdup
73 char * _afscrypto_strdup(const char *);
74
75 #define realloc _afscrypto_realloc
76 void * _afscrypto_realloc(void *, size_t);
77
78 /* we may not have strcasecmp in the kernel */
79 #define strcasecmp afs_strcasecmp
80
81 /* osi_readRandom is also prototyped in afs_prototypes.h, but pulling that in
82  * here creates loads of additional dependencies */
83 extern int osi_readRandom(void *, afs_size_t);
84
85 #if defined(getpid)
86 /* On linux, getpid() is unfortunately declared in terms of current, which
87  * already gives us a namespace clash.  It was lousy entropy, anyway. */
88 #undef getpid
89 #define getpid()        1
90 #else
91 static_inline pid_t getpid(void) {return 1;};
92 #endif
93 static_inline int open(const char *path, int flags, ...) {return -1;}
94 static_inline void abort(void) {osi_Panic("hckernel aborting\n");}
95 static_inline void rk_cloexec(int fd) {}
96 static_inline ssize_t read(int d, void *buf, size_t nbytes) {return -1;}
97 static_inline int close(int d) {return -1;}
98 #if defined(HAVE_GETUID)
99 #undef HAVE_GETUID
100 #endif
101 #ifdef HAVE_ARC4RANDOM
102 # undef HAVE_ARC4RANDOM
103 #endif
104
105 #if !defined(AFS_LINUX26_ENV)
106 /*
107  * gettimeofday is only used in rand-fortuna.c, not built for Linux.
108  * Linux 5.6 removes the native struct timeval, so this stub would not build.
109  */
110 static_inline int gettimeofday(struct timeval *tp, void *tzp)
111     {if (tp == NULL) return -1; tp->tv_sec = osi_Time(); tp->tv_usec = 0; return 0;}
112 #endif
113
114 #if defined(KERNEL) && (defined(AFS_SUN5_ENV) || defined(AFS_ARM64_LINUX26_ENV))
115 /*
116  * Some functions such as RAND_add take a 'double' as an argument, but floating
117  * point code generally cannot be used in kernelspace. We never actually use
118  * that argument in kernel code, but just that it exists as an argument is
119  * enough to break the kernel code on Linux (on arm64) and Solaris (depending
120  * on the compiler version and flags). Change all instances of double to void*
121  * to avoid this; if someone does try to use that argument, hopefully the fact
122  * that it is now a void* will flag an error at compile time before it causes
123  * any further problems.
124  */
125 # define double void*
126 #endif