Electroneum
Toggle main menu visibility
Loading...
Searching...
No Matches
glibc_compat.cpp
Go to the documentation of this file.
1
#include <cstddef>
2
#include <cstdint>
3
#include <strings.h>
4
#include <
string.h
>
5
#include <glob.h>
6
#include <unistd.h>
7
#include <fnmatch.h>
8
9
#if defined(HAVE_SYS_SELECT_H)
10
#include <sys/select.h>
11
#endif
12
13
// Prior to GLIBC_2.14, memcpy was aliased to memmove.
14
extern
"C"
void
*
memmove
(
void
*
a
,
const
void
* b,
size_t
c);
15
//extern "C" void* memset(void* a, int b, long unsigned int c);
16
extern
"C"
void
*
memcpy
(
void
*
a
,
const
void
* b,
size_t
c)
17
{
18
return
memmove
(
a
, b, c);
19
}
20
21
extern
"C"
void
__chk_fail
(
void
)
__attribute__
((__noreturn__));
22
23
#if defined(__i386__) || defined(__arm__)
24
25
extern
"C"
int64_t
__udivmoddi4(
uint64_t
u,
uint64_t
v,
uint64_t
* rp);
26
27
extern
"C"
int64_t
__wrap___divmoddi4(
int64_t
u,
int64_t
v,
int64_t
* rp)
28
{
29
int32_t
c1 = 0, c2 = 0;
30
int64_t
uu = u, vv = v;
31
int64_t
w;
32
int64_t
r;
33
34
if
(uu < 0) {
35
c1 = ~c1, c2 = ~c2, uu = -uu;
36
}
37
if
(vv < 0) {
38
c1 = ~c1, vv = -vv;
39
}
40
41
w = __udivmoddi4(uu, vv, (
uint64_t
*)&r);
42
if
(c1)
43
w = -w;
44
if
(c2)
45
r = -r;
46
47
*rp = r;
48
return
w;
49
}
50
#endif
51
52
/* glibc-internal users use __explicit_bzero_chk, and explicit_bzero
53
redirects to that. */
54
#undef explicit_bzero
55
/* Set LEN bytes of S to 0. The compiler will not delete a call to
56
this function, even if S is dead after the call. */
57
void
58
explicit_bzero
(
void
*s,
size_t
len)
59
{
60
memset (s,
'\0'
, len);
61
/* Compiler barrier. */
62
asm
volatile
(
""
:::
"memory"
);
63
}
64
65
// Redefine explicit_bzero_chk
66
void
67
__explicit_bzero_chk
(
void
*dst,
size_t
len,
size_t
dstlen)
68
{
69
/* Inline __memset_chk to avoid a PLT reference to __memset_chk. */
70
if
(__glibc_unlikely (dstlen < len))
71
__chk_fail
();
72
memset (dst,
'\0'
, len);
73
/* Compiler barrier. */
74
asm
volatile
(
""
:::
"memory"
);
75
}
76
/* libc-internal references use the hidden
77
__explicit_bzero_chk_internal symbol. This is necessary if
78
__explicit_bzero_chk is implemented as an IFUNC because some
79
targets do not support hidden references to IFUNC symbols. */
80
#define strong_alias (__explicit_bzero_chk, __explicit_bzero_chk_internal)
81
82
#undef glob
83
extern
"C"
int
glob_old
(
const
char
* pattern,
int
flags,
int
(*errfunc) (
const
char
*epath,
int
eerrno), glob_t *pglob);
84
#ifdef __i386__
85
__asm__(
".symver glob_old,glob@GLIBC_2.0"
);
86
#elif defined(__amd64__)
87
__asm__(
".symver glob_old,glob@GLIBC_2.2.5"
);
88
#elif defined(__arm__)
89
__asm(
".symver glob_old,glob@GLIBC_2.4"
);
90
#elif defined(__aarch64__)
91
__asm__(
".symver glob_old,glob@GLIBC_2.17"
);
92
#endif
93
94
extern
"C"
int
__wrap_glob
(
const
char
* pattern,
int
flags,
int
(*errfunc) (
const
char
*epath,
int
eerrno), glob_t *pglob)
95
{
96
return
glob_old
(pattern, flags, errfunc, pglob);
97
}
98
glob_old
int glob_old(const char *pattern, int flags, int(*errfunc)(const char *epath, int eerrno), glob_t *pglob)
memmove
void * memmove(void *a, const void *b, size_t c)
__chk_fail
void __chk_fail(void) __attribute__((__noreturn__))
__explicit_bzero_chk
void __explicit_bzero_chk(void *dst, size_t len, size_t dstlen)
Definition
glibc_compat.cpp:67
memcpy
void * memcpy(void *a, const void *b, size_t c)
Definition
glibc_compat.cpp:16
explicit_bzero
void explicit_bzero(void *s, size_t len)
Definition
glibc_compat.cpp:58
__wrap_glob
int __wrap_glob(const char *pattern, int flags, int(*errfunc)(const char *epath, int eerrno), glob_t *pglob)
Definition
glibc_compat.cpp:94
a
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition
pointer.h:1124
__attribute__
__attribute__((noreturn)) void CXA_THROW(void *ex
int64_t
signed __int64 int64_t
Definition
stdint.h:135
int32_t
signed int int32_t
Definition
stdint.h:123
uint64_t
unsigned __int64 uint64_t
Definition
stdint.h:136
string.h
src
common
compat
glibc_compat.cpp
Generated on
for Electroneum by
1.17.0