(file) Return to shmem.h CVS log (file) (dir) Up to [OMI] / omi / pal

  1 krisbash 1.1 #ifndef _pal_shmem_h
  2              #define _pal_shmem_h
  3              
  4              
  5              #include <stddef.h>
  6              #include "palcommon.h"
  7              
  8              #if defined(PAL_HAVE_POSIX)
  9              # include <unistd.h>
 10              # include <sys/mman.h>
 11              # include <sys/shm.h>
 12              # include <sys/stat.h>
 13              # include <fcntl.h>
 14              # include <string.h>
 15              #endif
 16              
 17              PAL_BEGIN_EXTERNC
 18              
 19              typedef struct _Shmem 
 20              {
 21              #if defined(_MSC_VER)
 22 krisbash 1.1     HANDLE handle;
 23              #else
 24                  int shmid;
 25                  char shmname[PAL_MAX_PATH_SIZE];
 26              #endif
 27              } 
 28              Shmem;
 29              
 30              typedef enum _ShmemUserAccess
 31              {
 32                  SHMEM_USER_ACCESS_DEFAULT = 1,
 33                  SHMEM_USER_ACCESS_ALLOW_ALL = 2
 34              } 
 35              ShmemUserAccess;
 36              
 37              typedef enum _ShmemAccess
 38              {
 39                  SHMEM_ACCESS_READONLY = 1,
 40                  SHMEM_ACCESS_READWRITE = 2
 41              }
 42              ShmemAccess;
 43 krisbash 1.1 
 44              int Shmem_Open(
 45                  _Out_ Shmem* self,
 46                  _In_z_ const PAL_Char* name,
 47                  _In_ ShmemAccess access,
 48                  ShmemUserAccess userAccess,
 49                  _In_ size_t size);
 50              
 51              PAL_INLINE int Shmem_Close(
 52                  _Inout_ Shmem* self)
 53              {
 54              #if defined(_MSC_VER)
 55                  return CloseHandle(self->handle) ? 0 : -1;
 56              #else
 57                  int status;
 58              
 59                  status = close(self->shmid) == 0 ? 0 : -1;
 60                  shm_unlink(self->shmname);
 61                  return status;
 62              #endif
 63              }
 64 krisbash 1.1 
 65              void* Shmem_Map(
 66                  _Inout_ Shmem* self,
 67                  _In_ ShmemAccess access,
 68                  _In_ ptrdiff_t offset,
 69                  _In_ size_t size);
 70              
 71              PAL_INLINE int Shmem_Unmap(
 72                  _Inout_ Shmem* self,
 73                  _In_ void* ptr,
 74                  _In_ size_t size)
 75              {
 76                  PAL_UNUSED(self);
 77                  PAL_UNUSED(ptr);
 78                  PAL_UNUSED(size);
 79              
 80              #if defined(_MSC_VER)
 81                  PAL_UNUSED(size);
 82                  return UnmapViewOfFile(ptr) ? 0 : -1;
 83              #else
 84                  return munmap(ptr, size) == 0 ? 0 : -1;
 85 krisbash 1.1 #endif
 86              }
 87              
 88              PAL_INLINE size_t Shmem_Granularity()
 89              {
 90              #if defined(_MSC_VER)
 91                  SYSTEM_INFO info;
 92                  GetSystemInfo(&info);
 93                  return info.dwAllocationGranularity;
 94              #else
 95                  return sysconf(_SC_PAGESIZE);
 96              #endif
 97              }
 98              
 99              PAL_END_EXTERNC
100              
101              #endif /* _pal_shmem_h */

ViewCVS 0.9.2