Avoid memory corruption in shared memory used by several processes?

Discussion in 'C Programming' started by Sune, Jul 6, 2007.

  1. Sune

    Sune Guest

    Hi all,

    I want to make data stored in-memory (not disk) available to several
    processes. My concern is that poorly written C applications with
    dangling pointers may(will) damage the data in this memory segment if
    it is open to all, i.e. shared memory mapped into all processes memory
    area.

    I don't want to use TCP/IP client/server between the apps and a data
    store process due to the overhead.

    I don't want to start calculating checksums for all updates in a
    shared memory area, since that means a lot of overhead.

    Now my question:
    Is it possible to expose just the interface of a data store component
    and have that i/f shared between all processes who want to access the
    data, and then have this shared interface make callbacks into a data
    store process' private memory?

    If yes, how do I achieve this? If not, why not?

    Thanks for helping out
    /Sune
     
    Sune, Jul 6, 2007
    #1
    1. Advertising

  2. Sune

    user923005 Guest

    On Jul 5, 7:50 pm, Sune <> wrote:
    > Hi all,
    >
    > I want to make data stored in-memory (not disk) available to several
    > processes. My concern is that poorly written C applications with
    > dangling pointers may(will) damage the data in this memory segment if
    > it is open to all, i.e. shared memory mapped into all processes memory
    > area.
    >
    > I don't want to use TCP/IP client/server between the apps and a data
    > store process due to the overhead.
    >
    > I don't want to start calculating checksums for all updates in a
    > shared memory area, since that means a lot of overhead.
    >
    > Now my question:
    > Is it possible to expose just the interface of a data store component
    > and have that i/f shared between all processes who want to access the
    > data, and then have this shared interface make callbacks into a data
    > store process' private memory?
    >
    > If yes, how do I achieve this? If not, why not?


    Try news:comp.programming.threads
     
    user923005, Jul 6, 2007
    #2
    1. Advertising

  3. Sune

    Thad Smith Guest

    Sune wrote:

    > I want to make data stored in-memory (not disk) available to several
    > processes. My concern is that poorly written C applications with
    > dangling pointers may(will) damage the data in this memory segment if
    > it is open to all, i.e. shared memory mapped into all processes memory
    > area.
    > ...
    > Is it possible to expose just the interface of a data store component
    > and have that i/f shared between all processes who want to access the
    > data, and then have this shared interface make callbacks into a data
    > store process' private memory?


    Something like that is possible, although callbacks are used for
    something different than what your describe. Standard C doesn't support
    multiple processes, so this is off-topic in this newsgroup.

    You need to check systems that support multiple processes. It may also
    be possible, in some systems, to allow a single process to write an area
    of memory and others to only read.


    --
    Thad
     
    Thad Smith, Jul 6, 2007
    #3
  4. user923005 <> writes:
    > On Jul 5, 7:50 pm, Sune <> wrote:
    >> I want to make data stored in-memory (not disk) available to several
    >> processes.

    [...]
    > Try news:comp.programming.threads


    I suspect that's not the right place to ask. The OP asked about
    processes, not threads; in many system, those are quite different
    things.

    It's probably better to ask in a newsgroup that deals with whatever
    operating system the OP is using. At a guess, comp.unix.programmer
    seems likely.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Jul 6, 2007
    #4
  5. Sune

    CBFalconer Guest

    Keith Thompson wrote:
    > user923005 <> writes:
    >> Sune <> wrote:
    >>
    >>> I want to make data stored in-memory (not disk) available to
    >>> several processes.

    >
    > [...]
    >> Try news:comp.programming.threads

    >
    > I suspect that's not the right place to ask. The OP asked about
    > processes, not threads; in many system, those are quite different
    > things.


    To share memory you either need threads or some other arrangement
    to specifically share a memory block. Threads are probably the
    easiest initial mechanism.

    --
    <http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
    <http://www.securityfocus.com/columnists/423>
    <http://www.aaxnet.com/editor/edit043.html>
    cbfalconer at maineline dot net



    --
    Posted via a free Usenet account from http://www.teranews.com
     
    CBFalconer, Jul 6, 2007
    #5
  6. CBFalconer <> writes:
    > Keith Thompson wrote:
    >> user923005 <> writes:
    >>> Sune <> wrote:
    >>>
    >>>> I want to make data stored in-memory (not disk) available to
    >>>> several processes.

    >>
    >> [...]
    >>> Try news:comp.programming.threads

    >>
    >> I suspect that's not the right place to ask. The OP asked about
    >> processes, not threads; in many system, those are quite different
    >> things.

    >
    > To share memory you either need threads or some other arrangement
    > to specifically share a memory block. Threads are probably the
    > easiest initial mechanism.


    <OT>
    How exactly do threads help you share memory between proceses?

    Unix-like systems typically have mechanisms to share memory between
    processes; these mechanisms are independent of threads, which exist
    within a single process.
    </OT>

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Jul 6, 2007
    #6
  7. Sune

    CBFalconer Guest

    Keith Thompson wrote:
    > CBFalconer <> writes:
    >

    .... snip ...
    >
    >> To share memory you either need threads or some other arrangement
    >> to specifically share a memory block. Threads are probably the
    >> easiest initial mechanism.

    >
    > <OT>
    > How exactly do threads help you share memory between proceses?
    >
    > Unix-like systems typically have mechanisms to share memory between
    > processes; these mechanisms are independent of threads, which exist
    > within a single process.
    > </OT>


    Because, at least in my mind, threads of a process all operate in
    the same memory space, and all we have to do is control access.
    Processes go to some trouble to keep the memory isolated.

    --
    <http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
    <http://www.securityfocus.com/columnists/423>
    <http://www.aaxnet.com/editor/edit043.html>
    cbfalconer at maineline dot net



    --
    Posted via a free Usenet account from http://www.teranews.com
     
    CBFalconer, Jul 6, 2007
    #7
  8. CBFalconer <> writes:
    > Keith Thompson wrote:
    >> CBFalconer <> writes:
    >>

    > ... snip ...
    >>
    >>> To share memory you either need threads or some other arrangement
    >>> to specifically share a memory block. Threads are probably the
    >>> easiest initial mechanism.

    >>
    >> <OT>
    >> How exactly do threads help you share memory between proceses?
    >>
    >> Unix-like systems typically have mechanisms to share memory between
    >> processes; these mechanisms are independent of threads, which exist
    >> within a single process.
    >> </OT>

    >
    > Because, at least in my mind, threads of a process all operate in
    > the same memory space, and all we have to do is control access.
    > Processes go to some trouble to keep the memory isolated.


    Yes, and the OP specifically asked about sharing memory among
    *processes*. Maybe threads are a better solution to his underlying
    problem, but you should at least mention that you're suggesting an
    alternative rather than answering his actual question.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Jul 6, 2007
    #8
  9. Sune

    user923005 Guest

    On Jul 6, 3:37 pm, Keith Thompson <> wrote:
    > CBFalconer <> writes:
    > > Keith Thompson wrote:
    > >> CBFalconer <> writes:

    >
    > > ... snip ...

    >
    > >>> To share memory you either need threads or some other arrangement
    > >>> to specifically share a memory block. Threads are probably the
    > >>> easiest initial mechanism.

    >
    > >> <OT>
    > >> How exactly do threads help you share memory between proceses?

    >
    > >> Unix-like systems typically have mechanisms to share memory between
    > >> processes; these mechanisms are independent of threads, which exist
    > >> within a single process.
    > >> </OT>

    >
    > > Because, at least in my mind, threads of a process all operate in
    > > the same memory space, and all we have to do is control access.
    > > Processes go to some trouble to keep the memory isolated.

    >
    > Yes, and the OP specifically asked about sharing memory among
    > *processes*. Maybe threads are a better solution to his underlying
    > problem, but you should at least mention that you're suggesting an
    > alternative rather than answering his actual question.


    Sharing memory between processes is actually a lot easier than sharing
    memory among threads. The same ideas apply except that threads also
    share the memory within the process.

    I suspect that if the O.P. just wants to know how to create, use, and
    destroy a shared memory segment then he will have to look at the
    documentation for the operating system that he is using or use an
    abstraction layer like ACE.

    The guy who wrote FastDB has some C shared memory libraries that make
    Windows boxes look like POSIX machines for shared memory calls. Of
    course, that won't help much if the O.P. is not on Windows or POSIX
    type operating systems.
    His site is:
    http://www.garret.ru/~knizhnik/
    but I can't seem to connect right now.
     
    user923005, Jul 6, 2007
    #9
  10. "Keith Thompson" <> wrote in message
    news:...
    > <OT>
    > How exactly do threads help you share memory between
    > proceses?
    >
    > Unix-like systems typically have mechanisms to share memory
    > between processes; these mechanisms are independent of
    > threads, which exist within a single process.


    Threads are sometimes referred to as lightweight processes.

    > </OT>


    S

    --
    Stephen Sprunk "Those people who think they know everything
    CCIE #3723 are a great annoyance to those of us who do."
    K5SSS --Isaac Asimov


    --
    Posted via a free Usenet account from http://www.teranews.com
     
    Stephen Sprunk, Jul 7, 2007
    #10
  11. Sune

    CBFalconer Guest

    Stephen Sprunk wrote:
    > "Keith Thompson" <> wrote in message
    >
    >> <OT>
    >> How exactly do threads help you share memory between
    >> proceses?
    >>
    >> Unix-like systems typically have mechanisms to share memory
    >> between processes; these mechanisms are independent of
    >> threads, which exist within a single process.

    >
    > Threads are sometimes referred to as lightweight processes.


    I believe Linux specifically creates processes and defeats the
    memory isolation provisions in creating threads.

    --
    <http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
    <http://www.securityfocus.com/columnists/423>
    <http://www.aaxnet.com/editor/edit043.html>
    cbfalconer at maineline dot net



    --
    Posted via a free Usenet account from http://www.teranews.com
     
    CBFalconer, Jul 7, 2007
    #11
  12. "CBFalconer" <> wrote in message
    news:...
    > Stephen Sprunk wrote:
    >> Threads are sometimes referred to as lightweight processes.

    >
    > I believe Linux specifically creates processes and defeats the
    > memory isolation provisions in creating threads.


    Linux now has a single spawn() syscall, which takes various options; some of
    them result in a separation of memory space (i.e. processes), and some don't
    (i.e. threads). All the kernel cares about is scheduling threads; which
    ones occupy the same memory space as others is a minor detail.

    S

    --
    Stephen Sprunk "Those people who think they know everything
    CCIE #3723 are a great annoyance to those of us who do."
    K5SSS --Isaac Asimov


    --
    Posted via a free Usenet account from http://www.teranews.com
     
    Stephen Sprunk, Jul 7, 2007
    #12
  13. Sune

    Flash Gordon Guest

    Stephen Sprunk wrote, On 07/07/07 09:10:
    > "CBFalconer" <> wrote in message
    > news:...
    >> Stephen Sprunk wrote:
    >>> Threads are sometimes referred to as lightweight processes.


    <snip>

    All of which is off topic. Both of you, if you want to discus it
    further, take it to email or a group where it is topical please.
    --
    Flash Gordon
     
    Flash Gordon, Jul 7, 2007
    #13
  14. "user923005" <> wrote in message
    news:...
    [...]

    > Sharing memory between processes is actually a lot easier than sharing
    > memory among threads.


    [...]

    Really? Maintaining consentient and coherent state between multi-processes
    synchronization is more difficult and cumbersome than doing the same for
    multi-threads. Why would you need to use a robust mutex for a purely
    threaded design? Designing reliable _and_ correct robust synchronization
    objects are more _complex_ than usual!
     
    Chris Thomasson, Aug 26, 2007
    #14
  15. "Sune" <> wrote in message
    news:...
    > Hi all,
    >
    > I want to make data stored in-memory (not disk) available to several
    > processes. My concern is that poorly written C applications with
    > dangling pointers may(will) damage the data in this memory segment if
    > it is open to all, i.e. shared memory mapped into all processes memory
    > area.

    [...]

    http://groups.google.com/group/comp.programming.threads/msg/dc86197f1882dc56

    http://groups.google.com/group/comp.programming.threads/browse_frm/thread/e445e6fe981788e7

    Read both of those and follow all links...
     
    Chris Thomasson, Aug 26, 2007
    #15
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    853
  2. grbVRCPP
    Replies:
    0
    Views:
    845
    grbVRCPP
    Mar 13, 2007
  3. Sune
    Replies:
    5
    Views:
    439
    Darko
    Jul 13, 2007
  4. Charles Fox (Sheffield)
    Replies:
    9
    Views:
    747
    Adam Skutt
    Feb 12, 2011
  5. Phil C.

    Shared variable storage/ Encryption Corruption

    Phil C., Jun 29, 2005, in forum: ASP .Net Security
    Replies:
    0
    Views:
    132
    Phil C.
    Jun 29, 2005
Loading...

Share This Page