Skip to content

MAP_SHARED isn't proper for anonymous mappings for VxWorks #80829

Closed

Description

@LihuaZhao
mannequin
BPO 36648
Nosy @vstinner, @LihuaZhao
PRs
  • bpo-36648: fix mmap issue for VxWorks #12394
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2019-05-21.11:59:28.300>
    created_at = <Date 2019-04-17.15:53:41.769>
    labels = ['3.8', 'type-feature', 'library']
    title = "MAP_SHARED isn't proper for anonymous mappings for VxWorks"
    updated_at = <Date 2019-05-21.11:59:28.300>
    user = 'https://github.com/LihuaZhao'

    bugs.python.org fields:

    activity = <Date 2019-05-21.11:59:28.300>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-05-21.11:59:28.300>
    closer = 'vstinner'
    components = ['Library (Lib)']
    creation = <Date 2019-04-17.15:53:41.769>
    creator = 'lzhao'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 36648
    keywords = ['patch']
    message_count = 5.0
    messages = ['340411', '340475', '340476', '340481', '343007']
    nosy_count = 2.0
    nosy_names = ['vstinner', 'lzhao']
    pr_nums = ['12394']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue36648'
    versions = ['Python 3.8']

    Activity

    1. LihuaZhao commented on Apr 17, 2019

      LihuaZhaomannequin
      MannequinAuthor

      anonymous mappings is not part of the POSIX standard, python user just need to specified -1 as fd value when do anonymous map, for example:

      m = mmap.mmap(-1, 100)

      then python adapter module(mmapmodule.c) try to specify MAP_SHARED or MAP_PRIVATE based on operate system requirement, Linux require MAP_SHARED, VxWorks require MAP_PRIVATE, this different should be hidden by this module, and python user won't be affected.

      Currently, mmap is only adapted for the system which use MAP_SHARED when do anonymous map, VxWorks need be supported.

      https://en.wikipedia.org/wiki/Mmap

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-featureA feature request or enhancement
      on Apr 17, 2019
    3. vstinner commented on Apr 18, 2019

      @vstinner
      Member

      What is the current behavior of m = mmap.mmap(-1, 100)? Does it raise an exception?

    4. vstinner commented on Apr 18, 2019

      @vstinner
      Member

      I don't understand why PR 12394 modifies flags afterwards, whereas "m = mmap.mmap(-1, 100)" doesn't specify explicitly flags. So the bug looks to be default flags set by Python, no?

          int flags = MAP_SHARED;
          ...
      if (!PyArg_ParseTupleAndKeywords(args, kwdict, "in|iii" _Py_PARSE_OFF_T, keywords,
                                       &fd, &map_size, &flags, &prot,
                                       &access, &offset))
      

      Is MAP_SHARED constant available in C on VxWorks?

      Is mmap.MAP_SHARED constant available in Python on VxWorks?

    5. LihuaZhao commented on Apr 18, 2019

      LihuaZhaomannequin
      MannequinAuthor

      >What is the current behavior of m = mmap.mmap(-1, 100)? Does it raise an exception?

      No, the following statement will return -1 without PR 12394

      m_obj->data = mmap(NULL, map_size,
                         prot, flags,
                         fd, offset);
      

      >I don't understand why PR 12394 modifies flags afterwards, whereas "m = mmap.mmap(-1, 100)" doesn't specify explicitly flags. So the bug looks to be default flags set by Python, no?

      Yes, this statement doesn't specify the flag, but as you said, the new_mmap_object() firstly set MAP_SHARED for flag, and in later code:

          if (fd == -1) {
              m_obj->fd = -1;
          .....
      #ifdef MAP_ANONYMOUS
              /* BSD way to map anonymous memory */
              flags |= MAP_ANONYMOUS;

      #else
      #endif

      This routine will pass (MAP_ANONYMOUS | MAP_SHARED) to mmap and fd is -1, this is true for Linux, but for VxWorks, if fd is -1, the flag type should be (MAP_ANONYMOUS | MAP_PRIVATE), and this behavior is not part of the POSIX standard, we can't say VxWorks isn't right.

      So my changes clear MAP_SHARED and set MAP_PRIVATE when the system type is VxWorks.

      >Is MAP_SHARED constant available in C on VxWorks?

      Yes, but for MAP_ANONYMOUS, it require set MAP_PRIVATE.

      This PR still is try to enhance VxWorks support, doesn't affect Python user, and only change the behavior of VxWorks, other system don't have this issue, and also won't be influenced

    6. vstinner commented on May 21, 2019

      @vstinner
      Member

      New changeset 4fb1502 by Victor Stinner (Lihua Zhao) in branch 'master':
      bpo-36648: fix mmap issue for VxWorks (GH-12394)
      4fb1502

    7. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.8 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions