mirror of
https://github.com/yann64/haikuports.git
synced 2026-04-16 08:40:06 +02:00
This patch syncs the changes of alaviss's libuv port from upstream into HaikuPorts with the following changes: * Implements uv__fs_utime() using utimensat() * Implements uv__fs_futime() using futimens() * Stub implementation of uv_get_constrained_memory() This is just enough to get npm (Node Package Manager) working.
440 lines
13 KiB
Plaintext
440 lines
13 KiB
Plaintext
From 6fec6a490af8575c0d7294d291bce304f17698fb Mon Sep 17 00:00:00 2001
|
|
From: Leorize <leorize+oss@disroot.org>
|
|
Date: Fri, 4 Jan 2019 23:45:20 +0700
|
|
Subject: build, core, unix: add support for Haiku
|
|
|
|
This commit add support for Haiku, an open-source operating system
|
|
inspired by BeOS.
|
|
|
|
diff --git a/Makefile.am b/Makefile.am
|
|
index 07224f3..32f4db7 100644
|
|
--- a/Makefile.am
|
|
+++ b/Makefile.am
|
|
@@ -409,6 +409,17 @@ libuv_la_SOURCES += src/unix/bsd-ifaddrs.c \
|
|
test_run_tests_LDFLAGS += -lutil
|
|
endif
|
|
|
|
+if HAIKU
|
|
+uvinclude_HEADERS += include/uv/posix.h
|
|
+libuv_la_CFLAGS += -D_BSD_SOURCE
|
|
+libuv_la_SOURCES += src/unix/bsd-ifaddrs.c \
|
|
+ src/unix/haiku.c \
|
|
+ src/unix/no-fsevents.c \
|
|
+ src/unix/no-proctitle.c \
|
|
+ src/unix/posix-hrtime.c \
|
|
+ src/unix/posix-poll.c
|
|
+endif
|
|
+
|
|
if HURD
|
|
uvinclude_HEADERS += include/uv/posix.h
|
|
libuv_la_SOURCES += src/unix/no-fsevents.c \
|
|
diff --git a/configure.ac b/configure.ac
|
|
index ad99f9a..5ab75b8 100644
|
|
--- a/configure.ac
|
|
+++ b/configure.ac
|
|
@@ -56,6 +56,7 @@ AM_CONDITIONAL([CYGWIN], [AS_CASE([$host_os],[cygwin*], [true], [false])
|
|
AM_CONDITIONAL([DARWIN], [AS_CASE([$host_os],[darwin*], [true], [false])])
|
|
AM_CONDITIONAL([DRAGONFLY],[AS_CASE([$host_os],[dragonfly*], [true], [false])])
|
|
AM_CONDITIONAL([FREEBSD], [AS_CASE([$host_os],[*freebsd*], [true], [false])])
|
|
+AM_CONDITIONAL([HAIKU], [AS_CASE([$host_os],[haiku], [true], [false])])
|
|
AM_CONDITIONAL([HURD], [AS_CASE([$host_os],[gnu*], [true], [false])])
|
|
AM_CONDITIONAL([LINUX], [AS_CASE([$host_os],[linux*], [true], [false])])
|
|
AM_CONDITIONAL([MSYS], [AS_CASE([$host_os],[msys*], [true], [false])])
|
|
@@ -71,6 +72,9 @@ AS_CASE([$host_os], [netbsd*], [AC_CHECK_LIB([kvm], [kvm_open])])
|
|
AS_CASE([$host_os], [kfreebsd*], [
|
|
LIBS="$LIBS -lfreebsd-glue"
|
|
])
|
|
+AS_CASE([$host_os], [haiku], [
|
|
+ LIBS="$LIBS -lnetwork"
|
|
+])
|
|
AC_CHECK_HEADERS([sys/ahafs_evProds.h])
|
|
AC_CONFIG_FILES([Makefile libuv.pc])
|
|
AC_CONFIG_LINKS([test/fixtures/empty_file:test/fixtures/empty_file])
|
|
diff --git a/include/uv/unix.h b/include/uv/unix.h
|
|
index f73b7b0..6c93ee9 100644
|
|
--- a/include/uv/unix.h
|
|
+++ b/include/uv/unix.h
|
|
@@ -66,6 +66,8 @@
|
|
defined(__MSYS__) || \
|
|
defined(__GNU__)
|
|
# include "uv/posix.h"
|
|
+#elif defined(__HAIKU__)
|
|
+# include "uv/posix.h"
|
|
#endif
|
|
|
|
#ifndef NI_MAXHOST
|
|
diff --git a/src/unix/bsd-ifaddrs.c b/src/unix/bsd-ifaddrs.c
|
|
index a4c6bf9..0d7bbe6 100644
|
|
--- a/src/unix/bsd-ifaddrs.c
|
|
+++ b/src/unix/bsd-ifaddrs.c
|
|
@@ -31,6 +31,10 @@
|
|
#include <net/if_dl.h>
|
|
#endif
|
|
|
|
+#if defined(__HAIKU__)
|
|
+#define IFF_RUNNING IFF_LINK
|
|
+#endif
|
|
+
|
|
static int uv__ifaddr_exclude(struct ifaddrs *ent, int exclude_type) {
|
|
if (!((ent->ifa_flags & IFF_UP) && (ent->ifa_flags & IFF_RUNNING)))
|
|
return 1;
|
|
@@ -45,7 +49,8 @@ static int uv__ifaddr_exclude(struct ifaddrs *ent, int exclude_type) {
|
|
if (exclude_type == UV__EXCLUDE_IFPHYS)
|
|
return (ent->ifa_addr->sa_family != AF_LINK);
|
|
#endif
|
|
-#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__)
|
|
+#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__) || \
|
|
+ defined(__HAIKU__)
|
|
/*
|
|
* On BSD getifaddrs returns information related to the raw underlying
|
|
* devices. We're not interested in this information.
|
|
diff --git a/src/unix/core.c b/src/unix/core.c
|
|
index 3bada90..1b3de43 100644
|
|
--- a/src/unix/core.c
|
|
+++ b/src/unix/core.c
|
|
@@ -579,7 +579,7 @@ int uv__nonblock_ioctl(int fd, int set) {
|
|
}
|
|
|
|
|
|
-#if !defined(__CYGWIN__) && !defined(__MSYS__)
|
|
+#if !defined(__CYGWIN__) && !defined(__MSYS__) && !defined(__HAIKU__)
|
|
int uv__cloexec_ioctl(int fd, int set) {
|
|
int r;
|
|
|
|
@@ -947,7 +947,7 @@ int uv_getrusage(uv_rusage_t* rusage) {
|
|
rusage->ru_stime.tv_sec = usage.ru_stime.tv_sec;
|
|
rusage->ru_stime.tv_usec = usage.ru_stime.tv_usec;
|
|
|
|
-#if !defined(__MVS__)
|
|
+#if !defined(__MVS__) && !defined(__HAIKU__)
|
|
rusage->ru_maxrss = usage.ru_maxrss;
|
|
rusage->ru_ixrss = usage.ru_ixrss;
|
|
rusage->ru_idrss = usage.ru_idrss;
|
|
diff --git a/src/unix/haiku.c b/src/unix/haiku.c
|
|
new file mode 100644
|
|
index 0000000..6f40365
|
|
--- /dev/null
|
|
+++ b/src/unix/haiku.c
|
|
@@ -0,0 +1,171 @@
|
|
+/* Copyright libuv project contributors. All rights reserved.
|
|
+ *
|
|
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
+ * of this software and associated documentation files (the "Software"), to
|
|
+ * deal in the Software without restriction, including without limitation the
|
|
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
+ * sell copies of the Software, and to permit persons to whom the Software is
|
|
+ * furnished to do so, subject to the following conditions:
|
|
+ *
|
|
+ * The above copyright notice and this permission notice shall be included in
|
|
+ * all copies or substantial portions of the Software.
|
|
+ *
|
|
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
+ * IN THE SOFTWARE.
|
|
+ */
|
|
+
|
|
+#include "uv.h"
|
|
+#include "internal.h"
|
|
+
|
|
+#include <FindDirectory.h> /* find_path() */
|
|
+#include <OS.h>
|
|
+
|
|
+
|
|
+void uv_loadavg(double avg[3]) {
|
|
+ avg[0] = 0;
|
|
+ avg[1] = 0;
|
|
+ avg[2] = 0;
|
|
+}
|
|
+
|
|
+
|
|
+int uv_exepath(char* buffer, size_t* size) {
|
|
+ char abspath[B_PATH_NAME_LENGTH];
|
|
+ status_t status;
|
|
+ ssize_t abspath_len;
|
|
+
|
|
+ if (buffer == NULL || size == NULL || *size == 0)
|
|
+ return UV_EINVAL;
|
|
+
|
|
+ status = find_path(B_APP_IMAGE_SYMBOL, B_FIND_PATH_IMAGE_PATH, NULL, abspath,
|
|
+ sizeof(abspath));
|
|
+ if (status != B_OK)
|
|
+ return UV__ERR(status);
|
|
+
|
|
+ abspath_len = uv__strscpy(buffer, abspath, *size);
|
|
+ *size -= 1;
|
|
+ if (abspath_len >= 0 && *size > (size_t)abspath_len)
|
|
+ *size = (size_t)abspath_len;
|
|
+
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+
|
|
+uint64_t uv_get_free_memory(void) {
|
|
+ status_t status;
|
|
+ system_info sinfo;
|
|
+
|
|
+ status = get_system_info(&sinfo);
|
|
+ if (status != B_OK)
|
|
+ return 0;
|
|
+
|
|
+ return (sinfo.max_pages - sinfo.used_pages) * B_PAGE_SIZE;
|
|
+}
|
|
+
|
|
+
|
|
+uint64_t uv_get_total_memory(void) {
|
|
+ status_t status;
|
|
+ system_info sinfo;
|
|
+
|
|
+ status = get_system_info(&sinfo);
|
|
+ if (status != B_OK)
|
|
+ return 0;
|
|
+
|
|
+ return sinfo.max_pages * B_PAGE_SIZE;
|
|
+}
|
|
+
|
|
+
|
|
+int uv_resident_set_memory(size_t* rss) {
|
|
+ area_info area;
|
|
+ ssize_t cookie;
|
|
+ status_t status;
|
|
+ thread_info thread;
|
|
+
|
|
+ status = get_thread_info(find_thread(NULL), &thread);
|
|
+ if (status != B_OK)
|
|
+ return UV__ERR(status);
|
|
+
|
|
+ cookie = 0;
|
|
+ *rss = 0;
|
|
+ while (get_next_area_info(thread.team, &cookie, &area) == B_OK)
|
|
+ *rss += area.ram_size;
|
|
+
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+
|
|
+int uv_uptime(double* uptime) {
|
|
+ /* system_time() returns time since booting in microseconds */
|
|
+ *uptime = (double)system_time() / 1000000;
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+
|
|
+int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
|
|
+ cpu_topology_node_info* topology_infos;
|
|
+ int i;
|
|
+ status_t status;
|
|
+ system_info system;
|
|
+ uint32_t topology_count;
|
|
+ uint64_t cpuspeed;
|
|
+ uv_cpu_info_t* cpu_info;
|
|
+
|
|
+ if (cpu_infos == NULL || count == NULL)
|
|
+ return UV_EINVAL;
|
|
+
|
|
+ status = get_cpu_topology_info(NULL, &topology_count);
|
|
+ if (status != B_OK)
|
|
+ return UV__ERR(status);
|
|
+
|
|
+ topology_infos = uv__malloc(topology_count * sizeof(*topology_infos));
|
|
+ if (topology_infos == NULL)
|
|
+ return UV_ENOMEM;
|
|
+
|
|
+ status = get_cpu_topology_info(topology_infos, &topology_count);
|
|
+ if (status != B_OK) {
|
|
+ uv__free(topology_infos);
|
|
+ return UV__ERR(status);
|
|
+ }
|
|
+
|
|
+ cpuspeed = 0;
|
|
+ for (i = 0; i < (int)topology_count; i++) {
|
|
+ if (topology_infos[i].type == B_TOPOLOGY_CORE) {
|
|
+ cpuspeed = topology_infos[i].data.core.default_frequency;
|
|
+ break;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ uv__free(topology_infos);
|
|
+
|
|
+ status = get_system_info(&system);
|
|
+ if (status != B_OK)
|
|
+ return UV__ERR(status);
|
|
+
|
|
+ *cpu_infos = uv__calloc(system.cpu_count, sizeof(**cpu_infos));
|
|
+ if (*cpu_infos == NULL)
|
|
+ return UV_ENOMEM;
|
|
+
|
|
+ /* CPU time and model are not exposed by Haiku. */
|
|
+ cpu_info = *cpu_infos;
|
|
+ for (i = 0; i < (int)system.cpu_count; i++) {
|
|
+ cpu_info->model = uv__strdup("unknown");
|
|
+ cpu_info->speed = (int)(cpuspeed / 1000000);
|
|
+ cpu_info++;
|
|
+ }
|
|
+ *count = system.cpu_count;
|
|
+
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
|
|
+ int i;
|
|
+
|
|
+ for (i = 0; i < count; i++)
|
|
+ uv__free(cpu_infos[i].model);
|
|
+
|
|
+ uv__free(cpu_infos);
|
|
+}
|
|
diff --git a/src/unix/process.c b/src/unix/process.c
|
|
index b284308..e29bf15 100644
|
|
--- a/src/unix/process.c
|
|
+++ b/src/unix/process.c
|
|
@@ -385,6 +385,11 @@ static void uv__process_child_init(const uv_process_options_t* options,
|
|
if (n == SIGKILL || n == SIGSTOP)
|
|
continue; /* Can't be changed. */
|
|
|
|
+#if defined(__HAIKU__)
|
|
+ if (n == SIGKILLTHR)
|
|
+ continue; /* Can't be changed. */
|
|
+#endif
|
|
+
|
|
if (SIG_ERR != signal(n, SIG_DFL))
|
|
continue;
|
|
|
|
--
|
|
2.21.0
|
|
|
|
|
|
From 82f8a7d7f00ebd552b9ad3aec5516c7cb6d3571a Mon Sep 17 00:00:00 2001
|
|
From: Leorize <leorize+oss@disroot.org>
|
|
Date: Sat, 5 Jan 2019 01:15:42 +0700
|
|
Subject: test: add Haiku support
|
|
|
|
|
|
diff --git a/Makefile.am b/Makefile.am
|
|
index 32f4db7..d143d08 100644
|
|
--- a/Makefile.am
|
|
+++ b/Makefile.am
|
|
@@ -320,6 +320,10 @@ test_run_tests_CFLAGS += -D_ALL_SOURCE \
|
|
-D_LINUX_SOURCE_COMPAT
|
|
endif
|
|
|
|
+if HAIKU
|
|
+test_run_tests_CFLAGS += -D_BSD_SOURCE
|
|
+endif
|
|
+
|
|
if LINUX
|
|
test_run_tests_CFLAGS += -D_GNU_SOURCE
|
|
endif
|
|
diff --git a/test/test-fs-copyfile.c b/test/test-fs-copyfile.c
|
|
index cd8a2ea..918c086 100644
|
|
--- a/test/test-fs-copyfile.c
|
|
+++ b/test/test-fs-copyfile.c
|
|
@@ -24,7 +24,8 @@
|
|
|
|
#if defined(__unix__) || defined(__POSIX__) || \
|
|
defined(__APPLE__) || defined(__sun) || \
|
|
- defined(_AIX) || defined(__MVS__)
|
|
+ defined(_AIX) || defined(__MVS__) || \
|
|
+ defined(__HAIKU__)
|
|
#include <unistd.h> /* unlink, etc. */
|
|
#else
|
|
# include <direct.h>
|
|
diff --git a/test/test-fs.c b/test/test-fs.c
|
|
index c3153c7..6cc2257 100644
|
|
--- a/test/test-fs.c
|
|
+++ b/test/test-fs.c
|
|
@@ -31,7 +31,8 @@
|
|
/* FIXME we shouldn't need to branch in this file */
|
|
#if defined(__unix__) || defined(__POSIX__) || \
|
|
defined(__APPLE__) || defined(__sun) || \
|
|
- defined(_AIX) || defined(__MVS__)
|
|
+ defined(_AIX) || defined(__MVS__) || \
|
|
+ defined(__HAIKU__)
|
|
#include <unistd.h> /* unlink, rmdir, etc. */
|
|
#else
|
|
# include <winioctl.h>
|
|
@@ -1653,6 +1654,8 @@ TEST_IMPL(fs_chown) {
|
|
uv_run(loop, UV_RUN_DEFAULT);
|
|
ASSERT(fchown_cb_count == 1);
|
|
|
|
+#ifndef __HAIKU__
|
|
+ /* Haiku doesn't support hardlink */
|
|
/* sync link */
|
|
r = uv_fs_link(NULL, &req, "test_file", "test_file_link", NULL);
|
|
ASSERT(r == 0);
|
|
@@ -1670,6 +1673,7 @@ TEST_IMPL(fs_chown) {
|
|
ASSERT(r == 0);
|
|
uv_run(loop, UV_RUN_DEFAULT);
|
|
ASSERT(lchown_cb_count == 1);
|
|
+#endif
|
|
|
|
/* Close file */
|
|
r = uv_fs_close(NULL, &req, file, NULL);
|
|
--
|
|
2.21.0
|
|
|
|
|
|
From fadf058a448f666ef5871a71a6d804d3f733aac7 Mon Sep 17 00:00:00 2001
|
|
From: Calvin Hill <calvin@hakobaito.co.uk>
|
|
Date: Mon, 3 Jun 2019 10:22:50 +0700
|
|
Subject: unix/fs: implement uv_fs_utime and uv_fs_futime for Haiku
|
|
|
|
|
|
diff --git a/src/unix/fs.c b/src/unix/fs.c
|
|
index 24a130f..bc2f8f3 100644
|
|
--- a/src/unix/fs.c
|
|
+++ b/src/unix/fs.c
|
|
@@ -189,7 +189,8 @@ static ssize_t uv__fs_fdatasync(uv_fs_t* req) {
|
|
|
|
static ssize_t uv__fs_futime(uv_fs_t* req) {
|
|
#if defined(__linux__) \
|
|
- || defined(_AIX71)
|
|
+ || defined(_AIX71) \
|
|
+ || defined(__HAIKU__)
|
|
/* utimesat() has nanosecond resolution but we stick to microseconds
|
|
* for the sake of consistency with other platforms.
|
|
*/
|
|
@@ -796,7 +797,8 @@ static ssize_t uv__fs_sendfile(uv_fs_t* req) {
|
|
static ssize_t uv__fs_utime(uv_fs_t* req) {
|
|
#if defined(__linux__) \
|
|
|| defined(_AIX71) \
|
|
- || defined(__sun)
|
|
+ || defined(__sun) \
|
|
+ || defined(__HAIKU__)
|
|
/* utimesat() has nanosecond resolution but we stick to microseconds
|
|
* for the sake of consistency with other platforms.
|
|
*/
|
|
--
|
|
2.21.0
|
|
|
|
|
|
From 59990bc91770dca4099c7c8d34a59dd2a2890e85 Mon Sep 17 00:00:00 2001
|
|
From: Leorize <leorize+oss@disroot.org>
|
|
Date: Mon, 3 Jun 2019 11:14:48 +0700
|
|
Subject: haiku: add uv_get_constrained_memory() stub
|
|
|
|
Haiku doesn't have memory limits.
|
|
|
|
diff --git a/src/unix/haiku.c b/src/unix/haiku.c
|
|
index 6f40365..7708851 100644
|
|
--- a/src/unix/haiku.c
|
|
+++ b/src/unix/haiku.c
|
|
@@ -79,6 +79,11 @@ uint64_t uv_get_total_memory(void) {
|
|
}
|
|
|
|
|
|
+uint64_t uv_get_constrained_memory(void) {
|
|
+ return 0; /* Memory constraints are unknown. */
|
|
+}
|
|
+
|
|
+
|
|
int uv_resident_set_memory(size_t* rss) {
|
|
area_info area;
|
|
ssize_t cookie;
|
|
--
|
|
2.21.0
|
|
|