From nobody Tue Aug 1 17:29:09 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4RFhtS4J56z4pfBB; Tue, 1 Aug 2023 17:29:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RFhtF4jdMz4RlD; Tue, 1 Aug 2023 17:29:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1690910950; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=W3V//YNBWGuPYd5fdN3Sl1HTRuTdkH3C7WMYMV2E9bs=; b=ZvG5ISop6yMqs3/bsO0y5sO43EnI8B24FGOdjbhWT4yRkeX0gCEmAnHXGdotMeCI7vFLmB MN5enPGwd0rrCXcAfBsL+qhUKDL5mzibtHHdQ+1Mimf5vaZgiVakoklkLC6Lmw9+pmGyJk 3gZ9rln7HU8o5pvw/AHXCL2l5UI/wm5qE45kAQI/8L/Kesd7cn3tfBeTkz6hcA5v/nffoe in4U4qW0+WeehSCK2aOSwLupovcHkWRReBAcxhKdb5NNvQNgAlacTP0RXRWZ5odKkK0bnS CY9zMzxDFIH7IUUJYa1a06NcPDYkwaeYpES+n8GY1pgPsZXaCT3v3NFLhL8EWg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1690910950; a=rsa-sha256; cv=none; b=k/sZyYRJ3sKlIDKmvdLWEbbbPPrTzSB2fw+79QQyEhsm2mYydrIuq3oaFVfE0FhpkgKzna n4ZFWHEo5gZyuruYiN8RiwRalTkHvCZzXB97v2ffxHAxctR6fdzAA+Xzw4jeNSbEEaY9nv Pv7gfb2HZKmmu4ylMy+o6XjsZx/64JpYgf+OloJCoBR6q2BgLLb5o1D9HdruRtG0ZIg/nF OYSJG8IYLPW/hBY+8jbirb34tFOrNBhN4FQ2HKUd8kHgDDuVR2Zd4ItJWk9dtsgynYIAx1 hreVNkJCtETRBGgKamKArJwIY1JJ9MYfILe2A0obIZvniU8iahJnHIkRa6keRg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1690910950; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=W3V//YNBWGuPYd5fdN3Sl1HTRuTdkH3C7WMYMV2E9bs=; b=lxqEpj0DKUIspqGGGzYz8OFNG6SiExu3zOVSSvFWo2v/v2Ra1jxlmDiYSIvPC/niLi9xdK QWFq3LorN+oj1QeWQbB67GjEgKNJU4EpoLcnApxq4b/n+kG70kMQMmUgxXgwSlSOYXtH0E 2ogs1lEU7OIOsBbGowYuvrDpITrsYxA6J7D35ENJbFAcIa6KdPUFa+2OsxVhtX3OxlmnTW RBUeB7aJwN0PN+Q5W7sqx8sXhHWeEXvy6PlyJCqJGO1CR/PFQU28crTJaHHdftos55AGmn Tq4BPGQQ5W//abPWsj4GI1eBFSnS8ORwOdkRz+8zVakeBuA3+w3aw8t1q9qQag== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4RFhtF2VD8zm9D; Tue, 1 Aug 2023 17:29:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 371HT9JI046892; Tue, 1 Aug 2023 17:29:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 371HT9vL046891; Tue, 1 Aug 2023 17:29:09 GMT (envelope-from git) Date: Tue, 1 Aug 2023 17:29:09 GMT Message-Id: <202308011729.371HT9vL046891@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Eric van Gyzen Subject: git: 837f6ecd88ee - main - dtrace: remove illumos code from dt_proc.c List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: vangyzen X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 837f6ecd88ee6c4285c088f4f0ddbf637889a130 Auto-Submitted: auto-generated The branch main has been updated by vangyzen: URL: https://cgit.FreeBSD.org/src/commit/?id=837f6ecd88ee6c4285c088f4f0ddbf637889a130 commit 837f6ecd88ee6c4285c088f4f0ddbf637889a130 Author: Eric van Gyzen AuthorDate: 2023-07-25 16:58:47 +0000 Commit: Eric van Gyzen CommitDate: 2023-08-01 17:28:50 +0000 dtrace: remove illumos code from dt_proc.c The illumos #ifdef's in this file make it harder to read and maintain. There is little change upstream, and increasing changes for FreeBSD. Remove the illumos code with `unifdef`. The only manual changes here are the #includes and #defines at the top, and removing blank lines. Reviewed by: markj MFC after: 1 week Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D41173 --- .../opensolaris/lib/libdtrace/common/dt_proc.c | 150 +-------------------- 1 file changed, 2 insertions(+), 148 deletions(-) diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_proc.c b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_proc.c index 02b63c0a788a..40b1f4108d1a 100644 --- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_proc.c +++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_proc.c @@ -80,10 +80,8 @@ * up using this condition and will then call the client handler as necessary. */ +#include #include -#ifdef illumos -#include -#endif #include #include #include @@ -93,14 +91,10 @@ #include #include -#ifndef illumos -#include #include -#define SYS_forksys SYS_fork -#endif #define IS_SYS_EXEC(w) (w == SYS_execve) -#define IS_SYS_FORK(w) (w == SYS_vfork || w == SYS_forksys) +#define IS_SYS_FORK(w) (w == SYS_vfork || w == SYS_fork) static dt_bkpt_t * dt_proc_bpcreate(dt_proc_t *dpr, uintptr_t addr, dt_bkpt_f *func, void *data) @@ -147,38 +141,23 @@ dt_proc_bpdestroy(dt_proc_t *dpr, int delbkpts) static void dt_proc_bpmatch(dtrace_hdl_t *dtp, dt_proc_t *dpr) { -#ifdef illumos - const lwpstatus_t *psp = &Pstatus(dpr->dpr_proc)->pr_lwp; -#else unsigned long pc; -#endif dt_bkpt_t *dbp; assert(DT_MUTEX_HELD(&dpr->dpr_lock)); -#ifndef illumos proc_regget(dpr->dpr_proc, REG_PC, &pc); proc_bkptregadj(&pc); -#endif for (dbp = dt_list_next(&dpr->dpr_bps); dbp != NULL; dbp = dt_list_next(dbp)) { -#ifdef illumos - if (psp->pr_reg[R_PC] == dbp->dbp_addr) - break; -#else if (pc == dbp->dbp_addr) break; -#endif } if (dbp == NULL) { dt_dprintf("pid %d: spurious breakpoint wakeup for %lx\n", -#ifdef illumos - (int)dpr->dpr_pid, (ulong_t)psp->pr_reg[R_PC]); -#else (int)dpr->dpr_pid, pc); -#endif return; } @@ -346,12 +325,8 @@ dt_proc_rdwatch(dt_proc_t *dpr, rd_event_e event, const char *evname) } (void) dt_proc_bpcreate(dpr, rdn.u.bptaddr, -#ifdef illumos - (dt_bkpt_f *)dt_proc_rdevent, (void *)evname); -#else /* XXX ugly */ (dt_bkpt_f *)dt_proc_rdevent, __DECONST(void *, evname)); -#endif } /* @@ -361,34 +336,18 @@ dt_proc_rdwatch(dt_proc_t *dpr, rd_event_e event, const char *evname) static void dt_proc_attach(dt_proc_t *dpr, int exec) { -#ifdef illumos - const pstatus_t *psp = Pstatus(dpr->dpr_proc); -#endif rd_err_e err; GElf_Sym sym; assert(DT_MUTEX_HELD(&dpr->dpr_lock)); if (exec) { -#ifdef illumos - if (psp->pr_lwp.pr_errno != 0) - return; /* exec failed: nothing needs to be done */ -#endif dt_proc_bpdestroy(dpr, B_FALSE); -#ifdef illumos - Preset_maps(dpr->dpr_proc); -#endif } if ((dpr->dpr_rtld = Prd_agent(dpr->dpr_proc)) != NULL && (err = rd_event_enable(dpr->dpr_rtld, B_TRUE)) == RD_OK) { -#ifdef illumos - dt_proc_rdwatch(dpr, RD_PREINIT, "RD_PREINIT"); -#endif dt_proc_rdwatch(dpr, RD_POSTINIT, "RD_POSTINIT"); -#ifdef illumos - dt_proc_rdwatch(dpr, RD_DLACTIVITY, "RD_DLACTIVITY"); -#endif } else { dt_dprintf("pid %d: failed to enable rtld events: %s\n", (int)dpr->dpr_pid, dpr->dpr_rtld ? rd_errstr(err) : @@ -511,12 +470,6 @@ dt_proc_control(void *arg) dt_proc_hash_t *dph = dtp->dt_procs; struct ps_prochandle *P = dpr->dpr_proc; int pid = dpr->dpr_pid; - -#ifdef illumos - int pfd = Pctlfd(P); - - const long wstop = PCWSTOP; -#endif int notify = B_FALSE; /* @@ -534,44 +487,13 @@ dt_proc_control(void *arg) */ (void) pthread_mutex_lock(&dpr->dpr_lock); -#ifdef illumos - (void) Punsetflags(P, PR_ASYNC); /* require synchronous mode */ - (void) Psetflags(P, PR_BPTADJ); /* always adjust eip on x86 */ - (void) Punsetflags(P, PR_FORK); /* do not inherit on fork */ - - (void) Pfault(P, FLTBPT, B_TRUE); /* always trace breakpoints */ - (void) Pfault(P, FLTTRACE, B_TRUE); /* always trace single-step */ - - /* - * We must trace exit from exec() system calls so that if the exec is - * successful, we can reset our breakpoints and re-initialize libproc. - */ - (void) Psysexit(P, SYS_execve, B_TRUE); - - /* - * We must trace entry and exit for fork() system calls in order to - * disable our breakpoints temporarily during the fork. We do not set - * the PR_FORK flag, so if fork succeeds the child begins executing and - * does not inherit any other tracing behaviors or a control thread. - */ - (void) Psysentry(P, SYS_vfork, B_TRUE); - (void) Psysexit(P, SYS_vfork, B_TRUE); - (void) Psysentry(P, SYS_forksys, B_TRUE); - (void) Psysexit(P, SYS_forksys, B_TRUE); - - Psync(P); /* enable all /proc changes */ -#endif dt_proc_attach(dpr, B_FALSE); /* enable rtld breakpoints */ /* * If PR_KLC is set, we created the process; otherwise we grabbed it. * Check for an appropriate stop request and wait for dt_proc_continue. */ -#ifdef illumos - if (Pstatus(P)->pr_flags & PR_KLC) -#else if (proc_getflags(P) & PR_KLC) -#endif dt_proc_stop(dpr, DT_PROC_STOP_CREATE); else dt_proc_stop(dpr, DT_PROC_STOP_GRAB); @@ -595,33 +517,16 @@ dt_proc_control(void *arg) while (!dpr->dpr_quit) { const lwpstatus_t *psp; -#ifdef illumos - if (write(pfd, &wstop, sizeof (wstop)) == -1 && errno == EINTR) - continue; /* check dpr_quit and continue waiting */ -#else /* Wait for the process to report status. */ proc_wstatus(P); if (errno == EINTR) continue; /* check dpr_quit and continue waiting */ -#endif (void) pthread_mutex_lock(&dpr->dpr_lock); -#ifdef illumos -pwait_locked: - if (Pstopstatus(P, PCNULL, 0) == -1 && errno == EINTR) { - (void) pthread_mutex_unlock(&dpr->dpr_lock); - continue; /* check dpr_quit and continue waiting */ - } -#endif - switch (Pstate(P)) { case PS_STOP: -#ifdef illumos - psp = &Pstatus(P)->pr_lwp; -#else psp = proc_getlwpstatus(P); -#endif dt_dprintf("pid %d: proc stopped showing %d/%d\n", pid, psp->pr_why, psp->pr_what); @@ -666,11 +571,6 @@ pwait_locked: break; case PS_LOST: -#ifdef illumos - if (Preopen(P) == 0) - goto pwait_locked; -#endif - dt_dprintf("pid %d: proc lost: %s\n", pid, strerror(errno)); @@ -749,11 +649,7 @@ dt_proc_t * dt_proc_lookup(dtrace_hdl_t *dtp, struct ps_prochandle *P, int remove) { dt_proc_hash_t *dph = dtp->dt_procs; -#ifdef illumos - pid_t pid = Pstatus(P)->pr_pid; -#else pid_t pid = proc_getpid(P); -#endif dt_proc_t *dpr, **dpp = &dph->dph_hash[pid & (dph->dph_hashlen - 1)]; for (dpr = *dpp; dpr != NULL; dpr = dpr->dpr_hash) { @@ -787,18 +683,10 @@ dt_proc_destroy(dtrace_hdl_t *dtp, struct ps_prochandle *P) * an external debugger and we were waiting in dt_proc_waitrun(). * Leave the process in this condition using PRELEASE_HANG. */ -#ifdef illumos - if (!(Pstatus(dpr->dpr_proc)->pr_flags & (PR_KLC | PR_RLC))) { -#else if (!(proc_getflags(dpr->dpr_proc) & (PR_KLC | PR_RLC))) { -#endif dt_dprintf("abandoning pid %d\n", (int)dpr->dpr_pid); rflag = PRELEASE_HANG; -#ifdef illumos - } else if (Pstatus(dpr->dpr_proc)->pr_flags & PR_KLC) { -#else } else if (proc_getflags(dpr->dpr_proc) & PR_KLC) { -#endif dt_dprintf("killing pid %d\n", (int)dpr->dpr_pid); rflag = PRELEASE_KILL; /* apply kill-on-last-close */ } else { @@ -823,11 +711,7 @@ dt_proc_destroy(dtrace_hdl_t *dtp, struct ps_prochandle *P) */ (void) pthread_mutex_lock(&dpr->dpr_lock); dpr->dpr_quit = B_TRUE; -#ifdef illumos - (void) _lwp_kill(dpr->dpr_tid, SIGCANCEL); -#else pthread_kill(dpr->dpr_tid, SIGTHR); -#endif /* * If the process is currently idling in dt_proc_stop(), re- @@ -895,11 +779,7 @@ dt_proc_create_thread(dtrace_hdl_t *dtp, dt_proc_t *dpr, uint_t stop) (void) sigfillset(&nset); (void) sigdelset(&nset, SIGABRT); /* unblocked for assert() */ -#ifdef illumos - (void) sigdelset(&nset, SIGCANCEL); /* see dt_proc_destroy() */ -#else (void) sigdelset(&nset, SIGUSR1); /* see dt_proc_destroy() */ -#endif data.dpcd_hdl = dtp; data.dpcd_proc = dpr; @@ -927,14 +807,8 @@ dt_proc_create_thread(dtrace_hdl_t *dtp, dt_proc_t *dpr, uint_t stop) * small amount of useful information to help figure it out. */ if (dpr->dpr_done) { -#ifdef illumos - const psinfo_t *prp = Ppsinfo(dpr->dpr_proc); - int stat = prp ? prp->pr_wstat : 0; - int pid = dpr->dpr_pid; -#else int stat = proc_getwstat(dpr->dpr_proc); int pid = proc_getpid(dpr->dpr_proc); -#endif if (proc_state(dpr->dpr_proc) == PS_LOST) { (void) dt_proc_error(dpr->dpr_hdl, dpr, "failed to control pid %d: process exec'd " @@ -978,26 +852,14 @@ dt_proc_create(dtrace_hdl_t *dtp, const char *file, char *const *argv, (void) pthread_mutex_init(&dpr->dpr_lock, NULL); (void) pthread_cond_init(&dpr->dpr_cv, NULL); -#ifdef illumos - dpr->dpr_proc = Pxcreate(file, argv, dtp->dt_proc_env, &err, NULL, 0); - if (dpr->dpr_proc == NULL) { - return (dt_proc_error(dtp, dpr, - "failed to execute %s: %s\n", file, Pcreate_error(err))); - } -#else if ((err = proc_create(file, argv, dtp->dt_proc_env, pcf, child_arg, &dpr->dpr_proc)) != 0) { return (dt_proc_error(dtp, dpr, "failed to execute %s: %s\n", file, Pcreate_error(err))); } -#endif dpr->dpr_hdl = dtp; -#ifdef illumos - dpr->dpr_pid = Pstatus(dpr->dpr_proc)->pr_pid; -#else dpr->dpr_pid = proc_getpid(dpr->dpr_proc); -#endif (void) Punsetflags(dpr->dpr_proc, PR_RLC); (void) Psetflags(dpr->dpr_proc, PR_KLC); @@ -1058,11 +920,7 @@ dt_proc_grab(dtrace_hdl_t *dtp, pid_t pid, int flags, int nomonitor) (void) pthread_mutex_init(&dpr->dpr_lock, NULL); (void) pthread_cond_init(&dpr->dpr_cv, NULL); -#ifdef illumos - if ((dpr->dpr_proc = Pgrab(pid, flags, &err)) == NULL) { -#else if ((err = proc_attach(pid, flags, &dpr->dpr_proc)) != 0) { -#endif return (dt_proc_error(dtp, dpr, "failed to grab pid %d: %s\n", (int)pid, Pgrab_error(err))); } @@ -1237,11 +1095,7 @@ dtrace_proc_create(dtrace_hdl_t *dtp, const char *file, char *const *argv, struct ps_prochandle *P = dt_proc_create(dtp, file, argv, pcf, child_arg); if (P != NULL && idp != NULL && idp->di_id == 0) { -#ifdef illumos - idp->di_id = Pstatus(P)->pr_pid; /* $target = created pid */ -#else idp->di_id = proc_getpid(P); /* $target = created pid */ -#endif } return (P);