Add FreeBSD support

This commit is contained in:
Saúl Ibarra Corretgé 2023-12-05 09:14:12 +01:00
parent 478bcf74f2
commit 8128e66145
4 changed files with 22 additions and 5 deletions

View file

@ -401,3 +401,18 @@ jobs:
cmake -B build cmake -B build
cmake --build build -j $(sysctl -n hw.ncpu) cmake --build build -j $(sysctl -n hw.ncpu)
./build/qjs -qd ./build/qjs -qd
freebsd:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: build + test
uses: vmactions/freebsd-vm@v1
with:
usesh: true
prepare: |
pkg install -y cmake
run: |
cmake -B build
cmake --build build -j $(sysctl -n hw.ncpu)
./build/qjs -qd

4
qjs.c
View file

@ -38,6 +38,8 @@
#include <malloc/malloc.h> #include <malloc/malloc.h>
#elif defined(__linux__) || defined(__CYGWIN__) #elif defined(__linux__) || defined(__CYGWIN__)
#include <malloc.h> #include <malloc.h>
#elif defined(__FreeBSD__)
#include <malloc_np.h>
#endif #endif
#include "cutils.h" #include "cutils.h"
@ -135,7 +137,7 @@ static inline size_t js_trace_malloc_usable_size(void *ptr)
return malloc_size(ptr); return malloc_size(ptr);
#elif defined(_WIN32) #elif defined(_WIN32)
return _msize(ptr); return _msize(ptr);
#elif defined(__linux__) #elif defined(__linux__) || defined(__FreeBSD__)
return malloc_usable_size(ptr); return malloc_usable_size(ptr);
#else #else
return 0; return 0;

View file

@ -67,13 +67,11 @@
#if defined(__APPLE__) #if defined(__APPLE__)
typedef sig_t sighandler_t; typedef sig_t sighandler_t;
#if !defined(environ)
#include <crt_externs.h> #include <crt_externs.h>
#define environ (*_NSGetEnviron()) #define environ (*_NSGetEnviron())
#endif #endif
#endif /* __APPLE__ */
#if defined(__OpenBSD__) #if defined(__OpenBSD__) || defined(__FreeBSD__)
typedef sig_t sighandler_t; typedef sig_t sighandler_t;
extern char **environ; extern char **environ;
#endif #endif
@ -3591,6 +3589,8 @@ void js_std_set_worker_new_context_func(JSContext *(*func)(JSRuntime *rt))
#define OS_PLATFORM "linux" #define OS_PLATFORM "linux"
#elif defined(__OpenBSD__) #elif defined(__OpenBSD__)
#define OS_PLATFORM "openbsd" #define OS_PLATFORM "openbsd"
#elif defined(__FreeBSD__)
#define OS_PLATFORM "freebsd"
#else #else
#define OS_PLATFORM "unknown" #define OS_PLATFORM "unknown"
#endif #endif

View file

@ -1646,7 +1646,7 @@ static inline size_t js_def_malloc_usable_size(void *ptr)
return malloc_size(ptr); return malloc_size(ptr);
#elif defined(_WIN32) #elif defined(_WIN32)
return _msize(ptr); return _msize(ptr);
#elif defined(__linux__) #elif defined(__linux__) || defined(__FreeBSD__)
return malloc_usable_size(ptr); return malloc_usable_size(ptr);
#else #else
return 0; return 0;