OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [uclinux/] [uC-libc/] [malloc-simple/] [alloc.c] - Blame information for rev 1767

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
#include <unistd.h>
2
#include <sys/mman.h>
3
#include <stdio.h>
4
#include <stdlib.h>
5
 
6
#ifdef L_calloc_dbg
7
 
8
void *
9
calloc_dbg(size_t num, size_t size, char * function, char * file, int line)
10
{
11
        void * ptr;
12
        fprintf(stderr, "calloc of %d bytes at %s @%s:%d = ", num*size, function, file, line);
13
        ptr = calloc(num,size);
14
        fprtinf(stderr, "%p\n", ptr);
15
        return ptr;
16
}
17
 
18
#endif
19
 
20
#ifdef L_malloc_dbg
21
 
22
void *
23
malloc_dbg(size_t len, char * function, char * file, int line)
24
{
25
        void * result;
26
        fprintf(stderr, "malloc of %d bytes at %s @%s:%d = ", len, function, file, line);
27
        result = malloc(len);
28
        fprintf(stderr, "%p\n", result);
29
        return result;
30
}
31
 
32
#endif
33
 
34
#ifdef L_free_dbg
35
 
36
void
37
free_dbg(void * ptr, char * function, char * file, int line)
38
{
39
        fprintf(stderr, "free of %p at %s @%s:%d\n", ptr, function, file, line);
40
        free(ptr);
41
}
42
 
43
#endif
44
 
45
 
46
#ifdef L_calloc
47
 
48
void *
49
calloc(size_t num, size_t size)
50
{
51
        void * ptr = malloc(num*size);
52
        if (ptr)
53
                memset(ptr, 0, num*size);
54
        return ptr;
55
}
56
 
57
#endif
58
 
59
#ifdef L_malloc
60
 
61
void *
62
malloc(size_t len)
63
{
64
  void * result = mmap((void *)0, len, PROT_READ | PROT_WRITE,
65
                 MAP_SHARED | MAP_ANONYMOUS, 0, 0);
66
  if (result == (void*)-1)
67
    return 0;
68
 
69
  return result;
70
}
71
 
72
#endif
73
 
74
#ifdef L_free
75
 
76
void
77
free(void * ptr)
78
{
79
  munmap(ptr, 0);
80
}
81
 
82
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.