From patchwork Thu May 18 08:28:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: stsp X-Patchwork-Id: 69582 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5636A382E809 for ; Thu, 18 May 2023 08:34:22 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from forward102c.mail.yandex.net (forward102c.mail.yandex.net [178.154.239.213]) by sourceware.org (Postfix) with ESMTPS id 0E17D3854179 for ; Thu, 18 May 2023 08:29:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0E17D3854179 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=yandex.ru Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=yandex.ru Received: from mail-nwsmtp-smtp-production-main-91.iva.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-91.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:1186:0:640:38cb:0]) by forward102c.mail.yandex.net (Yandex) with ESMTP id 0E54A600A7 for ; Thu, 18 May 2023 11:29:47 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-91.iva.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id XTYe39MDZ0U0-Lo3BHGVk; Thu, 18 May 2023 11:29:46 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1684398586; bh=gTkyK+Xdn02mwlLMd9fncxkJHRYhq7rOeWqFn5VuaII=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=D1fw3D1/ixSoRWLumAdcqBBt0svfVjx9i7E6vcJ0R/TzEcjozoAiC1cl1yzPpEnCH WcUmFY1GvVYVu245bLlfrRg8SNaJ4toxRJ1125epD5OR+AifgDT2EVFn1chOGc+M9q 548hfioYgf8fhlS8wxBYo2fYzwVEFqvqLwVJ8h6U= Authentication-Results: mail-nwsmtp-smtp-production-main-91.iva.yp-c.yandex.net; dkim=pass header.i=@yandex.ru From: Stas Sergeev To: libc-alpha@sourceware.org Cc: Stas Sergeev Subject: [PATCH 12/14] implement RTLD_DI_MAPINFO dlinfo() request Date: Thu, 18 May 2023 13:28:52 +0500 Message-Id: <20230518082854.3903342-13-stsp2@yandex.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230518082854.3903342-1-stsp2@yandex.ru> References: <20230518082854.3903342-1-stsp2@yandex.ru> MIME-Version: 1.0 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" This request fills in the following structure: typedef struct { void *map_start; /* Beginning of mapping containing address. */ size_t map_length; /* Length of mapping. */ size_t map_align; /* Alignment of mapping. */ int relocated; /* Indicates whether an object was relocated. */ } Dl_mapinfo; This structure allows the user to move an unrelocated object. The test-suite was run on x86_64/64 and showed no regressions. Signed-off-by: Stas Sergeev --- dlfcn/dlfcn.h | 15 ++++++++++++++- dlfcn/dlinfo.c | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/dlfcn/dlfcn.h b/dlfcn/dlfcn.h index c3e228c667..7671c187a3 100644 --- a/dlfcn/dlfcn.h +++ b/dlfcn/dlfcn.h @@ -170,7 +170,12 @@ enum the number of program headers in the array. */ RTLD_DI_PHDR = 11, - RTLD_DI_MAX = 11 + /* Treat ARG as Dl_mapinfo *, and store the mapping information + at that location. The dlinfo call returns 0 on success or + -1 on failure. */ + RTLD_DI_MAPINFO = 12, + + RTLD_DI_MAX = 12 }; @@ -203,6 +208,14 @@ typedef struct # endif } Dl_serinfo; +typedef struct +{ + void *map_start; /* Beginning of mapping containing address. */ + size_t map_length; /* Length of mapping. */ + size_t map_align; /* Alignment of mapping. */ + int relocated; /* Indicates whether an object was relocated. */ +} Dl_mapinfo; + struct dl_find_object { __extension__ unsigned long long int dlfo_flags; diff --git a/dlfcn/dlinfo.c b/dlfcn/dlinfo.c index 1b5dd90ae5..8d7db7dbb8 100644 --- a/dlfcn/dlinfo.c +++ b/dlfcn/dlinfo.c @@ -85,6 +85,24 @@ dlinfo_doit (void *argsblock) *(const ElfW(Phdr) **) args->arg = l->l_phdr; args->result = l->l_phnum; break; + + case RTLD_DI_MAPINFO: + { + Dl_mapinfo *info = (Dl_mapinfo *) args->arg; + __rtld_lock_lock_recursive (GL(dl_load_lock)); + if (l->l_contiguous) + { + info->map_start = (void *) l->l_map_start; + info->map_length = l->l_map_end - l->l_map_start; + info->map_align = l->l_map_align; + info->relocated = l->l_relocated; + args->result = 0; + } + else + args->result = -1; + __rtld_lock_unlock_recursive (GL(dl_load_lock)); + break; + } } }