Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 560673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:22:06+00:00 2026-05-13T12:22:06+00:00

To see what memory map regions a running program contains, I write a simple

  • 0

To see what memory map regions a running program contains, I write a simple C program to read data from /proc/self/maps:

#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>

int main() {
    char buf[1024];
    int fd;
    ssize_t n;

    fd = open("/proc/self/maps", O_RDONLY);
    if (fd < 0) {
        perror("");
    }
    while ((n = read(fd, buf, 1000)) > 0) {
        buf[n] = 0;
        printf("%s", buf);
    }
    close(fd);

    return 0;
}

The output of the program looks like this (labeled):

1. 08048000-08049000 r-xp 00000000 08:01 2323014    /tmp/a.out
2. 08049000-0804a000 rw-p 00000000 08:01 2323014    /tmp/a.out
3. b7f69000-b7f6a000 rw-p b7f69000 00:00 0
4. b7f6a000-b80c6000 r-xp 00000000 08:01 1826975    /lib/tls/i686/cmov/libc-2.9.so
5. b80c6000-b80c7000 ---p 0015c000 08:01 1826975    /lib/tls/i686/cmov/libc-2.9.so
6. b80c7000-b80c9000 r--p 0015c000 08:01 1826975    /lib/tls/i686/cmov/libc-2.9.so
7. b80c9000-b80ca000 rw-p 0015e000 08:01 1826975    /lib/tls/i686/cmov/libc-2.9.so
8. b80ca000-b80cd000 rw-p b80ca000 00:00 0
9. b80dd000-b80df000 rw-p b80dd000 00:00 0
10.b80df000-b80e0000 r-xp b80df000 00:00 0          [vdso]
11.b80e0000-b80fc000 r-xp 00000000 08:01 1826830    /lib/ld-2.9.so
12.b80fc000-b80fd000 r--p 0001b000 08:01 1826830    /lib/ld-2.9.so
13.b80fd000-b80fe000 rw-p 0001c000 08:01 1826830    /lib/ld-2.9.so
14.bfee9000-bfefe000 rw-p bffeb000 00:00 0          [stack]

As we can infer from the execution bit and writable bit, the first two lines are associated with the code and data segments of the program respectively.

But what confuses me is that of libc.so, there are for regions which are mapped from libc.so. One of them even only has private bit, it cannot be written, read, or executed.
And another interesting thing is that ld.so has only three segments. Comparing to libc.so’s segments, the one with only private bit on is missing.

So I’d like to know what are the four segments do actually? I’m using Ubuntu SMP with kernel 2.6.28, gcc 3.4.6, and binutils 2.19.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T12:22:07+00:00Added an answer on May 13, 2026 at 12:22 pm

    The r-xp, r--p and rw-p mappings are simply regions that need different permissions.

    The mystery ---p mapping is a consequence of virtual memory offsets of sections described by the ELF file not necessarily matching the physical offsets within the file (there may be padding for alignment reasons).

    i.e. the ELF file itself might look like this:

    | .... sections .... | .... more sections .... |
    

    …but describe a memory layout that looks like this:

    | .... sections .... |     gap     | .... more sections .... |
    

    (You can see this using objdump -h or readelf -e.)

    So, the general principle is that ld.so needs to allocate enough memory for everything:

    |                                                            |
    

    …then make one mapping for the first part:

    | .... sections .... |                                       |
    

    …and then make a second mapping to get the second part in the right place:

    | .... sections .... |             | .... more sections .... |
    

    It then protects the “hole” that is left in virtual address space. This is the mystery mapping that you see:

    | .... sections .... |XXXXXXXXXXXXX| .... more sections .... |
    

    I believe the hole is protected – rather than freed for re-use – in order to keeps things simple: it ensures that each library has only a single virtual address range, which belongs to it and no-one else.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 378k
  • Answers 378k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer For me, release-prepare seems to be pushing three times: After… May 14, 2026 at 9:07 pm
  • Editorial Team
    Editorial Team added an answer Tools>Options>TextEditor>JScript You can turn it off there. May 14, 2026 at 9:07 pm
  • Editorial Team
    Editorial Team added an answer You can handle this with a custom type converter. See… May 14, 2026 at 9:07 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.