2 * Copyright (c) 2010 Your File System Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
25 #include <afsconfig.h>
26 #include "afs/param.h"
30 #include "afs/sysincludes.h"
31 #include "afs/afsincludes.h"
32 #include "afs/afs_prototypes.h"
37 #define assert osi_Assert
39 /* Linux's current.h defines current to get_current(), conflicing with
40 * heimdal's rand-fortuna.c's local variable. */
43 #define current current
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. */
53 /* hcrypto uses "static inline", which isn't supported by some of our
55 #if !defined(inline) && !defined(__GNUC__)
59 /* We need wrappers for the various memory management functions */
60 #define calloc _afscrypto_calloc
61 void * _afscrypto_calloc(int, size_t);
66 #define malloc _afscrypto_malloc
67 void * _afscrypto_malloc(size_t);
69 #define free _afscrypto_free
70 void _afscrypto_free(void *);
72 #define strdup _afscrypto_strdup
73 char * _afscrypto_strdup(const char *);
75 #define realloc _afscrypto_realloc
76 void * _afscrypto_realloc(void *, size_t);
78 /* we may not have strcasecmp in the kernel */
79 #define strcasecmp afs_strcasecmp
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);
86 /* On linux, getpid() is unfortunately declared in terms of current, which
87 * already gives us a namespace clash. It was lousy entropy, anyway. */
91 static_inline pid_t getpid(void) {return 1;};
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)
101 #ifdef HAVE_ARC4RANDOM
102 # undef HAVE_ARC4RANDOM
105 #if !defined(AFS_LINUX26_ENV)
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.
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;}
114 #if defined(KERNEL) && (defined(AFS_SUN5_ENV) || defined(AFS_ARM64_LINUX26_ENV))
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.
125 # define double void*