11/*
22 * Copyright (C) 2019 Intel Corporation. All rights reserved.
3+ * SPDX-FileCopyrightText: 2024 Siemens AG (For Zephyr usermode changes)
34 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
45 */
56
1819#include <misc/printk.h>
1920#endif
2021#else /* else of KERNEL_VERSION_NUMBER < 0x030200 */
21- #include <zephyr/kernel.h>
2222#include <zephyr/sys/printk.h>
2323#endif /* end of KERNEL_VERSION_NUMBER < 0x030200 */
2424
3737#endif
3838
3939#if KERNEL_VERSION_NUMBER < 0x030200 /* version 3.2.0 */
40+ #include <zephyr.h>
4041#include <net/net_pkt.h>
4142#include <net/net_if.h>
4243#include <net/net_ip.h>
4344#include <net/net_core.h>
4445#include <net/net_context.h>
4546#else /* else of KERNEL_VERSION_NUMBER < 0x030200 */
47+ #include <zephyr/kernel.h>
4648#include <zephyr/net/net_pkt.h>
4749#include <zephyr/net/net_if.h>
4850#include <zephyr/net/net_ip.h>
4951#include <zephyr/net/net_core.h>
5052#include <zephyr/net/net_context.h>
5153#endif /* end of KERNEL_VERSION_NUMBER < 0x030200 */
5254
55+ #ifdef CONFIG_USERSPACE
56+ #include <zephyr/sys/mutex.h>
57+ #include <zephyr/sys/sem.h>
58+ #endif /* end of CONFIG_USERSPACE */
59+
5360#if KERNEL_VERSION_NUMBER >= 0x030300 /* version 3.3.0 */
5461#include <zephyr/cache.h>
5562#endif /* end of KERNEL_VERSION_NUMBER > 0x030300 */
6471#endif
6572#endif
6673
74+ #ifdef signbit /* probably since Zephyr v3.5.0 a new picolib is included */
75+ #define BH_HAS_SIGNBIT 1
76+ #endif
77+
6778#ifndef BH_PLATFORM_ZEPHYR
6879#define BH_PLATFORM_ZEPHYR
6980#endif
7081
82+ // Synchronization primitives for usermode
83+ #ifdef CONFIG_USERSPACE
84+ #define mutex_t struct sys_mutex
85+ #define mutex_init (mtx ) sys_mutex_init(mtx)
86+ #define mutex_lock (mtx , timeout ) sys_mutex_lock(mtx, timeout)
87+ #define mutex_unlock (mtx ) sys_mutex_unlock(mtx)
88+
89+ #define sem_t struct sys_sem
90+ #define sem_init (sem , init_count , limit ) sys_sem_init(sem, init_count, limit)
91+ #define sem_give (sem ) sys_sem_give(sem)
92+ #define sem_take (sem , timeout ) sys_sem_take(sem, timeout)
93+ #define sem_count_get (sem ) sys_sem_count_get(sem)
94+ #else /* else of CONFIG_USERSPACE */
95+ #define mutex_t struct k_mutex
96+ #define mutex_init (mtx ) k_mutex_init(mtx)
97+ #define mutex_lock (mtx , timeout ) k_mutex_lock(mtx, timeout)
98+ #define mutex_unlock (mtx ) k_mutex_unlock(mtx)
99+
100+ #define sem_t struct k_sem
101+ #define sem_init (sem , init_count , limit ) k_sem_init(sem, init_count, limit)
102+ #define sem_give (sem ) k_sem_give(sem)
103+ #define sem_take (sem , timeout ) k_sem_take(sem, timeout)
104+ #define sem_count_get (sem ) k_sem_count_get(sem)
105+ #endif /* end of CONFIG_USERSPACE */
106+
71107#define BH_APPLET_PRESERVED_STACK_SIZE (2 * BH_KB)
72108
73109/* Default thread priority */
74110#define BH_THREAD_DEFAULT_PRIORITY 7
75111
76112typedef struct k_thread korp_thread ;
77113typedef korp_thread * korp_tid ;
78- typedef struct k_mutex korp_mutex ;
114+ typedef mutex_t korp_mutex ;
79115typedef unsigned int korp_sem ;
80116
81117/* korp_rwlock is used in platform_api_extension.h,
@@ -87,7 +123,7 @@ typedef struct {
87123struct os_thread_wait_node ;
88124typedef struct os_thread_wait_node * os_thread_wait_list ;
89125typedef struct korp_cond {
90- struct k_mutex wait_list_lock ;
126+ mutex_t wait_list_lock ;
91127 os_thread_wait_list thread_wait_list ;
92128} korp_cond ;
93129
@@ -120,11 +156,14 @@ float fmaxf(float x, float y);
120156float rintf (float x );
121157float fabsf (float x );
122158float truncf (float x );
123- int signbit (double x );
124159int isnan (double x );
125160double pow (double x , double y );
126161double scalbn (double x , int n );
127162
163+ #ifndef BH_HAS_SIGNBIT
164+ int signbit (double x );
165+ #endif
166+
128167unsigned long long int strtoull (const char * nptr , char * * endptr , int base );
129168double strtod (const char * nptr , char * * endptr );
130169float strtof (const char * nptr , char * * endptr );
0 commit comments