Avoid memory corruption in shared memory used by several processes?

Discussion in 'C Programming' started by Sune, Jul 10, 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
    --
    comp.lang.c.moderated - moderation address: -- you must
    have an appropriate newsgroups line in your header for your mail to be seen,
    or the newsgroup name in square brackets in the subject line. Sorry.
     
    Sune, Jul 10, 2007
    #1
    1. Advertising

  2. Sune <> writes:

    > 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.


    Whilst technically OT, this sounds like a swipe at C, so I feel
    justified in saying that it has nothing to do with "dangling
    pointers". Shared memory is shared, and totally well-defined and
    correct pointer usage can damage your data. Indeed, simply writing
    'x = 0;' can do so if x is in shared memory and should never be set
    to zero.

    > 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?


    <OT>That mechanism is called RPC (Remote Procedure Call) and it can be
    arranged to be optimised when the processes are not very "remote".
    You should ask about implementation for your target system or
    systems.</OT>

    --
    Ben.
     
    Ben Bacarisse, Jul 10, 2007
    #2
    1. Advertising

  3. Sune

    user923005 Guest

    On Jul 9, 8:41 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.


    Do you have any measurements that suggest TCP/IP is not fast enough?

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


    If you don't have CRCs then your transactions will be less secure. On
    the other hand, over the local bus, it is far less likely to have an
    error crop up.

    > 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?


    Yes, with a client/server metaphor.
    If you don't want to use TCP/IP, then use some other mechanism.

    However, the methods to achive this are beyond the scope of things
    discussed in news:comp.lang.c.
    Some of your goals are at odds with each other.

    I guess that what you really need to do is decide how fast and how
    safe your transactions need to be. Then you will need to decide what
    an acceptable performance goal is. If you don't write it down on
    paper, then there is no way to know if you are making progress towards
    it.

    Probably, a pre-built tool like MonetDB is what you really need,
    though you may think it is overkill.
    If you want things to be reliable, you will have to have transactions
    and the ability to roll back changes.
    That means a database. MonetDB is an in-memory database that allows
    multiple simultaneous writers which (I guess) is needed for your
    application.

    On the other hand, since I really have no idea what you are trying to
    accomplish I could be totally wrong.
    I have set the follow-ups to news:comp.programming since there is no C
    content in your queries (or in my answers for that matter).
    --
    comp.lang.c.moderated - moderation address: -- you must
    have an appropriate newsgroups line in your header for your mail to be seen,
    or the newsgroup name in square brackets in the subject line. Sorry.
     
    user923005, Jul 13, 2007
    #3
  4. Sune

    Azhar Guest

    On Jul 10, 8:41 am, 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 if 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
    > --
    > comp.lang.c.moderated - moderation address: -- you must
    > have an appropriate newsgroups line in your header for your mail to be seen,
    > or the newsgroup name in square brackets in the subject line. Sorry.


    Yes one can very well do that.
    infact that is the way one does memory allocation in embedded
    devices.
    You could allocate a pool and guard this pool by apt usage of
    semaphores. Next you could could expose a Callback stucture which may
    be point to fiunction that do operations like allocating the desired
    memory or deallocating, Reading from a location and writing to a
    locations.
    What you reaaly have to care of is that no one encroaches its desired
    area.
    --
    comp.lang.c.moderated - moderation address: -- you must
    have an appropriate newsgroups line in your header for your mail to be seen,
    or the newsgroup name in square brackets in the subject line. Sorry.
     
    Azhar, Jul 13, 2007
    #4
  5. Sune

    santosh Guest

    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.


    You asked this exact same question to this group a while back. This is
    not really a question to do with Standard C, but more of an operating
    system issue. You need to consult a group specific for your system.

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


    Have you actually measured the "overhead", or are you merely assuming
    it's unacceptable?

    > 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?


    And is this not going impose nearly as much overhead as the other
    methods?

    > If yes, how do I achieve this? If not, why not?
    >
    > Thanks for helping out
    > /Sune


    As I said, this is a general program design issue with connections to
    the system's memory and process management facilities. The
    implementation language is irrelevant. Consult a more specific group
    like comp.programming, comp.unix.programmer, comp.os.ms-
    windows.programmer.win32 etc.
    --
    comp.lang.c.moderated - moderation address: -- you must
    have an appropriate newsgroups line in your header for your mail to be seen,
    or the newsgroup name in square brackets in the subject line. Sorry.
     
    santosh, Jul 13, 2007
    #5
  6. Sune

    Darko Guest

    >
    > 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?
    >


    Write a couple of functions that access this shared memory segment
    (one for reading, another for writing and so on, whatever you need),
    and use semaphores in these functions.
    --
    comp.lang.c.moderated - moderation address: -- you must
    have an appropriate newsgroups line in your header for your mail to be seen,
    or the newsgroup name in square brackets in the subject line. Sorry.
     
    Darko, Jul 13, 2007
    #6
    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:
    842
  2. grbVRCPP
    Replies:
    0
    Views:
    837
    grbVRCPP
    Mar 13, 2007
  3. Sune
    Replies:
    14
    Views:
    873
    Chris Thomasson
    Aug 26, 2007
  4. Charles Fox (Sheffield)
    Replies:
    9
    Views:
    740
    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:
    129
    Phil C.
    Jun 29, 2005
Loading...

Share This Page