summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan Cantrill <bryan@joyent.com>2014-12-19 00:45:42 +0000
committerBryan Cantrill <bryan@joyent.com>2014-12-19 00:45:42 +0000
commit204b4d7418eff4f0de4262f4d5ef4edfb6b19b3d (patch)
tree1cdabd1fe21028ee7d8f05af033633f15500ffa1
parentcdeef4760f2dd607314b636836a436b0fe68b884 (diff)
downloadillumos-joyent-204b4d7418eff4f0de4262f4d5ef4edfb6b19b3d.tar.gz
OS-3643 lx brand: add USDT provider to lx_brand.so.1
OS-3644 lx brand: ptrace_init() never called
-rw-r--r--usr/src/Makefile.master.643
-rw-r--r--usr/src/lib/Makefile.lib21
-rw-r--r--usr/src/lib/Makefile.targ5
-rw-r--r--usr/src/lib/Makefile.usdt28
-rw-r--r--usr/src/lib/brand/lx/lx_brand/Makefile.com5
-rw-r--r--usr/src/lib/brand/lx/lx_brand/common/debug.c27
-rw-r--r--usr/src/lib/brand/lx/lx_brand/common/lx_brand.c6
-rw-r--r--usr/src/lib/brand/lx/lx_brand/common/lx_provider.d27
-rw-r--r--usr/src/lib/brand/lx/lx_brand/common/mem.c2
-rw-r--r--usr/src/lib/brand/lx/lx_brand/common/ptrace.c3
-rw-r--r--usr/src/lib/brand/lx/lx_brand/common/signal.c4
-rw-r--r--usr/src/lib/brand/lx/lx_brand/common/stat.c5
-rw-r--r--usr/src/lib/brand/lx/lx_brand/sys/lx_debug.h10
-rw-r--r--usr/src/lib/brand/lx/lx_brand/sys/lx_misc.h1
14 files changed, 132 insertions, 15 deletions
diff --git a/usr/src/Makefile.master.64 b/usr/src/Makefile.master.64
index 79ed039f66..c512cfc004 100644
--- a/usr/src/Makefile.master.64
+++ b/usr/src/Makefile.master.64
@@ -21,6 +21,7 @@
#
# Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
# Copyright 2014 Garrett D'Amore <garrett@damore.org>
+# Copyright (c) 2014 Joyent, Inc. All rights reserved.
#
# rebind basic build macros to 64-bit versions
@@ -68,7 +69,7 @@ REAL_CC= $(CW_CC_CMD:sh)
REAL_CCC= $(CW_CCC_CMD:sh)
BUILD.SO= $(CC) $(CFLAGS) -o $@ $(GSHARED) $(DYNFLAGS) \
- $(PICS) $(EXTPICS) -L $(ROOTLIBDIR64) $(LDLIBS)
+ $(PICS) $(EXTPICS) $(USDT_PICS) -L $(ROOTLIBDIR64) $(LDLIBS)
#
# ld(1) requires the -64 option to create a 64-bit filter solely from a mapfile
diff --git a/usr/src/lib/Makefile.lib b/usr/src/lib/Makefile.lib
index eeb89960f4..eb5ccb1db6 100644
--- a/usr/src/lib/Makefile.lib
+++ b/usr/src/lib/Makefile.lib
@@ -19,6 +19,7 @@
# CDDL HEADER END
#
# Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2014, Joyent, Inc.
#
#
# Definitions common to libraries.
@@ -134,6 +135,23 @@ SONAME= $(DYNLIB)
# combining relocations into one relocation table reduces startup costs.
# All options are tunable to allow overload/omission from lower makefiles.
+#
+# DTrace related rules
+#
+# These allow for multiple USDT providers to be specified by a library.
+# If a library needs to break up the set of objects that are passed to
+# the dtrace -G invocation, then they can place the following in heir
+# Makefile.com:
+#
+# pics/<provider>.o := USDT_G_PICS = <files>
+#
+# <provider> should be replaced with the basename of one of the USDT
+# providers specified in USDT_PROVIDERS in their Makefile.com.
+#
+USDT_HEADERS= $(USDT_PROVIDERS:%.d=%_impl.h)
+USDT_PICS= $(USDT_PROVIDERS:%.d=pics/%.o)
+USDT_G_PICS= $(PICS)
+
HSONAME= -h$(SONAME)
DYNFLAGS= $(HSONAME) $(ZTEXT) $(ZDEFS) $(BDIRECT) \
@@ -155,7 +173,8 @@ SRCS= $(OBJECTS:%.o=$(SRCDIR)/%.c)
# default build of an archive and a shared object,
# overridden locally when extra processing is needed
BUILD.AR= $(AR) $(ARFLAGS) $@ $(AROBJS)
-BUILD.SO= $(CC) -o $@ $(GSHARED) $(DYNFLAGS) $(PICS) $(EXTPICS) $(LDLIBS)
+BUILD.SO= $(CC) -o $@ $(GSHARED) $(DYNFLAGS) $(PICS) $(EXTPICS) \
+ $(USDT_PICS) $(LDLIBS)
BUILDCCC.SO= $(CCC) -o $@ $(GSHARED) $(DYNFLAGS) $(PICS) $(EXTPICS) $(LDLIBS)
# default dynamic library symlink
diff --git a/usr/src/lib/Makefile.targ b/usr/src/lib/Makefile.targ
index 61cb45969d..2798192343 100644
--- a/usr/src/lib/Makefile.targ
+++ b/usr/src/lib/Makefile.targ
@@ -20,6 +20,7 @@
#
#
# Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2014, Joyent, Inc.
#
#
@@ -90,7 +91,7 @@ $(LIBRARY): objs .WAIT $$(OBJS)
$(DYNLIB): $$(MAPFILES)
-$(DYNLIB): pics .WAIT $$(PICS) $$(ALTPICS) $$(EXTPICS)
+$(DYNLIB): pics $(USDT_HEADERS) .WAIT $$(PICS) $$(ALTPICS) $$(EXTPICS) .WAIT $(USDT_PICS)
$(BUILD.SO)
$(POST_PROCESS_SO)
@@ -111,5 +112,5 @@ clobber: clean
-$(RM) $(CLOBBERTARGFILES)
clean:
- -$(RM) $(OBJS)
+ -$(RM) $(OBJS) $(USDT_HEADERS) $(USDT_PICS)
-$(RM) $(PICS) $(DUPLICATE_SRC) $(LINTOUT) $(LINTLIB) $(CLEANFILES)
diff --git a/usr/src/lib/Makefile.usdt b/usr/src/lib/Makefile.usdt
new file mode 100644
index 0000000000..17140161ad
--- /dev/null
+++ b/usr/src/lib/Makefile.usdt
@@ -0,0 +1,28 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright (c) 2014 Joyent, Inc. All rights reserved.
+#
+
+#
+# This makefile contains the necessary targets for USDT providers; it should
+# be included after Makefile.targ. (It is in a separate file rather than in
+# Makefile.targ because the dependency on $(USDT_G_PICS) is incompatible with
+# libraries that dynamically define $(OBJECTS).)
+#
+pics/%.o: $(SRCDIR)/%.d $(USDT_G_PICS)
+ $(COMPILE.d) -o $@ -s $< $(USDT_G_PICS)
+ $(POST_PROCESS_O)
+
+%_impl.h: $(SRCDIR)/%.d
+ $(DTRACE) -h -o $@ -s $<
+
diff --git a/usr/src/lib/brand/lx/lx_brand/Makefile.com b/usr/src/lib/brand/lx/lx_brand/Makefile.com
index 2c9021ac1d..3e6f122973 100644
--- a/usr/src/lib/brand/lx/lx_brand/Makefile.com
+++ b/usr/src/lib/brand/lx/lx_brand/Makefile.com
@@ -67,6 +67,8 @@ CMNOBJS = lx_signum.o
ASOBJS = lx_handler.o lx_runexe.o lx_crt.o
OBJECTS = $(CMNOBJS) $(COBJS) $(ASOBJS)
+USDT_PROVIDERS = lx_provider.d
+
include ../../Makefile.lx
include ../../../../Makefile.lib
@@ -82,7 +84,7 @@ LDLIBS += -lc -lsocket -lmapmalloc -lproc -lrtld_db
DYNFLAGS += $(DYNFLAGS_$(CLASS))
DYNFLAGS += $(BLOCAL) $(ZNOVERSION) -Wl,-e_start -M../common/mapfile
CFLAGS += $(CCVERBOSE)
-CPPFLAGS += -D_REENTRANT -I../ -I$(UTSBASE)/common/brand/lx -I$(LX_CMN)
+CPPFLAGS += -D_REENTRANT -I. -I../ -I$(UTSBASE)/common/brand/lx -I$(LX_CMN)
ASFLAGS = -P $(ASFLAGS_$(CURTYPE)) -D_ASM -I../ \
-I$(UTSBASE)/common/brand/lx
@@ -93,6 +95,7 @@ all: $(LIBS)
lint: lintcheck
include ../../../../Makefile.targ
+include ../../../../Makefile.usdt
pics/%.o: $(ISASRCDIR)/%.s
$(COMPILE.s) -o $@ $<
diff --git a/usr/src/lib/brand/lx/lx_brand/common/debug.c b/usr/src/lib/brand/lx/lx_brand/common/debug.c
index 77131c70d3..7e58a0f941 100644
--- a/usr/src/lib/brand/lx/lx_brand/common/debug.c
+++ b/usr/src/lib/brand/lx/lx_brand/common/debug.c
@@ -46,6 +46,8 @@
static char *lx_debug_path = NULL; /* debug output file path */
static char lx_debug_path_buf[MAXPATHLEN];
+int lx_dtrace_lazyload = 1; /* patchable; see below */
+
void
lx_debug_enable(void)
{
@@ -57,6 +59,24 @@ lx_debug_enable(void)
void
lx_debug_init(void)
{
+ /*
+ * Our DTrace USDT provider is loaded in our .init section, which is
+ * not run by our e_entry ELF entry point (_start, which calls into
+ * lx_init()). We exploit this to only actually load our USDT provider
+ * if LX_DTRACE is set, assuring that we don't compromise fork()
+ * performance in the (common) case that DTrace of lx_brand.so.1 itself
+ * isn't enabled or desired. (As with all USDT providers, it can always
+ * be loaded by explicitly specifying the full provider name). Note
+ * that we also allow this behavior to be set via a manual override,
+ * lx_dtrace_lazyload -- allowing for USDT probes to be automatically
+ * provided in situations where setting an environment variable is
+ * tedious or otherwise impossible.
+ */
+ if (getenv("LX_DTRACE") != NULL || !lx_dtrace_lazyload) {
+ extern void _init(void);
+ _init();
+ }
+
if (getenv("LX_DEBUG") == NULL)
return;
@@ -95,7 +115,7 @@ lx_debug(const char *msg, ...)
int errno_backup;
int size = LX_MSG_MAXLEN + 1;
- if (lx_debug_enabled == 0)
+ if (lx_debug_enabled == 0 && !LX_DEBUG_ENABLED())
return;
/*
@@ -130,6 +150,11 @@ lx_debug(const char *msg, ...)
return;
}
+ LX_DEBUG(buf);
+
+ if (!lx_debug_enabled)
+ return;
+
/*
* Open the debugging output file. note that we don't protect
* ourselves against exec or fork1 here. if an mt process were
diff --git a/usr/src/lib/brand/lx/lx_brand/common/lx_brand.c b/usr/src/lib/brand/lx/lx_brand/common/lx_brand.c
index c4071d185d..7700509687 100644
--- a/usr/src/lib/brand/lx/lx_brand/common/lx_brand.c
+++ b/usr/src/lib/brand/lx/lx_brand/common/lx_brand.c
@@ -292,7 +292,7 @@ i_lx_msg(int fd, char *msg, va_list ap)
return;
/* if debugging is enabled, send this message to debug output */
- if (lx_debug_enabled != 0)
+ if (LX_DEBUG_ISENABLED)
lx_debug(buf);
if (fd == 2) {
@@ -573,7 +573,7 @@ lx_emulate(lx_regs_t *rp)
goto out;
}
- if (lx_debug_enabled != 0) {
+ if (LX_DEBUG_ISENABLED) {
const char *fmt = NULL;
switch (s->sy_narg) {
@@ -893,6 +893,8 @@ lx_init(int argc, char *argv[], char *envp[])
if (lx_statfs_init() != 0)
lx_err_fatal("failed to setup the statfs translator");
+ lx_ptrace_init();
+
#if defined(_LP64)
vdso_hdr = map_vdso();
#endif
diff --git a/usr/src/lib/brand/lx/lx_brand/common/lx_provider.d b/usr/src/lib/brand/lx/lx_brand/common/lx_provider.d
new file mode 100644
index 0000000000..2a07c00c7a
--- /dev/null
+++ b/usr/src/lib/brand/lx/lx_brand/common/lx_provider.d
@@ -0,0 +1,27 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright (c) 2014 Joyent, Inc. All rights reserved.
+ */
+
+provider lx {
+ probe debug(char *buf);
+ probe sigdeliver(int sig, void *lx_sigaction, void *lx_sigstack,
+ void *lx_ucontext);
+ probe sigreturn(void *lx_ucontext, void *ucontext, uintptr_t sp);
+};
+
+#pragma D attributes Evolving/Evolving/ISA provider lx provider
+#pragma D attributes Private/Private/Unknown provider lx module
+#pragma D attributes Private/Private/Unknown provider lx function
+#pragma D attributes Private/Private/ISA provider lx name
+#pragma D attributes Private/Private/ISA provider lx args
diff --git a/usr/src/lib/brand/lx/lx_brand/common/mem.c b/usr/src/lib/brand/lx/lx_brand/common/mem.c
index cebe2ec5bb..416596ae88 100644
--- a/usr/src/lib/brand/lx/lx_brand/common/mem.c
+++ b/usr/src/lib/brand/lx/lx_brand/common/mem.c
@@ -93,7 +93,7 @@ mmap_common(uintptr_t p1, uintptr_t p2, uintptr_t p3, uintptr_t p4,
off64_t off = p6;
void *ret;
- if (lx_debug_enabled != 0) {
+ if (LX_DEBUG_ISENABLED) {
char *path, path_buf[MAXPATHLEN];
path = lx_fd_to_path(fd, path_buf, sizeof (path_buf));
diff --git a/usr/src/lib/brand/lx/lx_brand/common/ptrace.c b/usr/src/lib/brand/lx/lx_brand/common/ptrace.c
index e43a38973a..06d5a583fa 100644
--- a/usr/src/lib/brand/lx/lx_brand/common/ptrace.c
+++ b/usr/src/lib/brand/lx/lx_brand/common/ptrace.c
@@ -259,9 +259,8 @@ extern void *_START_;
static sigset_t blockable_sigs;
-#pragma init(ptrace_init)
void
-ptrace_init(void)
+lx_ptrace_init(void)
{
(void) sigfillset(&blockable_sigs);
(void) sigdelset(&blockable_sigs, SIGKILL);
diff --git a/usr/src/lib/brand/lx/lx_brand/common/signal.c b/usr/src/lib/brand/lx/lx_brand/common/signal.c
index 1ba48cc0ea..8c4b6926f3 100644
--- a/usr/src/lib/brand/lx/lx_brand/common/signal.c
+++ b/usr/src/lib/brand/lx/lx_brand/common/signal.c
@@ -41,6 +41,7 @@
#include <sys/lx_syscall.h>
#include <sys/lx_thread.h>
#include <sys/syscall.h>
+#include <lx_provider_impl.h>
#include <assert.h>
#include <errno.h>
#include <poll.h>
@@ -1096,6 +1097,7 @@ lx_rt_sigreturn(void)
ucp = (ucontext_t *)(*(ssize_t *)(sp + 24));
lx_ucp = &lx_ssp->uc;
+ LX_SIGRETURN(lx_ucp, ucp, sp);
/*
* General register layout is completely different.
@@ -1448,6 +1450,8 @@ lx_build_signal_frame(int lx_sig, siginfo_t *sip, void *p, void *sp)
sizeof (lx_ssp->trampoline));
#endif
+ LX_SIGDELIVER(lx_sig, lxsap, lx_ssp, lx_ucp);
+
#if defined(_LP64)
/*
* For the 64-bit code this must be the last syscall we do in the
diff --git a/usr/src/lib/brand/lx/lx_brand/common/stat.c b/usr/src/lib/brand/lx/lx_brand/common/stat.c
index b1c9b18722..7c2b5008f6 100644
--- a/usr/src/lib/brand/lx/lx_brand/common/stat.c
+++ b/usr/src/lib/brand/lx/lx_brand/common/stat.c
@@ -56,6 +56,7 @@
#include <sys/lx_audio.h>
#include <sys/lx_fcntl.h>
#include <sys/lx_syscall.h>
+#include <sys/lx_debug.h>
#include <sys/modctl.h>
/* define _KERNEL to get the devt manipulation macros */
@@ -242,7 +243,7 @@ s2l_dev_report(dev_t dev, lx_dev_t jdev)
minor_t min;
int lx_maj, lx_min;
- if (lx_debug_enabled == 0)
+ if (!LX_DEBUG_ISENABLED)
return;
maj = getmajor(dev);
@@ -410,7 +411,7 @@ lx_fstat(uintptr_t p1, uintptr_t p2)
struct stat sbuf;
char *path, path_buf[MAXPATHLEN];
- if (lx_debug_enabled != 0) {
+ if (LX_DEBUG_ISENABLED) {
path = lx_fd_to_path(fd, path_buf, sizeof (path_buf));
if (path == NULL)
path = "?";
diff --git a/usr/src/lib/brand/lx/lx_brand/sys/lx_debug.h b/usr/src/lib/brand/lx/lx_brand/sys/lx_debug.h
index 80fb579665..57692cfcd1 100644
--- a/usr/src/lib/brand/lx/lx_brand/sys/lx_debug.h
+++ b/usr/src/lib/brand/lx/lx_brand/sys/lx_debug.h
@@ -23,10 +23,14 @@
* Use is subject to license terms.
*/
+/*
+ * Copyright (c) 2014 Joyent, Inc. All rights reserved.
+ */
+
#ifndef _LX_DEBUG_H
#define _LX_DEBUG_H
-#pragma ident "%Z%%M% %I% %E% SMI"
+#include <lx_provider_impl.h>
#ifdef __cplusplus
extern "C" {
@@ -38,9 +42,11 @@ extern void lx_debug_init(void);
/* printf() style debug message functionality */
extern void lx_debug(const char *, ...);
-/* set non-zero if the debugging subsystem is enabled */
extern int lx_debug_enabled;
+#define LX_DEBUG_ISENABLED \
+ (lx_debug_enabled || LX_DEBUG_ENABLED())
+
#ifdef __cplusplus
}
#endif
diff --git a/usr/src/lib/brand/lx/lx_brand/sys/lx_misc.h b/usr/src/lib/brand/lx/lx_brand/sys/lx_misc.h
index 220ae0b48f..76c75e919e 100644
--- a/usr/src/lib/brand/lx/lx_brand/sys/lx_misc.h
+++ b/usr/src/lib/brand/lx/lx_brand/sys/lx_misc.h
@@ -169,6 +169,7 @@ extern char *lx_fd_to_path(int fd, char *buf, int buf_size);
extern int lx_lpid_to_spair(pid_t, pid_t *, lwpid_t *);
extern int lx_lpid_to_spid(pid_t, pid_t *);
+extern void lx_ptrace_init();
extern int lx_ptrace_wait(siginfo_t *);
extern void lx_ptrace_fork(void);
extern void lx_ptrace_stop_if_option(int);