TransWikia.com

SIGBUS immediately after successful mremap for shared memory

Unix & Linux Asked by RTC222 on February 20, 2021

I am using POSIX shared memory. Initially I map four shared memory buffers. One of them exceeds its allocated size so I call mremap:

void * remap_shm(void *old_address, size_t old_size, size_t new_size)
{

    void * return_ptr;

    return_ptr = mremap(old_address, old_size, new_size, MREMAP_MAYMOVE);

    if (return_ptr <= 0){
        printf("Error on remap! %sn", strerror(errno)); }

    return return_ptr;
}

That successfully gets a pointer to a new mapping, but immediately after the remap I try to write past the end of the old mapping and get a SIGBUS error. However, I can still read from the original buffer area (the first ~8MB) using the new pointer, but I can’t read/write past the end of it the original ~8MB, even though it’s been remapped to a larger size.

The old memory was 8003584 and the new memory is double that size (16007168). Those sizes are even multiples of 4,096 (the page size). This is being called from a shared object, if that’s relevant.

I know that SIGBUS errors can happen with memory mapped pages, but why am I getting that here? Everything looks correct as described at https://www.man7.org/linux/man-pages//man2/mremap.2.html.

Thanks for any ideas on this.

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP