[DTrace-devel] [PATCH 15/47] Provide a standard dt_strtab_copystr() function
Kris Van Hees
kris.van.hees at oracle.com
Sun May 3 20:17:12 PDT 2020
Different parts in the DTrace source code were providing their own
custom copy string function to be passed to dt_strtab_write(). All
did essentially the same thing, so it is quite easy to provide a
single generic function to do this work. It is still possible to
use the dt_strtab_write() functionality with a more fancy copy
string function if needed.
Orabug: 31220525
Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees at oracle.com>
Reviewed-by: Eugene Loh <eugene.loh at oracle.com>
---
libdtrace/dt_as.c | 10 ++--------
libdtrace/dt_dlibs.c | 14 ++------------
libdtrace/dt_strtab.c | 13 ++++++++++++-
libdtrace/dt_strtab.h | 3 ++-
4 files changed, 18 insertions(+), 22 deletions(-)
diff --git a/libdtrace/dt_as.c b/libdtrace/dt_as.c
index 096e660a..2ddbc886 100644
--- a/libdtrace/dt_as.c
+++ b/libdtrace/dt_as.c
@@ -113,13 +113,6 @@ dt_copyvar(dt_idhash_t *dhp, dt_ident_t *idp, dtrace_hdl_t *dtp)
return (0);
}
-static ssize_t
-dt_copystr(const char *s, size_t n, size_t off, dtrace_hdl_t *dtp)
-{
- memcpy(dtp->dt_strtab + off, s, n);
- return n;
-}
-
#ifdef FIXME
/*
* Rewrite the xlate/xlarg instruction at dtdo_buf[i] so that the instruction's
@@ -549,7 +542,8 @@ fail:
longjmp(pcb->pcb_jmpbuf, EDT_NOMEM);
dt_strtab_write(dtp->dt_ccstab,
- (dt_strtab_write_f *)dt_copystr, dtp);
+ (dt_strtab_write_f *)dt_strtab_copystr,
+ dtp->dt_strtab);
dtp->dt_strlen = (uint32_t)n;
dp->dtdo_strtab = dtp->dt_strtab;
diff --git a/libdtrace/dt_dlibs.c b/libdtrace/dt_dlibs.c
index 1fd0f0a8..c3b2b902 100644
--- a/libdtrace/dt_dlibs.c
+++ b/libdtrace/dt_dlibs.c
@@ -214,23 +214,13 @@ relcmp(const void *a, const void *b)
: -1;
}
-/*
- * Copy strings from the compile-time string table into the final strtab.
- */
-static ssize_t
-copy_stab_str(const char *s, size_t n, size_t off, char *buf)
-{
- memcpy(buf + off, s, n);
- return n;
-}
-
/*
* Process the symbols in the ELF object, resolving BPF maps and functions
* against the known identifiers If an unknown identifier is encountered, we
* add it to the BPF identifier hash.
*
* For functions, we fix up the symbol size (to work around an issue with the
- * gcc BPF compiler not emitting symbol sizes), and then associated any listed
+ * gcc BPF compiler not emitting symbol sizes), and then associate any listed
* relocations with each function.
*/
static dt_bpf_func_t **
@@ -564,7 +554,7 @@ done:
goto out;
}
- dt_strtab_write(stab, (dt_strtab_write_f *)copy_stab_str,
+ dt_strtab_write(stab, (dt_strtab_write_f *)dt_strtab_copystr,
dp->dtdo_strtab);
dt_strtab_destroy(stab);
}
diff --git a/libdtrace/dt_strtab.c b/libdtrace/dt_strtab.c
index 49bbc82b..d312f4f5 100644
--- a/libdtrace/dt_strtab.c
+++ b/libdtrace/dt_strtab.c
@@ -1,6 +1,6 @@
/*
* Oracle Linux DTrace.
- * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2020, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
@@ -250,6 +250,17 @@ dt_strtab_size(const dt_strtab_t *sp)
return (sp->str_size);
}
+/*
+ * Copy strings from the compile-time string table into a DIFO-dtyle string
+ * table storage memory block.
+ */
+ssize_t
+dt_strtab_copystr(const char *s, size_t n, size_t off, char *buf)
+{
+ memcpy(buf + off, s, n);
+ return n;
+}
+
ssize_t
dt_strtab_write(const dt_strtab_t *sp, dt_strtab_write_f *func, void *private)
{
diff --git a/libdtrace/dt_strtab.h b/libdtrace/dt_strtab.h
index 54a84fbf..8f631fac 100644
--- a/libdtrace/dt_strtab.h
+++ b/libdtrace/dt_strtab.h
@@ -1,6 +1,6 @@
/*
* Oracle Linux DTrace.
- * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2020, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
@@ -41,6 +41,7 @@ extern void dt_strtab_destroy(dt_strtab_t *);
extern ssize_t dt_strtab_index(dt_strtab_t *, const char *);
extern ssize_t dt_strtab_insert(dt_strtab_t *, const char *);
extern size_t dt_strtab_size(const dt_strtab_t *);
+extern ssize_t dt_strtab_copystr(const char *, size_t, size_t, char *);
extern ssize_t dt_strtab_write(const dt_strtab_t *,
dt_strtab_write_f *, void *);
extern ulong_t dt_strtab_hash(const char *, size_t *);
--
2.26.0
More information about the DTrace-devel
mailing list