Contiki-NG
Loading...
Searching...
No Matches
syscalls.c
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2014, Institute for Pervasive Computing, ETH Zurich.
3
* All rights reserved.
4
*
5
* Author: Andreas Dröscher <contiki@anticat.ch>
6
*
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions
9
* are met:
10
* 1. Redistributions of source code must retain the above copyright
11
* notice, this list of conditions and the following disclaimer.
12
* 2. Redistributions in binary form must reproduce the above copyright
13
* notice, this list of conditions and the following disclaimer in the
14
* documentation and/or other materials provided with the distribution.
15
* 3. Neither the name of the Institute nor the names of its contributors
16
* may be used to endorse or promote products derived from this software
17
* without specific prior written permission.
18
*
19
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS "AS IS" AND
20
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
23
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29
* SUCH DAMAGE.
30
*/
31
/**
32
* \addtogroup lib
33
* @{
34
*
35
* \defgroup newlib Generic Newlib customizations
36
*
37
* Library providing generic implementations of Newlib features for Contiki
38
* @{
39
*
40
* \file
41
* System calls
42
*/
43
#include <sys/types.h>
44
#include <errno.h>
45
#include <stdint.h>
46
#include <stdio.h>
47
/*---------------------------------------------------------------------------*/
48
#define DEBUG 0
49
#if DEBUG
50
#define PRINTF(...) printf(__VA_ARGS__)
51
#else
52
#define PRINTF(...)
53
#endif
54
/*---------------------------------------------------------------------------*/
55
/**
56
* \brief Enlarges the allocated heap space
57
* \param incr Number of bytes by which to increase the heap space
58
* \return The previous end of heap on success (which is also a pointer to the
59
* start of the newly allocated memory if \p incr is positive), or
60
* <tt>(caddr_t)-1</tt> with \c errno set to \c ENOMEM on error
61
*/
62
caddr_t
63
_sbrk
(
int
incr)
64
{
65
/*
66
* Newlib's _sbrk_r() assumes that this global errno variable is used here,
67
* which is different from the errno definition provided by <errno.h>.
68
*/
69
#undef errno
70
extern
int
errno;
71
72
/* Heap boundaries from linker script. */
73
extern
uint8_t _heap;
74
extern
uint8_t _eheap;
75
76
static
uint8_t *heap_end = &_heap;
77
uint8_t *prev_heap_end = heap_end;
78
79
if
(heap_end + incr > &_eheap) {
80
PRINTF(
"Out of heap space!\n"
);
81
errno = ENOMEM;
82
return
(caddr_t)-1;
83
}
84
85
heap_end += incr;
86
return
(caddr_t)prev_heap_end;
87
}
88
89
/**
90
* @}
91
* @}
92
*/
_sbrk
caddr_t _sbrk(int incr)
Enlarges the allocated heap space.
Definition
syscalls.c:63
os
lib
newlib
syscalls.c
Generated on Sat May 4 2024 19:29:57 for Contiki-NG by
1.10.0