public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Stas Sergeev <stsp2@yandex.ru>
To: libc-alpha@sourceware.org
Cc: Stas Sergeev <stsp2@yandex.ru>
Subject: [PATCH 12/14] implement RTLD_DI_MAPINFO dlinfo() request
Date: Thu, 18 May 2023 13:28:52 +0500	[thread overview]
Message-ID: <20230518082854.3903342-13-stsp2@yandex.ru> (raw)
In-Reply-To: <20230518082854.3903342-1-stsp2@yandex.ru>

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 <stsp2@yandex.ru>
---
 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;
+      }
     }
 }
 
-- 
2.39.2


  parent reply	other threads:[~2023-05-18  8:29 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-18  8:28 [PATCH 00/14] implement RTLD_NORELOCATE api [BZ #30007] Stas Sergeev
2023-05-18  8:28 ` [PATCH 01/14] elf: switch _dl_map_segment() to anonymous mapping Stas Sergeev
2023-05-18  8:28 ` [PATCH 02/14] use initial mmap also for ET_EXEC Stas Sergeev
2023-05-18  8:28 ` [PATCH 03/14] rework maphole Stas Sergeev
2023-05-18  8:28 ` [PATCH 04/14] split do_reloc_1() from dl_open_worker_begin() Stas Sergeev
2023-05-18  8:28 ` [PATCH 05/14] split do_reloc_2() out of do_open_worker() Stas Sergeev
2023-05-18  8:28 ` [PATCH 06/14] move relocation into _dl_object_reloc() func Stas Sergeev
2023-05-18  8:28 ` [PATCH 07/14] split out _dl_finalize_segments() Stas Sergeev
2023-05-18  8:28 ` [PATCH 08/14] finalize elf segments on a relocation step Stas Sergeev
2023-05-18  8:28 ` [PATCH 09/14] implement RTLD_NORELOCATE dlopen() flag Stas Sergeev
2023-05-18  8:28 ` [PATCH 10/14] add test-case for RTLD_NORELOCATE Stas Sergeev
2023-05-18  8:28 ` [PATCH 11/14] implement dlrelocate() function Stas Sergeev
2023-05-18  8:28 ` Stas Sergeev [this message]
2023-05-18  8:28 ` [PATCH 13/14] implement dlset_object_base() function Stas Sergeev
2023-05-18  8:28 ` [PATCH 14/14] implement RTLD_DI_DEPLIST dlinfo() request Stas Sergeev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230518082854.3903342-13-stsp2@yandex.ru \
    --to=stsp2@yandex.ru \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).