Skip to content

Commit d6e3fa0

Browse files
authored
Fixes to picolibc_interface (#1795)
* Fixes to picolibc_interface - Don't include bindings for tinystdio if picolibc was compiled with POSIX_IO. - Add times() function, which seems to be missed, in the same pattern as settimeofday/gettimeofday.
1 parent d0db378 commit d6e3fa0

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/rp2_common/pico_clib_interface/picolibc_interface.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <stdlib.h>
99
#include <unistd.h>
1010
#include <sys/time.h>
11+
#include <sys/times.h>
1112

1213
#include "pico.h"
1314
#if LIB_PICO_STDIO
@@ -39,6 +40,7 @@ static int picolibc_getc(__unused FILE *file) {
3940
#if LIB_PICO_STDIO
4041
return stdio_getchar();
4142
#endif
43+
return -1;
4244
}
4345

4446
static int picolibc_flush(__unused FILE *file) {
@@ -93,6 +95,17 @@ __weak int settimeofday(__unused const struct timeval *tv, __unused const struct
9395
return 0;
9496
}
9597

98+
__weak clock_t times(struct tms *tms) {
99+
#if CLOCKS_PER_SEC >= 1000000
100+
tms->tms_utime = (clock_t)(to_us_since_boot(get_absolute_time()) * (CLOCKS_PER_SEC / 1000000));
101+
#else
102+
tms->tms_utime = (clock_t)(to_us_since_boot(get_absolute_time()) / (1000000 / CLOCKS_PER_SEC));
103+
#endif
104+
tms->tms_stime = 0;
105+
tms->tms_cutime = 0;
106+
tms->tms_cstime = 0;
107+
return 0;
108+
}
96109

97110
void runtime_init(void) {
98111
#ifndef NDEBUG
@@ -118,9 +131,9 @@ __weak void runtime_init_pre_core_tls_setup(void) {
118131
// for now we just set the same global area on both cores
119132
// note: that this is superfluous with the stock picolibc it seems, since it is itself
120133
// using a version of __aeabi_read_tp that returns the same pointer on both cores
121-
extern void __tls_base;
134+
extern char __tls_base[];
122135
extern void _set_tls(void *tls);
123-
_set_tls(&__tls_base);
136+
_set_tls(__tls_base);
124137
}
125138
#endif
126139

0 commit comments

Comments
 (0)