From patchwork Mon Jun 13 10:38:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gary Benson X-Patchwork-Id: 13019 Received: (qmail 61002 invoked by alias); 13 Jun 2016 10:41:25 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 60705 invoked by uid 89); 13 Jun 2016 10:41:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.3 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Lesser, Hx-languages-length:3764, lesser X-HELO: mx1.redhat.com From: Gary Benson To: libc-alpha@sourceware.org Subject: [RFC v2][PATCH 26/27] Add Infinity notes implementing libpthread::thr_get_lwpid Date: Mon, 13 Jun 2016 11:38:30 +0100 Message-Id: <1465814311-31470-27-git-send-email-gbenson@redhat.com> In-Reply-To: <1465814311-31470-1-git-send-email-gbenson@redhat.com> References: <1465814311-31470-1-git-send-email-gbenson@redhat.com> This commit adds the Infinity function libpthread::thr_get_lwpid. It has no libthread_db equivalent (in libthread_db the LWPID of a thread is read from the ti_lid field of the td_thrinfo_t that td_thr_get_info fills in). --- nptl/Makefile | 3 +- nptl/infinity-thr_get_lwpid.i8 | 38 ++++++++++++++++++++++++++++++++++++ nptl/tst-infinity-thr_get_lwpid.py | 37 +++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 1 deletions(-) create mode 100644 nptl/infinity-thr_get_lwpid.i8 create mode 100644 nptl/tst-infinity-thr_get_lwpid.py diff --git a/nptl/Makefile b/nptl/Makefile index 6967940..bdfe656 100644 --- a/nptl/Makefile +++ b/nptl/Makefile @@ -139,7 +139,8 @@ libpthread-routines = nptl-init vars events version pt-interp \ # pthread_setresgid ifeq ($(build-infinity),yes) -infinity-routines = infinity-map_lwp2thr infinity-thr_iter +infinity-routines = infinity-map_lwp2thr infinity-thr_iter \ + infinity-thr_get_lwpid libpthread-routines += $(infinity-routines) endif diff --git a/nptl/infinity-thr_get_lwpid.i8 b/nptl/infinity-thr_get_lwpid.i8 new file mode 100644 index 0000000..4755de7 --- /dev/null +++ b/nptl/infinity-thr_get_lwpid.i8 @@ -0,0 +1,38 @@ +/* Get LWPID of a thread. + Copyright (C) 2016 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include "infinity-nptl.i8" + +/* Return the LWPID of this thread. */ + +define MODULE_NAME::thr_get_lwpid returns td_err_e, lwpid_t + argument pthread_t descr + + dup + beq NULL, fake_descriptor + +real_descriptor: + add PTHREAD_TID_OFFSET + deref pid_t + load TD_OK + return + +fake_descriptor: + call procservice::getpid + load TD_OK + return diff --git a/nptl/tst-infinity-thr_get_lwpid.py b/nptl/tst-infinity-thr_get_lwpid.py new file mode 100644 index 0000000..150b6d1 --- /dev/null +++ b/nptl/tst-infinity-thr_get_lwpid.py @@ -0,0 +1,37 @@ +from i8c.runtime import TestCase + +TestCase.import_builtin_constants() +TestCase.import_constants_from("infinity-nptl-constants.h") +TestCase.import_constants_from("infinity-nptl_db-constants.h") + +class TestThrGetLWPID(TestCase): + TESTFUNC = "libpthread::thr_get_lwpid(p)ii" + MAIN_PID = 12345 + + def setUp(self): + self.ps_getpid_called = False + + def call_procservice_getpid(self): + """Implementation of procservice::getpid.""" + self.ps_getpid_called = True + return self.MAIN_PID + + def __do_test(self, descr, expect_lwpid): + result = self.i8ctx.call(self.TESTFUNC, descr) + self.assertEqual(len(result), 2) + self.assertEqual(result[0], TD_OK) + self.assertEqual(result[1], expect_lwpid) + + def test_faked(self): + """Test thr_get_lwpid with a faked descriptor""" + self.__do_test(NULL, self.MAIN_PID) + self.assertTrue(self.ps_getpid_called) + + def test_real(self): + """Test thr_get_lwpid with a real descriptor""" + lwpid = self.MAIN_PID - 5 + with self.memory.builder() as mem: + descr = mem.alloc() + descr.store_i32(PTHREAD_TID_OFFSET, lwpid) + self.__do_test(descr, lwpid) + self.assertFalse(self.ps_getpid_called)