Skip to content

Commit

Permalink
Merge pull request #3 from Dr15Jones/annotate_interprocess_exception
Browse files Browse the repository at this point in the history
Better annotate interprocess_exception
  • Loading branch information
smuzaffar authored Dec 16, 2022
2 parents eb41967 + fc6a197 commit d4f566f
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 48 deletions.
18 changes: 9 additions & 9 deletions boost/interprocess/detail/managed_open_or_create_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ class managed_open_or_create_impl
//File existing when trying to create, but non-existing when
//trying to open, and tried MaxCreateOrOpenTries times. Something fishy
//is happening here and we can't solve it
throw interprocess_exception(error_info(corrupted_error));
throw interprocess_exception(error_info(corrupted_error), "do_create_else_open: file exists when trying to create, but not when trying to open");
}
else{
BOOST_TRY{
Expand Down Expand Up @@ -367,7 +367,7 @@ class managed_open_or_create_impl
}
else{
atomic_write32(patomic_word, CorruptedSegment);
throw interprocess_exception(error_info(corrupted_error));
throw interprocess_exception(error_info(corrupted_error), "do_map_after_create: corrupted segment");
}
}
BOOST_CATCH(...){
Expand Down Expand Up @@ -401,7 +401,7 @@ class managed_open_or_create_impl
while(1){
if(!get_file_size(file_handle_from_mapping_handle(dev.get_mapping_handle()), filesize)){
error_info err = system_error_code();
throw interprocess_exception(err);
throw interprocess_exception(err, "do_map_after_open: get_file_size failed");
}
if (filesize != 0)
break;
Expand All @@ -410,14 +410,14 @@ class managed_open_or_create_impl
//to minimally increase the size of the file: something bad has happened
const usduration elapsed(microsec_clock<ustime>::universal_time() - ustime_start);
if (elapsed > TimeoutSec){
throw interprocess_exception(error_info(corrupted_error));
throw interprocess_exception(error_info(corrupted_error), "do_map_after_open: too much elapsed time in get_file_size");
}
swait.yield();
}
}
//The creator detected an error creating the file and signalled it with size 1
if(filesize == 1){
throw interprocess_exception(error_info(corrupted_error));
throw interprocess_exception(error_info(corrupted_error), "do_map_after_open: creating of file failed");
}
}

Expand All @@ -431,13 +431,13 @@ class managed_open_or_create_impl
spin_wait swait;
while ((value = atomic_read32(patomic_word)) != InitializedSegment){
if(value == CorruptedSegment){
throw interprocess_exception(error_info(corrupted_error));
throw interprocess_exception(error_info(corrupted_error), "do_map_after_open: corrupted segment");
}
//More than MaxZeroTruncateTimeSec seconds waiting to the creator
//to minimally increase the size of the file: something bad has happened
const usduration elapsed(microsec_clock<ustime>::universal_time() - ustime_start);
if (elapsed > TimeoutSec){
throw interprocess_exception(error_info(corrupted_error));
throw interprocess_exception(error_info(corrupted_error), "do_map_after_open: too much time elapsed in reading patomic_word");
}
swait.yield();
}
Expand Down Expand Up @@ -470,11 +470,11 @@ class managed_open_or_create_impl
const std::size_t func_min_size = construct_func.get_min_size();
if( (std::size_t(-1) - ManagedOpenOrCreateUserOffset) < func_min_size ||
size < (func_min_size + ManagedOpenOrCreateUserOffset) ){
throw interprocess_exception(error_info(size_error));
throw interprocess_exception(error_info(size_error), "priv_open_or_create: insufficient size");
}
//Check size can be represented by offset_t (used by truncate)
if (!check_offset_t_size<FileBased>(size, file_like_t())){
throw interprocess_exception(error_info(size_error));
throw interprocess_exception(error_info(size_error),"priv_open_or_create: size does not fit as offset_t");
}
}

Expand Down
8 changes: 4 additions & 4 deletions boost/interprocess/detail/shared_dir_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ struct shared_dir_constants<wchar_t>
//Throw if bootstamp not available
if(!winapi::get_last_bootup_time(stamp)){
error_info err = system_error_code();
throw interprocess_exception(err);
throw interprocess_exception(err, "windows_bootstamp: winapi::get_last_bootup_time failed");
}
}
//Use std::string. Even if this will be constructed in shared memory, all
Expand Down Expand Up @@ -139,7 +139,7 @@ inline void get_shared_dir_root(std::basic_string<CharT> &dir_path)
//We always need this path, so throw on error
if(dir_path.empty()){
error_info err = system_error_code();
throw interprocess_exception(err);
throw interprocess_exception(err, "get_shared_dir_root: empty dir_path");
}

dir_path += shared_dir_constants<CharT>::dir_interprocess();
Expand Down Expand Up @@ -211,7 +211,7 @@ inline void create_shared_dir_and_clean_old(std::basic_string<CharT> &shared_dir
//If fails, check that it's because already exists
if(!open_or_create_shared_directory(root_shared_dir.c_str())){
error_info info(system_error_code());
throw interprocess_exception(info);
throw interprocess_exception(info, "create_shared_dir_and_clean_old: open_or_create_shared_directory failed");
}

#if defined(BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME)
Expand All @@ -220,7 +220,7 @@ inline void create_shared_dir_and_clean_old(std::basic_string<CharT> &shared_dir
//If fails, check that it's because already exists
if(!open_or_create_shared_directory(shared_dir.c_str())){
error_info info(system_error_code());
throw interprocess_exception(info);
throw interprocess_exception(info, "open_or_create_shared_directory: open_or_create_shared_directory");
}
//Now erase all old directories created in the previous boot sessions
std::basic_string<CharT> subdir = shared_dir;
Expand Down
4 changes: 2 additions & 2 deletions boost/interprocess/exceptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class BOOST_SYMBOL_VISIBLE interprocess_exception : public std::exception
BOOST_CATCH(...) {} BOOST_CATCH_END
}

interprocess_exception(const error_info &err_info, const char *str = 0)
interprocess_exception(const error_info &err_info, const char *str /*= 0*/)
: m_err(err_info)
{
BOOST_TRY{
Expand Down Expand Up @@ -83,7 +83,7 @@ class BOOST_SYMBOL_VISIBLE lock_exception : public interprocess_exception
{
public:
lock_exception(error_code_t err = lock_error) BOOST_NOEXCEPT
: interprocess_exception(err)
: interprocess_exception(err, "lock_exception")
{}

const char* what() const BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE
Expand Down
28 changes: 14 additions & 14 deletions boost/interprocess/mapped_region.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ inline void mapped_region::priv_size_from_mapping_size
boost::uintmax_t(mapping_size - (offset - page_offset)) >
boost::uintmax_t(std::size_t(-1))){
error_info err(size_error);
throw interprocess_exception(err);
throw interprocess_exception(err, "mapped_region::priv_size_from_mapping_size failed");
}
size = static_cast<std::size_t>(mapping_size - offset);
}
Expand Down Expand Up @@ -426,7 +426,7 @@ inline mapped_region::mapped_region
default:
{
error_info err(mode_error);
throw interprocess_exception(err);
throw interprocess_exception(err, "mapped_region::ctr unknown mode");
}
break;
}
Expand All @@ -446,7 +446,7 @@ inline mapped_region::mapped_region
//Check if all is correct
if(!native_mapping_handle){
error_info err ((int)winapi::get_last_error());
throw interprocess_exception(err);
throw interprocess_exception(err, "mapped_region::ctr winapi::create_file_mapping failed");
}
handle_to_close = native_mapping_handle;
}
Expand All @@ -466,7 +466,7 @@ inline mapped_region::mapped_region
offset_t mapping_size;
if(!winapi::get_file_mapping_size(native_mapping_handle, mapping_size)){
error_info err((int)winapi::get_last_error());
throw interprocess_exception(err);
throw interprocess_exception(err, "mapped_region::ctr: get_file_mapping_size failed");
}
//This can throw
priv_size_from_mapping_size(mapping_size, offset, page_offset, size);
Expand All @@ -482,7 +482,7 @@ inline mapped_region::mapped_region
//Check error
if(!base){
error_info err((int)winapi::get_last_error());
throw interprocess_exception(err);
throw interprocess_exception(err, "mapped_region::ctr: winapi::map_view_of_file_ex failed");
}

//Calculate new base for the user
Expand All @@ -497,7 +497,7 @@ inline mapped_region::mapped_region
if(!winapi::duplicate_current_process_handle(mhandle.handle, &m_file_or_mapping_hnd)){
error_info err((int)winapi::get_last_error());
this->priv_close();
throw interprocess_exception(err);
throw interprocess_exception(err, "mapped_region::ctr: winapi::duplicate_current_process_handle failed");
}
}

Expand Down Expand Up @@ -600,15 +600,15 @@ inline mapped_region::mapped_region
int ret = ::shmctl(map_hnd.handle, IPC_STAT, &xsi_ds);
if(ret == -1){
error_info err(system_error_code());
throw interprocess_exception(err);
throw interprocess_exception(err, "mapped_region::ctr: shmctl failed");
}
//Compare sizess
if(size == 0){
size = (std::size_t)xsi_ds.shm_segsz;
}
else if(size != (std::size_t)xsi_ds.shm_segsz){
error_info err(size_error);
throw interprocess_exception(err);
throw interprocess_exception(err, "mapped_region::ctr: size not xsi_ds.shm_segsz");
}
//Calculate flag
int flag = map_options == default_map_options ? 0 : map_options;
Expand All @@ -617,7 +617,7 @@ inline mapped_region::mapped_region
}
else if(m_mode != read_write){
error_info err(mode_error);
throw interprocess_exception(err);
throw interprocess_exception(err, "mapped_region::ctr: unknown mode");
}
//Attach memory
//Some old shmat implementation take the address as a non-const void pointer
Expand All @@ -626,7 +626,7 @@ inline mapped_region::mapped_region
void *base = ::shmat(map_hnd.handle, final_address, flag);
if(base == (void*)-1){
error_info err(system_error_code());
throw interprocess_exception(err);
throw interprocess_exception(err, "mapped_region::ctr: shmat failed");
}
//Update members
m_base = base;
Expand All @@ -645,7 +645,7 @@ inline mapped_region::mapped_region
struct ::stat buf;
if(0 != fstat(map_hnd.handle, &buf)){
error_info err(system_error_code());
throw interprocess_exception(err);
throw interprocess_exception(err, "mapped_region::ctr: fstat == 0");
}
//This can throw
priv_size_from_mapping_size(buf.st_size, offset, page_offset, size);
Expand Down Expand Up @@ -688,7 +688,7 @@ inline mapped_region::mapped_region
default:
{
error_info err(mode_error);
throw interprocess_exception(err);
throw interprocess_exception(err, "mapped_region::ctr: unknown mode");
}
break;
}
Expand All @@ -704,7 +704,7 @@ inline mapped_region::mapped_region
//Check if mapping was successful
if(base == MAP_FAILED){
error_info err = system_error_code();
throw interprocess_exception(err);
throw interprocess_exception(err, "mapped_region::ctr: mmap failed");
}

//Calculate new base for the user
Expand All @@ -716,7 +716,7 @@ inline mapped_region::mapped_region
if(address && (base != address)){
error_info err(busy_error);
this->priv_close();
throw interprocess_exception(err);
throw interprocess_exception(err, "mapped_region::ctr: fixed mapping error");
}
}

Expand Down
2 changes: 1 addition & 1 deletion boost/interprocess/segment_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,7 @@ class segment_manager
return it->get_block_header()->value();
}
if(dothrow){
throw interprocess_exception(already_exists_error);
throw interprocess_exception(already_exists_error,"priv_generic_named_construct: dowthrow == true");
}
else{
return 0;
Expand Down
18 changes: 9 additions & 9 deletions boost/interprocess/shared_memory_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ inline bool shared_memory_object::priv_open_or_create
//Set accesses
if (mode != read_write && mode != read_only){
error_info err = other_error;
throw interprocess_exception(err);
throw interprocess_exception(err, "shared_memory_object::priv_open_or_create shared dir failure");
}

switch(type){
Expand All @@ -250,15 +250,15 @@ inline bool shared_memory_object::priv_open_or_create
default:
{
error_info err = other_error;
throw interprocess_exception(err);
throw interprocess_exception(err, "shared_memory_object::priv_open_or_create unknown type");
}
}

//Check for error
if(m_handle == ipcdetail::invalid_file()){
error_info err = system_error_code();
this->priv_close();
throw interprocess_exception(err);
throw interprocess_exception(err, "shared_memory_object::priv_open_or_create invalid_file");
}

m_mode = mode;
Expand Down Expand Up @@ -299,7 +299,7 @@ inline void shared_memory_object::truncate(offset_t length)
{
if(!ipcdetail::truncate_file(m_handle, (std::size_t)length)){
error_info err = system_error_code();
throw interprocess_exception(err);
throw interprocess_exception(err, "shared_memory_object::truncate");
}
}

Expand Down Expand Up @@ -366,7 +366,7 @@ inline bool shared_memory_object::priv_open_or_create
}
else{
error_info err(mode_error);
throw interprocess_exception(err);
throw interprocess_exception(err, "shared_memory_object::priv_open_or_create unknown mode");
}
::mode_t unix_perm = perm.get_permissions();

Expand Down Expand Up @@ -414,15 +414,15 @@ inline bool shared_memory_object::priv_open_or_create
default:
{
error_info err = other_error;
throw interprocess_exception(err);
throw interprocess_exception(err, "shared_memory_object::priv_open_or_create type unknown");
}
}

//Check for error
if(m_handle < 0){
error_info err = errno;
this->priv_close();
throw interprocess_exception(err);
throw interprocess_exception(err, "shared_memory_object::priv_open_or_create shm_open failed");
}

m_filename = filename;
Expand Down Expand Up @@ -464,7 +464,7 @@ inline void shared_memory_object::truncate(offset_t length)

if (ret && ret != EOPNOTSUPP && ret != ENODEV){
error_info err(ret);
throw interprocess_exception(err);
throw interprocess_exception(err, "shared_memory_object::truncate posix failure");
}
//ftruncate fallback
#endif //BOOST_INTERPROCESS_POSIX_FALLOCATE
Expand All @@ -474,7 +474,7 @@ inline void shared_memory_object::truncate(offset_t length)
if (errno == EINTR)
goto handle_eintr;
error_info err(system_error_code());
throw interprocess_exception(err);
throw interprocess_exception(err, "shared_memory_object::truncate failure");
}
}

Expand Down
4 changes: 2 additions & 2 deletions boost/interprocess/sync/posix/condition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,12 @@ inline posix_condition::posix_condition()
res = pthread_condattr_setpshared(&cond_attr, PTHREAD_PROCESS_SHARED);
if(res != 0){
pthread_condattr_destroy(&cond_attr);
throw interprocess_exception(res);
throw interprocess_exception(res,"posix_condition::ctr pthread_condattr_setpshared failed");
}
res = pthread_cond_init(&m_condition, &cond_attr);
pthread_condattr_destroy(&cond_attr);
if(res != 0){
throw interprocess_exception(res);
throw interprocess_exception(res, "posix_condition::ctr pthread_cond_init failed");
}
}

Expand Down
Loading

0 comments on commit d4f566f

Please sign in to comment.