aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc
diff options
context:
space:
mode:
Diffstat (limited to 'src/alloc')
-rw-r--r--src/alloc/alloc_mmap/mmap_mem.cpp27
-rw-r--r--src/alloc/alloc_mmap/mmap_mem.h7
-rw-r--r--src/alloc/allocate.h2
-rw-r--r--src/alloc/mem_pool/mem_pool.h2
-rw-r--r--src/alloc/secmem.h24
-rw-r--r--src/alloc/system_alloc/defalloc.h8
6 files changed, 40 insertions, 30 deletions
diff --git a/src/alloc/alloc_mmap/mmap_mem.cpp b/src/alloc/alloc_mmap/mmap_mem.cpp
index 4a7019ae7..a2059a6ea 100644
--- a/src/alloc/alloc_mmap/mmap_mem.cpp
+++ b/src/alloc/alloc_mmap/mmap_mem.cpp
@@ -6,6 +6,7 @@
*/
#include <botan/internal/mmap_mem.h>
+#include <vector>
#include <cstring>
#include <sys/types.h>
@@ -44,29 +45,38 @@ void* MemoryMapping_Allocator::alloc_block(u32bit n)
{
public:
int get_fd() const { return fd; }
- const std::string path() const { return filepath; }
TemporaryFile(const std::string& base)
{
- const std::string path = base + "XXXXXX";
+ const std::string mkstemp_template = base + "XXXXXX";
- filepath = new char[path.length() + 1];
- std::strcpy(filepath, path.c_str());
+ std::vector<char> filepath(mkstemp_template.begin(),
+ mkstemp_template.end());
+ filepath.push_back(0); // add terminating NULL
mode_t old_umask = ::umask(077);
- fd = ::mkstemp(filepath);
+ fd = ::mkstemp(&filepath[0]);
::umask(old_umask);
+
+ if(fd == -1)
+ throw MemoryMapping_Failed("Temporary file allocation failed");
+
+ if(::unlink(&filepath[0]) != 0)
+ throw MemoryMapping_Failed("Could not unlink temporary file");
}
~TemporaryFile()
{
- delete[] filepath;
+ /*
+ * We can safely close here, because post-mmap the file
+ * will continue to exist until the mmap is unmapped from
+ * our address space upon deallocation.
+ */
if(fd != -1 && ::close(fd) == -1)
throw MemoryMapping_Failed("Could not close file");
}
private:
int fd;
- char* filepath;
};
TemporaryFile file("/tmp/botan_");
@@ -74,9 +84,6 @@ void* MemoryMapping_Allocator::alloc_block(u32bit n)
if(file.get_fd() == -1)
throw MemoryMapping_Failed("Could not create file");
- if(::unlink(file.path().c_str()))
- throw MemoryMapping_Failed("Could not unlink file '" + file.path() + "'");
-
if(::lseek(file.get_fd(), n-1, SEEK_SET) < 0)
throw MemoryMapping_Failed("Could not seek file");
diff --git a/src/alloc/alloc_mmap/mmap_mem.h b/src/alloc/alloc_mmap/mmap_mem.h
index 14caf5db1..890658ebc 100644
--- a/src/alloc/alloc_mmap/mmap_mem.h
+++ b/src/alloc/alloc_mmap/mmap_mem.h
@@ -12,8 +12,11 @@
namespace Botan {
-/*
-* Memory Mapping Allocator
+/**
+* Allocator that uses memory maps backed by disk. We zeroize the map
+* upon deallocation. If swap occurs, the VM will swap to the shared
+* file backing rather than to a swap device, which means we know where
+* it is and can zap it later.
*/
class MemoryMapping_Allocator : public Pooling_Allocator
{
diff --git a/src/alloc/allocate.h b/src/alloc/allocate.h
index 180f2c021..819e2542c 100644
--- a/src/alloc/allocate.h
+++ b/src/alloc/allocate.h
@@ -13,7 +13,7 @@
namespace Botan {
-/*
+/**
* Allocator Interface
*/
class BOTAN_DLL Allocator
diff --git a/src/alloc/mem_pool/mem_pool.h b/src/alloc/mem_pool/mem_pool.h
index f0a564965..f2b57a73b 100644
--- a/src/alloc/mem_pool/mem_pool.h
+++ b/src/alloc/mem_pool/mem_pool.h
@@ -16,7 +16,7 @@
namespace Botan {
-/*
+/**
* Pooling Allocator
*/
class Pooling_Allocator : public Allocator
diff --git a/src/alloc/secmem.h b/src/alloc/secmem.h
index b3b3fa973..39b5549a9 100644
--- a/src/alloc/secmem.h
+++ b/src/alloc/secmem.h
@@ -24,7 +24,7 @@ class MemoryRegion
/**
* Find out the size of the buffer, i.e. how many objects of type T it
* contains.
- * @return the size of the buffer
+ * @return size of the buffer
*/
u32bit size() const { return used; }
@@ -36,37 +36,37 @@ class MemoryRegion
/**
* Get a pointer to the first element in the buffer.
- * @return a pointer to the first element in the buffer
+ * @return pointer to the first element in the buffer
*/
operator T* () { return buf; }
/**
* Get a constant pointer to the first element in the buffer.
- * @return a constant pointer to the first element in the buffer
+ * @return constant pointer to the first element in the buffer
*/
operator const T* () const { return buf; }
/**
* Get a pointer to the first element in the buffer.
- * @return a pointer to the first element in the buffer
+ * @return pointer to the first element in the buffer
*/
T* begin() { return buf; }
/**
* Get a constant pointer to the first element in the buffer.
- * @return a constant pointer to the first element in the buffer
+ * @return constant pointer to the first element in the buffer
*/
const T* begin() const { return buf; }
/**
* Get a pointer to the last element in the buffer.
- * @return a pointer to the last element in the buffer
+ * @return pointer to the last element in the buffer
*/
T* end() { return (buf + size()); }
/**
* Get a constant pointer to the last element in the buffer.
- * @return a constant pointer to the last element in the buffer
+ * @return constant pointer to the last element in the buffer
*/
const T* end() const { return (buf + size()); }
@@ -97,8 +97,8 @@ class MemoryRegion
/**
* Copy the contents of another buffer into this buffer.
* The former contents of *this are discarded.
- * @param in the buffer to copy the contents from.
- * @return a reference to *this
+ * @param other the buffer to copy the contents from.
+ * @return reference to *this
*/
MemoryRegion<T>& operator=(const MemoryRegion<T>& other)
{ if(this != &other) set(other); return (*this); }
@@ -156,7 +156,7 @@ class MemoryRegion
/**
* Append data to the end of this buffer.
- * @param data the buffer containing the data to append
+ * @param other the buffer containing the data to append
*/
void append(const MemoryRegion<T>& other)
{ append(other.begin(), other.size()); }
@@ -299,7 +299,7 @@ class MemoryVector : public MemoryRegion<T>
/**
* Copy the contents of another buffer into this buffer.
* @param in the buffer to copy the contents from
- * @return a reference to *this
+ * @return reference to *this
*/
MemoryVector<T>& operator=(const MemoryRegion<T>& in)
{ if(this != &in) set(in); return (*this); }
@@ -352,7 +352,7 @@ class SecureVector : public MemoryRegion<T>
/**
* Copy the contents of another buffer into this buffer.
* @param in the buffer to copy the contents from
- * @return a reference to *this
+ * @return reference to *this
*/
SecureVector<T>& operator=(const MemoryRegion<T>& in)
{ if(this != &in) set(in); return (*this); }
diff --git a/src/alloc/system_alloc/defalloc.h b/src/alloc/system_alloc/defalloc.h
index 436549540..54583d7b1 100644
--- a/src/alloc/system_alloc/defalloc.h
+++ b/src/alloc/system_alloc/defalloc.h
@@ -12,8 +12,8 @@
namespace Botan {
-/*
-* Malloc Allocator
+/**
+* Allocator using malloc
*/
class Malloc_Allocator : public Allocator
{
@@ -24,8 +24,8 @@ class Malloc_Allocator : public Allocator
std::string type() const { return "malloc"; }
};
-/*
-* Locking Allocator
+/**
+* Allocator using malloc plus locking
*/
class Locking_Allocator : public Pooling_Allocator
{