-
Notifications
You must be signed in to change notification settings - Fork 29
/
infrastructure.c
71 lines (63 loc) · 1.71 KB
/
infrastructure.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* Basic implementations of common functions.
*
* Copyright (c) Antmicro
* Copyright (c) Realtime Embedded
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include "callbacks.h"
#include "infrastructure.h"
void *global_retaddr = 0;
#if defined(__linux__) && defined(__x86_64__)
asm (".symver memcpy, memcpy@GLIBC_2.2.5");
void *__wrap_memcpy(void *dest, const void *src, size_t n)
{
return memcpy(dest, src, n);
}
#endif
void *tlib_mallocz(size_t size)
{
void *ret = tlib_malloc(size);
memset(ret, 0, size);
return ret;
}
char *tlib_strdup(const char * str)
{
int length = strlen(str);
char *ret = tlib_malloc(length + 1);
strcpy(ret, str);
return ret;
}
void tlib_printf(enum log_level level, char *fmt, ...)
{
char s[1024];
va_list ap;
va_start(ap, fmt);
vsnprintf(s, 1024, fmt, ap);
tlib_log(level, s);
va_end(ap);
}
void tlib_abortf(char *fmt, ...)
{
char result[1024];
va_list ap;
va_start(ap, fmt);
vsnprintf(result, 1024, fmt, ap);
tlib_abort(result);
va_end(ap);
}