From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id gCgrMcIobWL8dwMAWB0awg (envelope-from ) for ; Sat, 30 Apr 2022 08:17:06 -0400 Received: by simark.ca (Postfix, from userid 112) id C505A1E058; Sat, 30 Apr 2022 08:17:06 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 291951E01D for ; Sat, 30 Apr 2022 08:17:06 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ABF5D385742B for ; Sat, 30 Apr 2022 12:17:05 +0000 (GMT) Received: from nx236.node02.secure-mailgate.com (nx236.node02.secure-mailgate.com [192.162.87.236]) by sourceware.org (Postfix) with ESMTPS id 74CD5385800E for ; Sat, 30 Apr 2022 12:16:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 74CD5385800E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=trande.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=trande.de Received: from host202.checkdomain.de ([185.137.168.148]) by node02.secure-mailgate.com with esmtps (TLSv1.2:AES128-GCM-SHA256:128) (Exim 4.92) (envelope-from ) id 1nkm1s-003Wlf-Pm for gdb-patches@sourceware.org; Sat, 30 Apr 2022 14:16:53 +0200 X-SecureMailgate-Identity: zied.guermazi@trande.de;host202.checkdomain.de Received: from Trande0001.fritz.box (dynamic-077-180-176-167.77.180.pool.telefonica.de [77.180.176.167]) (Authenticated sender: zied.guermazi@trande.de) by host202.checkdomain.de (Postfix) with ESMTPSA id 43AD428115D; Sat, 30 Apr 2022 14:16:52 +0200 (CEST) X-SecureMailgate-Identity: zied.guermazi@trande.de;host202.checkdomain.de From: Zied Guermazi To: gdb-patches@sourceware.org Subject: [PATCH 1/1] get page size using sysconf (_SC_PAGESIZE) instead of PAGE_SIZE Date: Sat, 30 Apr 2022 14:16:23 +0200 Message-Id: <20220430121623.42196-2-zied.guermazi@trande.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220430121623.42196-1-zied.guermazi@trande.de> References: <20220430121623.42196-1-zied.guermazi@trande.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-PPP-Message-ID: <20220430121652.197412.54011@host202.checkdomain.de> X-PPP-Vhost: trande.de X-Originating-IP: 185.137.168.148 X-SecureMailgate-Domain: host202.checkdomain.de X-SecureMailgate-Username: 185.137.168.148 Authentication-Results: secure-mailgate.com; auth=pass smtp.auth=185.137.168.148@host202.checkdomain.de X-SecureMailgate-Outgoing-Class: ham X-SecureMailgate-Outgoing-Evidence: SB/global_tokens (0.000823659685475) X-Recommended-Action: accept X-Filter-ID: Pt3MvcO5N4iKaDQ5O6lkdGlMVN6RH8bjRMzItlySaT9/E7J9Bf3d4ZROga+Vqek6PUtbdvnXkggZ 3YnVId/Y5jcf0yeVQAvfjHznO7+bT5wgSQOko5ya3orWH1MkzQXa2oPZqVS5i0KNMNtVCi0tRw/C h5SE4jAyhe1COeASyU8eye59kEhGpnVkp2DyEzD74ld5rdi2ZxohSIq+dqifZoVY3IcDeckxfee+ NDQ6wUl3g/WbBekzB3IK8RY7uNAEcY1i02TJefD768F5oV2iM8C0xB8SW32wy2mbLZXD/P8Efoct ypGbPthjE2UrR12FlU4PumfG+1zay7DesNa5m7XDLRhLABXs81Y8X58rOcwLMK9HC+pUQBAyR03+ Yzd8ARsynxDH0D+SLDJWdESXziw50BoEYB44qFPH6be8XgtMhiMRK0C70oXENkWqJaNtpfX1h/uL cDQJCG2naSen4S0KEAnwyE9dte+FkDKSV99EDBffVZVjmVaNbG4ZJG7F2RgQw3d3zmVen9wp80qQ nk5/t+UnI24Hleg6UWHjmGlvyMjbyNpr4xR6RL2C9+qlIny++hg9dJLqN5zmWqF/oNe6FVV7drXD mtOldfpWzeXX3Vs0+OVZ6o01Ur0UfsSgVqahaS1Xn3nbmTfiR5jKRrn6qQ/in5NA6oG3bP7L0DnU JleWftUulkbC12DciiOUAQy3WRoWhjJ4ABRp4spTBKsH/WzE78WB+6LKJkk4wWAos7Vk+4I720v2 H9/mQncon4T7OymHvLHT1C7MG/JfB9kY6yXVYpmS2BTspFWylXdFXdcOXXm38/++NKnQrU/tOnYQ psOL3D4WKYPb9hiQqsMR3pimW+H6hrLs7bihM+ep7Sq+vnK5vq335GkOmYDoHPDsFqo1t5bEBI0m 4NsB3v57rn7svr0CR7c5hAqOktyw0IwIS4zYB1I7SItub4U1wGhIHHuuf0SZcW57JTZpHTwJWw42 swm4bO6gacpMpzI93NKmpOx249IDJgHZhSqYgJJFthw94zyDVRbqPxaxhXoarW2MF3gazIzgmJi5 UydShOH22SRgbHWq1uciMDoDhcd9NG1JDoOknqc6qrb4AiZPF6HXPq5gLm4Q4ElmvUALMK9HC+pU QBAyR03+Yzd87yCUgX8YuF5WBQr1Bq861zvA3BXN5HBbApl4eIrLaWewxjLyThsLecb51qdaSQev MS+4ayUpOtEhdxekWDmK9g== X-Report-Abuse-To: spam@node04.secure-mailgate.com X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zied Guermazi Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" PAGE_SIZE is not defined in all build configurations, e.g cross compiling for aarch64 GNU/Linux machine. This patch gets the value at runtime using posix call sysconf (_SC_PAGESIZE) --- gdb/nat/linux-btrace.c | 43 ++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/gdb/nat/linux-btrace.c b/gdb/nat/linux-btrace.c index b0d6dcd7cf1..d99ec8e01e3 100644 --- a/gdb/nat/linux-btrace.c +++ b/gdb/nat/linux-btrace.c @@ -445,6 +445,17 @@ diagnose_perf_event_open_fail () error (_("Failed to start recording: %s"), safe_strerror (errno)); } +/* Returns System page size. */ + +static long +system_page_size () +{ + long page_size = sysconf (_SC_PAGESIZE); + if (page_size == -1) + perror_with_name (_("Failed to get system page size")); + return page_size; +} + /* Enable branch tracing in BTS format. */ static struct btrace_target_info * @@ -486,9 +497,10 @@ linux_enable_bts (ptid_t ptid, const struct btrace_config_bts *conf) if (fd.get () < 0) diagnose_perf_event_open_fail (); + long page_size = system_page_size (); /* Convert the requested size in bytes to pages (rounding up). */ - pages = ((size_t) conf->size / PAGE_SIZE - + ((conf->size % PAGE_SIZE) == 0 ? 0 : 1)); + pages = ((size_t) conf->size / page_size + + ((conf->size % page_size) == 0 ? 0 : 1)); /* We need at least one page. */ if (pages == 0) pages = 1; @@ -507,17 +519,17 @@ linux_enable_bts (ptid_t ptid, const struct btrace_config_bts *conf) size_t length; __u64 data_size; - data_size = (__u64) pages * PAGE_SIZE; + data_size = (__u64) pages * (__u64) page_size; /* Don't ask for more than we can represent in the configuration. */ if ((__u64) UINT_MAX < data_size) continue; size = (size_t) data_size; - length = size + PAGE_SIZE; + length = size + (size_t) page_size; /* Check for overflows. */ - if ((__u64) length != data_size + PAGE_SIZE) + if ((__u64) length != data_size + (__u64) page_size) continue; errno = 0; @@ -532,7 +544,7 @@ linux_enable_bts (ptid_t ptid, const struct btrace_config_bts *conf) struct perf_event_mmap_page *header = (struct perf_event_mmap_page *) data.get (); - data_offset = PAGE_SIZE; + data_offset = (__u64) page_size; #if defined (PERF_ATTR_SIZE_VER5) if (offsetof (struct perf_event_mmap_page, data_size) <= header->size) @@ -630,8 +642,9 @@ linux_enable_pt (ptid_t ptid, const struct btrace_config_pt *conf) diagnose_perf_event_open_fail (); /* Allocate the configuration page. */ - scoped_mmap data (nullptr, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, - fd.get (), 0); + long page_size = system_page_size (); + scoped_mmap data (nullptr, (size_t) page_size, PROT_READ | PROT_WRITE, + MAP_SHARED, fd.get (), 0); if (data.get () == MAP_FAILED) error (_("Failed to map trace user page: %s."), safe_strerror (errno)); @@ -641,8 +654,8 @@ linux_enable_pt (ptid_t ptid, const struct btrace_config_pt *conf) header->aux_offset = header->data_offset + header->data_size; /* Convert the requested size in bytes to pages (rounding up). */ - pages = ((size_t) conf->size / PAGE_SIZE - + ((conf->size % PAGE_SIZE) == 0 ? 0 : 1)); + pages = ((size_t) conf->size / page_size + + ((conf->size % page_size) == 0 ? 0 : 1)); /* We need at least one page. */ if (pages == 0) pages = 1; @@ -661,7 +674,7 @@ linux_enable_pt (ptid_t ptid, const struct btrace_config_pt *conf) size_t length; __u64 data_size; - data_size = (__u64) pages * PAGE_SIZE; + data_size = (__u64) pages * (__u64) page_size; /* Don't ask for more than we can represent in the configuration. */ if ((__u64) UINT_MAX < data_size) @@ -732,7 +745,8 @@ linux_enable_btrace (ptid_t ptid, const struct btrace_config *conf) static enum btrace_error linux_disable_bts (struct btrace_tinfo_bts *tinfo) { - munmap((void *) tinfo->header, tinfo->bts.size + PAGE_SIZE); + long page_size = system_page_size (); + munmap ((void *) tinfo->header, (size_t) (tinfo->bts.size + page_size)); close (tinfo->file); return BTRACE_ERR_NONE; @@ -743,8 +757,9 @@ linux_disable_bts (struct btrace_tinfo_bts *tinfo) static enum btrace_error linux_disable_pt (struct btrace_tinfo_pt *tinfo) { - munmap((void *) tinfo->pt.mem, tinfo->pt.size); - munmap((void *) tinfo->header, PAGE_SIZE); + long page_size = system_page_size (); + munmap ((void *) tinfo->pt.mem, tinfo->pt.size); + munmap ((void *) tinfo->header, (size_t) page_size); close (tinfo->file); return BTRACE_ERR_NONE; -- 2.25.1