-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libc/picolibc: Split hooks into separate files
This splits the picolibc helper functions into separate files instead of smashing them all together. Signed-off-by: Keith Packard <[email protected]>
- Loading branch information
1 parent
e4b830f
commit c759b8a
Showing
11 changed files
with
317 additions
and
260 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright © 2021, Keith Packard <[email protected]> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "picolibc-hooks.h" | ||
|
||
#ifdef CONFIG_PICOLIBC_ASSERT_VERBOSE | ||
|
||
FUNC_NORETURN void __assert_func(const char *file, int line, | ||
const char *function, const char *expression) | ||
{ | ||
__ASSERT(0, "assertion \"%s\" failed: file \"%s\", line %d%s%s\n", | ||
expression, file, line, | ||
function ? ", function: " : "", function ? function : ""); | ||
CODE_UNREACHABLE; | ||
} | ||
|
||
#else | ||
|
||
FUNC_NORETURN void __assert_no_args(void) | ||
{ | ||
__ASSERT_NO_MSG(0); | ||
CODE_UNREACHABLE; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright © 2021, Keith Packard <[email protected]> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "picolibc-hooks.h" | ||
|
||
struct cb_bits { | ||
FILE f; | ||
cbprintf_cb out; | ||
void *ctx; | ||
}; | ||
|
||
static int cbputc(char c, FILE *_s) | ||
{ | ||
struct cb_bits *s = (struct cb_bits *) _s; | ||
|
||
(*s->out) (c, s->ctx); | ||
return 0; | ||
} | ||
|
||
int cbvprintf(cbprintf_cb out, void *ctx, const char *fp, va_list ap) | ||
{ | ||
struct cb_bits s = { | ||
.f = FDEV_SETUP_STREAM(cbputc, NULL, NULL, _FDEV_SETUP_WRITE), | ||
.out = out, | ||
.ctx = ctx, | ||
}; | ||
return vfprintf(&s.f, fp, ap); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright © 2021, Keith Packard <[email protected]> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "picolibc-hooks.h" | ||
|
||
/* This function gets called if static buffer overflow detection is enabled on | ||
* stdlib side (Picolibc here), in case such an overflow is detected. Picolibc | ||
* provides an implementation not suitable for us, so we override it here. | ||
*/ | ||
__weak FUNC_NORETURN void __chk_fail(void) | ||
{ | ||
printk("* buffer overflow detected *\n"); | ||
z_except_reason(K_ERR_STACK_CHK_FAIL); | ||
CODE_UNREACHABLE; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright © 2021, Keith Packard <[email protected]> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "picolibc-hooks.h" | ||
|
||
#ifndef CONFIG_LIBC_ERRNO | ||
|
||
/* | ||
* Picolibc needs to be able to declare this itself so that the library | ||
* doesn't end up needing zephyr header files. That means using a regular | ||
* function instead of an inline. | ||
*/ | ||
int *z_errno_wrap(void) | ||
{ | ||
return z_errno(); | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright © 2021, Keith Packard <[email protected]> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "picolibc-hooks.h" | ||
|
||
__weak void _exit(int status) | ||
{ | ||
printf("exit\n"); | ||
while (1) { | ||
Z_SPIN_DELAY(100); | ||
} | ||
} |
Oops, something went wrong.