PIVX Core  5.6.99
P2P Digital Currency
glibc_compat.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2017 The Bitcoin Core developers
2 // Copyright (c) 2017-2020 The PIVX Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #if defined(HAVE_CONFIG_H)
7 #include "config/pivx-config.h"
8 #endif
9 
10 #include <cstddef>
11 #include <cstdint>
12 #include <cstring>
13 #include <pthread.h>
14 #include <stdlib.h>
15 
16 // Prior to GLIBC_2.14, memcpy was aliased to memmove.
17 extern "C" void* memmove(void* a, const void* b, size_t c);
18 extern "C" void* memcpy(void* a, const void* b, size_t c)
19 {
20  return memmove(a, b, c);
21 }
22 
23 extern "C" void __chk_fail(void) __attribute__((__noreturn__));
24 
25 #if defined(__i386__) || defined(__arm__)
26 
27 extern "C" int64_t __udivmoddi4(uint64_t u, uint64_t v, uint64_t* rp);
28 
29 extern "C" int64_t __wrap___divmoddi4(int64_t u, int64_t v, int64_t* rp)
30 {
31  int32_t c1 = 0, c2 = 0;
32  int64_t uu = u, vv = v;
33  int64_t w;
34  int64_t r;
35 
36  if (uu < 0) {
37  c1 = ~c1, c2 = ~c2, uu = -uu;
38  }
39  if (vv < 0) {
40  c1 = ~c1, vv = -vv;
41  }
42 
43  w = __udivmoddi4(uu, vv, (uint64_t*)&r);
44  if (c1)
45  w = -w;
46  if (c2)
47  r = -r;
48 
49  *rp = r;
50  return w;
51 }
52 #endif
53 
54 extern "C" float log2f_old(float x);
55 #ifdef __i386__
56 __asm(".symver log2f_old,log2f@GLIBC_2.1");
57 #elif defined(__amd64__)
58 __asm(".symver log2f_old,log2f@GLIBC_2.2.5");
59 #elif defined(__arm__)
60 __asm(".symver log2f_old,log2f@GLIBC_2.4");
61 #elif defined(__aarch64__)
62 __asm(".symver log2f_old,log2f@GLIBC_2.17");
63 #elif defined(__riscv)
64 __asm(".symver log2f_old,log2f@GLIBC_2.27");
65 #endif
66 extern "C" float __wrap_log2f(float x)
67 {
68  return log2f_old(x);
69 }
70 
71 /* glibc-internal users use __explicit_bzero_chk, and explicit_bzero
72 redirects to that. */
73 #undef explicit_bzero
74 /* Set LEN bytes of S to 0. The compiler will not delete a call to
75 this function, even if S is dead after the call. */
76 void explicit_bzero (void *s, size_t len)
77 {
78  memset (s, '\0', len);
79  /* Compiler barrier. */
80  asm volatile ("" ::: "memory");
81 }
82 
83 // Redefine explicit_bzero_chk
84 void __explicit_bzero_chk (void *dst, size_t len, size_t dstlen)
85 {
86  /* Inline __memset_chk to avoid a PLT reference to __memset_chk. */
87  if (__glibc_unlikely (dstlen < len))
88  __chk_fail ();
89  memset (dst, '\0', len);
90  /* Compiler barrier. */
91  asm volatile ("" ::: "memory");
92 }
93 /* libc-internal references use the hidden
94 __explicit_bzero_chk_internal symbol. This is necessary if
95 __explicit_bzero_chk is implemented as an IFUNC because some
96 targets do not support hidden references to IFUNC symbols. */
97 #define strong_alias (__explicit_bzero_chk, __explicit_bzero_chk_internal)
__attribute__((weak)) int main(int argc
void * memcpy(void *a, const void *b, size_t c)
void __chk_fail(void) __attribute__((__noreturn__))
float __wrap_log2f(float x)
void * memmove(void *a, const void *b, size_t c)
void __explicit_bzero_chk(void *dst, size_t len, size_t dstlen)
float log2f_old(float x)
void explicit_bzero(void *s, size_t len)