Skip to content

Commit d1c5010

Browse files
authored
Merge pull request zephyrproject-rtos#19 from endresshauser-lp/backport/pr-87784
Backport support for picolibc 1.8.10
2 parents 8c6ce62 + c4a3c3a commit d1c5010

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

include/zephyr/posix/posix_features.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,13 @@
245245
/* #define _XOPEN_UNIX (-1L) */
246246
/* #define _XOPEN_UUCP (-1L) */
247247

248+
#if _POSIX_C_SOURCE >= 200809L && (__PICOLIBC__ > 1 || \
249+
(__PICOLIBC__ == 1 && (__PICOLIBC_MINOR__ > 8 || \
250+
__PICOLIBC_MINOR__ == 8 && __PICOLIBC_PATCHLEVEL__ >= 9)))
251+
/* Use picolibc's limits.h when building POSIX code */
252+
#include <limits.h>
253+
#else
254+
248255
/* Maximum values */
249256
#define _POSIX_CLOCKRES_MIN (20000000L)
250257

@@ -307,6 +314,8 @@
307314
#define _XOPEN_NAME_MAX (255)
308315
#define _XOPEN_PATH_MAX (1024)
309316

317+
#endif /* __PICOLIBC__ */
318+
310319
/* Other invariant values */
311320
#define NL_LANGMAX (14)
312321
#define NL_MSGMAX (32767)

lib/libc/picolibc/locks.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,18 @@
77
#include "picolibc-hooks.h"
88

99
#ifdef CONFIG_MULTITHREADING
10-
#define _LOCK_T void *
11-
K_MUTEX_DEFINE(__lock___libc_recursive_mutex);
10+
11+
#include <sys/lock.h>
12+
13+
/* Define the picolibc lock type */
14+
struct __lock {
15+
struct k_mutex m;
16+
};
17+
18+
STRUCT_SECTION_ITERABLE_ALTERNATE(k_mutex, __lock,
19+
__lock___libc_recursive_mutex) = {
20+
.m = Z_MUTEX_INITIALIZER(__lock___libc_recursive_mutex.m),
21+
};
1222

1323
#ifdef CONFIG_USERSPACE
1424
/* Grant public access to picolibc lock after boot */
@@ -32,13 +42,13 @@ void __retarget_lock_init_recursive(_LOCK_T *lock)
3242

3343
/* Allocate mutex object */
3444
#ifndef CONFIG_USERSPACE
35-
*lock = malloc(sizeof(struct k_mutex));
45+
*lock = malloc(sizeof(struct __lock));
3646
#else
3747
*lock = k_object_alloc(K_OBJ_MUTEX);
3848
#endif /* !CONFIG_USERSPACE */
3949
__ASSERT(*lock != NULL, "recursive lock allocation failed");
4050

41-
k_mutex_init((struct k_mutex *)*lock);
51+
k_mutex_init(&(*lock)->m);
4252
}
4353

4454
/* Create a new dynamic non-recursive lock */
@@ -68,7 +78,7 @@ void __retarget_lock_close(_LOCK_T lock)
6878
void __retarget_lock_acquire_recursive(_LOCK_T lock)
6979
{
7080
__ASSERT_NO_MSG(lock != NULL);
71-
k_mutex_lock((struct k_mutex *)lock, K_FOREVER);
81+
k_mutex_lock(&lock->m, K_FOREVER);
7282
}
7383

7484
/* Acquiure non-recursive lock */
@@ -81,7 +91,7 @@ void __retarget_lock_acquire(_LOCK_T lock)
8191
int __retarget_lock_try_acquire_recursive(_LOCK_T lock)
8292
{
8393
__ASSERT_NO_MSG(lock != NULL);
84-
return !k_mutex_lock((struct k_mutex *)lock, K_NO_WAIT);
94+
return !k_mutex_lock(&lock->m, K_NO_WAIT);
8595
}
8696

8797
/* Try acquiring non-recursive lock */
@@ -94,7 +104,7 @@ int __retarget_lock_try_acquire(_LOCK_T lock)
94104
void __retarget_lock_release_recursive(_LOCK_T lock)
95105
{
96106
__ASSERT_NO_MSG(lock != NULL);
97-
k_mutex_unlock((struct k_mutex *)lock);
107+
k_mutex_unlock(&lock->m);
98108
}
99109

100110
/* Release non-recursive lock */

tests/kernel/common/src/printk.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ char expected_32[] = "22 113 10000 32768 40000 22\n"
6565
"42 42 42 42\n"
6666
"42 42 42 42\n"
6767
"25542abcdef 42\n"
68-
#if defined(_WANT_MINIMAL_IO_LONG_LONG)
68+
#if defined(_WANT_MINIMAL_IO_LONG_LONG) || defined(__IO_MINIMAL_LONG_LONG)
6969
"68719476735 -1 18446744073709551615 ffffffffffffffff\n"
7070
#else
7171
"-1 -1 4294967295 ffffffff\n"

west.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ manifest:
336336
- debug
337337
- name: picolibc
338338
path: modules/lib/picolibc
339-
revision: 82d62ed1ac55b4e34a12d0390aced2dc9af13fc9
339+
revision: 560946f26db075c296beea5b39d99e6de43c9010
340340
- name: segger
341341
revision: cf56b1d9c80f81a26e2ac5727c9cf177116a4692
342342
path: modules/debug/segger

0 commit comments

Comments
 (0)