Add memtest support.
[syslinux-debian/hramrach.git] / com32 / lib / sys / module / elfutils.c
blobb7d760b4c52c383d8ed6913d3cc228ba44550e66
1 #include <stdlib.h>
2 #include <errno.h>
4 #include "elfutils.h"
6 unsigned long elf_hash(const unsigned char *name) {
7 unsigned long h = 0;
8 unsigned long g;
10 while (*name) {
11 h = (h << 4) + *name++;
12 if ((g = h & 0xF0000000))
13 h ^= g >> 24;
15 h &= ~g;
18 return h;
21 unsigned long elf_gnu_hash(const unsigned char *name) {
22 unsigned long h = 5381;
23 unsigned char c;
25 for (c = *name; c != '\0'; c = *++name) {
26 h = h * 33 + c;
29 return h & 0xFFFFFFFF;
32 #ifndef HAVE_ELF_POSIX_MEMALIGN
34 struct memalign_info {
35 void *start_addr;
36 char data[0];
39 int elf_malloc(void **memptr, size_t alignment, size_t size) {
40 char *start_addr = NULL;
41 struct memalign_info *info;
43 if ((alignment & (alignment - 1)) != 0)
44 return EINVAL;
45 if (alignment % sizeof(void*) != 0)
46 alignment = sizeof(void*);
48 start_addr = malloc(size + (alignment > sizeof(struct memalign_info) ?
49 alignment : sizeof(struct memalign_info)));
51 if (start_addr == NULL)
52 return ENOMEM;
55 info = (struct memalign_info*)(start_addr -
56 ((unsigned long)start_addr % alignment) +
57 alignment - sizeof(struct memalign_info));
59 info->start_addr = start_addr;
61 *memptr = info->data;
63 return 0;
66 void elf_free(char *memptr) {
67 struct memalign_info *info = (struct memalign_info*)(memptr -
68 sizeof(struct memalign_info));
70 free(info->start_addr);
73 #else
75 int elf_malloc(void **memptr, size_t alignment, size_t size) {
76 if ((alignment & (alignment - 1)) != 0)
77 return EINVAL;
79 if (alignment % sizeof(void*) != 0)
80 alignment = sizeof(void*);
82 return posix_memalign(memptr, alignment, size);
85 void elf_free(void *memptr) {
86 free(memptr);
89 #endif //HAVE_ELF_POSIX_MEMALIGN