| 2514 | #ifdef HAVE_MMAP |
| 2515 | #define ISC_REMAP_FILE_DEFINED |
| 2516 | bool SharedMemoryBase::remapFile(CheckStatusWrapper* statusVector, ULONG new_length, bool flag) |
| 2517 | { |
| 2518 | /************************************** |
| 2519 | * |
| 2520 | * I S C _ r e m a p _ f i l e ( U N I X - m m a p ) |
| 2521 | * |
| 2522 | ************************************** |
| 2523 | * |
| 2524 | * Functional description |
| 2525 | * Try to re-map a given file. |
| 2526 | * |
| 2527 | **************************************/ |
| 2528 | if (!new_length) |
| 2529 | { |
| 2530 | error(statusVector, "Zero new_length is requested", 0); |
| 2531 | return false; |
| 2532 | } |
| 2533 | |
| 2534 | if (flag) |
| 2535 | { |
| 2536 | new_length = FB_ALIGN(new_length, getSystemPageSize(statusVector)); |
| 2537 | |
| 2538 | FB_UNUSED(os_utils::ftruncate(mainLock->getFd(), new_length)); |
| 2539 | |
| 2540 | if (new_length > sh_mem_length_mapped) |
| 2541 | { |
| 2542 | if (!allocFileSpace(mainLock->getFd(), sh_mem_length_mapped, |
| 2543 | new_length - sh_mem_length_mapped, statusVector)) |
| 2544 | { |
| 2545 | return false; |
| 2546 | } |
| 2547 | } |
| 2548 | } |
| 2549 | |
| 2550 | MemoryHeader* const address = (MemoryHeader*) os_utils::mmap(0, new_length, |
| 2551 | PROT_READ | PROT_WRITE, MAP_SHARED, mainLock->getFd(), 0); |
| 2552 | |
| 2553 | if ((U_IPTR) address == (U_IPTR) -1) |
| 2554 | { |
| 2555 | error(statusVector, "mmap() failed", errno); |
| 2556 | return false; |
| 2557 | } |
| 2558 | |
| 2559 | munmap(sh_mem_header, sh_mem_length_mapped); |
| 2560 | |
| 2561 | IPC_TRACE(("ISC_remap_file %p to %p %d\n", sh_mem_header, address, new_length)); |
| 2562 | |
| 2563 | sh_mem_header = (MemoryHeader*) address; |
| 2564 | sh_mem_length_mapped = new_length; |
| 2565 | |
| 2566 | #if defined(HAVE_SHARED_MUTEX_SECTION) && !defined(USE_MUTEX_MAP) |
| 2567 | sh_mem_mutex = &sh_mem_header->mhb_mutex; |
| 2568 | #endif |
| 2569 | |
| 2570 | return address; |
| 2571 | } |
| 2572 | #endif // HAVE_MMAP |
| 2573 | #endif // UNIX |
no test coverage detected