From patchwork Mon Aug 24 12:42:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrik Jakobsson X-Patchwork-Id: 7063931 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id F00CD9F358 for ; Mon, 24 Aug 2015 12:42:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 292DE2073E for ; Mon, 24 Aug 2015 12:42:12 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 3B42020642 for ; Mon, 24 Aug 2015 12:42:11 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7A01F6E96C; Mon, 24 Aug 2015 05:42:10 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by gabe.freedesktop.org (Postfix) with ESMTP id 0184C6E748 for ; Mon, 24 Aug 2015 05:42:08 -0700 (PDT) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP; 24 Aug 2015 05:42:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,737,1432623600"; d="scan'208";a="789846386" Received: from patrik-desktop.isw.intel.com ([10.237.180.143]) by orsmga002.jf.intel.com with ESMTP; 24 Aug 2015 05:42:07 -0700 From: Patrik Jakobsson To: strace-devel@lists.sourceforge.net Date: Mon, 24 Aug 2015 14:42:47 +0200 Message-Id: <1440420170-13337-3-git-send-email-patrik.jakobsson@linux.intel.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1440420170-13337-1-git-send-email-patrik.jakobsson@linux.intel.com> References: <1440420170-13337-1-git-send-email-patrik.jakobsson@linux.intel.com> Cc: intel-gfx@lists.freedesktop.org, ldv@altlinux.org Subject: [Intel-gfx] [PATCH v4 2/5] drm: Add private data field to trace control block X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-5.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We need to be able to store private data in the tcb across it's lifetime. To ensure proper destruction of the data a free_priv_data callback must be provided if an allocation is stored in priv_data. The callback is executed automatically when the life of the tcb ends. * defs.h: Add extern declaration of free_tcb_priv_data. (struct tcb): Add priv_data and free_priv_data. * strace.c (free_tcb_priv_data): New function (drop_tcb): Execute free_tcb_priv_data callback * syscall.c (trace_syscall_exiting): Execute free_tcb_priv_data callback Signed-off-by: Patrik Jakobsson --- defs.h | 6 ++++++ strace.c | 14 ++++++++++++++ syscall.c | 1 + 3 files changed, 21 insertions(+) diff --git a/defs.h b/defs.h index 9059026..bc3bd83 100644 --- a/defs.h +++ b/defs.h @@ -266,6 +266,10 @@ struct tcb { int u_error; /* Error code */ long scno; /* System call number */ long u_arg[MAX_ARGS]; /* System call arguments */ + + void *priv_data; /* Private data for syscall decoding functions */ + void (*free_priv_data)(void *); /* Callback for freeing priv_data */ + #if defined(LINUX_MIPSN32) || defined(X32) long long ext_arg[MAX_ARGS]; long long u_lrval; /* long long return value */ @@ -470,6 +474,8 @@ extern void get_regs(pid_t pid); extern int get_scno(struct tcb *tcp); extern const char *syscall_name(long scno); +extern void free_tcb_priv_data(struct tcb *tcp); + extern int umoven(struct tcb *, long, unsigned int, void *); #define umove(pid, addr, objp) \ umoven((pid), (addr), sizeof(*(objp)), (void *) (objp)) diff --git a/strace.c b/strace.c index 9b93e79..7a71152 100644 --- a/strace.c +++ b/strace.c @@ -711,12 +711,26 @@ alloctcb(int pid) error_msg_and_die("bug in alloctcb"); } +void +free_tcb_priv_data(struct tcb *tcp) +{ + if (tcp->priv_data) { + if (tcp->free_priv_data) { + tcp->free_priv_data(tcp->priv_data); + tcp->free_priv_data = NULL; + } + tcp->priv_data = NULL; + } +} + static void droptcb(struct tcb *tcp) { if (tcp->pid == 0) return; + free_tcb_priv_data(tcp); + #ifdef USE_LIBUNWIND if (stack_trace_enabled) { unwind_tcb_fin(tcp); diff --git a/syscall.c b/syscall.c index 396a7dd..39b973b 100644 --- a/syscall.c +++ b/syscall.c @@ -1099,6 +1099,7 @@ trace_syscall_exiting(struct tcb *tcp) #endif ret: + free_tcb_priv_data(tcp); tcp->flags &= ~TCB_INSYSCALL; tcp->sys_func_rval = 0; return 0;