2 * @file Bug_3911_Regression_Test.cpp
4 * Reproduces the problem reported in bug 3911
5 * http://bugzilla.dre.vanderbilt.edu/show_bug.cgi?id=3911
8 #include "test_config.h"
10 #include <ace/Malloc_T.h>
11 #include <ace/Memory_Pool.h>
12 #include <ace/Process_Mutex.h>
13 #include <ace/Null_Mutex.h>
14 #include <ace/PI_Malloc.h>
16 #define MMAP_FILENAME ACE_TEXT ("shared_memory")
21 // Cleanup the MMAP file so we won't trip over the leftover mmap
22 // file from the previous crash.
23 ACE_MMAP_Memory_Pool_Options
options (ACE_DEFAULT_BASE_ADDR
);
24 //FUZZ: disable check_for_lack_ACE_OS
25 ACE_MMAP_Memory_Pool
mmap (MMAP_FILENAME
, &options
);
26 //FUZZ: enable check_for_lack_ACE_OS
30 mmap
.init_acquire (1024, rbyte
, ft
);
37 // Used to implement the singleton pattern:
38 static ShmemMan
* c_instance
;
40 // The memory pool managing all the shared memory:
41 ACE_Malloc_T
<ACE_MMAP_MEMORY_POOL
,
43 ACE_PI_Control_Block
>* c_memory_pool
;
46 ShmemMan(bool no_crash
)
50 ACE_MMAP_Memory_Pool_Options
options (ACE_DEFAULT_BASE_ADDR
);
51 c_memory_pool
= new ACE_Malloc_T
<ACE_MMAP_MEMORY_POOL
,
53 ACE_PI_Control_Block
>(MMAP_FILENAME
54 , ACE_TEXT(""), &options
59 c_memory_pool
= new ACE_Malloc_T
<ACE_MMAP_MEMORY_POOL
,
61 ACE_PI_Control_Block
>(MMAP_FILENAME
);
68 c_memory_pool
->release();
72 static ShmemMan
* getInstance(bool no_crash
)
76 c_instance
= new ShmemMan(no_crash
);
83 c_memory_pool
->release();
84 c_memory_pool
->remove();
89 void* getMemoryBlock(const char* block_name
, unsigned int block_size
)
93 ACE_DEBUG((LM_INFO
, ACE_TEXT("errno = %d. Looking for a Shared Memory block named %C\n"),
97 if (c_memory_pool
->find(block_name
, shared
) == 0)
99 // An existing block was found, so take that:
100 ACE_DEBUG((LM_INFO
, ACE_TEXT("Shared Memory block %C was found."),
105 // Allocate the memory and bind it to a name:
106 ACE_DEBUG((LM_INFO
, ACE_TEXT("Shared Memory block %C was not found. errno = %d. Trying to allocate new block\n"),
108 ACE_OS::last_error()));
109 shared
= c_memory_pool
->malloc(block_size
);
110 // reinterpret_cast due to some compilers warning against ordering pointers with integers
111 if (ptrdiff_t (shared
) < 0)
113 ACE_DEBUG((LM_INFO
, ACE_TEXT("New Shared Memory block could not be allocated. errno = %d.\n"),
114 ACE_OS::last_error()));
117 ACE_DEBUG((LM_INFO
, ACE_TEXT("New Shared Memory block was allocated, trying to bind it to the name %C\n"),
119 if (c_memory_pool
->bind(block_name
, shared
) < 0)
121 ACE_DEBUG((LM_INFO
, ACE_TEXT("New Shared Memory block could not be bound to the name %C. errno = %d.\n"),
123 ACE_OS::last_error()));
133 ShmemMan
* ShmemMan::c_instance
= 0;
135 const char* block_name
= "block_1";
139 run_main (int argc
, ACE_TCHAR
* argv
[])
141 ACE_START_TEST (ACE_TEXT ("Bug_3911_Regression_Test"));
145 bool no_crash
= (argc
>1 && argv
[1][0]=='1');
146 ShmemMan
* smm
= ShmemMan::getInstance (no_crash
);
148 void* buf
= smm
->getMemoryBlock (block_name
, 10 * 4096);
150 ACE_DEBUG((LM_INFO
, ACE_TEXT("allocated shmem block at %@\n"), buf
));