1 /* SPDX-License-Identifier: GPL-2.0+ OR BSD-3- 1 /* SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause */ 2 /* 2 /* 3 * Copyright (c) Facebook, Inc. 3 * Copyright (c) Facebook, Inc. 4 * All rights reserved. 4 * All rights reserved. 5 * 5 * 6 * This source code is licensed under both the 6 * This source code is licensed under both the BSD-style license (found in the 7 * LICENSE file in the root directory of this 7 * LICENSE file in the root directory of this source tree) and the GPLv2 (found 8 * in the COPYING file in the root directory o 8 * in the COPYING file in the root directory of this source tree). 9 * You may select, at your option, one of the 9 * You may select, at your option, one of the above-listed licenses. 10 */ 10 */ 11 11 12 /* 12 /* 13 * This file provides common libc dependencies 13 * This file provides common libc dependencies that zstd requires. 14 * The purpose is to allow replacing this file 14 * The purpose is to allow replacing this file with a custom implementation 15 * to compile zstd without libc support. 15 * to compile zstd without libc support. 16 */ 16 */ 17 17 18 /* Need: 18 /* Need: 19 * NULL 19 * NULL 20 * INT_MAX 20 * INT_MAX 21 * UINT_MAX 21 * UINT_MAX 22 * ZSTD_memcpy() 22 * ZSTD_memcpy() 23 * ZSTD_memset() 23 * ZSTD_memset() 24 * ZSTD_memmove() 24 * ZSTD_memmove() 25 */ 25 */ 26 #ifndef ZSTD_DEPS_COMMON 26 #ifndef ZSTD_DEPS_COMMON 27 #define ZSTD_DEPS_COMMON 27 #define ZSTD_DEPS_COMMON 28 28 29 #include <linux/limits.h> 29 #include <linux/limits.h> 30 #include <linux/stddef.h> 30 #include <linux/stddef.h> 31 31 32 #define ZSTD_memcpy(d,s,n) __builtin_memcpy((d 32 #define ZSTD_memcpy(d,s,n) __builtin_memcpy((d),(s),(n)) 33 #define ZSTD_memmove(d,s,n) __builtin_memmove( 33 #define ZSTD_memmove(d,s,n) __builtin_memmove((d),(s),(n)) 34 #define ZSTD_memset(d,s,n) __builtin_memset((d 34 #define ZSTD_memset(d,s,n) __builtin_memset((d),(s),(n)) 35 35 36 #endif /* ZSTD_DEPS_COMMON */ 36 #endif /* ZSTD_DEPS_COMMON */ 37 37 38 /* 38 /* 39 * Define malloc as always failing. That means 39 * Define malloc as always failing. That means the user must 40 * either use ZSTD_customMem or statically all 40 * either use ZSTD_customMem or statically allocate memory. 41 * Need: 41 * Need: 42 * ZSTD_malloc() 42 * ZSTD_malloc() 43 * ZSTD_free() 43 * ZSTD_free() 44 * ZSTD_calloc() 44 * ZSTD_calloc() 45 */ 45 */ 46 #ifdef ZSTD_DEPS_NEED_MALLOC 46 #ifdef ZSTD_DEPS_NEED_MALLOC 47 #ifndef ZSTD_DEPS_MALLOC 47 #ifndef ZSTD_DEPS_MALLOC 48 #define ZSTD_DEPS_MALLOC 48 #define ZSTD_DEPS_MALLOC 49 49 50 #define ZSTD_malloc(s) ({ (void)(s); NULL; }) 50 #define ZSTD_malloc(s) ({ (void)(s); NULL; }) 51 #define ZSTD_free(p) ((void)(p)) 51 #define ZSTD_free(p) ((void)(p)) 52 #define ZSTD_calloc(n,s) ({ (void)(n); (void)( 52 #define ZSTD_calloc(n,s) ({ (void)(n); (void)(s); NULL; }) 53 53 54 #endif /* ZSTD_DEPS_MALLOC */ 54 #endif /* ZSTD_DEPS_MALLOC */ 55 #endif /* ZSTD_DEPS_NEED_MALLOC */ 55 #endif /* ZSTD_DEPS_NEED_MALLOC */ 56 56 57 /* 57 /* 58 * Provides 64-bit math support. 58 * Provides 64-bit math support. 59 * Need: 59 * Need: 60 * U64 ZSTD_div64(U64 dividend, U32 divisor) 60 * U64 ZSTD_div64(U64 dividend, U32 divisor) 61 */ 61 */ 62 #ifdef ZSTD_DEPS_NEED_MATH64 62 #ifdef ZSTD_DEPS_NEED_MATH64 63 #ifndef ZSTD_DEPS_MATH64 63 #ifndef ZSTD_DEPS_MATH64 64 #define ZSTD_DEPS_MATH64 64 #define ZSTD_DEPS_MATH64 65 65 66 #include <linux/math64.h> 66 #include <linux/math64.h> 67 67 68 static uint64_t ZSTD_div64(uint64_t dividend, 68 static uint64_t ZSTD_div64(uint64_t dividend, uint32_t divisor) { 69 return div_u64(dividend, divisor); 69 return div_u64(dividend, divisor); 70 } 70 } 71 71 72 #endif /* ZSTD_DEPS_MATH64 */ 72 #endif /* ZSTD_DEPS_MATH64 */ 73 #endif /* ZSTD_DEPS_NEED_MATH64 */ 73 #endif /* ZSTD_DEPS_NEED_MATH64 */ 74 74 75 /* 75 /* 76 * This is only requested when DEBUGLEVEL >= 1 76 * This is only requested when DEBUGLEVEL >= 1, meaning 77 * it is disabled in production. 77 * it is disabled in production. 78 * Need: 78 * Need: 79 * assert() 79 * assert() 80 */ 80 */ 81 #ifdef ZSTD_DEPS_NEED_ASSERT 81 #ifdef ZSTD_DEPS_NEED_ASSERT 82 #ifndef ZSTD_DEPS_ASSERT 82 #ifndef ZSTD_DEPS_ASSERT 83 #define ZSTD_DEPS_ASSERT 83 #define ZSTD_DEPS_ASSERT 84 84 85 #include <linux/kernel.h> 85 #include <linux/kernel.h> 86 86 87 #define assert(x) WARN_ON(!(x)) 87 #define assert(x) WARN_ON(!(x)) 88 88 89 #endif /* ZSTD_DEPS_ASSERT */ 89 #endif /* ZSTD_DEPS_ASSERT */ 90 #endif /* ZSTD_DEPS_NEED_ASSERT */ 90 #endif /* ZSTD_DEPS_NEED_ASSERT */ 91 91 92 /* 92 /* 93 * This is only requested when DEBUGLEVEL >= 2 93 * This is only requested when DEBUGLEVEL >= 2, meaning 94 * it is disabled in production. 94 * it is disabled in production. 95 * Need: 95 * Need: 96 * ZSTD_DEBUG_PRINT() 96 * ZSTD_DEBUG_PRINT() 97 */ 97 */ 98 #ifdef ZSTD_DEPS_NEED_IO 98 #ifdef ZSTD_DEPS_NEED_IO 99 #ifndef ZSTD_DEPS_IO 99 #ifndef ZSTD_DEPS_IO 100 #define ZSTD_DEPS_IO 100 #define ZSTD_DEPS_IO 101 101 102 #include <linux/printk.h> 102 #include <linux/printk.h> 103 103 104 #define ZSTD_DEBUG_PRINT(...) pr_debug(__VA_AR 104 #define ZSTD_DEBUG_PRINT(...) pr_debug(__VA_ARGS__) 105 105 106 #endif /* ZSTD_DEPS_IO */ 106 #endif /* ZSTD_DEPS_IO */ 107 #endif /* ZSTD_DEPS_NEED_IO */ 107 #endif /* ZSTD_DEPS_NEED_IO */ 108 108
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.