]> git.pld-linux.org Git - packages/dietlibc.git/blame - dietlibc-memalign.patch
- add umount-arch.patch from debian, fixing umount syscalls for alpha, ia64
[packages/dietlibc.git] / dietlibc-memalign.patch
CommitLineData
7ab3114f
JR
1diff -ur dietlibc-0.31/include/stdlib.h dietlibc-0.31-memalign/include/stdlib.h
2--- dietlibc-0.31/include/stdlib.h 2009-03-19 15:39:48.000000000 +0100
3+++ dietlibc-0.31-memalign/include/stdlib.h 2009-03-19 15:39:37.000000000 +0100
0aadcf56 4@@ -13,6 +13,9 @@
7ab3114f
JR
5 void *malloc(size_t size) __THROW __attribute_malloc__;
6 void free(void *ptr) __THROW;
7 void *realloc(void *ptr, size_t size) __THROW __attribute_malloc__;
8+void *memalign(size_t alignment, size_t size) __THROW __attribute_malloc__;
0aadcf56 9+int posix_memalign(void **memptr, size_t alignment, size_t size) __THROW __attribute_malloc__;
7ab3114f
JR
10+void *valloc(size_t size) __THROW __attribute_malloc__;
11
12 char *getenv(const char *name) __THROW __pure;
13 int putenv(const char *string) __THROW;
14diff -ur dietlibc-0.31/lib/alloc.c dietlibc-0.31-memalign/lib/alloc.c
15--- dietlibc-0.31/lib/alloc.c 2009-03-19 15:39:48.000000000 +0100
16+++ dietlibc-0.31-memalign/lib/alloc.c 2009-03-19 15:38:33.000000000 +0100
17@@ -128,10 +128,14 @@
18 }
19
20 /* -- PUBLIC FUNCTIONS ---------------------------------------------------- */
21-
22+int __libc_free_aligned(void *ptr);
23 static void _alloc_libc_free(void *ptr) {
24 register size_t size;
25- if (ptr) {
26+ if (ptr == NULL)
27+ return;
28+ if (__libc_free_aligned(ptr))
29+ return;
30+
31 size=((__alloc_t*)BLOCK_START(ptr))->size;
32 if (size) {
33 if (size<=__MAX_SMALL_SIZE)
34@@ -139,7 +143,6 @@
35 else
36 munmap(BLOCK_START(ptr),size);
37 }
38- }
39 }
40 void __libc_free(void *ptr) __attribute__((alias("_alloc_libc_free")));
41 void free(void *ptr) __attribute__((weak,alias("_alloc_libc_free")));
0aadcf56 42@@ -268,3 +249,83 @@
7ab3114f
JR
43 }
44 void* realloc(void* ptr, size_t size) __attribute__((weak,alias("__libc_realloc")));
45
46+/* List of blocks allocated with memalign or valloc */
47+struct alignlist {
48+ struct alignlist *next;
49+ void *aligned; /* The address that memaligned returned. */
50+ void *exact; /* The address that malloc returned. */
51+};
52+struct alignlist *_aligned_blocks;
53+
54+/* Return memory to the heap. */
55+int __libc_free_aligned(void *ptr);
56+int __libc_free_aligned(void *ptr) {
57+ struct alignlist *l;
58+ register size_t size;
59+
60+ if (ptr == NULL)
61+ return 0;
62+
63+ for (l = _aligned_blocks; l != NULL; l = l->next) {
64+ if (l->aligned == ptr) {
65+ size=((__alloc_t*)BLOCK_START(l->exact))->size;
66+ if (size) {
67+ if (size<=__MAX_SMALL_SIZE)
68+ __small_free(l->exact,size);
69+ else
70+ munmap(BLOCK_START(l->exact),size);
71+ }
72+ /* Mark the block as free */
73+ l->aligned = NULL;
74+ return 1;
75+ }
76+ }
77+ return 0;
78+}
79+
80+void * memalign (size_t alignment, size_t size);
81+void * memalign (size_t alignment, size_t size) {
82+ void * result;
83+ unsigned long int adj;
84+
85+ result = malloc (size + alignment - 1);
86+ if (result == NULL)
87+ return NULL;
88+
89+ adj = (unsigned long int) ((unsigned long int) ((char *) result - (char *) NULL)) % alignment;
90+ if (adj != 0) {
91+ struct alignlist *l;
92+ for (l = _aligned_blocks; l != NULL; l = l->next)
93+ if (l->aligned == NULL)
94+ /* This slot is free. Use it. */
95+ break;
96+ if (l == NULL) {
97+ l = (struct alignlist *) malloc (sizeof (struct alignlist));
98+ if (l == NULL) {
99+ _alloc_libc_free(result);
100+ result = NULL;
101+ goto DONE;
102+ }
103+ l->next = _aligned_blocks;
104+ _aligned_blocks = l;
105+ }
106+ l->exact = result;
107+ result = l->aligned = (char *) result + alignment - adj;
108+ }
109+DONE:
110+
111+ return result;
112+}
113+
0aadcf56
JB
114+int posix_memalign(void **memptr, size_t alignment, size_t size);
115+int posix_memalign(void **memptr, size_t alignment, size_t size)
116+{
117+ if(alignment % sizeof(void*) != 0) return EINVAL;
118+ *memptr = memalign(alignment, size);
119+ return (*memptr != NULL) ? 0 : ENOMEM;
120+}
121+
7ab3114f
JR
122+void * valloc (size_t size);
123+void * valloc (size_t size) {
124+ return memalign(PAGE_SIZE, size);
125+}
This page took 0.055031 seconds and 4 git commands to generate.