Method: ConcurrentSHM::Region.map

Defined in:
ext/concurrent-shm/posix.c

.map(file, off, len) ⇒ Region

Memory-map a region of a file or shared memory space. The region is read/write and shared.

Parameters:

  • the file or shared memory space

  • the offset of the region

  • the length of the region

Returns:

  • the mapped region

Raises:

  • if the file is not a regular file, or the file is not open for reading, not open for writing, or append-only

  • if the file is locked or too much memory has been locked

  • if file.lineno is not a valid file descriptor

  • if the length or offset are too large or the length is 0

  • if the system-wide limit on the total number of open files has been reached

  • if the underlying filesystem of the specified file does not support memory mapping

  • if no memory is available, or the process’s number of mappings limit has been reached

  • if the operation was prevented by a file seal



328
329
330
331
332
333
334
335
336
337
338
339
# File 'ext/concurrent-shm/posix.c', line 328

static VALUE region_map(VALUE self, VALUE file, VALUE off, VALUE len)
{
    UNUSED(self);

    int fd = FIX2INT(rb_funcall(file, rb_intern("fileno"), 0));
    void * data = mmap(NULL, FIX2INT(len), PROT_READ | PROT_WRITE, MAP_SHARED, fd, FIX2INT(off));
    if (data == MAP_FAILED) {
        rb_syserr_fail_strf(errno, "mmap(fd=%d, len=%d)", fd, FIX2INT(len));
    }

    return __new_region(data, FIX2INT(len), 1, file);
}