[RFC 1/2] Rename xmalloc and xcalloc to strace_malloc and strace_calloc
Masatake YAMATO
yamato at redhat.com
Tue Dec 5 10:01:02 UTC 2017
I'm planning to linke strace with libiberty for mangling C++
symbol appearted in stack trace enabled with -k option.
Both the names, xmalloc and xcalloc, are already used in the
library. Therefore I rename the symbols defined in strace.
---
bpf.c | 2 +-
count.c | 4 ++--
dyxlat.c | 4 ++--
filter_qualify.c | 2 +-
mmsghdr.c | 2 +-
number_set.c | 2 +-
pathtrace.c | 2 +-
perf.c | 4 ++--
strace.c | 4 ++--
syscall.c | 4 ++--
unwind.c | 8 ++++----
util.c | 4 ++--
xmalloc.c | 6 +++---
xmalloc.h | 4 ++--
14 files changed, 26 insertions(+), 26 deletions(-)
diff --git a/bpf.c b/bpf.c
index 59d1e749..4706bcfd 100644
--- a/bpf.c
+++ b/bpf.c
@@ -411,7 +411,7 @@ SYS_FUNC(bpf)
if (!buf) {
page_size = get_pagesize();
- buf = xmalloc(page_size);
+ buf = strace_malloc(page_size);
}
printxval(bpf_commands, cmd, "BPF_???");
diff --git a/count.c b/count.c
index f5e4f12f..bfcd7eca 100644
--- a/count.c
+++ b/count.c
@@ -59,7 +59,7 @@ count_syscall(struct tcb *tcp, const struct timeval *syscall_exiting_tv)
return;
if (!counts)
- counts = xcalloc(nsyscalls, sizeof(*counts));
+ counts = strace_calloc(nsyscalls, sizeof(*counts));
cc = &counts[tcp->scno];
cc->calls++;
@@ -169,7 +169,7 @@ call_summary_pers(FILE *outf)
fprintf(outf, "%6.6s %11.11s %11.11s %9.9s %9.9s %s\n",
dashes, dashes, dashes, dashes, dashes, dashes);
- sorted_count = xcalloc(sizeof(int), nsyscalls);
+ sorted_count = strace_calloc(sizeof(int), nsyscalls);
call_cum = error_cum = tv_cum.tv_sec = tv_cum.tv_usec = 0;
if (overhead.tv_sec == -1) {
tv_mul(&overhead, &shortest, 8);
diff --git a/dyxlat.c b/dyxlat.c
index ef6bef4f..d9b86100 100644
--- a/dyxlat.c
+++ b/dyxlat.c
@@ -41,11 +41,11 @@ struct dyxlat {
struct dyxlat *
dyxlat_alloc(const size_t nmemb)
{
- struct dyxlat *const dyxlat = xmalloc(sizeof(*dyxlat));
+ struct dyxlat *const dyxlat = strace_malloc(sizeof(*dyxlat));
dyxlat->used = 1;
dyxlat->allocated = nmemb ? nmemb : 16;
- dyxlat->xlat = xcalloc(dyxlat->allocated, sizeof(struct xlat));
+ dyxlat->xlat = strace_calloc(dyxlat->allocated, sizeof(struct xlat));
MARK_END(dyxlat->xlat[0]);
return dyxlat;
diff --git a/filter_qualify.c b/filter_qualify.c
index 5b0ef28c..09a42c63 100644
--- a/filter_qualify.c
+++ b/filter_qualify.c
@@ -283,7 +283,7 @@ qualify_inject_common(const char *const str,
alloc_number_set_array(SUPPORTED_PERSONALITIES);
}
if (!inject_vec[p]) {
- inject_vec[p] = xcalloc(nsyscall_vec[p],
+ inject_vec[p] = strace_calloc(nsyscall_vec[p],
sizeof(*inject_vec[p]));
}
diff --git a/mmsghdr.c b/mmsghdr.c
index c9e6cf0b..008e9fd8 100644
--- a/mmsghdr.c
+++ b/mmsghdr.c
@@ -106,7 +106,7 @@ save_mmsgvec_namelen(struct tcb *const tcp, kernel_ulong_t addr,
const size_t data_size = offsetof(struct mmsgvec_data, namelen)
+ sizeof(int) * len;
- struct mmsgvec_data *const data = xmalloc(data_size);
+ struct mmsgvec_data *const data = strace_malloc(data_size);
data->timeout = xstrdup(timeout);
unsigned int i, fetched;
diff --git a/number_set.c b/number_set.c
index b8aa28c7..ae0fecc1 100644
--- a/number_set.c
+++ b/number_set.c
@@ -128,7 +128,7 @@ invert_number_set_array(struct number_set *const set, const unsigned int nmemb)
struct number_set *
alloc_number_set_array(const unsigned int nmemb)
{
- return xcalloc(nmemb, sizeof(struct number_set));
+ return strace_calloc(nmemb, sizeof(struct number_set));
}
void
diff --git a/pathtrace.c b/pathtrace.c
index 52582380..956a341b 100644
--- a/pathtrace.c
+++ b/pathtrace.c
@@ -291,7 +291,7 @@ pathtrace_match_set(struct tcb *tcp, struct path_set *set)
if (nfds > 1024*1024)
nfds = 1024*1024;
fdsize = (((nfds + 7) / 8) + current_wordsize-1) & -current_wordsize;
- fds = xmalloc(fdsize);
+ fds = strace_malloc(fdsize);
for (i = 1; i <= 3; ++i) {
if (args[i] == 0)
diff --git a/perf.c b/perf.c
index 6af0f42a..498ba42a 100644
--- a/perf.c
+++ b/perf.c
@@ -93,7 +93,7 @@ fetch_perf_event_attr(struct tcb *const tcp, const kernel_ulong_t addr)
/* Size should be multiple of 8, but kernel doesn't check for it */
/* size &= ~7; */
- attr = xcalloc(1, sizeof(*attr));
+ attr = strace_calloc(1, sizeof(*attr));
if (umoven_or_printaddr(tcp, addr, size, attr)) {
free(attr);
@@ -101,7 +101,7 @@ fetch_perf_event_attr(struct tcb *const tcp, const kernel_ulong_t addr)
return 1;
}
- desc = xmalloc(sizeof(*desc));
+ desc = strace_malloc(sizeof(*desc));
desc->attr = attr;
desc->size = size;
diff --git a/strace.c b/strace.c
index 6ed86a6f..cbbee704 100644
--- a/strace.c
+++ b/strace.c
@@ -693,7 +693,7 @@ expand_tcbtab(void)
new_tcbtabsize = alloc_tcbtabsize = 1;
}
- newtcbs = xcalloc(alloc_tcbtabsize, sizeof(newtcbs[0]));
+ newtcbs = strace_calloc(alloc_tcbtabsize, sizeof(newtcbs[0]));
tcbtab = xreallocarray(tcbtab, new_tcbtabsize, sizeof(tcbtab[0]));
while (tcbtabsize < new_tcbtabsize)
tcbtab[tcbtabsize++] = newtcbs++;
@@ -1759,7 +1759,7 @@ init(int argc, char *argv[])
tflag = 1;
}
- acolumn_spaces = xmalloc(acolumn + 1);
+ acolumn_spaces = strace_malloc(acolumn + 1);
memset(acolumn_spaces, ' ', acolumn);
acolumn_spaces[acolumn] = '\0';
diff --git a/syscall.c b/syscall.c
index b1047feb..7efe83b6 100644
--- a/syscall.c
+++ b/syscall.c
@@ -552,7 +552,7 @@ tamper_with_syscall_entering(struct tcb *tcp, unsigned int *signo)
{
if (!tcp->inject_vec[current_personality]) {
tcp->inject_vec[current_personality] =
- xcalloc(nsyscalls, sizeof(**inject_vec));
+ strace_calloc(nsyscalls, sizeof(**inject_vec));
memcpy(tcp->inject_vec[current_personality],
inject_vec[current_personality],
nsyscalls * sizeof(**inject_vec));
@@ -1197,7 +1197,7 @@ get_scno(struct tcb *tcp)
tcp->s_ent = &sysent[tcp->scno];
tcp->qual_flg = qual_flags(tcp->scno);
} else {
- struct sysent_buf *s = xcalloc(1, sizeof(*s));
+ struct sysent_buf *s = strace_calloc(1, sizeof(*s));
s->tcp = tcp;
s->ent.nargs = MAX_ARGS;
diff --git a/unwind.c b/unwind.c
index c097e875..031795cc 100644
--- a/unwind.c
+++ b/unwind.c
@@ -115,7 +115,7 @@ unwind_tcb_init(struct tcb *tcp)
if (!tcp->libunwind_ui)
perror_msg_and_die("_UPT_create");
- tcp->queue = xmalloc(sizeof(*tcp->queue));
+ tcp->queue = strace_malloc(sizeof(*tcp->queue));
tcp->queue->head = NULL;
tcp->queue->tail = NULL;
}
@@ -158,7 +158,7 @@ build_mmap_cache(struct tcb *tcp)
return;
}
- cache_head = xcalloc(cur_array_size, sizeof(*cache_head));
+ cache_head = strace_calloc(cur_array_size, sizeof(*cache_head));
while (fgets(buffer, sizeof(buffer), fp) != NULL) {
struct mmap_cache_t *entry;
@@ -366,7 +366,7 @@ stacktrace_walk(struct tcb *tcp,
if (tcp->mmap_cache_size == 0)
error_msg_and_die("bug: mmap_cache is empty");
- symbol_name = xmalloc(symbol_name_size);
+ symbol_name = strace_malloc(symbol_name_size);
if (unw_init_remote(&cursor, libunwind_as, tcp->libunwind_ui) < 0)
perror_msg_and_die("Can't initiate libunwind");
@@ -482,7 +482,7 @@ queue_put(struct queue_t *queue,
{
struct call_t *call;
- call = xmalloc(sizeof(*call));
+ call = strace_malloc(sizeof(*call));
call->output_line = sprint_call_or_error(binary_filename,
symbol_name,
function_offset,
diff --git a/util.c b/util.c
index 05c9fb80..bbbee16f 100644
--- a/util.c
+++ b/util.c
@@ -745,8 +745,8 @@ printstr_ex(struct tcb *const tcp, const kernel_ulong_t addr,
* since we have a guarantee that max_strlen <= -1U / 4.
*/
- str = xmalloc(max_strlen + 1);
- outstr = xmalloc(outstr_size);
+ str = strace_malloc(max_strlen + 1);
+ outstr = strace_malloc(outstr_size);
}
/* Fetch one byte more because string_quote may look one byte ahead. */
diff --git a/xmalloc.c b/xmalloc.c
index 8ec475a1..88af17b3 100644
--- a/xmalloc.c
+++ b/xmalloc.c
@@ -49,7 +49,7 @@ die_out_of_memory(void)
}
void *
-xmalloc(size_t size)
+strace_malloc(size_t size)
{
void *p = malloc(size);
@@ -60,7 +60,7 @@ xmalloc(size_t size)
}
void *
-xcalloc(size_t nmemb, size_t size)
+strace_calloc(size_t nmemb, size_t size)
{
void *p = calloc(nmemb, size);
@@ -114,7 +114,7 @@ xstrndup(const char *str, size_t n)
#ifdef HAVE_STRNDUP
p = strndup(str, n);
#else
- p = xmalloc(n + 1);
+ p = strace_malloc(n + 1);
#endif
if (!p)
diff --git a/xmalloc.h b/xmalloc.h
index d1feeb91..ae47d96b 100644
--- a/xmalloc.h
+++ b/xmalloc.h
@@ -36,9 +36,9 @@
#include <stddef.h>
#include "gcc_compat.h"
-void *xcalloc(size_t nmemb, size_t size)
+void *strace_calloc(size_t nmemb, size_t size)
ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE((1, 2));
-void *xmalloc(size_t size) ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE((1));
+void *strace_malloc(size_t size) ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE((1));
void *xreallocarray(void *ptr, size_t nmemb, size_t size)
ATTRIBUTE_ALLOC_SIZE((2, 3));
--
2.13.6
More information about the Strace-devel
mailing list