1 /*
2 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
3 * Alexander Warg <warg@os.inf.tu-dresden.de>
4 * economic rights: Technische Universität Dresden (Germany)
5 *
6 * This file is part of TUD:OS and distributed under the terms of the
7 * GNU General Public License 2.
8 * Please see the COPYING-GPL-2 file for details.
9 */
10 #define _GNU_SOURCE 1
11 #include <bits/l4-malloc.h>
12 #include <sys/mman.h>
13 #include <errno.h>
14
15 #include "page_alloc.h"
16
17 #include <l4/sys/types.h>
18
19 #include <l4/cxx/iostream>
20
21 static void *current_morecore_end;
22
uclibc_morecore(long bytes)23 void *uclibc_morecore(long bytes)
24 {
25 // Calling morecore with 0 size is done by the malloc/free implementation
26 // to check for the amount of memory it got from the last call to
27 // morecore.
28 // With a negative value, 'free' wants to return memory, we do not support
29 // that here.
30 if (bytes <= 0)
31 return current_morecore_end;
32
33 size_t s = l4_round_page(bytes);
34 void *b = Single_page_alloc_base::_alloc(Single_page_alloc_base::nothrow,
35 s, L4_PAGESIZE);
36 if (L4_UNLIKELY(!b))
37 return MAP_FAILED;
38
39 current_morecore_end = static_cast<char *>(b) + s;
40 return b;
41 }
42
43 void *
mmap(void * start,size_t length,int prot,int flags,int fd,off_t offset)44 mmap(void *start, size_t length, int prot,
45 int flags, int fd, off_t offset)
46 noexcept(noexcept(mmap(start, length, prot, flags, fd, offset)))
47 {
48 L4::cout << "mmap() called: unimplemented!\n";
49 errno = EINVAL;
50 return MAP_FAILED;
51 }
52
53 int
munmap(void * start,size_t length)54 munmap(void *start, size_t length) noexcept(noexcept(munmap(start, length)))
55 {
56 L4::cout << "munmap() called: unimplemented!\n";
57 errno = EINVAL;
58 return -1;
59 }
60
61 void *
mremap(void * old_address,size_t old_size,size_t new_size,int may_move,...)62 mremap(void *old_address, size_t old_size, size_t new_size,
63 int may_move, ...)
64 noexcept(noexcept(mremap(old_address, old_size, new_size, may_move)))
65 {
66 L4::cout << "mremap() called: unimplemented!\n";
67 errno = EINVAL;
68 return MAP_FAILED;
69 }
70