edb348833aaacfa1176e502ad38875fd0b2717abAdam H. Leventhal * CDDL HEADER START
edb348833aaacfa1176e502ad38875fd0b2717abAdam H. Leventhal * This file and its contents are supplied under the terms of the
edb348833aaacfa1176e502ad38875fd0b2717abAdam H. Leventhal * Common Development and Distribution License ("CDDL"), version 1.0.
edb348833aaacfa1176e502ad38875fd0b2717abAdam H. Leventhal * You may only use this file in accordance with the terms of version
edb348833aaacfa1176e502ad38875fd0b2717abAdam H. Leventhal * 1.0 of the CDDL.
edb348833aaacfa1176e502ad38875fd0b2717abAdam H. Leventhal * A full copy of the text of the CDDL should have accompanied this
edb348833aaacfa1176e502ad38875fd0b2717abAdam H. Leventhal * source. A copy of the CDDL is also available via the Internet at
edb348833aaacfa1176e502ad38875fd0b2717abAdam H. Leventhal * CDDL HEADER END
edb348833aaacfa1176e502ad38875fd0b2717abAdam H. Leventhal * Copyright (c) 2012 by Delphix. All rights reserved.
edb348833aaacfa1176e502ad38875fd0b2717abAdam H. Leventhal * This file implements an audit library that can be used to force the loading
edb348833aaacfa1176e502ad38875fd0b2717abAdam H. Leventhal * of helper providers. The default disposition for a helper provider -- USDT
edb348833aaacfa1176e502ad38875fd0b2717abAdam H. Leventhal * and ustack helpers -- is to load itself from it's containing object's .init
edb348833aaacfa1176e502ad38875fd0b2717abAdam H. Leventhal * section. In cases where startup time is deemed critical, USDT authors can
edb348833aaacfa1176e502ad38875fd0b2717abAdam H. Leventhal * use the -xlazyload option to dtrace(1M) to disable automatic loading (it's
edb348833aaacfa1176e502ad38875fd0b2717abAdam H. Leventhal * difficult to make the case for the utility of this feature for anything
edb348833aaacfa1176e502ad38875fd0b2717abAdam H. Leventhal * other than libc which, indeed, was the sole motivation). If a binary has
edb348833aaacfa1176e502ad38875fd0b2717abAdam H. Leventhal * been compiled with automatic loading disabled, this audit library may be
edb348833aaacfa1176e502ad38875fd0b2717abAdam H. Leventhal * used to force automatic loading:
edb348833aaacfa1176e502ad38875fd0b2717abAdam H. Leventhal * LD_AUDIT_32=/usr/lib/dtrace/libdaudit.so
edb348833aaacfa1176e502ad38875fd0b2717abAdam H. Leventhal * LD_AUDIT_64=/usr/lib/dtrace/64/libdaudit.so
edb348833aaacfa1176e502ad38875fd0b2717abAdam H. Leventhal * Record objects into our linked list as they're loaded.
edb348833aaacfa1176e502ad38875fd0b2717abAdam H. Leventhalla_objopen(Link_map *lmp, Lmid_t lmid, uintptr_t *cookie)
edb348833aaacfa1176e502ad38875fd0b2717abAdam H. Leventhal * If we can't allocate the next node in our list, we'll try to emit a
edb348833aaacfa1176e502ad38875fd0b2717abAdam H. Leventhal * message, but it's possible that might fail as well.
edb348833aaacfa1176e502ad38875fd0b2717abAdam H. Leventhal if ((node = malloc(sizeof (obj_list_t))) == NULL) {
edb348833aaacfa1176e502ad38875fd0b2717abAdam H. Leventhal dprintf(0, "libdaudit: failed to allocate");
edb348833aaacfa1176e502ad38875fd0b2717abAdam H. Leventhal * Once the link maps have reached a consistent state, process the list of
edb348833aaacfa1176e502ad38875fd0b2717abAdam H. Leventhal * objects that were loaded. We need to use libproc to search for the
edb348833aaacfa1176e502ad38875fd0b2717abAdam H. Leventhal * ___SUNW_dof symbol rather than dlsym(3C) since the symbol is not in the
edb348833aaacfa1176e502ad38875fd0b2717abAdam H. Leventhal * dynamic (run-time) symbol table (though it is, of course, in the symtab).
edb348833aaacfa1176e502ad38875fd0b2717abAdam H. Leventhal * Once we find it, we ioctl(2) it to the kernel just as we would have from
edb348833aaacfa1176e502ad38875fd0b2717abAdam H. Leventhal * the .init section if automatic loading were enabled.
edb348833aaacfa1176e502ad38875fd0b2717abAdam H. Leventhalla_activity(uintptr_t *cookie, uint_t flags)
edb348833aaacfa1176e502ad38875fd0b2717abAdam H. Leventhal ret = Plookup_by_name(P, name, "___SUNW_dof", &sym);
edb348833aaacfa1176e502ad38875fd0b2717abAdam H. Leventhal dtrace_link_dof((void *)(uintptr_t)sym.st_value,