mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-07-15 08:48:33 +00:00
Cleanup + add Flag to ignore errors
This commit is contained in:
parent
214345aa42
commit
d6eac93b86
|
@ -172,7 +172,7 @@ blocking_op_openat(wasm_exec_env_t exec_env, os_file_handle handle,
|
|||
return error;
|
||||
}
|
||||
|
||||
#ifndef BH_PLATFORM_WINDOWS
|
||||
#if !defined(BH_PLATFORM_WINDOWS) && !defined(WAMR_PLATFORM_ZEPHYR_FORCE_NO_ERROR)
|
||||
/* REVISIT: apply the os_file_handle style abstraction for pollfd? */
|
||||
__wasi_errno_t
|
||||
blocking_op_poll(wasm_exec_env_t exec_env, os_poll_file_handle *pfds, os_nfds_t nfds,
|
||||
|
|
|
@ -55,7 +55,7 @@ blocking_op_openat(wasm_exec_env_t exec_env, os_file_handle handle,
|
|||
__wasi_fdflags_t fd_flags, __wasi_lookupflags_t lookup_flags,
|
||||
wasi_libc_file_access_mode access_mode, os_file_handle *out);
|
||||
|
||||
#ifndef BH_PLATFORM_WINDOWS
|
||||
#if !defined(BH_PLATFORM_WINDOWS) && !defined(WAMR_PLATFORM_ZEPHYR_FORCE_NO_ERROR)
|
||||
__wasi_errno_t
|
||||
blocking_op_poll(wasm_exec_env_t exec_env, os_poll_file_handle *pfds, os_nfds_t nfds,
|
||||
int timeout, int *retp);
|
||||
|
|
|
@ -128,7 +128,7 @@ struct LOCKABLE cond {
|
|||
clockid_t clock;
|
||||
#endif
|
||||
};
|
||||
#if !defined(BH_PLATFORM_ZEPHYR)
|
||||
#if !defined(WAMR_PLATFORM_ZEPHYR_FORCE_NO_ERROR)
|
||||
static inline bool
|
||||
cond_init_monotonic(struct cond *cond)
|
||||
{
|
||||
|
@ -177,7 +177,7 @@ cond_init_realtime(struct cond *cond)
|
|||
|
||||
return true;
|
||||
}
|
||||
#endif /* !defined(BH_PLATFORM_ZEPHYR) */
|
||||
#endif /* !defWAMR) */
|
||||
static inline void
|
||||
cond_destroy(struct cond *cond)
|
||||
{
|
||||
|
@ -196,7 +196,12 @@ static inline bool
|
|||
cond_timedwait(struct cond *cond, struct mutex *lock, uint64_t timeout,
|
||||
bool abstime) REQUIRES_EXCLUSIVE(*lock) NO_LOCK_ANALYSIS
|
||||
{
|
||||
#if defined(WAMR_PLATFORM_ZEPHYR_FORCE_NO_ERROR)
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
int ret;
|
||||
|
||||
struct os_timespec ts = {
|
||||
.tv_sec = (time_t)(timeout / 1000000000),
|
||||
.tv_nsec = (long)(timeout % 1000000000),
|
||||
|
@ -229,7 +234,7 @@ cond_timedwait(struct cond *cond, struct mutex *lock, uint64_t timeout,
|
|||
++ts.tv_sec;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif /* !CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK */
|
||||
}
|
||||
else {
|
||||
#if CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP
|
||||
|
@ -253,7 +258,7 @@ cond_timedwait(struct cond *cond, struct mutex *lock, uint64_t timeout,
|
|||
ts.tv_nsec -= 1000000000;
|
||||
++ts.tv_sec;
|
||||
}
|
||||
#endif
|
||||
#endif /* CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP */
|
||||
}
|
||||
|
||||
ret = pthread_cond_timedwait(&cond->object, &lock->object, &ts);
|
||||
|
@ -261,6 +266,7 @@ cond_timedwait(struct cond *cond, struct mutex *lock, uint64_t timeout,
|
|||
&& "pthread_cond_timedwait() failed");
|
||||
return ret == ETIMEDOUT;
|
||||
}
|
||||
#endif /* WAMR_PLATFORM_ZEPHYR_FORCE_NO_ERROR */
|
||||
#endif
|
||||
|
||||
static inline void
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "refcount.h"
|
||||
#include "rights.h"
|
||||
#include "str.h"
|
||||
#include "assert.h"
|
||||
|
||||
/* Some platforms (e.g. Windows) already define `min()` macro.
|
||||
We're undefing it here to make sure the `min` call does exactly
|
||||
|
@ -1857,8 +1858,12 @@ wasmtime_ssp_fd_filestat_get(wasm_exec_env_t exec_env, struct fd_table *curfds,
|
|||
}
|
||||
|
||||
static void
|
||||
convert_timestamp(__wasi_timestamp_t in, struct timespec *out)
|
||||
convert_timestamp(__wasi_timestamp_t in, struct os_timespec *out)
|
||||
{
|
||||
#if defined(WAMR_PLATFORM_ZEPHYR_FORCE_NO_ERROR)
|
||||
// No clock implem
|
||||
}
|
||||
#else
|
||||
// Store sub-second remainder.
|
||||
#if defined(__SYSCALL_SLONG_TYPE)
|
||||
out->tv_nsec = (__SYSCALL_SLONG_TYPE)(in % 1000000000);
|
||||
|
@ -1870,7 +1875,7 @@ convert_timestamp(__wasi_timestamp_t in, struct timespec *out)
|
|||
// Clamp to the maximum in case it would overflow our system's time_t.
|
||||
out->tv_sec = (time_t)in < BH_TIME_T_MAX ? (time_t)in : BH_TIME_T_MAX;
|
||||
}
|
||||
|
||||
#endif /* WAMR_PLATFORM_ZEPHYR_FORCE_NO_ERROR */
|
||||
__wasi_errno_t
|
||||
wasmtime_ssp_fd_filestat_set_size(wasm_exec_env_t exec_env,
|
||||
struct fd_table *curfds, __wasi_fd_t fd,
|
||||
|
@ -2055,9 +2060,7 @@ wasmtime_ssp_poll_oneoff(wasm_exec_env_t exec_env, struct fd_table *curfds,
|
|||
size_t nsubscriptions,
|
||||
size_t *nevents) NO_LOCK_ANALYSIS
|
||||
{
|
||||
#ifdef BH_PLATFORM_WINDOWS
|
||||
return __WASI_ENOSYS;
|
||||
#elif BH_PLATEFORM_ZEPHYR
|
||||
#if defined(BH_PLATFORM_WINDOWS) || defined(WAMR_PLATFORM_ZEPHYR_FORCE_NO_ERROR)
|
||||
return __WASI_ENOSYS;
|
||||
#else
|
||||
// Sleeping.
|
||||
|
@ -2069,7 +2072,7 @@ wasmtime_ssp_poll_oneoff(wasm_exec_env_t exec_env, struct fd_table *curfds,
|
|||
#if CONFIG_HAS_CLOCK_NANOSLEEP
|
||||
clockid_t clock_id;
|
||||
if (wasi_clockid_to_clockid(in[0].u.u.clock.clock_id, &clock_id)) {
|
||||
struct timespec ts;
|
||||
struct os_timespec ts;
|
||||
convert_timestamp(in[0].u.u.clock.timeout, &ts);
|
||||
int ret = clock_nanosleep(
|
||||
clock_id,
|
||||
|
@ -2096,7 +2099,7 @@ wasmtime_ssp_poll_oneoff(wasm_exec_env_t exec_env, struct fd_table *curfds,
|
|||
else {
|
||||
// Perform relative sleeps on the monotonic clock also using
|
||||
// nanosleep(). This is incorrect, but good enough for now.
|
||||
struct timespec ts;
|
||||
struct os_timespec ts;
|
||||
convert_timestamp(in[0].u.u.clock.timeout, &ts);
|
||||
nanosleep(&ts, NULL);
|
||||
}
|
||||
|
@ -2124,7 +2127,7 @@ wasmtime_ssp_poll_oneoff(wasm_exec_env_t exec_env, struct fd_table *curfds,
|
|||
}
|
||||
else {
|
||||
// Relative sleeps can be done using nanosleep().
|
||||
struct timespec ts;
|
||||
struct os_timespec ts;
|
||||
convert_timestamp(in[0].u.u.clock.timeout, &ts);
|
||||
nanosleep(&ts, NULL);
|
||||
}
|
||||
|
@ -2911,8 +2914,10 @@ wasmtime_ssp_sock_shutdown(wasm_exec_env_t exec_env, struct fd_table *curfds,
|
|||
__wasi_errno_t
|
||||
wasmtime_ssp_sched_yield(void)
|
||||
{
|
||||
#ifdef BH_PLATFORM_WINDOWS
|
||||
#if defined(BH_PLATFORM_WINDOWS)
|
||||
SwitchToThread();
|
||||
#elif defined(WAMR_PLATFORM_ZEPHYR_FORCE_NO_ERROR)
|
||||
k_yield();
|
||||
#else
|
||||
if (sched_yield() < 0)
|
||||
return convert_errno(errno);
|
||||
|
|
|
@ -1636,12 +1636,12 @@ os_clock_time_get(__wasi_clockid_t clock_id, __wasi_timestamp_t precision,
|
|||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* Expermimental :*/
|
||||
#if !defined(WAMR_PLATFORM_ZEPHYR_FORCE_NO_ERROR)
|
||||
__wasi_errno_t
|
||||
os_ioctl(os_file_handle *handle, int request, void *argp);
|
||||
os_ioctl(os_file_handle handle, int request, ...);
|
||||
|
||||
__wasi_errno_t
|
||||
os_poll(os_poll_file_handle *pfds, os_nfds_t nfs, int timeout);
|
||||
|
||||
#endif
|
||||
#endif /* #ifndef PLATFORM_API_EXTENSION_H */
|
||||
|
|
|
@ -88,6 +88,12 @@ typedef struct korp_cond {
|
|||
os_thread_wait_list thread_wait_list;
|
||||
} korp_cond;
|
||||
|
||||
typedef struct {
|
||||
struct k_mutex mtx; // Mutex for exclusive access
|
||||
struct k_sem sem; // Semaphore for shared access
|
||||
int read_count; // Number of readers
|
||||
} korp_rwlock;
|
||||
|
||||
#ifndef Z_TIMEOUT_MS
|
||||
#define Z_TIMEOUT_MS(ms) ms
|
||||
#endif
|
||||
|
@ -167,7 +173,9 @@ typedef void *os_dir_stream;
|
|||
typedef int os_raw_file_handle;
|
||||
|
||||
/*********************************************************/
|
||||
// try to stub POSIX implementation in sandboxed env.
|
||||
//try to stub POSIX implementation in sandboxed env.
|
||||
#if !defined(WAMR_PLATFORM_ZEPHYR_FORCE_NO_ERROR)
|
||||
|
||||
typedef struct zsock_pollfd os_poll_file_handle;
|
||||
typedef unsigned int os_nfds_t;
|
||||
|
||||
|
@ -188,11 +196,13 @@ typedef struct {
|
|||
#define CLOCK_REALTIME 1
|
||||
#define CLOCK_MONOTONIC 4
|
||||
|
||||
typedef struct {
|
||||
struct k_mutex mtx; // Mutex for exclusive access
|
||||
struct k_sem sem; // Semaphore for shared access
|
||||
int read_count; // Number of readers
|
||||
} korp_rwlock;
|
||||
// TODO: use it in sandboxed posix.c.
|
||||
// int os_sched_yield(void)
|
||||
// {
|
||||
// k_yield();
|
||||
// return 0;
|
||||
// }
|
||||
#endif
|
||||
/*********************************************************/
|
||||
|
||||
static inline os_file_handle
|
||||
|
|
|
@ -5,6 +5,8 @@ set (PLATFORM_SHARED_DIR ${CMAKE_CURRENT_LIST_DIR})
|
|||
|
||||
add_definitions(-DBH_PLATFORM_ZEPHYR)
|
||||
|
||||
# add_definitions (-DWAMR_PLATFORM_ZEPHYR_FORCE_NO_ERROR)
|
||||
|
||||
include_directories(${PLATFORM_SHARED_DIR})
|
||||
include_directories(${PLATFORM_SHARED_DIR}/../include)
|
||||
|
||||
|
@ -18,6 +20,7 @@ endif()
|
|||
if (NOT WAMR_BUILD_LIBC_WASI EQUAL 1)
|
||||
list(REMOVE_ITEM source_all ${PLATFORM_SHARED_DIR}/zephyr_socket.c)
|
||||
list(REMOVE_ITEM source_all ${PLATFORM_SHARED_DIR}/zephyr_file.c)
|
||||
list(REMOVE_ITEM source_all ${PLATFORM_SHARED_DIR}/zephyr_clock.c)
|
||||
else()
|
||||
include (${CMAKE_CURRENT_LIST_DIR}/../common/libc-util/platform_common_libc_util.cmake)
|
||||
set(source_all ${source_all} ${PLATFORM_COMMON_LIBC_UTIL_SOURCE})
|
||||
|
|
17
core/shared/platform/zephyr/zephyr_clock.c
Normal file
17
core/shared/platform/zephyr/zephyr_clock.c
Normal file
|
@ -0,0 +1,17 @@
|
|||
#include "platform_api_extension.h"
|
||||
#include "platform_api_vmcore.h"
|
||||
|
||||
#include "zephyr_errno.h"
|
||||
|
||||
__wasi_errno_t
|
||||
os_clock_res_get(__wasi_clockid_t clock_id, __wasi_timestamp_t *resolution)
|
||||
{
|
||||
return __WASI_ENOSYS;
|
||||
}
|
||||
|
||||
__wasi_errno_t
|
||||
os_clock_time_get(__wasi_clockid_t clock_id, __wasi_timestamp_t precision,
|
||||
__wasi_timestamp_t *time)
|
||||
{
|
||||
return __WASI_ENOSYS;
|
||||
}
|
|
@ -187,11 +187,14 @@ os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file)
|
|||
return BH_MALLOC(size);
|
||||
}
|
||||
|
||||
#if !defined(WASM_ENABLE_LIBC_WASI)
|
||||
/* os_mremap cause linking errors */
|
||||
void *
|
||||
os_mremap(void *old_addr, size_t old_size, size_t new_size)
|
||||
{
|
||||
return os_mremap_slow(old_addr, old_size, new_size);
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
os_munmap(void *addr, size_t size)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#include "platform_api_extension.h"
|
||||
#include "platform_api_vmcore.h"
|
||||
|
||||
|
||||
#include <zephyr/net/net_ip.h>
|
||||
#include <zephyr/net/socket.h>
|
||||
#include <zephyr/net/socket_types.h>
|
||||
|
@ -11,6 +10,7 @@
|
|||
|
||||
#include "zephyr_errno.h"
|
||||
#include <assert.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
// Static functions
|
||||
static bool
|
||||
|
@ -574,7 +574,7 @@ os_socket_get_send_timeout(bh_socket_t socket, uint64 *timeout_us)
|
|||
struct timeval tv;
|
||||
socklen_t tv_len = sizeof(tv);
|
||||
|
||||
if (zsock_setsockopt(socket, SOL_SOCKET, SO_SNDTIMEO, &tv, &tv_len) != 0) {
|
||||
if (zsock_setsockopt(socket, SOL_SOCKET, SO_SNDTIMEO, &tv, tv_len) != 0) {
|
||||
return BHT_ERROR;
|
||||
}
|
||||
*timeout_us = (tv.tv_sec * 1000000UL) + tv.tv_usec;
|
||||
|
@ -602,7 +602,7 @@ os_socket_get_recv_timeout(bh_socket_t socket, uint64 *timeout_us)
|
|||
struct timeval tv;
|
||||
socklen_t tv_len = sizeof(tv);
|
||||
|
||||
if (zsock_setsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, &tv, &tv_len) != 0) {
|
||||
if (zsock_setsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, &tv, tv_len) != 0) {
|
||||
return BHT_ERROR;
|
||||
}
|
||||
*timeout_us = (tv.tv_sec * 1000000UL) + tv.tv_usec;
|
||||
|
@ -722,7 +722,7 @@ os_socket_get_tcp_keep_idle(bh_socket_t socket, uint32_t *time_s)
|
|||
socklen_t time_s_len = sizeof(time_s_int);
|
||||
|
||||
#ifdef TCP_KEEPIDLE
|
||||
if (zsock_setsockopt(socket, IPPROTO_TCP, TCP_KEEPIDLE, &time_s_int, &time_s_len)
|
||||
if (zsock_setsockopt(socket, IPPROTO_TCP, TCP_KEEPIDLE, &time_s_int, time_s_len)
|
||||
!= 0) {
|
||||
return BHT_ERROR;
|
||||
}
|
||||
|
@ -730,7 +730,7 @@ os_socket_get_tcp_keep_idle(bh_socket_t socket, uint32_t *time_s)
|
|||
|
||||
return BHT_OK;
|
||||
#elif defined(TCP_KEEPALIVE)
|
||||
if (zsock_setsockopt(socket, IPPROTO_TCP, TCP_KEEPALIVE, &time_s_int, &time_s_len)
|
||||
if (zsock_setsockopt(socket, IPPROTO_TCP, TCP_KEEPALIVE, &time_s_int, time_s_len)
|
||||
!= 0) {
|
||||
return BHT_ERROR;
|
||||
}
|
||||
|
@ -901,6 +901,7 @@ os_socket_set_ip_drop_membership(bh_socket_t socket,
|
|||
return BHT_ERROR;
|
||||
}
|
||||
}
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -918,7 +919,7 @@ os_socket_get_ip_ttl(bh_socket_t socket, uint8_t *ttl_s)
|
|||
{
|
||||
socklen_t opt_len = sizeof(*ttl_s);
|
||||
|
||||
if (zsock_setsockopt(socket, IPPROTO_IP, IP_MULTICAST_TTL, ttl_s, &opt_len)
|
||||
if (zsock_setsockopt(socket, IPPROTO_IP, IP_MULTICAST_TTL, ttl_s, opt_len)
|
||||
!= 0) {
|
||||
return BHT_ERROR;
|
||||
}
|
||||
|
@ -942,7 +943,7 @@ os_socket_get_ip_multicast_ttl(bh_socket_t socket, uint8_t *ttl_s)
|
|||
{
|
||||
socklen_t opt_len = sizeof(*ttl_s);
|
||||
|
||||
if (zsock_setsockopt(socket, IPPROTO_IP, IP_MULTICAST_TTL, ttl_s, &opt_len)
|
||||
if (zsock_setsockopt(socket, IPPROTO_IP, IP_MULTICAST_TTL, ttl_s, opt_len)
|
||||
!= 0) {
|
||||
return BHT_ERROR;
|
||||
}
|
||||
|
@ -993,14 +994,19 @@ os_socket_get_broadcast(bh_socket_t socket, bool *is_enabled)
|
|||
}
|
||||
|
||||
// Experimental :
|
||||
#if !defined(WAMR_PLATFORM_ZEPHYR_FORCE_NO_ERROR)
|
||||
__wasi_errno_t
|
||||
os_ioctl(os_file_handle *handle, int request, void *argp)
|
||||
os_ioctl(os_file_handle handle, int request, ...)
|
||||
{
|
||||
__wasi_errno_t wasi_errno = __WASI_ESUCCESS;
|
||||
va_list args;
|
||||
|
||||
if(zsock_ioctl_wrapper(handle, request, argp) < 0){
|
||||
va_start(args, request);
|
||||
if(zsock_ioctl(handle, request, args) < 0){
|
||||
wasi_errno = zephyr_to_wasi_errno(errno);
|
||||
}
|
||||
va_end(args);
|
||||
|
||||
return wasi_errno;
|
||||
}
|
||||
|
||||
|
@ -1010,13 +1016,13 @@ os_poll(os_poll_file_handle *fds, os_nfds_t nfs, int timeout)
|
|||
__wasi_errno_t wasi_errno = __WASI_ESUCCESS;
|
||||
int rc = 0;
|
||||
|
||||
rc = zsock_poll(fds, nfs, timeout)
|
||||
rc = zsock_poll(fds, nfs, timeout);
|
||||
if(rc < 0){
|
||||
wasi_errno = zephyr_to_wasi_errno(errno);
|
||||
}
|
||||
switch(rc){
|
||||
case 0:
|
||||
wasi_errno = __WASI_ETIMEOUT;
|
||||
wasi_errno = __WASI_ETIMEDOUT;
|
||||
break;
|
||||
case -1:
|
||||
wasi_errno = zephyr_to_wasi_errno(errno);
|
||||
|
@ -1026,3 +1032,4 @@ os_poll(os_poll_file_handle *fds, os_nfds_t nfs, int timeout)
|
|||
}
|
||||
return wasi_errno;
|
||||
}
|
||||
#endif
|
|
@ -579,6 +579,41 @@ void
|
|||
os_thread_jit_write_protect_np(bool enabled)
|
||||
{}
|
||||
|
||||
int
|
||||
os_rwlock_init(korp_rwlock *lock)
|
||||
{
|
||||
/* Not implemented */
|
||||
return BHT_ERROR;
|
||||
}
|
||||
|
||||
int
|
||||
os_rwlock_rdlock(korp_rwlock *lock)
|
||||
{
|
||||
/* Not implemented */
|
||||
return BHT_ERROR;
|
||||
}
|
||||
|
||||
int
|
||||
os_rwlock_wrlock(korp_rwlock *lock)
|
||||
{
|
||||
/* Not implemented */
|
||||
return BHT_ERROR;
|
||||
}
|
||||
|
||||
int
|
||||
os_rwlock_unlock(korp_rwlock *lock)
|
||||
{
|
||||
/* Not implemented */
|
||||
return BHT_ERROR;
|
||||
}
|
||||
|
||||
int
|
||||
os_rwlock_destroy(korp_rwlock *lock)
|
||||
{
|
||||
/* Not implemented */
|
||||
return BHT_ERROR;
|
||||
}
|
||||
|
||||
int
|
||||
os_thread_detach(korp_tid thread)
|
||||
{
|
||||
|
|
|
@ -10,35 +10,17 @@ enable_language (ASM)
|
|||
|
||||
set (WAMR_BUILD_PLATFORM "zephyr")
|
||||
|
||||
############################################################################################################################
|
||||
# __ __ __ __ _____ _____ ____ _ _ ______ _____ _____ _ _ _____ _______ _____ ____ _ _ #
|
||||
# \ \ / /\ | \/ | __ \ / ____/ __ \| \ | | ____|_ _/ ____| | | | __ \ /\|__ __|_ _/ __ \| \ | | #
|
||||
# \ \ /\ / / \ | \ / | |__) | | | | | | | \| | |__ | || | __| | | | |__) | / \ | | | || | | | \| | #
|
||||
# \ \/ \/ / /\ \ | |\/| | _ / | | | | | | . ` | __| | || | |_ | | | | _ / / /\ \ | | | || | | | . ` | #
|
||||
# \ /\ / ____ \| | | | | \ \ | |___| |__| | |\ | | _| || |__| | |__| | | \ \ / ____ \| | _| || |__| | |\ | #
|
||||
# \/ \/_/ \_\_| |_|_| \_\ \_____\____/|_| \_|_| |_____\_____|\____/|_| \_\/_/ \_\_| |_____\____/|_| \_| #
|
||||
############################################################################################################################
|
||||
|
||||
# Build as X86_32 by default, change to "AARCH64[sub]", "ARM[sub]", "THUMB[sub]", "MIPS" or "XTENSA"
|
||||
# if we want to support arm, thumb, mips or xtensa
|
||||
|
||||
# WAMR Configuration:
|
||||
set (WAMR_BUILD_TARGET "THUMB")
|
||||
set (WAMR_BUILD_INTERP 1)
|
||||
set (WAMR_BUILD_AOT 1)
|
||||
set (WAMR_BUILD_LIBC_BUILTIN 1)
|
||||
set (WAMR_BUILD_LIBC_WASI 1) # 1 to use sockets
|
||||
set (WAMR_BUILD_LIB_PTHREAD 0) # 1 to use sockets => cause errors
|
||||
set (WAMR_BUILD_LIB_PTHREAD 0)
|
||||
set (WAMR_BUILD_GLOBAL_HEAP_POOL 1)
|
||||
set (WAMR_BUILD_GLOBAL_HEAP_SIZE 131072) # 128 KB
|
||||
|
||||
###################################################
|
||||
# _____ ______ _______ ______ _ ___ __ #
|
||||
# / ____| ____|__ __| | ____| \ | \ \ / / #
|
||||
# | (___ | |__ | | | |__ | \| |\ \ / / #
|
||||
# \___ \| __| | | | __| | . ` | \ \/ / #
|
||||
# ____) | |____ | | | |____| |\ | \ / #
|
||||
# |_____/|______| |_| |______|_| \_| \/ #
|
||||
###################################################
|
||||
# Environment variables:
|
||||
|
||||
# Check if WAMR_ROOT_DIR is set
|
||||
if(DEFINED ENV{WAMR_ROOT_DIR})
|
||||
|
@ -78,7 +60,7 @@ set(WAMR_SDK_DIR
|
|||
${WAMR_APP_FRAMEWORK_DIR}/wamr-sdk
|
||||
)
|
||||
|
||||
# set the WAMR_LIBC_BUILTIN_DIR with the path specified in the environment variable
|
||||
# set the WAMR_LIBC_BUILTIN_DIR
|
||||
set(WAMR_LIBC_BUILTIN_DIR
|
||||
${WAMR_SDK_DIR}/wamr-sdk/app/libc-builtin-sysroot
|
||||
)
|
||||
|
@ -106,15 +88,8 @@ target_sources(app PRIVATE
|
|||
${WAMR_RUNTIME_LIB_SOURCE}
|
||||
src/main.c)
|
||||
|
||||
####################################################################################################
|
||||
# ____ _ _ _____ _ _____ __ __ _____ __ __ __ __ ____ _____
|
||||
# | _ \| | | |_ _| | | __ \ \ \ / /\ / ____| \/ | | \/ |/ __ \| __ \
|
||||
# | |_) | | | | | | | | | | | | \ \ /\ / / \ | (___ | \ / | | \ / | | | | | | |
|
||||
# | _ <| | | | | | | | | | | | \ \/ \/ / /\ \ \___ \| |\/| | | |\/| | | | | | | |
|
||||
# | |_) | |__| |_| |_| |____| |__| | \ /\ / ____ \ ____) | | | | | | | | |__| | |__| |
|
||||
# |____/ \____/|_____|______|_____/ \/ \/_/ \_\_____/|_| |_| |_| |_|\____/|_____/
|
||||
####################################################################################################
|
||||
|
||||
# Build wasm module with WAMR SDK
|
||||
add_dependencies(app wamr-sdk)
|
||||
|
||||
include(ExternalProject)
|
||||
|
@ -141,6 +116,7 @@ ExternalProject_Add(wamr-sdk
|
|||
USES_TERMINAL
|
||||
)
|
||||
|
||||
# Curently only one app is present
|
||||
set(WASM_APPS
|
||||
http_get
|
||||
)
|
||||
|
@ -156,7 +132,6 @@ foreach(WASM_APP ${WASM_APPS})
|
|||
${WASI_SDK_PATH}/bin/clang -O3
|
||||
-I${WAMR_LIBC_BUILTIN_DIR}/include
|
||||
-I${WAMR_SDK_PACKAGE_OUT_DIR}/include
|
||||
-I/usr/include/ # temp
|
||||
-L${WAMR_SDK_PACKAGE_OUT_DIR}/lib
|
||||
-lapp_framework
|
||||
-z stack-size=8192 -Wl,--initial-memory=65536
|
||||
|
@ -173,7 +148,6 @@ foreach(WASM_APP ${WASM_APPS})
|
|||
USES_TERMINAL
|
||||
)
|
||||
|
||||
|
||||
# Run python script to generate the header file
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/${WASM_APP}.h
|
||||
|
|
|
@ -2,15 +2,83 @@
|
|||
This is a simple http client that make a GET request to a server.
|
||||
|
||||
## Setup
|
||||
TODO
|
||||
1. Connect the USB cable to the Nucleo board.
|
||||
|
||||
2. Optional: Connect a network cable to the board ethernet port.
|
||||
|
||||
## Run Command
|
||||
Replace `nucleo_h743zi` with your board name.
|
||||
|
||||
```bash
|
||||
ZEPHYR_BASE=~/zephyrproject/zephyr \
|
||||
WAMR_ROOT_DIR=~/wasm-micro-runtime \
|
||||
WASI_SDK_PATH=~/wasi-sdk-21.0 \
|
||||
WAMR_APP_FRAMEWORK_DIR=~/wamr-app-framework \
|
||||
west build . -b nucleo_h563zi -p always -- -DWAMR_BUILD_TARGET=THUMBV8 -DCONFIG_LOG_MODE_IMMEDIATE=y
|
||||
1. **Build:** Replace `nucleo_h743zi` with your board name and `THUMBV8` with your target architecture.
|
||||
```bash
|
||||
ZEPHYR_BASE=~/zephyrproject/zephyr \
|
||||
WAMR_ROOT_DIR=~/wasm-micro-runtime \
|
||||
WASI_SDK_PATH=~/wasi-sdk-21.0 \
|
||||
WAMR_APP_FRAMEWORK_DIR=~/wamr-app-framework \
|
||||
west build . -b nucleo_h563zi -p always -- -DWAMR_BUILD_TARGET=THUMBV8
|
||||
```
|
||||
⚠️ **Warning:** The flags `ZEPHYR_BASE`, `WAMR_ROOT_DIR`, `WASI_SDK_PATH`, and `WAMR_APP_FRAMEWORK_DIR` need to be set otherwise the build will fail.
|
||||
|
||||
2. **Flash:**
|
||||
```bash
|
||||
ZEPHYR_BASE=~/zephyrproject/zephyr west flash
|
||||
```
|
||||
|
||||
3. **Monitor:** Use a serial link to monitor the output. Personally, I use minicom.
|
||||
```bash
|
||||
minicom -D /dev/ttyACM0
|
||||
```
|
||||
|
||||
4. **Debug:** Curently investigating.
|
||||
|
||||
## Different approach
|
||||
|
||||
* **Soft:** Trying to implement missing API, and enhancing the existing abstraction API.
|
||||
|
||||
* **Hard:** Making the code compile and run with the existing API.
|
||||
|
||||
By default, we are following the **Soft** approach. If you want to follow the **Hard** approach, you need to uncomment the following line in the `shared_plateform.cmake` file.
|
||||
```cmake
|
||||
# add_definitions (-DWAMR_PLATFORM_ZEPHYR_FORCE_NO_ERROR)
|
||||
```
|
||||
|
||||
### Outputs
|
||||
|
||||
* **Soft:** Unable to compile the code.
|
||||
|
||||
* **Hard:** The code will compile but cause a stack overflow error.
|
||||
```bash
|
||||
[00:00:00.001,000] <err> os: ***** USAGE FAULT *****
|
||||
[00:00:00.007,000] <err> os: Stack overflow (context area not valid)
|
||||
[00:00:00.014,000] <err> os: r0/a1: 0xf0f0f0f0 r1/a2: 0x693b613b r2/a3: 0x0807be46
|
||||
[00:00:00.022,000] <err> os: r3/a4: 0x09000000 r12/ip: 0x2002fb58 r14/lr: 0x0804f0b1
|
||||
[00:00:00.031,000] <err> os: xpsr: 0x08080c00
|
||||
[00:00:00.036,000] <err> os: Faulting instruction address (r15/pc): 0x2a1b681b
|
||||
[00:00:00.044,000] <err> os: >>> ZEPHYR FATAL ERROR 2: Stack overflow on CPU 0
|
||||
[00:00:00.052,000] <err> os: Current thread: 0x20002ef8 (unknown)
|
||||
[00:00:00.059,000] <err> os: Halting system
|
||||
```
|
||||
|
||||
## Expected Output
|
||||
|
||||
### Host
|
||||
```bash
|
||||
python3 -m http.server --bind 0.0.0.0
|
||||
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
|
||||
127.0.0.1 - - [12/Apr/2024 09:54:24] "GET / HTTP/1.0" 200 -
|
||||
```
|
||||
|
||||
### Target
|
||||
```bash
|
||||
Preparing HTTP GET request for http://127.0.0.1:8000/
|
||||
sock = 5
|
||||
Response:
|
||||
|
||||
HTTP/1.0 200 OK
|
||||
Server: SimpleHTTP/0.6 Python/3.10.12
|
||||
Date: Thu, 11 Apr 2024 13:41:11 GMT
|
||||
Content-type: text/html
|
||||
Content-Length: 14054
|
||||
Last-Modified: Thu, 30 Mar 2023 09:11:09 GMT
|
||||
|
||||
# Skip HTML content
|
||||
```
|
|
@ -1,7 +1,35 @@
|
|||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
CONFIG_STACK_SENTINEL=y
|
||||
# Log config
|
||||
CONFIG_PRINTK=y
|
||||
CONFIG_LOG=y
|
||||
CONFIG_LOG_MODE_IMMEDIATE=y
|
||||
CONFIG_LOG_MAX_LEVEL=4
|
||||
#Info=4 Debug=3 Warn=2 Error=1 Off=0
|
||||
|
||||
# Networking config
|
||||
CONFIG_NETWORKING=y
|
||||
CONFIG_NET_IPV4=y
|
||||
CONFIG_NET_TCP=y
|
||||
CONFIG_NET_SOCKETS=y
|
||||
CONFIG_POSIX_API=n
|
||||
|
||||
# Stack conf
|
||||
CONFIG_NO_OPTIMIZATIONS=y
|
||||
CONFIG_STACK_SENTINEL=y
|
||||
CONFIG_HW_STACK_PROTECTION=y
|
||||
|
||||
# Debug
|
||||
# CONFIG_DEBUG=y
|
||||
# CONFIG_STACK_USAGE=y
|
||||
# CONFIG_THREAD_ANALYZER=y
|
||||
# CONFIG_THREAD_ANALYZER_USE_PRINTK=y
|
||||
# CONFIG_THREAD_ANALYZER_AUTO=y
|
||||
# CONFIG_THREAD_ANALYZER_AUTO_INTERVAL=5
|
||||
|
||||
# GDB
|
||||
# CONFIG_SERIAL=y
|
||||
# CONFIG_UART_USE_RUNTIME_CONFIGURE=y
|
||||
# CONFIG_GDBSTUB=y
|
||||
# CONFIG_GDBSTUB_SERIAL_BACKEND=y
|
File diff suppressed because one or more lines are too long
|
@ -21,7 +21,7 @@
|
|||
#define CONFIG_APP_HEAP_SIZE 8192
|
||||
|
||||
#ifdef CONFIG_NO_OPTIMIZATIONS
|
||||
#define CONFIG_MAIN_THREAD_STACK_SIZE 8192
|
||||
#define CONFIG_MAIN_THREAD_STACK_SIZE 8192 * 4
|
||||
#else
|
||||
#define CONFIG_MAIN_THREAD_STACK_SIZE 4096
|
||||
#endif
|
||||
|
@ -126,23 +126,19 @@ iwasm_main(void *arg1, void *arg2, void *arg3)
|
|||
#error "memory allocation scheme is not defined."
|
||||
#endif
|
||||
|
||||
// Use the address pool in wasm-micro-runtime
|
||||
// #if WASM_ENABLE_LIBC_WASI != 0
|
||||
// #define HUMAN_READABLE_ADDRESS "192.0.2.10\\24"
|
||||
// libc_wasi_parse_context_t wasi_parse_ctx;
|
||||
// memset(&wasi_parse_ctx, 0, sizeof(wasi_parse_ctx));
|
||||
/* Use the address pool in wasm-micro-runtime */
|
||||
#if WASM_ENABLE_LIBC_WASI != 0
|
||||
#define ADDRESS_POOL_SIZE 1
|
||||
const char *addr_pool[ADDRESS_POOL_SIZE] = {
|
||||
"192.0.2.10\\24",
|
||||
// Add more addresses here if needed
|
||||
};
|
||||
|
||||
// libc_wasi_parse_result_t result = libc_wasi_parse(HUMAN_READABLE_ADDRESS, &wasi_parse_ctx);
|
||||
// switch (result) {
|
||||
// case LIBC_WASI_PARSE_RESULT_OK:
|
||||
// continue;
|
||||
// case LIBC_WASI_PARSE_RESULT_NEED_HELP:
|
||||
// return;
|
||||
// case LIBC_WASI_PARSE_RESULT_BAD_PARAM:
|
||||
// return;
|
||||
// }
|
||||
// libc_wasi_init(wasm_module, argc, argv, &wasi_parse_ctx);
|
||||
// #endif
|
||||
/*wasm_runtime_set_wasi_addr_pool(wasm_module_t module,
|
||||
const char *addr_pool[], uint32_t addr_pool_size); */
|
||||
wasm_runtime_set_wasi_addr_pool(wasm_module, addr_pool,
|
||||
ADDRESS_POOL_SIZE);
|
||||
#endif
|
||||
|
||||
/* initialize runtime environment */
|
||||
if (!wasm_runtime_full_init(&init_args)) {
|
||||
|
@ -176,7 +172,7 @@ iwasm_main(void *arg1, void *arg2, void *arg3)
|
|||
/* invoke the main function */
|
||||
app_instance_main(wasm_module_inst);
|
||||
|
||||
//
|
||||
// TODO: adapt app_instance_main to have a ret code.
|
||||
// #if WASM_ENABLE_LIBC_WASI != 0
|
||||
// if (ret == 0) {
|
||||
// /* propagate wasi exit code. */
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
/**
|
||||
* The byte array buffer is the file content of a test wasm binary file,
|
||||
* which is compiled by wasi-sdk toolchain from C source file of:
|
||||
* product-mini/app-samples/hello-world/main.c.
|
||||
*/
|
||||
unsigned char __aligned(4) wasm_test_file[] = {
|
||||
0x00, 0x61, 0x73, 0x6D, 0x01, 0x00, 0x00, 0x00, 0x01, 0x10, 0x03, 0x60,
|
||||
0x01, 0x7F, 0x01, 0x7F, 0x60, 0x02, 0x7F, 0x7F, 0x01, 0x7F, 0x60, 0x01,
|
||||
0x7F, 0x00, 0x02, 0x31, 0x04, 0x03, 0x65, 0x6E, 0x76, 0x04, 0x70, 0x75,
|
||||
0x74, 0x73, 0x00, 0x00, 0x03, 0x65, 0x6E, 0x76, 0x06, 0x6D, 0x61, 0x6C,
|
||||
0x6C, 0x6F, 0x63, 0x00, 0x00, 0x03, 0x65, 0x6E, 0x76, 0x06, 0x70, 0x72,
|
||||
0x69, 0x6E, 0x74, 0x66, 0x00, 0x01, 0x03, 0x65, 0x6E, 0x76, 0x04, 0x66,
|
||||
0x72, 0x65, 0x65, 0x00, 0x02, 0x03, 0x02, 0x01, 0x01, 0x04, 0x05, 0x01,
|
||||
0x70, 0x01, 0x01, 0x01, 0x05, 0x03, 0x01, 0x00, 0x01, 0x06, 0x13, 0x03,
|
||||
0x7F, 0x01, 0x41, 0xC0, 0x28, 0x0B, 0x7F, 0x00, 0x41, 0xBA, 0x08, 0x0B,
|
||||
0x7F, 0x00, 0x41, 0xC0, 0x28, 0x0B, 0x07, 0x2C, 0x04, 0x06, 0x6D, 0x65,
|
||||
0x6D, 0x6F, 0x72, 0x79, 0x02, 0x00, 0x0A, 0x5F, 0x5F, 0x64, 0x61, 0x74,
|
||||
0x61, 0x5F, 0x65, 0x6E, 0x64, 0x03, 0x01, 0x0B, 0x5F, 0x5F, 0x68, 0x65,
|
||||
0x61, 0x70, 0x5F, 0x62, 0x61, 0x73, 0x65, 0x03, 0x02, 0x04, 0x6D, 0x61,
|
||||
0x69, 0x6E, 0x00, 0x04, 0x0A, 0xB2, 0x01, 0x01, 0xAF, 0x01, 0x01, 0x03,
|
||||
0x7F, 0x23, 0x80, 0x80, 0x80, 0x80, 0x00, 0x41, 0x20, 0x6B, 0x22, 0x02,
|
||||
0x24, 0x80, 0x80, 0x80, 0x80, 0x00, 0x41, 0x9B, 0x88, 0x80, 0x80, 0x00,
|
||||
0x10, 0x80, 0x80, 0x80, 0x80, 0x00, 0x1A, 0x02, 0x40, 0x02, 0x40, 0x41,
|
||||
0x80, 0x08, 0x10, 0x81, 0x80, 0x80, 0x80, 0x00, 0x22, 0x03, 0x0D, 0x00,
|
||||
0x41, 0xA8, 0x88, 0x80, 0x80, 0x00, 0x10, 0x80, 0x80, 0x80, 0x80, 0x00,
|
||||
0x1A, 0x41, 0x7F, 0x21, 0x04, 0x0C, 0x01, 0x0B, 0x20, 0x02, 0x20, 0x03,
|
||||
0x36, 0x02, 0x10, 0x41, 0x80, 0x88, 0x80, 0x80, 0x00, 0x20, 0x02, 0x41,
|
||||
0x10, 0x6A, 0x10, 0x82, 0x80, 0x80, 0x80, 0x00, 0x1A, 0x41, 0x00, 0x21,
|
||||
0x04, 0x20, 0x03, 0x41, 0x04, 0x6A, 0x41, 0x00, 0x2F, 0x00, 0x91, 0x88,
|
||||
0x80, 0x80, 0x00, 0x3B, 0x00, 0x00, 0x20, 0x03, 0x41, 0x00, 0x28, 0x00,
|
||||
0x8D, 0x88, 0x80, 0x80, 0x00, 0x36, 0x00, 0x00, 0x20, 0x02, 0x20, 0x03,
|
||||
0x36, 0x02, 0x00, 0x41, 0x93, 0x88, 0x80, 0x80, 0x00, 0x20, 0x02, 0x10,
|
||||
0x82, 0x80, 0x80, 0x80, 0x00, 0x1A, 0x20, 0x03, 0x10, 0x83, 0x80, 0x80,
|
||||
0x80, 0x00, 0x0B, 0x20, 0x02, 0x41, 0x20, 0x6A, 0x24, 0x80, 0x80, 0x80,
|
||||
0x80, 0x00, 0x20, 0x04, 0x0B, 0x0B, 0x41, 0x01, 0x00, 0x41, 0x80, 0x08,
|
||||
0x0B, 0x3A, 0x62, 0x75, 0x66, 0x20, 0x70, 0x74, 0x72, 0x3A, 0x20, 0x25,
|
||||
0x70, 0x0A, 0x00, 0x31, 0x32, 0x33, 0x34, 0x0A, 0x00, 0x62, 0x75, 0x66,
|
||||
0x3A, 0x20, 0x25, 0x73, 0x00, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x77,
|
||||
0x6F, 0x72, 0x6C, 0x64, 0x21, 0x00, 0x6D, 0x61, 0x6C, 0x6C, 0x6F, 0x63,
|
||||
0x20, 0x62, 0x75, 0x66, 0x20, 0x66, 0x61, 0x69, 0x6C, 0x65, 0x64, 0x00
|
||||
};
|
|
@ -1,41 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
unsigned char __aligned(4) wasm_test_file[] = {
|
||||
0x00, 0x61, 0x73, 0x6D, 0x01, 0x00, 0x00, 0x00, 0x01, 0x10, 0x03, 0x60,
|
||||
0x01, 0x7F, 0x01, 0x7F, 0x60, 0x02, 0x7F, 0x7F, 0x01, 0x7F, 0x60, 0x01,
|
||||
0x7F, 0x00, 0x02, 0x31, 0x04, 0x03, 0x65, 0x6E, 0x76, 0x04, 0x70, 0x75,
|
||||
0x74, 0x73, 0x00, 0x00, 0x03, 0x65, 0x6E, 0x76, 0x06, 0x6D, 0x61, 0x6C,
|
||||
0x6C, 0x6F, 0x63, 0x00, 0x00, 0x03, 0x65, 0x6E, 0x76, 0x06, 0x70, 0x72,
|
||||
0x69, 0x6E, 0x74, 0x66, 0x00, 0x01, 0x03, 0x65, 0x6E, 0x76, 0x04, 0x66,
|
||||
0x72, 0x65, 0x65, 0x00, 0x02, 0x03, 0x02, 0x01, 0x01, 0x04, 0x05, 0x01,
|
||||
0x70, 0x01, 0x01, 0x01, 0x05, 0x03, 0x01, 0x00, 0x01, 0x06, 0x12, 0x03,
|
||||
0x7F, 0x01, 0x41, 0xC0, 0x01, 0x0B, 0x7F, 0x00, 0x41, 0x3A, 0x0B, 0x7F,
|
||||
0x00, 0x41, 0xC0, 0x01, 0x0B, 0x07, 0x2C, 0x04, 0x06, 0x6D, 0x65, 0x6D,
|
||||
0x6F, 0x72, 0x79, 0x02, 0x00, 0x04, 0x6D, 0x61, 0x69, 0x6E, 0x00, 0x04,
|
||||
0x0A, 0x5F, 0x5F, 0x64, 0x61, 0x74, 0x61, 0x5F, 0x65, 0x6E, 0x64, 0x03,
|
||||
0x01, 0x0B, 0x5F, 0x5F, 0x68, 0x65, 0x61, 0x70, 0x5F, 0x62, 0x61, 0x73,
|
||||
0x65, 0x03, 0x02, 0x0A, 0xB1, 0x01, 0x01, 0xAE, 0x01, 0x01, 0x03, 0x7F,
|
||||
0x23, 0x80, 0x80, 0x80, 0x80, 0x00, 0x41, 0x20, 0x6B, 0x22, 0x02, 0x24,
|
||||
0x80, 0x80, 0x80, 0x80, 0x00, 0x41, 0x9B, 0x80, 0x80, 0x80, 0x00, 0x10,
|
||||
0x80, 0x80, 0x80, 0x80, 0x00, 0x1A, 0x02, 0x40, 0x02, 0x40, 0x41, 0x10,
|
||||
0x10, 0x81, 0x80, 0x80, 0x80, 0x00, 0x22, 0x03, 0x0D, 0x00, 0x41, 0xA8,
|
||||
0x80, 0x80, 0x80, 0x00, 0x10, 0x80, 0x80, 0x80, 0x80, 0x00, 0x1A, 0x41,
|
||||
0x7F, 0x21, 0x04, 0x0C, 0x01, 0x0B, 0x20, 0x02, 0x20, 0x03, 0x36, 0x02,
|
||||
0x10, 0x41, 0x80, 0x80, 0x80, 0x80, 0x00, 0x20, 0x02, 0x41, 0x10, 0x6A,
|
||||
0x10, 0x82, 0x80, 0x80, 0x80, 0x00, 0x1A, 0x41, 0x00, 0x21, 0x04, 0x20,
|
||||
0x03, 0x41, 0x04, 0x6A, 0x41, 0x00, 0x2F, 0x00, 0x91, 0x80, 0x80, 0x80,
|
||||
0x00, 0x3B, 0x00, 0x00, 0x20, 0x03, 0x41, 0x00, 0x28, 0x00, 0x8D, 0x80,
|
||||
0x80, 0x80, 0x00, 0x36, 0x00, 0x00, 0x20, 0x02, 0x20, 0x03, 0x36, 0x02,
|
||||
0x00, 0x41, 0x93, 0x80, 0x80, 0x80, 0x00, 0x20, 0x02, 0x10, 0x82, 0x80,
|
||||
0x80, 0x80, 0x00, 0x1A, 0x20, 0x03, 0x10, 0x83, 0x80, 0x80, 0x80, 0x00,
|
||||
0x0B, 0x20, 0x02, 0x41, 0x20, 0x6A, 0x24, 0x80, 0x80, 0x80, 0x80, 0x00,
|
||||
0x20, 0x04, 0x0B, 0x0B, 0x40, 0x01, 0x00, 0x41, 0x00, 0x0B, 0x3A, 0x62,
|
||||
0x75, 0x66, 0x20, 0x70, 0x74, 0x72, 0x3A, 0x20, 0x25, 0x70, 0x0A, 0x00,
|
||||
0x31, 0x32, 0x33, 0x34, 0x0A, 0x00, 0x62, 0x75, 0x66, 0x3A, 0x20, 0x25,
|
||||
0x73, 0x00, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x77, 0x6F, 0x72, 0x6C,
|
||||
0x64, 0x21, 0x00, 0x6D, 0x61, 0x6C, 0x6C, 0x6F, 0x63, 0x20, 0x62, 0x75,
|
||||
0x66, 0x20, 0x66, 0x61, 0x69, 0x6C, 0x65, 0x64, 0x00
|
||||
};
|
|
@ -1,9 +1,7 @@
|
|||
# Python script to convert wasm file to byte array in a .h file
|
||||
import os
|
||||
|
||||
|
||||
CWD = os.getcwd()
|
||||
|
||||
CMAKE_CURRENT_BINARY_DIR = os.getenv('CMAKE_CURRENT_BINARY_DIR', CWD)
|
||||
CMAKE_CURRENT_SOURCE_DIR = os.getenv('CMAKE_CURRENT_SOURCE_DIR', f'{CWD}/../src')
|
||||
|
||||
|
|
|
@ -7,22 +7,16 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if !defined(__ZEPHYR__) || defined(CONFIG_POSIX_API)
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <unistd.h>
|
||||
#include <netdb.h>
|
||||
#include <errno.h>
|
||||
#else
|
||||
#include <zephyr/net/socket.h>
|
||||
#include <zephyr/kernel.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
|
||||
// #ifdef __wasi__
|
||||
// #include <wasi_socket_ext.h>
|
||||
// #endif
|
||||
#ifdef __wasi__
|
||||
#include "inc/wasi_socket_ext.h"
|
||||
#endif
|
||||
|
||||
|
||||
/* HTTP server to connect to */
|
||||
|
@ -40,65 +34,25 @@
|
|||
|
||||
static char response[1024];
|
||||
|
||||
void dump_addrinfo(const struct addrinfo *ai)
|
||||
{
|
||||
printf("addrinfo @%p: ai_family=%d, ai_socktype=%d, ai_protocol=%d, "
|
||||
"sa_family=%d, sin_port=%x\n",
|
||||
ai, ai->ai_family, ai->ai_socktype, ai->ai_protocol,
|
||||
ai->ai_addr->sa_family,
|
||||
((struct sockaddr_in *)ai->ai_addr)->sin_port);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
static struct addrinfo hints;
|
||||
struct addrinfo *res;
|
||||
int st, sock;
|
||||
struct sockaddr_in addr;
|
||||
|
||||
printf("Preparing HTTP GET request for http://" HTTP_HOST
|
||||
":" HTTP_PORT HTTP_PATH "\n");
|
||||
|
||||
hints.ai_family = AF_INET;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
st = getaddrinfo(HTTP_HOST, HTTP_PORT, &hints, &res);
|
||||
printf("getaddrinfo status: %d\n", st);
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(atoi(HTTP_PORT));
|
||||
inet_pton(AF_INET, HTTP_HOST, &(addr.sin_addr));
|
||||
|
||||
if (st != 0) {
|
||||
printf("Unable to resolve address, quitting\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
dump_addrinfo(res);
|
||||
|
||||
//sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
|
||||
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
|
||||
CHECK(sock);
|
||||
printf("sock = %d\n", sock);
|
||||
|
||||
CHECK(connect(sock, res->ai_addr, res->ai_addrlen));
|
||||
// int rc = 0;
|
||||
// for(int i = 0; i < 10; i++){
|
||||
// rc = connect(sock, res->ai_addr, res->ai_addrlen);
|
||||
// if (rc == 0) {
|
||||
// break;
|
||||
// }
|
||||
// else{
|
||||
// printf("[Debug] Connect try %d: status %d\n", i+1, errno);
|
||||
// close(sock);
|
||||
// k_sleep(K_MSEC(100)); // 10 mil seconds
|
||||
// sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
|
||||
// if (sock < 0) {
|
||||
// printf("[Error] Unable to create socket, exiting...");
|
||||
// exit(1);
|
||||
// }
|
||||
// }
|
||||
// k_sleep(K_MSEC(1000 * 5)); // 5 seconds
|
||||
// }
|
||||
// if(rc){
|
||||
// printf("[Error] Unable to Connect exiting...");
|
||||
// exit(1);
|
||||
// }
|
||||
CHECK(connect(sock, (struct sockaddr*)&addr, sizeof(addr)));
|
||||
|
||||
CHECK(send(sock, REQUEST, SSTRLEN(REQUEST), 0));
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user