Path: blob/main/cddl/contrib/opensolaris/lib/libdtrace/riscv/dt_isadep.c
39563 views
/*1* CDDL HEADER START2*3* The contents of this file are subject to the terms of the4* Common Development and Distribution License, Version 1.0 only5* (the "License"). You may not use this file except in compliance6* with the License.7*8* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE9* or http://www.opensolaris.org/os/licensing.10* See the License for the specific language governing permissions11* and limitations under the License.12*13* When distributing Covered Code, include this CDDL HEADER in each14* file and include the License file at usr/src/OPENSOLARIS.LICENSE.15* If applicable, add the following below this CDDL HEADER, with the16* fields enclosed by brackets "[]" replaced with your own identifying17* information: Portions Copyright [yyyy] [name of copyright owner]18*19* CDDL HEADER END20*/21/*22* Copyright 2005 Sun Microsystems, Inc. All rights reserved.23* Use is subject to license terms.24* Copyright 2014 Howard Su25* Copyright 2015 George V. Neville-Neil26* Copyright 2015 Ruslan Bukin <[email protected]>27*/2829#pragma ident "%Z%%M% %I% %E% SMI"3031#include <stdlib.h>32#include <assert.h>33#include <errno.h>34#include <string.h>35#include <libgen.h>3637#include <dt_impl.h>38#include <dt_pid.h>3940#if !defined(sun)41#include <libproc_compat.h>42#endif4344/*ARGSUSED*/45int46dt_pid_create_entry_probe(struct ps_prochandle *P, dtrace_hdl_t *dtp,47fasttrap_probe_spec_t *ftp, const GElf_Sym *symp)48{4950ftp->ftps_type = DTFTP_ENTRY;51ftp->ftps_pc = (uintptr_t)symp->st_value;52ftp->ftps_size = (size_t)symp->st_size;53ftp->ftps_noffs = 1;54ftp->ftps_offs[0] = 0;5556if (ioctl(dtp->dt_ftfd, FASTTRAPIOC_MAKEPROBE, ftp) != 0) {57dt_dprintf("fasttrap probe creation ioctl failed: %s\n",58strerror(errno));59return (dt_set_errno(dtp, errno));60}6162return (1);63}6465int66dt_pid_create_return_probe(struct ps_prochandle *P, dtrace_hdl_t *dtp,67fasttrap_probe_spec_t *ftp, const GElf_Sym *symp, uint64_t *stret)68{6970dt_dprintf("%s: unimplemented\n", __func__);7172return (DT_PROC_ERR);73}7475/*ARGSUSED*/76int77dt_pid_create_offset_probe(struct ps_prochandle *P, dtrace_hdl_t *dtp,78fasttrap_probe_spec_t *ftp, const GElf_Sym *symp, ulong_t off)79{8081if (!ALIGNED_POINTER(off, 4))82return (DT_PROC_ALIGN);8384ftp->ftps_type = DTFTP_OFFSETS;85ftp->ftps_pc = (uintptr_t)symp->st_value;86ftp->ftps_size = (size_t)symp->st_size;87ftp->ftps_noffs = 1;88ftp->ftps_offs[0] = off;8990if (ioctl(dtp->dt_ftfd, FASTTRAPIOC_MAKEPROBE, ftp) != 0) {91dt_dprintf("fasttrap probe creation ioctl failed: %s\n",92strerror(errno));93return (dt_set_errno(dtp, errno));94}9596return (1);97}9899/*ARGSUSED*/100int101dt_pid_create_glob_offset_probes(struct ps_prochandle *P, dtrace_hdl_t *dtp,102fasttrap_probe_spec_t *ftp, const GElf_Sym *symp, const char *pattern)103{104ulong_t i;105106ftp->ftps_type = DTFTP_OFFSETS;107ftp->ftps_pc = (uintptr_t)symp->st_value;108ftp->ftps_size = (size_t)symp->st_size;109ftp->ftps_noffs = 0;110111/*112* If we're matching against everything, just iterate through each113* instruction in the function, otherwise look for matching offset114* names by constructing the string and comparing it against the115* pattern.116*/117if (strcmp("*", pattern) == 0) {118for (i = 0; i < symp->st_size; i += 4) {119ftp->ftps_offs[ftp->ftps_noffs++] = i;120}121} else {122char name[sizeof (i) * 2 + 1];123124for (i = 0; i < symp->st_size; i += 4) {125(void) sprintf(name, "%lx", i);126if (gmatch(name, pattern))127ftp->ftps_offs[ftp->ftps_noffs++] = i;128}129}130131if (ioctl(dtp->dt_ftfd, FASTTRAPIOC_MAKEPROBE, ftp) != 0) {132dt_dprintf("fasttrap probe creation ioctl failed: %s\n",133strerror(errno));134return (dt_set_errno(dtp, errno));135}136137return (ftp->ftps_noffs);138}139140141