// CLASS METHODS void Allocator::throwBadAlloc() { BSLS_THROW(std::bad_alloc()); }
BSLS_BSLEXCEPTIONUTIL_NORETURN void BslExceptionUtil::throwException() { BSLS_THROW(std::exception()); }
void SharedPtrUtil::throwBadWeakPtr() { BSLS_THROW(bsl::bad_weak_ptr()); }
BSLS_BSLEXCEPTIONUTIL_NORETURN void BslExceptionUtil::throwBadCast() { BSLS_THROW(std::bad_cast()); }
BSLS_BSLEXCEPTIONUTIL_NORETURN void BslExceptionUtil::throwBadTypeid() { BSLS_THROW(std::bad_typeid()); }
BSLSTL_STDEXCEPTUTIL_NORETURN void StdExceptUtil::throwUnderflowError(const char *message) { BSLS_THROW(std::underflow_error(message)); }
// MANIPULATORS void *GuardingAllocator::allocate(size_type size) { if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(0 == size)) { BSLS_PERFORMANCEHINT_UNLIKELY_HINT; return 0; // RETURN } const size_type paddedSize = bsls::AlignmentUtil::roundUpToMaximalAlignment(size); // Adjust for additional memory needed to stash reference addresses when // 'e_AFTER_USER_BLOCK' is in use. const int adjustedSize = e_AFTER_USER_BLOCK == d_guardPageLocation ? paddedSize + OFFSET * 2 : paddedSize; // Calculate the number of pages to allocate, *not* counting the guard // page. const int pageSize = getSystemPageSize(); const int numPages = (adjustedSize + pageSize - 1) / pageSize; const size_type totalSize = (numPages + 1) * pageSize; // add 1 for guard void *firstPage = systemAlloc(totalSize); if (!firstPage) { #ifdef BDE_BUILD_TARGET_EXC BSLS_THROW(bsl::bad_alloc()); #else return 0; // RETURN #endif } void *userAddress; // address to return to the caller void *guardPage; // address of the guard page for this allocation if (e_BEFORE_USER_BLOCK == d_guardPageLocation) { // Protect the memory page before the block returned to the user. guardPage = firstPage; userAddress = static_cast<char *>(firstPage) + pageSize; } else { // Protect the memory page after the block returned to the user. guardPage = static_cast<char *>(firstPage) + (numPages * pageSize); userAddress = static_cast<char *>(guardPage) - paddedSize; // Stash the reference addresses required by 'deallocate'. *(void **)(static_cast<char *>(userAddress) - OFFSET) = firstPage; *(void **)(static_cast<char *>(userAddress) - OFFSET * 2) = guardPage; } // Protect the guard page from read/write access. if (0 != systemProtect(guardPage, pageSize)) { systemFree(firstPage); #ifdef BDE_BUILD_TARGET_EXC BSLS_THROW(bsl::bad_alloc()); #else return 0; // RETURN #endif } return userAddress; }
BSLSTL_STDEXCEPTUTIL_NORETURN void StdExceptUtil::throwRangeError(const char *message) { BSLS_THROW(std::range_error(message)); }
BSLSTL_STDEXCEPTUTIL_NORETURN void StdExceptUtil::throwOutOfRange(const char *message) { BSLS_THROW(std::out_of_range(message)); }
BSLSTL_STDEXCEPTUTIL_NORETURN void StdExceptUtil::throwLengthError(const char *message) { BSLS_THROW(std::length_error(message)); }
BSLSTL_STDEXCEPTUTIL_NORETURN void StdExceptUtil::throwInvalidArgument(const char *message) { BSLS_THROW(std::invalid_argument(message)); }
BSLSTL_STDEXCEPTUTIL_NORETURN void StdExceptUtil::throwDomainError(const char *message) { BSLS_THROW(std::domain_error(message)); }