summaryrefslogtreecommitdiff
path: root/gnuradio-runtime/lib/malloc16.c
diff options
context:
space:
mode:
authorBen Reynwar <ben@reynwar.net>2013-04-02 23:04:08 -0700
committerBen Reynwar <ben@reynwar.net>2013-04-02 23:04:08 -0700
commitc6dbde23b256a41b3d92cb4ad6b63287095d53c7 (patch)
tree71db12ea2e1667770c22568dcdf5e0857d5f1e59 /gnuradio-runtime/lib/malloc16.c
parent22b70d0889ef3c51e27a31ee18d153093a55cbb8 (diff)
parent98758cbfa9a2aff714952d19e773bc370dfa2185 (diff)
Merged next into uninstalled import branch.
Diffstat (limited to 'gnuradio-runtime/lib/malloc16.c')
-rw-r--r--gnuradio-runtime/lib/malloc16.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/gnuradio-runtime/lib/malloc16.c b/gnuradio-runtime/lib/malloc16.c
new file mode 100644
index 0000000000..2cc6135e77
--- /dev/null
+++ b/gnuradio-runtime/lib/malloc16.c
@@ -0,0 +1,46 @@
+/* Wrapper functions for malloc/free that force 16-byte alignment
+ * See http://perso.club-internet.fr/matmac/sourcesc.htm
+
+ * Copyright 2001 Phil Karn, KA9Q
+ * May be used under the terms of the GNU Public License (GPL)
+ */
+
+#include "malloc16.h"
+#include <string.h>
+
+void *malloc16Align(int size){
+ void *p;
+ void **p1;
+
+ if((p = malloc(size+31)) == NULL)
+ return NULL;
+
+ /* Round up to next 16-byte boundary */
+ p1 = (void **)(((long)p + 31) & (~15));
+
+ /* Stash actual start of block just before ptr we return */
+ p1[-1] = p;
+
+ /* Return 16-byte aligned address */
+ return (void *)p1;
+}
+
+void *calloc16Align(size_t nmemb,size_t size){
+ int nbytes;
+ void *p;
+
+ nbytes = nmemb*size;
+ if((p = malloc16Align(nbytes)) == NULL)
+ return NULL;
+
+ memset(p,0,nbytes);
+ return p;
+}
+
+void free16Align(void *p){
+
+ if(p != NULL){
+ /* Retrieve pointer to actual start of block and free it */
+ free(((void **)p)[-1]);
+ }
+}