diff options
author | lloyd <lloyd@randombit.net> | 2006-08-09 02:31:28 +0000 |
---|---|---|
committer | lloyd <lloyd@randombit.net> | 2006-08-09 02:31:28 +0000 |
commit | f0b0fc8c01c442221ff9442d3792c4a8a408dfdb (patch) | |
tree | 77aec21ad8050037a3dab665d2ac4e0361d36eba /modules/alloc_mmap | |
parent | b1557adf97fdcd4075da339e05bb5cab6e80eb12 (diff) |
Add an exception type specific for MemoryMapping_Allocator, simply to cut
down on repeated strings a bit.
Diffstat (limited to 'modules/alloc_mmap')
-rw-r--r-- | modules/alloc_mmap/mmap_mem.cpp | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/modules/alloc_mmap/mmap_mem.cpp b/modules/alloc_mmap/mmap_mem.cpp index d2e66d0cc..a55a54869 100644 --- a/modules/alloc_mmap/mmap_mem.cpp +++ b/modules/alloc_mmap/mmap_mem.cpp @@ -27,6 +27,20 @@ namespace Botan { +namespace { + +/************************************************* +* MemoryMapping_Allocator Exception * +*************************************************/ +class MemoryMapping_Failed : public Exception + { + public: + MemoryMapping_Failed(const std::string& msg) : + Exception("MemoryMapping_Allocator: " + msg) {} + }; + +} + /************************************************* * Memory Map a File into Memory * *************************************************/ @@ -42,20 +56,21 @@ void* MemoryMapping_Allocator::alloc_block(u32bit n) umask(old_umask); if(fd == -1) - throw Exception("MemoryMapping_Allocator: Could not create file"); + throw MemoryMapping_Failed("Could not create file"); if(unlink(filepath)) - throw Exception("MemoryMapping_Allocator: Could not unlink file " + - std::string(filepath)); + throw MemoryMapping_Failed("Could not unlink file " + + std::string(filepath)); + delete[] filepath; lseek(fd, n-1, SEEK_SET); if(write(fd, "\0", 1) != 1) - throw Exception("MemoryMapping_Allocator: Could not write to file"); + throw MemoryMapping_Failed("Could not write to file"); void* ptr = mmap(0, n, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if(ptr == (void*)MAP_FAILED) - throw Exception("MemoryMapping_Allocator: Could not map file"); + throw MemoryMapping_Failed("Could not map file"); if(close(fd)) - throw Exception("MemoryMapping_Allocator: Could not close file"); + throw MemoryMapping_Failed("Could not close file"); return ptr; } @@ -75,14 +90,14 @@ void MemoryMapping_Allocator::dealloc_block(void* ptr, u32bit n) { std::memset(ptr, PATTERNS[j % sizeof(PATTERNS)], n); if(msync(ptr, n, MS_SYNC)) - throw Exception("MemoryMapping_Allocator: Sync operation failed"); + throw MemoryMapping_Failed("Sync operation failed"); } std::memset(ptr, 0, n); if(msync(ptr, n, MS_SYNC)) - throw Exception("MemoryMapping_Allocator: Sync operation failed"); + throw MemoryMapping_Failed("Sync operation failed"); if(munmap(ptr, n)) - throw Exception("MemoryMapping_Allocator: Could not unmap file"); + throw MemoryMapping_Failed("Could not unmap file"); } } |