Back to index

php5  5.3.10
Functions
fpm_shm.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void * fpm_shm_alloc (size_t size)
int fpm_shm_free (void *mem, size_t size)
size_t fpm_shm_get_size_allocated ()

Function Documentation

void* fpm_shm_alloc ( size_t  size)

Definition at line 20 of file fpm_shm.c.

{
       void *mem;

       mem = mmap(0, size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, -1, 0);

#ifdef MAP_FAILED
       if (mem == MAP_FAILED) {
              zlog(ZLOG_SYSERROR, "unable to allocate %zu bytes in shared memory: %s", size, strerror(errno));
              return NULL;
       }
#endif

       if (!mem) {
              zlog(ZLOG_SYSERROR, "unable to allocate %zu bytes in shared memory", size);
              return NULL;
       }

       memset(mem, size, 0);
       fpm_shm_size += size;
       return mem;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int fpm_shm_free ( void *  mem,
size_t  size 
)

Definition at line 44 of file fpm_shm.c.

{
       if (!mem) {
              zlog(ZLOG_ERROR, "mem is NULL");
              return 0;
       }

       if (munmap(mem, size) == -1) {
              zlog(ZLOG_SYSERROR, "Unable to free shm");
              return 0;
       }

       if (fpm_shm_size - size > 0) {
              fpm_shm_size -= size;
       } else {
              fpm_shm_size = 0;
       }

       return 1;
}

Here is the caller graph for this function:

Definition at line 66 of file fpm_shm.c.

{
       return fpm_shm_size;
}

Here is the caller graph for this function: