NSPR Reference Previous Contents Next |
Shared Memory Protocol
Named Shared Memory Functions
PR_OpenSharedMemory
call
should be manipulated according to the protocol described here. Failing to follow
the protocol may yield unpredictable results.
Using Named Shared Memory Functions
Filenames
Limits on Shared Memory Resources
Security Considerations
PR_OpenSharedMemory
creates the shared memory segment, if it does not already
exist, or opens a connection with the existing shared memory segment if it already
exists.
PR_AttachSharedMemory
should be called following PR_OpenSharedMemory
to
map the memory segment to an address in the application's address space.
PR_AttachSharedMemory
may also be called to remap a shared memory segment
after detaching the same PRSharedMemory
object. Be sure to detach it when you're
finished.
PR_DetachSharedMemory
should be called to unmap the shared memory segment
from the application's address space.
PR_CloseSharedMemory
should be called when no further use of the
PRSharedMemory
object is required within a process. Following a call to
PR_CloseSharedMemory
, the PRSharedMemory
object is invalid and cannot be
reused.
PR_DeleteSharedMemory
should be called before process termination. After you
call PR_DeleteSharedMemory
, any further use of the shared memory associated
with the name may cause unpredictable results.
PR_OpenSharedMemory
should be a valid filename for a Unix
platform. PR_OpenSharedMemory
creates file using the name passed in. Some
platforms may mangle the name before creating the file and the shared memory.
The Unix implementation may use SysV IPC shared memory, Posix shared
memory, or memory mapped files; the filename may be used to define the
namespace. On Windows, the name is significant, but there is no file associated
with the name.
No assumptions about the persistence of data in the named file should be made. Depending on platform, the shared memory may be mapped onto system paging space and be discarded at process termination.
All names provided to PR_OpenSharedMemory
should be valid filename syntax or
name syntax for shared memory for the target platform. Referenced directories
should have permissions appropriate for writing.
On Windows platforms, no special security measures are provided.
PR_OpenSharedMemory
PR_AttachSharedMemory
PR_DetachSharedMemory
PR_CloseSharedMemory
PR_DeleteSharedMemory
#include <prshm.h>
NSPR_API( PRSharedMemory * )
PR_OpenSharedMemory(
const char *name,
PRSize size,
PRIntn flags,
PRIntn mode
);
/* Define values for PR_OpenShareMemory(...,create) */
#define PR_SHM_CREATE 0x1 /* create if not exist */
#define PR_SHM_EXCL 0x2 /* fail if already exists */
name |
The name of the shared memory segment.
|
size |
The size of the shared memory segment.
|
flags |
Options for creating the shared memory.
|
mode |
Same as passed to PR_Open .
|
PRSharedMemory
, or NULL
if an error occurs. Retrieve
the reason for the failure by calling PR_GetError
and PR_GetOSError
.
PR_OpenSharedMemory
creates a new shared memory segment or associates a
previously created memory segment with the specified name. When parameter
create
is (PR_SHM_EXCL | PR_SHM_CREATE)
and the shared memory already
exists, the function returns NULL
with the error set to PR_FILE_EXISTS_ERROR
.
When parameter create
is PR_SHM_CREATE
and the shared memory already exists,
a handle to that memory segment is returned. If the segment does not exist, it is
created and a pointer to the related PRSharedMemory
structure is returned.
When parameter create
is 0, and the shared memory exists, a pointer to a
PRSharedMemory
structure is returned. If the shared memory does not exist, NULL
is
returned with the error set to PR_FILE_NOT_FOUND_ERROR
.
PR_OpenSharedMemory
and
maps it into the process memory space.
#include <prshm.h>
NSPR_API( void * )
PR_AttachSharedMemory(
PRSharedMemory *shm,
PRIntn flags
);
/* Define values for PR_AttachSharedMemory(...,flags) */
#define PR_SHM_READONLY 0x01
shm |
The handle returned from PR_OpenSharedMemory .
|
flags |
Options for mapping the shared memory. PR_SHM_READONLY causes
the memory to be attached read-only.
|
NULL
if an error occurs. Retrieve the
reason for the failure by calling PR_GetError
and PR_GetOSError
.
#include <prshm.h>
NSPR_API( PRStatus )
PR_DetachSharedMemory(
PRSharedMemory *shm,
void *addr
);
shm |
The handle returned from PR_OpenSharedMemory .
|
|
The address to which the shared memory segment is mapped.
|
PRStatus
.
#include <prshm.h>
NSPR_API( PRStatus )
PR_CloseSharedMemory(
PRSharedMemory *shm
);
|
The handle returned from PR_OpenSharedMemory .
|
PRStatus
.
#include <prshm.h>
NSPR_API( PRStatus )
PR_DeleteSharedMemory(
const char *name
);
shm |
The handle returned from PR_OpenSharedMemory .
|
PRStatus
.
Last Updated May 18, 2001