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 6053425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:02:20+00:00 2026-05-23T08:02:20+00:00

I have a pre-built userspace library that has an API along the lines of

  • 0

I have a pre-built userspace library that has an API along the lines of

void getBuffer (void **ppBuf, unsigned long *pSize);
void bufferFilled (void *pBuf, unsigned long size);

The idea being that my code requests a buffer from the lib, fills it with stuff, then hands it back to the lib.

I want another process to be able to fill this buffer. I can do this by creating some new shared buffer via shm*/shm_* APIs, have the other process fill that, then copy it to the lib’s buffer in the lib’s local process, but this has the overhead of an extra (potentially large) copy.

Is there a way to share memory that has ALREADY been mapped for a process? eg something like:

[local lib process]
getBuffer (&myLocalBuf, &mySize);
shmName = shareThisMemory (myLocalBuf, mySize);

[other process]
myLocalBuf = openTheSharedMemory (shmName);

That way the other process could write directly into the lib’s buffer.
(Synchronization between the processes is already taken care of so no problems there).

  • 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-23T08:02:21+00:00Added an answer on May 23, 2026 at 8:02 am

    There are good reasons for not allowing this functionality, particularly from the security side of things. A “share this mem” API would subvert the access permissions system.

    Just assume an application holds some sort of critical/sensitive information in memory; the app links (via e.g. using a shared library, a preload, a modified linker/loader) to whatever component outside, and said component for the sheer fun of it decides to “share out the address space”. It’d be a free-for-all, a method to bypass any sort of data access permission/restriction. You’d tunnel your way into the app.

    Not good for your usecase, admitted, but rather justified from the system / application integrity point of view. Try searching the web for /proc/pid/mem mmap vulnerability for some explanation why this sort of access isn’t wanted (in general).

    If the library you use is designed to allow such shared access, it must itself provide the hooks to either allocate such a shared buffer, or use an elsewhere-preallocated (and possibly shared) buffer.

    Edit: To make this clear, the process boundary is explicitly about not sharing the address space (amongst other things).
    If you require a shared address space, either use threads (then the entire address space is shared and there’s never any need to “export” anything), or explicitly set up a shared memory region in the same way as you’d set up a shared file.

    Look at it from the latter point of view, two processes not opening it O_EXCL would share access to a file. But if one process already has it open O_EXCL, then the only way to “make it shared” (open-able to another process) is to close() it first then open() it again without O_EXCL. There’s no other way to “remove” exclusive access from a file that you’ve opened as such other than to close it first.
    Just as there is no way to remove exclusive access to a memory region mapped as such other than to unmap it first – and for a process’ memory, MAP_PRIVATE is the default, for good reasons.

    More: a process-shared memory buffer really isn’t much different than a process shared file; using SysV-IPC style semantics, you have:

                  | SysV IPC shared memory            Files
    ==============+===================================================================
    creation      | id = shmget(key,..., IPC_CREAT);  fd = open("name",...,O_CREAT);
    lookup        | id = shmget(key,...);             fd = open("name",...);
    access        | addr = shmat(id,...);             addr = mmap(...,fd,...);
                  |
    global handle | IPC key                           filename
    local handle  | SHM ID number                     filedescriptor number
    mem location  | created by shmat()                created by mmap()

    I.e. the key is the “handle” you’re looking for, pass that the same way you would pass a filename, and both sides of the IPC connection can then use that key to check whether the shared resource exists, as well at access (attach to the handle) the contents though that.

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

Sidebar

Related Questions

I have a project that comprises pre-build Dll modules, built some time in the
Fedora Core 9 seems to have FCGID instead of FastCGI as a pre-built, YUM-managed
The basics have already been answered here . But is there a pre-built PHP
We have multiple config files (app.DEV.config, app.TEST.config, etc) and a pre-build event that copies
I have a pre tag within my page that contains quite a bit of
I have a form that I pre-populate with test data though jQuery. $('INPUT[name=subscription.FirstName]').val('Jef'); but
We have an NAnt script to update our pre-built assemblies in TFS as one
Has anyone tried compiling SciPy 0.7.1 on Windows using numpy-1.3.0 that was built with
I have an Android App with a pre-built SQLite DB packaged with it. However,
I have the MS-Excel 2010 Starter Edition - it comes bundled into pre-built PCs.

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.