From patchwork Mon Jan 8 21:28:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas De Marchi X-Patchwork-Id: 10150613 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3972660210 for ; Mon, 8 Jan 2018 21:28:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3502027F9F for ; Mon, 8 Jan 2018 21:28:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 28B3228449; Mon, 8 Jan 2018 21:28:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C86FE27F9F for ; Mon, 8 Jan 2018 21:28:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755995AbeAHV2f (ORCPT ); Mon, 8 Jan 2018 16:28:35 -0500 Received: from mga11.intel.com ([192.55.52.93]:24430 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755991AbeAHV2e (ORCPT ); Mon, 8 Jan 2018 16:28:34 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Jan 2018 13:28:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,332,1511856000"; d="scan'208";a="19974951" Received: from ldmartin-desk.jf.intel.com ([10.24.10.86]) by fmsmga001.fm.intel.com with ESMTP; 08 Jan 2018 13:28:34 -0800 From: Lucas De Marchi To: linux-modules@vger.kernel.org Cc: caio.oliveira@intel.com Subject: [PATCH v2] testsuite: also wrap gettid in syscall() Date: Mon, 8 Jan 2018 13:28:29 -0800 Message-Id: <20180108212829.14484-1-lucas.demarchi@intel.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180108162708.16662-1-lucas.demarchi@intel.com> References: <20180108162708.16662-1-lucas.demarchi@intel.com> Sender: owner-linux-modules@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Not a perfect solution for overriding syscall(), but at least it makes the testsuite to pass in a modified nsswitch.conf (one that has a module which calls syscall() to get the thread id). --- v2: - Check nextlib_syscall rather than nextlib to avoid races in multithreaded programs - Add error message in case we fail to get symbol testsuite/init_module.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/testsuite/init_module.c b/testsuite/init_module.c index 199186b..c70147e 100644 --- a/testsuite/init_module.c +++ b/testsuite/init_module.c @@ -355,6 +355,26 @@ TS_EXPORT long int syscall(long int __sysno, ...) return ret; } + if (__sysno == __NR_gettid) { + static void *nextlib = NULL; + static long (*nextlib_syscall)(long number, ...); + + if (nextlib_syscall == NULL) { +#ifdef RTLD_NEXT + nextlib = RTLD_NEXT; +#else + nextlib = dlopen("libc.so.6", RTLD_LAZY); +#endif + nextlib_syscall = dlsym(nextlib, "syscall"); + if (nextlib_syscall == NULL) { + fprintf(stderr, "FIXME FIXME FIXME: libc is missing syscall symbol\n"); + abort(); + } + } + + return nextlib_syscall(__NR_gettid); + } + /* * FIXME: no way to call the libc function due since this is a * variadic argument function and we don't have a vsyscall() variant