aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc
diff options
context:
space:
mode:
Diffstat (limited to 'src/alloc')
-rw-r--r--src/alloc/alloc_mmap/mmap_mem.cpp28
-rw-r--r--src/alloc/alloc_mmap/mmap_mem.h16
-rw-r--r--src/alloc/allocate.h16
-rw-r--r--src/alloc/mem_pool/mem_pool.cpp86
-rw-r--r--src/alloc/mem_pool/mem_pool.h16
-rw-r--r--src/alloc/system_alloc/defalloc.cpp52
-rw-r--r--src/alloc/system_alloc/defalloc.h22
7 files changed, 125 insertions, 111 deletions
diff --git a/src/alloc/alloc_mmap/mmap_mem.cpp b/src/alloc/alloc_mmap/mmap_mem.cpp
index 8ecb5f4fe..546da7a81 100644
--- a/src/alloc/alloc_mmap/mmap_mem.cpp
+++ b/src/alloc/alloc_mmap/mmap_mem.cpp
@@ -1,7 +1,9 @@
-/*************************************************
-* Memory Mapping Allocator Source File *
-* (C) 1999-2007 Jack Lloyd *
-*************************************************/
+/*
+* Memory Mapping Allocator
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
#include <botan/mmap_mem.h>
#include <cstring>
@@ -21,9 +23,9 @@ namespace Botan {
namespace {
-/*************************************************
-* MemoryMapping_Allocator Exception *
-*************************************************/
+/*
+* MemoryMapping_Allocator Exception
+*/
class MemoryMapping_Failed : public Exception
{
public:
@@ -33,9 +35,9 @@ class MemoryMapping_Failed : public Exception
}
-/*************************************************
-* Memory Map a File into Memory *
-*************************************************/
+/*
+* Memory Map a File into Memory
+*/
void* MemoryMapping_Allocator::alloc_block(u32bit n)
{
class TemporaryFile
@@ -96,9 +98,9 @@ void* MemoryMapping_Allocator::alloc_block(u32bit n)
return ptr;
}
-/*************************************************
-* Remove a Memory Mapping *
-*************************************************/
+/*
+* Remove a Memory Mapping
+*/
void MemoryMapping_Allocator::dealloc_block(void* ptr, u32bit n)
{
if(ptr == 0)
diff --git a/src/alloc/alloc_mmap/mmap_mem.h b/src/alloc/alloc_mmap/mmap_mem.h
index 3d3c1c48e..bef166a16 100644
--- a/src/alloc/alloc_mmap/mmap_mem.h
+++ b/src/alloc/alloc_mmap/mmap_mem.h
@@ -1,7 +1,9 @@
-/*************************************************
-* Memory Mapping Allocator Header File *
-* (C) 1999-2007 Jack Lloyd *
-*************************************************/
+/*
+* Memory Mapping Allocator
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
#ifndef BOTAN_MMAP_ALLOCATOR_H__
#define BOTAN_MMAP_ALLOCATOR_H__
@@ -10,9 +12,9 @@
namespace Botan {
-/*************************************************
-* Memory Mapping Allocator *
-*************************************************/
+/*
+* Memory Mapping Allocator
+*/
class BOTAN_DLL MemoryMapping_Allocator : public Pooling_Allocator
{
public:
diff --git a/src/alloc/allocate.h b/src/alloc/allocate.h
index efbb77291..180f2c021 100644
--- a/src/alloc/allocate.h
+++ b/src/alloc/allocate.h
@@ -1,7 +1,9 @@
-/*************************************************
-* Allocator Header File *
-* (C) 1999-2007 Jack Lloyd *
-*************************************************/
+/*
+* Allocator
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
#ifndef BOTAN_ALLOCATOR_H__
#define BOTAN_ALLOCATOR_H__
@@ -11,9 +13,9 @@
namespace Botan {
-/*************************************************
-* Allocator Interface *
-*************************************************/
+/*
+* Allocator Interface
+*/
class BOTAN_DLL Allocator
{
public:
diff --git a/src/alloc/mem_pool/mem_pool.cpp b/src/alloc/mem_pool/mem_pool.cpp
index cddfe0152..38e0c3285 100644
--- a/src/alloc/mem_pool/mem_pool.cpp
+++ b/src/alloc/mem_pool/mem_pool.cpp
@@ -1,9 +1,11 @@
-/*************************************************
-* Pooling Allocator Source File *
-* (C) 1999-2008 Jack Lloyd *
-* 2005 Matthew Gregan *
-* 2005-2006 Matt Johnston *
-*************************************************/
+/*
+* Pooling Allocator
+* (C) 1999-2008 Jack Lloyd
+* 2005 Matthew Gregan
+* 2005-2006 Matt Johnston
+*
+* Distributed under the terms of the Botan license
+*/
#include <botan/mem_pool.h>
#include <botan/util.h>
@@ -15,9 +17,9 @@ namespace Botan {
namespace {
-/*************************************************
-* Memory Allocation Exception *
-*************************************************/
+/*
+* Memory Allocation Exception
+*/
struct Memory_Exhaustion : public std::bad_alloc
{
const char* what() const throw()
@@ -26,9 +28,9 @@ struct Memory_Exhaustion : public std::bad_alloc
}
-/*************************************************
-* Memory_Block Constructor *
-*************************************************/
+/*
+* Memory_Block Constructor
+*/
Pooling_Allocator::Memory_Block::Memory_Block(void* buf)
{
buffer = static_cast<byte*>(buf);
@@ -36,9 +38,9 @@ Pooling_Allocator::Memory_Block::Memory_Block(void* buf)
buffer_end = buffer + (BLOCK_SIZE * BITMAP_SIZE);
}
-/*************************************************
-* See if ptr is contained by this block *
-*************************************************/
+/*
+* See if ptr is contained by this block
+*/
bool Pooling_Allocator::Memory_Block::contains(void* ptr,
u32bit length) const throw()
{
@@ -46,9 +48,9 @@ bool Pooling_Allocator::Memory_Block::contains(void* ptr,
(buffer_end >= static_cast<byte*>(ptr) + length * BLOCK_SIZE));
}
-/*************************************************
-* Allocate some memory, if possible *
-*************************************************/
+/*
+* Allocate some memory, if possible
+*/
byte* Pooling_Allocator::Memory_Block::alloc(u32bit n) throw()
{
if(n == 0 || n > BITMAP_SIZE)
@@ -86,9 +88,9 @@ byte* Pooling_Allocator::Memory_Block::alloc(u32bit n) throw()
return buffer + offset * BLOCK_SIZE;
}
-/*************************************************
-* Mark this memory as free, if we own it *
-*************************************************/
+/*
+* Mark this memory as free, if we own it
+*/
void Pooling_Allocator::Memory_Block::free(void* ptr, u32bit blocks) throw()
{
clear_mem(static_cast<byte*>(ptr), blocks * BLOCK_SIZE);
@@ -104,17 +106,17 @@ void Pooling_Allocator::Memory_Block::free(void* ptr, u32bit blocks) throw()
}
}
-/*************************************************
-* Pooling_Allocator Constructor *
-*************************************************/
+/*
+* Pooling_Allocator Constructor
+*/
Pooling_Allocator::Pooling_Allocator(Mutex* m) : mutex(m)
{
last_used = blocks.begin();
}
-/*************************************************
-* Pooling_Allocator Destructor *
-*************************************************/
+/*
+* Pooling_Allocator Destructor
+*/
Pooling_Allocator::~Pooling_Allocator()
{
delete mutex;
@@ -122,9 +124,9 @@ Pooling_Allocator::~Pooling_Allocator()
throw Invalid_State("Pooling_Allocator: Never released memory");
}
-/*************************************************
-* Free all remaining memory *
-*************************************************/
+/*
+* Free all remaining memory
+*/
void Pooling_Allocator::destroy()
{
Mutex_Holder lock(mutex);
@@ -136,9 +138,9 @@ void Pooling_Allocator::destroy()
allocated.clear();
}
-/*************************************************
-* Allocation *
-*************************************************/
+/*
+* Allocation
+*/
void* Pooling_Allocator::allocate(u32bit n)
{
const u32bit BITMAP_SIZE = Memory_Block::bitmap_size();
@@ -170,9 +172,9 @@ void* Pooling_Allocator::allocate(u32bit n)
throw Memory_Exhaustion();
}
-/*************************************************
-* Deallocation *
-*************************************************/
+/*
+* Deallocation
+*/
void Pooling_Allocator::deallocate(void* ptr, u32bit n)
{
const u32bit BITMAP_SIZE = Memory_Block::bitmap_size();
@@ -199,9 +201,9 @@ void Pooling_Allocator::deallocate(void* ptr, u32bit n)
}
}
-/*************************************************
-* Try to get some memory from an existing block *
-*************************************************/
+/*
+* Try to get some memory from an existing block
+*/
byte* Pooling_Allocator::allocate_blocks(u32bit n)
{
if(blocks.empty())
@@ -227,9 +229,9 @@ byte* Pooling_Allocator::allocate_blocks(u32bit n)
return 0;
}
-/*************************************************
-* Allocate more memory for the pool *
-*************************************************/
+/*
+* Allocate more memory for the pool
+*/
void Pooling_Allocator::get_more_core(u32bit in_bytes)
{
const u32bit BITMAP_SIZE = Memory_Block::bitmap_size();
diff --git a/src/alloc/mem_pool/mem_pool.h b/src/alloc/mem_pool/mem_pool.h
index 80ed2ddfd..a57800972 100644
--- a/src/alloc/mem_pool/mem_pool.h
+++ b/src/alloc/mem_pool/mem_pool.h
@@ -1,7 +1,9 @@
-/*************************************************
-* Pooling Allocator Header File *
-* (C) 1999-2007 Jack Lloyd *
-*************************************************/
+/*
+* Pooling Allocator
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
#ifndef BOTAN_POOLING_ALLOCATOR_H__
#define BOTAN_POOLING_ALLOCATOR_H__
@@ -14,9 +16,9 @@
namespace Botan {
-/*************************************************
-* Pooling Allocator *
-*************************************************/
+/*
+* Pooling Allocator
+*/
class BOTAN_DLL Pooling_Allocator : public Allocator
{
public:
diff --git a/src/alloc/system_alloc/defalloc.cpp b/src/alloc/system_alloc/defalloc.cpp
index 5fb8e1447..8791c74e4 100644
--- a/src/alloc/system_alloc/defalloc.cpp
+++ b/src/alloc/system_alloc/defalloc.cpp
@@ -1,7 +1,9 @@
-/*************************************************
-* Basic Allocators Source File *
-* (C) 1999-2007 Jack Lloyd *
-*************************************************/
+/*
+* Basic Allocators
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
#include <botan/defalloc.h>
#include <botan/libstate.h>
@@ -13,9 +15,9 @@ namespace Botan {
namespace {
-/*************************************************
-* Perform Memory Allocation *
-*************************************************/
+/*
+* Perform Memory Allocation
+*/
void* do_malloc(u32bit n, bool do_lock)
{
void* ptr = std::malloc(n);
@@ -30,9 +32,9 @@ void* do_malloc(u32bit n, bool do_lock)
return ptr;
}
-/*************************************************
-* Perform Memory Deallocation *
-*************************************************/
+/*
+* Perform Memory Deallocation
+*/
void do_free(void* ptr, u32bit n, bool do_lock)
{
if(!ptr)
@@ -47,41 +49,41 @@ void do_free(void* ptr, u32bit n, bool do_lock)
}
-/*************************************************
-* Malloc_Allocator's Allocation *
-*************************************************/
+/*
+* Malloc_Allocator's Allocation
+*/
void* Malloc_Allocator::allocate(u32bit n)
{
return do_malloc(n, false);
}
-/*************************************************
-* Malloc_Allocator's Deallocation *
-*************************************************/
+/*
+* Malloc_Allocator's Deallocation
+*/
void Malloc_Allocator::deallocate(void* ptr, u32bit n)
{
do_free(ptr, n, false);
}
-/*************************************************
-* Locking_Allocator's Allocation *
-*************************************************/
+/*
+* Locking_Allocator's Allocation
+*/
void* Locking_Allocator::alloc_block(u32bit n)
{
return do_malloc(n, true);
}
-/*************************************************
-* Locking_Allocator's Deallocation *
-*************************************************/
+/*
+* Locking_Allocator's Deallocation
+*/
void Locking_Allocator::dealloc_block(void* ptr, u32bit n)
{
do_free(ptr, n, true);
}
-/*************************************************
-* Get an allocator *
-*************************************************/
+/*
+* Get an allocator
+*/
Allocator* Allocator::get(bool locking)
{
std::string type = "";
diff --git a/src/alloc/system_alloc/defalloc.h b/src/alloc/system_alloc/defalloc.h
index dc01ee47f..627e8df70 100644
--- a/src/alloc/system_alloc/defalloc.h
+++ b/src/alloc/system_alloc/defalloc.h
@@ -1,7 +1,9 @@
-/*************************************************
-* Basic Allocators Header File *
-* (C) 1999-2007 Jack Lloyd *
-*************************************************/
+/*
+* Basic Allocators
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
#ifndef BOTAN_BASIC_ALLOC_H__
#define BOTAN_BASIC_ALLOC_H__
@@ -10,9 +12,9 @@
namespace Botan {
-/*************************************************
-* Malloc Allocator *
-*************************************************/
+/*
+* Malloc Allocator
+*/
class BOTAN_DLL Malloc_Allocator : public Allocator
{
public:
@@ -22,9 +24,9 @@ class BOTAN_DLL Malloc_Allocator : public Allocator
std::string type() const { return "malloc"; }
};
-/*************************************************
-* Locking Allocator *
-*************************************************/
+/*
+* Locking Allocator
+*/
class BOTAN_DLL Locking_Allocator : public Pooling_Allocator
{
public: