Skip to content

Commit 5c52d3a

Browse files
committed
CTL: Add a CTL sources to the UMF
This commit introduces sources and compilation of the CTL. The CTL sources are copied from: https://github.com/pmem/pmdk/tree/master/src/common Signed-off-by: Krzysztof Filipek <[email protected]>
1 parent 93566f6 commit 5c52d3a

File tree

6 files changed

+1001
-1029
lines changed

6 files changed

+1001
-1029
lines changed

src/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ set(BA_SOURCES
2525
${CMAKE_CURRENT_SOURCE_DIR}/base_alloc/base_alloc_linear.c
2626
${CMAKE_CURRENT_SOURCE_DIR}/base_alloc/base_alloc_global.c)
2727

28-
set(CTL_SOURCES
29-
${CMAKE_CURRENT_SOURCE_DIR}/ctl/alloc.c
30-
${CMAKE_CURRENT_SOURCE_DIR}/ctl/ctl.c)
28+
set(CTL_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/ctl/alloc.c
29+
${CMAKE_CURRENT_SOURCE_DIR}/ctl/ctl.c)
3130

3231
if(LINUX)
3332
set(BA_SOURCES ${BA_SOURCES} ${CTL_SOURCES}

src/ctl/alloc.c

Lines changed: 51 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -18,74 +18,61 @@ static __thread int malloc_num;
1818
static __thread int fail_malloc_num;
1919
static __thread const char *fail_malloc_from;
2020

21-
void *
22-
_flt_Malloc(size_t size, const char *func)
23-
{
24-
if (fail_malloc_from && strcmp(func, fail_malloc_from) == 0) {
25-
if (++malloc_num == fail_malloc_num) {
26-
errno = ENOMEM;
27-
return NULL;
28-
}
29-
}
30-
return fn_malloc(size);
21+
void *_flt_Malloc(size_t size, const char *func) {
22+
if (fail_malloc_from && strcmp(func, fail_malloc_from) == 0) {
23+
if (++malloc_num == fail_malloc_num) {
24+
errno = ENOMEM;
25+
return NULL;
26+
}
27+
}
28+
return fn_malloc(size);
3129
}
3230

3331
static __thread int realloc_num;
3432
static __thread int fail_realloc_num;
3533
static __thread const char *fail_realloc_from;
3634

37-
void *
38-
_flt_Realloc(void *ptr, size_t size, const char *func)
39-
{
40-
if (fail_realloc_from && strcmp(func, fail_realloc_from) == 0) {
41-
if (++realloc_num == fail_realloc_num) {
42-
errno = ENOMEM;
43-
return NULL;
44-
}
45-
}
46-
return fn_realloc(ptr, size);
35+
void *_flt_Realloc(void *ptr, size_t size, const char *func) {
36+
if (fail_realloc_from && strcmp(func, fail_realloc_from) == 0) {
37+
if (++realloc_num == fail_realloc_num) {
38+
errno = ENOMEM;
39+
return NULL;
40+
}
41+
}
42+
return fn_realloc(ptr, size);
4743
}
4844

49-
void
50-
core_inject_fault_at(enum pmem_allocation_type type, int nth, const char *at)
51-
{
52-
switch (type) {
53-
case PMEM_MALLOC:
54-
malloc_num = 0;
55-
fail_malloc_num = nth;
56-
fail_malloc_from = at;
57-
break;
58-
case PMEM_REALLOC:
59-
realloc_num = 0;
60-
fail_realloc_num = nth;
61-
fail_realloc_from = at;
62-
break;
63-
default:
64-
CORE_LOG_FATAL("unknown allocation type");
65-
}
45+
void core_inject_fault_at(enum pmem_allocation_type type, int nth,
46+
const char *at) {
47+
switch (type) {
48+
case PMEM_MALLOC:
49+
malloc_num = 0;
50+
fail_malloc_num = nth;
51+
fail_malloc_from = at;
52+
break;
53+
case PMEM_REALLOC:
54+
realloc_num = 0;
55+
fail_realloc_num = nth;
56+
fail_realloc_from = at;
57+
break;
58+
default:
59+
CORE_LOG_FATAL("unknown allocation type");
60+
}
6661
}
6762

68-
int
69-
core_fault_injection_enabled(void)
70-
{
71-
return 1;
72-
}
63+
int core_fault_injection_enabled(void) { return 1; }
7364
#else
74-
void *_Malloc(size_t size) {
75-
return fn_malloc(size);
76-
}
65+
void *_Malloc(size_t size) { return fn_malloc(size); }
7766

78-
void *_Realloc(void *ptr, size_t size) {
79-
return fn_realloc(ptr, size);
80-
}
67+
void *_Realloc(void *ptr, size_t size) { return fn_realloc(ptr, size); }
8168
#endif
8269

8370
void set_func_malloc(void *(*malloc_func)(size_t size)) {
84-
fn_malloc = (malloc_func == NULL) ? malloc : malloc_func;
71+
fn_malloc = (malloc_func == NULL) ? malloc : malloc_func;
8572
}
8673

8774
void set_func_realloc(void *(*realloc_func)(void *ptr, size_t size)) {
88-
fn_realloc = (realloc_func == NULL) ? realloc : realloc_func;
75+
fn_realloc = (realloc_func == NULL) ? realloc : realloc_func;
8976
}
9077

9178
/*
@@ -97,26 +84,23 @@ Strdup_func Strdup = strdup;
9784
/*
9885
* Zalloc -- allocate zeroed memory
9986
*/
100-
void *
101-
Zalloc(size_t sz)
102-
{
103-
void *ret = Malloc(sz);
104-
if (!ret)
105-
return NULL;
106-
return memset(ret, 0, sz);
87+
void *Zalloc(size_t sz) {
88+
void *ret = Malloc(sz);
89+
if (!ret) {
90+
return NULL;
91+
}
92+
return memset(ret, 0, sz);
10793
}
10894

10995
/*
11096
* util_set_alloc_funcs -- allow one to override malloc, etc.
11197
*/
112-
void
113-
util_set_alloc_funcs(void *(*malloc_func)(size_t size),
114-
void (*free_func)(void *ptr),
115-
void *(*realloc_func)(void *ptr, size_t size),
116-
char *(*strdup_func)(const char *s))
117-
{
118-
set_func_malloc(malloc_func);
119-
Free = (free_func == NULL) ? free : free_func;
120-
set_func_realloc(realloc_func);
121-
Strdup = (strdup_func == NULL) ? strdup : strdup_func;
98+
void util_set_alloc_funcs(void *(*malloc_func)(size_t size),
99+
void (*free_func)(void *ptr),
100+
void *(*realloc_func)(void *ptr, size_t size),
101+
char *(*strdup_func)(const char *s)) {
102+
set_func_malloc(malloc_func);
103+
Free = (free_func == NULL) ? free : free_func;
104+
set_func_realloc(realloc_func);
105+
Strdup = (strdup_func == NULL) ? strdup : strdup_func;
122106
}

0 commit comments

Comments
 (0)