Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions arch/sim/src/cmake/Toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ endif()
if(CONFIG_COVERAGE_ALL)
if(CONFIG_ARCH_TOOLCHAIN_GCC)
add_compile_options(-fprofile-arcs -ftest-coverage -fno-inline)
if(APPLE)
add_link_options(-fprofile-arcs -ftest-coverage)
endif()
elseif(CONFIG_ARCH_TOOLCHAIN_CLANG)
add_compile_options(-fprofile-instr-generate -fcoverage-mapping)
add_link_options(-fprofile-instr-generate)
Expand Down
4 changes: 3 additions & 1 deletion arch/sim/src/sim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ set(HOSTSRCS)
set(HOST_INCLUDE_DIRS)
set(STDLIBS pthread)

if(CONFIG_COVERAGE_TOOLCHAIN)
if(CONFIG_COVERAGE_TOOLCHAIN
AND CONFIG_ARCH_TOOLCHAIN_GCC
AND NOT APPLE)
list(APPEND STDLIBS gcov)
endif()

Expand Down
26 changes: 17 additions & 9 deletions arch/sim/src/sim/posix/sim_macho_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include <sys/mman.h>

#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>

Expand Down Expand Up @@ -78,11 +80,12 @@ static void save_and_replace_init_funcs(int argc, const char *argv[],
const char *apple[])
{
init_func_t *fp;
bool found_self = false;
unsigned int i;
unsigned int nfuncs = &mod_init_func_end - &mod_init_func_start;

assert(nfuncs > 0);
g_num_saved_init_funcs = nfuncs - 1;
if (g_num_saved_init_funcs == 0)
if (nfuncs == 1)
{
/* This function is the only constructor in the binary.
* no need to apply the following hack.
Expand All @@ -96,23 +99,28 @@ static void save_and_replace_init_funcs(int argc, const char *argv[],
g_saved_envp = envp;
g_saved_apple = apple;

g_saved_init_funcs = malloc(g_num_saved_init_funcs *
sizeof(*g_saved_init_funcs));
g_saved_init_funcs = malloc((nfuncs - 1) * sizeof(*g_saved_init_funcs));
allow_write(&mod_init_func_start, &mod_init_func_end);
int i = 0;
i = 0;
for (fp = &mod_init_func_start; fp < &mod_init_func_end; fp++)
{
if (*fp == save_and_replace_init_funcs)
{
assert(i == 0);
found_self = true;
continue;
}
else

if (found_self)
{
g_saved_init_funcs[i - 1] = *fp;
assert(i < nfuncs - 1);
g_saved_init_funcs[i] = *fp;
*fp = noop;
i++;
}
i++;
}

assert(found_self);
g_num_saved_init_funcs = i;
}

/****************************************************************************
Expand Down
21 changes: 20 additions & 1 deletion sched/clock/clock_gettime.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@
# include "clock/clock_timekeeping.h"
#endif

/****************************************************************************
* Pre-processor Definitions
****************************************************************************/

#if defined(CONFIG_ARCH_SIM) && defined(CONFIG_HOST_MACOS)
/* Rust code built for the macOS host uses Darwin's libc clock IDs. When it
* is linked into the NuttX simulator, those values are passed to NuttX's
* clock_gettime() implementation instead of Darwin's one.
*/

# define DARWIN_CLOCK_MONOTONIC 6
# define DARWIN_CLOCK_UPTIME_RAW 8
#endif

/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -97,7 +111,12 @@ int nxclock_gettime(clockid_t clock_id, FAR struct timespec *tp)
return -EINVAL;
}

if (clock_id == CLOCK_MONOTONIC)
if (clock_id == CLOCK_MONOTONIC
#if defined(CONFIG_ARCH_SIM) && defined(CONFIG_HOST_MACOS)
|| clock_id == DARWIN_CLOCK_MONOTONIC
|| clock_id == DARWIN_CLOCK_UPTIME_RAW
#endif
)
{
/* The the time elapsed since the timer was initialized at power on
* reset, excluding the time that the system is suspended.
Expand Down
Loading