Skip to content

Commit 35c8cc5

Browse files
wwtdcpq
authored andcommitted
Modify README_zh-CN.md
Update on explanation of _sbrk syscall
1 parent bee7ab2 commit 35c8cc5

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

README_zh-CN.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ fstatr.c:(.text._fstat_r+0xe): undefined reference to `_fstat'
954954
isattyr.c:(.text._isatty_r+0xc): undefined reference to `_isatty'
955955
```
956956

957-
这是因为我们使用了newlib的标准输入输出函数,那么就需要把newlib中其它的系统调用也实现。加入一些简单的什么都不做的桩函数
957+
这是因为我们使用了newlib的标准输入输出函数,那么就需要把newlib中其它的系统调用也实现。除了_sbrk之外我们可以加入一些简单的什么都不做的桩函数。而_sbrk会在printf()函数中使用malloc()的时候被调用到,所以它需要被实现
958958

959959
```c
960960
int _fstat(int fd, struct stat *st) {
@@ -963,8 +963,13 @@ int _fstat(int fd, struct stat *st) {
963963
}
964964

965965
void *_sbrk(int incr) {
966-
(void) incr;
967-
return NULL;
966+
extern char _end;
967+
static unsigned char *heap = NULL;
968+
unsigned char *prev_heap;
969+
if (heap == NULL) heap = (unsigned char *) &_end;
970+
prev_heap = heap;
971+
heap += incr;
972+
return prev_heap;
968973
}
969974

970975
int _close(int fd) {

0 commit comments

Comments
 (0)