diff --git a/library/amiga.lib_rev.h b/library/amiga.lib_rev.h index 01378d4..9347717 100644 --- a/library/amiga.lib_rev.h +++ b/library/amiga.lib_rev.h @@ -1,6 +1,6 @@ #define VERSION 1 -#define REVISION 208 -#define DATE "19.11.2016" -#define VERS "amiga.lib 1.208" -#define VSTRING "amiga.lib 1.208 (19.11.2016)\r\n" -#define VERSTAG "\0$VER: amiga.lib 1.208 (19.11.2016)" +#define REVISION 209 +#define DATE "21.11.2016" +#define VERS "amiga.lib 1.209" +#define VSTRING "amiga.lib 1.209 (21.11.2016)\r\n" +#define VERSTAG "\0$VER: amiga.lib 1.209 (21.11.2016)" diff --git a/library/amiga.lib_rev.rev b/library/amiga.lib_rev.rev index 7d645f5..7fba2b4 100644 --- a/library/amiga.lib_rev.rev +++ b/library/amiga.lib_rev.rev @@ -1 +1 @@ -208 +209 diff --git a/library/c.lib_rev.h b/library/c.lib_rev.h index 3bddb28..064e4c8 100644 --- a/library/c.lib_rev.h +++ b/library/c.lib_rev.h @@ -1,6 +1,6 @@ #define VERSION 1 -#define REVISION 208 -#define DATE "19.11.2016" -#define VERS "c.lib 1.208" -#define VSTRING "c.lib 1.208 (19.11.2016)\r\n" -#define VERSTAG "\0$VER: c.lib 1.208 (19.11.2016)" +#define REVISION 209 +#define DATE "21.11.2016" +#define VERS "c.lib 1.209" +#define VSTRING "c.lib 1.209 (21.11.2016)\r\n" +#define VERSTAG "\0$VER: c.lib 1.209 (21.11.2016)" diff --git a/library/c.lib_rev.rev b/library/c.lib_rev.rev index 7d645f5..7fba2b4 100644 --- a/library/c.lib_rev.rev +++ b/library/c.lib_rev.rev @@ -1 +1 @@ -208 +209 diff --git a/library/changes b/library/changes index 6486cb8..5983013 100644 --- a/library/changes +++ b/library/changes @@ -1,3 +1,13 @@ +c.lib 1.209 (21.11.2016) + +- The maximum slab size is now 2^17 bytes (= 131072). If you request + a slab size larger than this, you will get slab sizes of 131072 + bytes instead. + +- Enabling the memory management debugging code no longer produces + compiler errors. + + c.lib 1.208 (19.11.2016) - Updated with new functions and data structures for diff --git a/library/debug.lib_rev.h b/library/debug.lib_rev.h index 4518a3a..21ba441 100644 --- a/library/debug.lib_rev.h +++ b/library/debug.lib_rev.h @@ -1,6 +1,6 @@ #define VERSION 1 -#define REVISION 208 -#define DATE "19.11.2016" -#define VERS "debug.lib 1.208" -#define VSTRING "debug.lib 1.208 (19.11.2016)\r\n" -#define VERSTAG "\0$VER: debug.lib 1.208 (19.11.2016)" +#define REVISION 209 +#define DATE "21.11.2016" +#define VERS "debug.lib 1.209" +#define VSTRING "debug.lib 1.209 (21.11.2016)\r\n" +#define VERSTAG "\0$VER: debug.lib 1.209 (21.11.2016)" diff --git a/library/debug.lib_rev.rev b/library/debug.lib_rev.rev index 7d645f5..7fba2b4 100644 --- a/library/debug.lib_rev.rev +++ b/library/debug.lib_rev.rev @@ -1 +1 @@ -208 +209 diff --git a/library/m.lib_rev.h b/library/m.lib_rev.h index 5eea846..c75bd70 100644 --- a/library/m.lib_rev.h +++ b/library/m.lib_rev.h @@ -1,6 +1,6 @@ #define VERSION 1 -#define REVISION 208 -#define DATE "19.11.2016" -#define VERS "m.lib 1.208" -#define VSTRING "m.lib 1.208 (19.11.2016)\r\n" -#define VERSTAG "\0$VER: m.lib 1.208 (19.11.2016)" +#define REVISION 209 +#define DATE "21.11.2016" +#define VERS "m.lib 1.209" +#define VSTRING "m.lib 1.209 (21.11.2016)\r\n" +#define VERSTAG "\0$VER: m.lib 1.209 (21.11.2016)" diff --git a/library/m.lib_rev.rev b/library/m.lib_rev.rev index 7d645f5..7fba2b4 100644 --- a/library/m.lib_rev.rev +++ b/library/m.lib_rev.rev @@ -1 +1 @@ -208 +209 diff --git a/library/m881.lib_rev.h b/library/m881.lib_rev.h index a900c0b..540298e 100644 --- a/library/m881.lib_rev.h +++ b/library/m881.lib_rev.h @@ -1,6 +1,6 @@ #define VERSION 1 -#define REVISION 208 -#define DATE "19.11.2016" -#define VERS "m881.lib 1.208" -#define VSTRING "m881.lib 1.208 (19.11.2016)\r\n" -#define VERSTAG "\0$VER: m881.lib 1.208 (19.11.2016)" +#define REVISION 209 +#define DATE "21.11.2016" +#define VERS "m881.lib 1.209" +#define VSTRING "m881.lib 1.209 (21.11.2016)\r\n" +#define VERSTAG "\0$VER: m881.lib 1.209 (21.11.2016)" diff --git a/library/m881.lib_rev.rev b/library/m881.lib_rev.rev index 7d645f5..7fba2b4 100644 --- a/library/m881.lib_rev.rev +++ b/library/m881.lib_rev.rev @@ -1 +1 @@ -208 +209 diff --git a/library/net.lib_rev.h b/library/net.lib_rev.h index 168f46b..85ed785 100644 --- a/library/net.lib_rev.h +++ b/library/net.lib_rev.h @@ -1,6 +1,6 @@ #define VERSION 1 -#define REVISION 208 -#define DATE "19.11.2016" -#define VERS "net.lib 1.208" -#define VSTRING "net.lib 1.208 (19.11.2016)\r\n" -#define VERSTAG "\0$VER: net.lib 1.208 (19.11.2016)" +#define REVISION 209 +#define DATE "21.11.2016" +#define VERS "net.lib 1.209" +#define VSTRING "net.lib 1.209 (21.11.2016)\r\n" +#define VERSTAG "\0$VER: net.lib 1.209 (21.11.2016)" diff --git a/library/net.lib_rev.rev b/library/net.lib_rev.rev index 7d645f5..7fba2b4 100644 --- a/library/net.lib_rev.rev +++ b/library/net.lib_rev.rev @@ -1 +1 @@ -208 +209 diff --git a/library/stdlib_get_slab_usage.c b/library/stdlib_get_slab_usage.c index 82329a3..6804169 100644 --- a/library/stdlib_get_slab_usage.c +++ b/library/stdlib_get_slab_usage.c @@ -55,7 +55,7 @@ __get_slab_usage(__slab_usage_callback callback) __memory_lock(); - sui.sui_slab_size = __slab_data.sd_MaxSlabSize; + sui.sui_slab_size = __slab_data.sd_StandardSlabSize; sui.sui_num_single_allocations = __slab_data.sd_NumSingleAllocations; sui.sui_total_single_allocation_size = __slab_data.sd_TotalSingleAllocationSize; @@ -72,7 +72,7 @@ __get_slab_usage(__slab_usage_callback callback) sui.sui_num_slabs++; - sui.sui_total_slab_allocation_size += sizeof(*sn) + __slab_data.sd_MaxSlabSize; + sui.sui_total_slab_allocation_size += sizeof(*sn) + __slab_data.sd_StandardSlabSize; } } diff --git a/library/stdlib_malloc.c b/library/stdlib_malloc.c index ac760b4..22988d5 100644 --- a/library/stdlib_malloc.c +++ b/library/stdlib_malloc.c @@ -92,7 +92,7 @@ __get_allocation_size(size_t size) /****************************************************************************/ void * -__allocate_memory(size_t size,BOOL never_free,const char * UNUSED unused_file,int UNUSED unused_line) +__allocate_memory(size_t size,BOOL never_free,const char * UNUSED debug_file_name,int UNUSED debug_line_number) { struct MemoryNode * mn; size_t allocation_size; @@ -215,8 +215,8 @@ __allocate_memory(size_t size,BOOL never_free,const char * UNUSED unused_file,in mn->mn_AlreadyFree = FALSE; mn->mn_Allocation = body; mn->mn_AllocationSize = allocation_size; - mn->mn_File = (char *)file; - mn->mn_Line = line; + mn->mn_File = (char *)debug_file_name; + mn->mn_Line = debug_line_number; mn->mn_FreeFile = NULL; mn->mn_FreeLine = 0; @@ -228,7 +228,7 @@ __allocate_memory(size_t size,BOOL never_free,const char * UNUSED unused_file,in { kprintf("[%s] + %10ld 0x%08lx [",__program_name,size,body); - kprintf("allocated at %s:%ld]\n",file,line); + kprintf("allocated at %s:%ld]\n",debug_file_name,debug_line_number); } #endif /* __MEM_DEBUG_LOG */ @@ -264,7 +264,7 @@ __allocate_memory(size_t size,BOOL never_free,const char * UNUSED unused_file,in { kprintf("[%s] + %10ld 0x%08lx [",__program_name,size,NULL); - kprintf("FAILED: allocated at %s:%ld]\n",file,line); + kprintf("FAILED: allocated at %s:%ld]\n",debug_file_name,debug_line_number); } } #endif /* __MEM_DEBUG_LOG */ diff --git a/library/stdlib_memory.h b/library/stdlib_memory.h index 8ac48d2..e6e9e4b 100644 --- a/library/stdlib_memory.h +++ b/library/stdlib_memory.h @@ -200,7 +200,7 @@ struct MemoryTree /* This keeps track of individual slabs. Each slab begins with this * header and is followed by the memory it manages. The size of that * memory "slab" is fixed and matches what is stored in - * SlabData.sd_MaxSlabSize. + * SlabData.sd_StandardSlabSize. * * Each slab manages allocations of a specific maximum size, e.g. 8, 16, 32, * 64, etc. bytes. Multiple slabs can exist which manage allocations of the same @@ -245,13 +245,13 @@ struct SlabData * which are 8 bytes in size, sd_Slabs[4] is for 16 byte * chunks, etc. The minimum chunk size is 8, which is why * lists 0..2 are not used. Currently, there is an upper limit - * of 2^31 bytes per chunk, but you should not be using slab + * of 2^17 bytes per chunk, but you should not be using slab * chunks much larger than 4096 bytes. */ - struct MinList sd_Slabs[31]; + struct MinList sd_Slabs[17]; /* Memory allocations which are larger than the limit - * found in the sd_MaxSlabSize field are kept in this list. + * found in the sd_StandardSlabSize field are kept in this list. * They are never associated with a slab. */ struct MinList sd_SingleAllocations; @@ -262,13 +262,13 @@ struct SlabData */ struct MinList sd_EmptySlabs; - /* This is the maximum size of a memory allocation which may + /* This is the standard size of a memory allocation which may * be made from a slab that can accommodate it. This number * is initialized from the __slab_max_size global variable, * if > 0, and unless it already is a power of two, it will * be rounded up to the next largest power of two. */ - size_t sd_MaxSlabSize; + size_t sd_StandardSlabSize; /* These fields kees track of how many entries there are in * the sd_SingleAllocations list, and how much memory these diff --git a/library/stdlib_slab.c b/library/stdlib_slab.c index 5803157..3b59c6e 100644 --- a/library/stdlib_slab.c +++ b/library/stdlib_slab.c @@ -54,17 +54,17 @@ __slab_allocate(size_t allocation_size) D(("allocating %lu bytes of memory",allocation_size)); - assert( __slab_data.sd_MaxSlabSize > 0 ); + assert( __slab_data.sd_StandardSlabSize > 0 ); /* Number of bytes to allocate exceeds the slab size? * If so, allocate this memory chunk separately and * keep track of it. */ - if(allocation_size > __slab_data.sd_MaxSlabSize) + if(allocation_size > __slab_data.sd_StandardSlabSize) { struct MinNode * single_allocation; - D(("allocation size is > %ld; this will be stored separately",__slab_data.sd_MaxSlabSize)); + D(("allocation size is > %ld; this will be stored separately",__slab_data.sd_StandardSlabSize)); D(("allocating %ld (MinNode) + %ld = %ld bytes",sizeof(*single_allocation),allocation_size,sizeof(*single_allocation) + allocation_size)); #if defined(__amigaos4__) @@ -103,7 +103,7 @@ __slab_allocate(size_t allocation_size) ULONG chunk_size; int slab_index; - D(("allocation size is <= %ld; this will be allocated from a slab",__slab_data.sd_MaxSlabSize)); + D(("allocation size is <= %ld; this will be allocated from a slab",__slab_data.sd_StandardSlabSize)); /* Chunks must be at least as small as a MinNode, because * that's what we use for keeping track of the chunks which @@ -230,15 +230,15 @@ __slab_allocate(size_t allocation_size) */ if(new_sn == NULL) { - D(("no slab is available for reuse; allocating a new slab (%lu bytes)",sizeof(*sn) + __slab_data.sd_MaxSlabSize)); + D(("no slab is available for reuse; allocating a new slab (%lu bytes)",sizeof(*sn) + __slab_data.sd_StandardSlabSize)); #if defined(__amigaos4__) { - new_sn = (struct SlabNode *)AllocVec(sizeof(*sn) + __slab_data.sd_MaxSlabSize,MEMF_PRIVATE); + new_sn = (struct SlabNode *)AllocVec(sizeof(*sn) + __slab_data.sd_StandardSlabSize,MEMF_PRIVATE); } #else { - new_sn = (struct SlabNode *)AllocVec(sizeof(*sn) + __slab_data.sd_MaxSlabSize,MEMF_ANY); + new_sn = (struct SlabNode *)AllocVec(sizeof(*sn) + __slab_data.sd_StandardSlabSize,MEMF_ANY); } #endif /* __amigaos4__ */ @@ -257,7 +257,7 @@ __slab_allocate(size_t allocation_size) D(("setting up slab 0x%08lx", new_sn)); - assert( chunk_size <= __slab_data.sd_MaxSlabSize ); + assert( chunk_size <= __slab_data.sd_StandardSlabSize ); memset(new_sn,0,sizeof(*new_sn)); @@ -270,7 +270,7 @@ __slab_allocate(size_t allocation_size) * SlabNode header. */ first_byte = (BYTE *)&new_sn[1]; - last_byte = &first_byte[__slab_data.sd_MaxSlabSize - chunk_size]; + last_byte = &first_byte[__slab_data.sd_StandardSlabSize - chunk_size]; for(free_chunk = (struct MinNode *)first_byte ; free_chunk <= (struct MinNode *)last_byte; @@ -356,16 +356,16 @@ __slab_free(void * address,size_t allocation_size) { D(("freeing allocation at 0x%08lx, %lu bytes",address,allocation_size)); - assert( __slab_data.sd_MaxSlabSize > 0 ); + assert( __slab_data.sd_StandardSlabSize > 0 ); /* Number of bytes allocated exceeds the slab size? * Then the chunk was allocated separately. */ - if(allocation_size > __slab_data.sd_MaxSlabSize) + if(allocation_size > __slab_data.sd_StandardSlabSize) { struct MinNode * mn = address; - D(("allocation size is > %ld; this was stored separately",__slab_data.sd_MaxSlabSize)); + D(("allocation size is > %ld; this was stored separately",__slab_data.sd_StandardSlabSize)); Remove((struct Node *)&mn[-1]); @@ -389,7 +389,7 @@ __slab_free(void * address,size_t allocation_size) ULONG chunk_size; int slab_index; - D(("allocation size is <= %ld; this was allocated from a slab",__slab_data.sd_MaxSlabSize)); + D(("allocation size is <= %ld; this was allocated from a slab",__slab_data.sd_StandardSlabSize)); /* Chunks must be at least as small as a MinNode, because * that's what we use for keeping track of the chunks which @@ -422,13 +422,13 @@ __slab_free(void * address,size_t allocation_size) /* Find the slab which contains the memory chunk. */ if(slab_list != NULL) { - const size_t usable_range = __slab_data.sd_MaxSlabSize - chunk_size; + const size_t usable_range = __slab_data.sd_StandardSlabSize - chunk_size; struct SlabNode * sn; BYTE * first_byte; BYTE * last_byte; BOOL freed = FALSE; - assert( chunk_size <= __slab_data.sd_MaxSlabSize ); + assert( chunk_size <= __slab_data.sd_StandardSlabSize ); for(sn = (struct SlabNode *)slab_list->mlh_Head ; sn->sn_MinNode.mln_Succ != NULL ; @@ -495,15 +495,22 @@ __slab_free(void * address,size_t allocation_size) void __slab_init(size_t slab_size) { + const size_t max_slab_size = (1UL << (NUM_ENTRIES(__slab_data.sd_Slabs))); size_t size; SETDEBUGLEVEL(2); D(("slab_size = %ld",slab_size)); + /* Do not allow for a slab size that is larger than + * what we support. + */ + if(slab_size > max_slab_size) + slab_size = max_slab_size; + /* If the maximum allocation size to be made from the slab * is not already a power of 2, round it up. We do not - * support allocations larger than 2^31, and the maximum + * support allocations larger than 2^17, and the maximum * allocation size should be much smaller. * * Note that the maximum allocation size also defines the @@ -533,8 +540,8 @@ __slab_init(size_t slab_size) NewList((struct List *)&__slab_data.sd_SingleAllocations); NewList((struct List *)&__slab_data.sd_EmptySlabs); - __slab_data.sd_MaxSlabSize = size; - __slab_data.sd_InUse = TRUE; + __slab_data.sd_StandardSlabSize = size; + __slab_data.sd_InUse = TRUE; } } diff --git a/library/unix.lib_rev.h b/library/unix.lib_rev.h index 0e8415d..c85f155 100644 --- a/library/unix.lib_rev.h +++ b/library/unix.lib_rev.h @@ -1,6 +1,6 @@ #define VERSION 1 -#define REVISION 208 -#define DATE "19.11.2016" -#define VERS "unix.lib 1.208" -#define VSTRING "unix.lib 1.208 (19.11.2016)\r\n" -#define VERSTAG "\0$VER: unix.lib 1.208 (19.11.2016)" +#define REVISION 209 +#define DATE "21.11.2016" +#define VERS "unix.lib 1.209" +#define VSTRING "unix.lib 1.209 (21.11.2016)\r\n" +#define VERSTAG "\0$VER: unix.lib 1.209 (21.11.2016)" diff --git a/library/unix.lib_rev.rev b/library/unix.lib_rev.rev index 7d645f5..7fba2b4 100644 --- a/library/unix.lib_rev.rev +++ b/library/unix.lib_rev.rev @@ -1 +1 @@ -208 +209