summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2001-11-19 01:30:58 (GMT)
committerH. Peter Anvin <hpa@zytor.com>2001-11-19 01:30:58 (GMT)
commit2e29697587a19b41aff44f40f5d2d7f16dbd64ad (patch)
tree07e3ddde6a86432b4d5ecaa9f6bbdc317f1a348f
parent3a9ce59347e473f4a8181ac91e04866b7375f281 (diff)
downloadlpsm-2e29697587a19b41aff44f40f5d2d7f16dbd64ad.zip
lpsm-2e29697587a19b41aff44f40f5d2d7f16dbd64ad.tar.gz
lpsm-2e29697587a19b41aff44f40f5d2d7f16dbd64ad.tar.bz2
lpsm-2e29697587a19b41aff44f40f5d2d7f16dbd64ad.tar.xz
Move version to a separate file
Add lpsm_alloc_size()
-rw-r--r--CHANGES5
-rw-r--r--Makefile5
-rw-r--r--allocsize.c62
-rw-r--r--free.c2
-rw-r--r--internals.h2
-rw-r--r--lpsm.7.in8
-rw-r--r--lpsm_alloc_stats.3.in7
-rw-r--r--lpsm_malloc.3.in1
-rw-r--r--version1
9 files changed, 86 insertions, 7 deletions
diff --git a/CHANGES b/CHANGES
index 89c3366..589326e 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,8 @@
+Changes in 0.1.11:
+------------------
+* Change the base address for ARM, Cris, and PA/RISC to match i386.
+* Add lpsm_alloc_size().
+
Changes in 0.1.10:
------------------
* Actually make the SPARC addresses work. On sparc32, if sun4c
diff --git a/Makefile b/Makefile
index 5bc48d9..1efcc09 100644
--- a/Makefile
+++ b/Makefile
@@ -14,11 +14,12 @@
TEST = teststore testbuddy testalloc testrecovery zallocevil \
test_mmap ftrunctest
SONAME = libpsm.so.0
-VERSION = 0.1.11
+VERSION = $(shell cat version)
LIBPSM = libpsm.so.$(VERSION) libpsm.a
CFILES = arena.c bitops.c \
- mgmt.c malloc.c free.c realloc.c zalloc.c calloc.c stats.c
+ mgmt.c malloc.c free.c realloc.c zalloc.c calloc.c \
+ stats.c allocsize.c
OSOBJ = $(patsubst %.c,%.o,$(CFILES))
OSPICOBJ = $(patsubst %.c,%.pic.o,$(CFILES))
# MAN1PAGES = $(patsubst %.in,%,$(wildcard *.1.in))
diff --git a/allocsize.c b/allocsize.c
new file mode 100644
index 0000000..5ade41b
--- /dev/null
+++ b/allocsize.c
@@ -0,0 +1,62 @@
+#ident "$Id$"
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2000-2001 H. Peter Anvin - All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, Inc.,
+ * 59 Temple Place Ste 330, Boston MA 02111-1307, USA, version 2.1,
+ * incorporated herein by reference.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * allocsize.c
+ *
+ * Detemine the "true" size of the specified allocation
+ */
+
+#include <assert.h>
+#include <stdlib.h>
+#include <inttypes.h>
+#include <limits.h>
+#include <string.h>
+
+#include "lpsm.h"
+#include "internals.h"
+#include "bitops.h"
+
+static size_t
+lpsm_alloc_size_buddy(const void *ptr)
+{
+ struct buddy_params bp;
+ bp = lpsm_find_alloc_buddy(ptr);
+
+ return ((size_t)1) << (AH->arena_size_lg2-bp.rorder);
+}
+
+static size_t
+lpsm_alloc_size_slab(const void *ptr)
+{
+ const struct slab_header *sh;
+ const struct slab_info *si;
+
+ sh = (struct slab_header *)((uintptr_t)ptr & ~(BUDDY_SIZE_MIN-1));
+ si = &AH->slab[sh->index];
+
+ return si->size;
+}
+
+size_t
+lpsm_alloc_size(const void *ptr)
+{
+ if ( !ptr )
+ return 0;
+
+ /* Buddy allocations are ALWAYS page-aligned, SLAB allocations never */
+ if ( (uintptr_t)ptr & (BUDDY_SIZE_MIN-1) )
+ return lpsm_alloc_size_slab(ptr);
+ else
+ return lpsm_alloc_size_buddy(ptr);
+}
diff --git a/free.c b/free.c
index f38f1db..ac88516 100644
--- a/free.c
+++ b/free.c
@@ -48,7 +48,7 @@ static void lpsm_free_chunk(int xbit, int rorder)
* buddy allocation from its address; used by free() and
* realloc().
*/
-struct buddy_params lpsm_find_alloc_buddy(void *ptr)
+struct buddy_params lpsm_find_alloc_buddy(const void *ptr)
{
struct buddy_params bp;
uintptr_t offset = (uintptr_t)ptr - (uintptr_t)AH->data_start;
diff --git a/internals.h b/internals.h
index 81aa518..dc7d043 100644
--- a/internals.h
+++ b/internals.h
@@ -133,7 +133,7 @@ struct buddy_params {
int xbit;
int rorder;
};
-struct buddy_params lpsm_find_alloc_buddy(void *ptr);
+struct buddy_params lpsm_find_alloc_buddy(const void *ptr);
int lpsm_extend_arena(int logsize);
int lpsm_malloc_buddy_xbit(int order);
void *lpsm_malloc_buddy(size_t size);
diff --git a/lpsm.7.in b/lpsm.7.in
index c4749b0..57e9576 100644
--- a/lpsm.7.in
+++ b/lpsm.7.in
@@ -91,9 +91,16 @@ memory functions
is similar to
.B calloc()
but with a different interface.)
+.PP
+The function
+.B lpsm_alloc_size()
+returns the actual size \- as opposed to the requested size \- of a
+memory allocation.
+.PP
The function
.B lpsm_alloc_stats()
provide extended statistics on the memory allocation.
+.PP
As in unmanaged mode,
.B lpsm_checkpoint()
is used to checkpoint the data store, and
@@ -122,6 +129,7 @@ signal.
.SH "SEE ALSO"
.BR lpsm_init (3),
.BR lpsm_malloc (3),
+.BR lpsm_alloc_size (3),
.BR lpsm_alloc_stats (3),
.BR lpsm_arena_init (3),
.BR lpsm_extend (3),
diff --git a/lpsm_alloc_stats.3.in b/lpsm_alloc_stats.3.in
index c5f806c..05cec61 100644
--- a/lpsm_alloc_stats.3.in
+++ b/lpsm_alloc_stats.3.in
@@ -64,10 +64,11 @@ and
.I errno
is set to
.BR ENOMEM .
+.SH "NOTES"
+.B lpsm_alloc_stats()
+can be a very heavyweight operation.
.SH "SEE ALSO"
+.BR lpsm_alloc_size (3),
.BR lpsm_malloc (3),
.BR malloc (3),
.BR lpsm (7).
-.SH "NOTES"
-.B lpsm_alloc_stats()
-is a fairly heavyweight operation.
diff --git a/lpsm_malloc.3.in b/lpsm_malloc.3.in
index 49bd8d9..dbac918 100644
--- a/lpsm_malloc.3.in
+++ b/lpsm_malloc.3.in
@@ -143,6 +143,7 @@ were unable to allocate the memory requested.
These functions mimic in as much as possible the ISO C and POSIX
behaviour of the equivalent transient memory allocation functions.
.SH "SEE ALSO"
+.BR lpsm_alloc_size (3),
.BR lpsm_alloc_stats (3),
.BR lpsm_init (3),
.BR malloc (3),
diff --git a/version b/version
new file mode 100644
index 0000000..20f4951
--- /dev/null
+++ b/version
@@ -0,0 +1 @@
+0.1.11