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
int
90
_close(
int
fd)
91
{
92
(void)fd;
93
return
-1;
94
}
95
/*---------------------------------------------------------------------------*/
96
int
97
_fstat(
int
fd,
void
*st)
98
{
99
(void)fd;
100
(void)st;
101
return
-1;
102
}
103
/*---------------------------------------------------------------------------*/
104
int
105
_getpid(
void
)
106
{
107
return
1;
108
}
109
/*---------------------------------------------------------------------------*/
110
int
111
_isatty(
int
fd)
112
{
113
(void)fd;
114
return
0;
115
}
116
/*---------------------------------------------------------------------------*/
117
int
118
_kill(
int
pid,
int
sig)
119
{
120
(void)pid;
121
(void)sig;
122
return
-1;
123
}
124
/*---------------------------------------------------------------------------*/
125
int
126
_lseek(
int
fd,
int
offset,
int
whence)
127
{
128
(void)fd;
129
(void)offset;
130
(void)whence;
131
return
-1;
132
}
133
/*---------------------------------------------------------------------------*/
134
int
135
_read(
int
fd,
char
*buf,
int
count
)
136
{
137
(void)fd;
138
(void)buf;
139
(void)
count
;
140
return
-1;
141
}
142
/*---------------------------------------------------------------------------*/
143
int
144
_write(
int
fd,
const
char
*buf,
int
count
)
145
{
146
(void)fd;
147
(void)buf;
148
(void)
count
;
149
return
-1;
150
}
151
/*---------------------------------------------------------------------------*/
152
153
/**
154
* @}
155
* @}
156
*/
count
static volatile uint64_t count
Num.
Definition
clock.c:50
_sbrk
caddr_t _sbrk(int incr)
Enlarges the allocated heap space.
Definition
syscalls.c:63
os
lib
newlib
syscalls.c
Generated on Sat Sep 20 2025 07:49:19 for Contiki-NG by
1.10.0