Codebase list libuv1 / ed5b42d
build,unix: add QNX support Refs: https://github.com/libuv/libuv/pull/2881 PR-URL: https://github.com/libuv/libuv/pull/2991 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Elad Lahav authored 3 years ago cjihrig committed 3 years ago
9 changed file(s) with 192 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
145145 list(APPEND uv_test_sources src/win/snprintf.c test/runner-win.c)
146146 else()
147147 list(APPEND uv_defines _FILE_OFFSET_BITS=64 _LARGEFILE_SOURCE)
148 if(NOT CMAKE_SYSTEM_NAME MATCHES "Android|OS390")
148 if(NOT CMAKE_SYSTEM_NAME MATCHES "Android|OS390|QNX")
149149 # TODO: This should be replaced with find_package(Threads) if possible
150150 # Android has pthread as part of its c library, not as a separate
151151 # libpthread.so.
307307 src/unix/no-proctitle.c
308308 src/unix/posix-hrtime.c
309309 src/unix/posix-poll.c)
310 endif()
311
312 if(CMAKE_SYSTEM_NAME STREQUAL "QNX")
313 list(APPEND uv_sources
314 src/unix/posix-hrtime.c
315 src/unix/posix-poll.c
316 src/unix/qnx.c
317 src/unix/bsd-ifaddrs.c
318 src/unix/no-proctitle.c
319 src/unix/no-fsevents.c)
320 list(APPEND uv_cflags -fno-strict-aliasing)
321 list(APPEND uv_libraries socket)
310322 endif()
311323
312324 if(APPLE OR CMAKE_SYSTEM_NAME MATCHES "DragonFly|FreeBSD|Linux|NetBSD|OpenBSD")
6767 defined(__GNU__)
6868 # include "uv/posix.h"
6969 #elif defined(__HAIKU__)
70 # include "uv/posix.h"
71 #elif defined(__QNX__)
7072 # include "uv/posix.h"
7173 #endif
7274
3232
3333 #if defined(__PASE__)
3434 rc = uv__random_readpath("/dev/urandom", buf, buflen);
35 #elif defined(_AIX)
35 #elif defined(_AIX) || defined(__QNX__)
3636 rc = uv__random_readpath("/dev/random", buf, buflen);
3737 #elif defined(__APPLE__) || defined(__OpenBSD__) || \
3838 (defined(__ANDROID_API__) && __ANDROID_API__ >= 28)
112112 address->address.address4 = *((struct sockaddr_in*) ent->ifa_addr);
113113 }
114114
115 if (ent->ifa_netmask->sa_family == AF_INET6) {
115 if (ent->ifa_netmask == NULL) {
116 memset(&address->netmask, 0, sizeof(address->netmask));
117 } else if (ent->ifa_netmask->sa_family == AF_INET6) {
116118 address->netmask.netmask6 = *((struct sockaddr_in6*) ent->ifa_netmask);
117119 } else {
118120 address->netmask.netmask4 = *((struct sockaddr_in*) ent->ifa_netmask);
7878 defined(__NetBSD__)
7979 # include <sys/param.h>
8080 # include <sys/mount.h>
81 #elif defined(__sun) || defined(__MVS__) || defined(__NetBSD__) || defined(__HAIKU__)
81 #elif defined(__sun) || \
82 defined(__MVS__) || \
83 defined(__NetBSD__) || \
84 defined(__HAIKU__) || \
85 defined(__QNX__)
8286 # include <sys/statvfs.h>
8387 #else
8488 # include <sys/statfs.h>
628632
629633 static int uv__fs_statfs(uv_fs_t* req) {
630634 uv_statfs_t* stat_fs;
631 #if defined(__sun) || defined(__MVS__) || defined(__NetBSD__) || defined(__HAIKU__)
635 #if defined(__sun) || \
636 defined(__MVS__) || \
637 defined(__NetBSD__) || \
638 defined(__HAIKU__) || \
639 defined(__QNX__)
632640 struct statvfs buf;
633641
634642 if (0 != statvfs(req->path, &buf))
645653 return -1;
646654 }
647655
648 #if defined(__sun) || defined(__MVS__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__)
656 #if defined(__sun) || \
657 defined(__MVS__) || \
658 defined(__OpenBSD__) || \
659 defined(__NetBSD__) || \
660 defined(__HAIKU__) || \
661 defined(__QNX__)
649662 stat_fs->f_type = 0; /* f_type is not supported. */
650663 #else
651664 stat_fs->f_type = buf.f_type;
0 /* Copyright libuv contributors. All rights reserved.
1 *
2 * Permission is hereby granted, free of charge, to any person obtaining a copy
3 * of this software and associated documentation files (the "Software"), to
4 * deal in the Software without restriction, including without limitation the
5 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
6 * sell copies of the Software, and to permit persons to whom the Software is
7 * furnished to do so, subject to the following conditions:
8 *
9 * The above copyright notice and this permission notice shall be included in
10 * all copies or substantial portions of the Software.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
18 * IN THE SOFTWARE.
19 */
20
21 #include "uv.h"
22 #include "internal.h"
23
24 #include <string.h>
25 #include <sys/process.h>
26 #include <sys/neutrino.h>
27 #include <sys/memmsg.h>
28 #include <sys/syspage.h>
29 #include <sys/procfs.h>
30
31 static void
32 get_mem_info(uint64_t* totalmem, uint64_t* freemem) {
33 mem_info_t msg;
34
35 memset(&msg, 0, sizeof(msg));
36 msg.i.type = _MEM_INFO;
37 msg.i.fd = -1;
38
39 if (MsgSend(MEMMGR_COID, &msg.i, sizeof(msg.i), &msg.o, sizeof(msg.o))
40 != -1) {
41 *totalmem = msg.o.info.__posix_tmi_total;
42 *freemem = msg.o.info.posix_tmi_length;
43 } else {
44 *totalmem = 0;
45 *freemem = 0;
46 }
47 }
48
49
50 void uv_loadavg(double avg[3]) {
51 avg[0] = 0.0;
52 avg[1] = 0.0;
53 avg[2] = 0.0;
54 }
55
56
57 int uv_exepath(char* buffer, size_t* size) {
58 char path[PATH_MAX];
59 if (buffer == NULL || size == NULL || *size == 0)
60 return UV_EINVAL;
61
62 realpath(_cmdname(NULL), path);
63 strlcpy(buffer, path, *size);
64 *size = strlen(buffer);
65 return 0;
66 }
67
68
69 uint64_t uv_get_free_memory(void) {
70 uint64_t totalmem;
71 uint64_t freemem;
72 get_mem_info(&totalmem, &freemem);
73 return freemem;
74 }
75
76
77 uint64_t uv_get_total_memory(void) {
78 uint64_t totalmem;
79 uint64_t freemem;
80 get_mem_info(&totalmem, &freemem);
81 return totalmem;
82 }
83
84
85 uint64_t uv_get_constrained_memory(void) {
86 return 0;
87 }
88
89
90 int uv_resident_set_memory(size_t* rss) {
91 int fd;
92 procfs_asinfo asinfo;
93
94 fd = uv__open_cloexec("/proc/self/ctl", O_RDONLY);
95 if (fd == -1)
96 return UV__ERR(errno);
97
98 if (devctl(fd, DCMD_PROC_ASINFO, &asinfo, sizeof(asinfo), 0) == -1) {
99 uv__close(fd);
100 return UV__ERR(errno);
101 }
102
103 uv__close(fd);
104 *rss = asinfo.rss;
105 return 0;
106 }
107
108
109 int uv_uptime(double* uptime) {
110 struct qtime_entry* qtime = _SYSPAGE_ENTRY(_syspage_ptr, qtime);
111 *uptime = (qtime->nsec / 1000000000.0);
112 return 0;
113 }
114
115
116 int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
117 struct cpuinfo_entry* cpuinfo =
118 (struct cpuinfo_entry*)_SYSPAGE_ENTRY(_syspage_ptr, new_cpuinfo);
119 size_t cpuinfo_size = _SYSPAGE_ELEMENT_SIZE(_syspage_ptr, cpuinfo);
120 struct strings_entry* strings = _SYSPAGE_ENTRY(_syspage_ptr, strings);
121 int num_cpus = _syspage_ptr->num_cpu;
122 int i;
123
124 *count = num_cpus;
125 *cpu_infos = uv__malloc(num_cpus * sizeof(**cpu_infos));
126 if (*cpu_infos == NULL)
127 return UV_ENOMEM;
128
129 for (i = 0; i < num_cpus; i++) {
130 (*cpu_infos)[i].model = strdup(&strings->data[cpuinfo->name]);
131 (*cpu_infos)[i].speed = cpuinfo->speed;
132 SYSPAGE_ARRAY_ADJ_OFFSET(cpuinfo, cpuinfo, cpuinfo_size);
133 }
134
135 return 0;
136 }
850850 }
851851
852852
853 #if !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__ANDROID__) && !defined(__DragonFly__)
853 #if !defined(__OpenBSD__) && \
854 !defined(__NetBSD__) && \
855 !defined(__ANDROID__) && \
856 !defined(__DragonFly__) & \
857 !defined(__QNX__)
854858 static int uv__udp_set_source_membership4(uv_udp_t* handle,
855859 const struct sockaddr_in* multicast_addr,
856860 const char* interface_addr,
10381042 const char* interface_addr,
10391043 const char* source_addr,
10401044 uv_membership membership) {
1041 #if !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__ANDROID__) && !defined(__DragonFly__)
1045 #if !defined(__OpenBSD__) && \
1046 !defined(__NetBSD__) && \
1047 !defined(__ANDROID__) && \
1048 !defined(__DragonFly__) && \
1049 !defined(__QNX__)
10421050 int err;
10431051 union uv__sockaddr mcast_addr;
10441052 union uv__sockaddr src_addr;
11451153 * and use the general uv__setsockopt_maybe_char call on other platforms.
11461154 */
11471155 #if defined(__sun) || defined(_AIX) || defined(__OpenBSD__) || \
1148 defined(__MVS__)
1156 defined(__MVS__) || defined(__QNX__)
11491157
11501158 return uv__setsockopt(handle,
11511159 IP_TTL,
11541162 sizeof(ttl));
11551163
11561164 #else /* !(defined(__sun) || defined(_AIX) || defined (__OpenBSD__) ||
1157 defined(__MVS__)) */
1165 defined(__MVS__) || defined(__QNX__)) */
11581166
11591167 return uv__setsockopt_maybe_char(handle,
11601168 IP_TTL,
11621170 ttl);
11631171
11641172 #endif /* defined(__sun) || defined(_AIX) || defined (__OpenBSD__) ||
1165 defined(__MVS__) */
1173 defined(__MVS__) || defined(__QNX__) */
11661174 }
11671175
11681176
11741182 * and use the general uv__setsockopt_maybe_char call otherwise.
11751183 */
11761184 #if defined(__sun) || defined(_AIX) || defined(__OpenBSD__) || \
1177 defined(__MVS__)
1185 defined(__MVS__) || defined(__QNX__)
11781186 if (handle->flags & UV_HANDLE_IPV6)
11791187 return uv__setsockopt(handle,
11801188 IP_MULTICAST_TTL,
11821190 &ttl,
11831191 sizeof(ttl));
11841192 #endif /* defined(__sun) || defined(_AIX) || defined(__OpenBSD__) || \
1185 defined(__MVS__) */
1193 defined(__MVS__) || defined(__QNX__) */
11861194
11871195 return uv__setsockopt_maybe_char(handle,
11881196 IP_MULTICAST_TTL,
11991207 * and use the general uv__setsockopt_maybe_char call otherwise.
12001208 */
12011209 #if defined(__sun) || defined(_AIX) || defined(__OpenBSD__) || \
1202 defined(__MVS__)
1210 defined(__MVS__) || defined(__QNX__)
12031211 if (handle->flags & UV_HANDLE_IPV6)
12041212 return uv__setsockopt(handle,
12051213 IP_MULTICAST_LOOP,
12071215 &on,
12081216 sizeof(on));
12091217 #endif /* defined(__sun) || defined(_AIX) ||defined(__OpenBSD__) ||
1210 defined(__MVS__) */
1218 defined(__MVS__) || defined(__QNX__) */
12111219
12121220 return uv__setsockopt_maybe_char(handle,
12131221 IP_MULTICAST_LOOP,
4141
4242 msg = uv_dlerror(&lib);
4343 ASSERT(msg != NULL);
44 #ifndef __OpenBSD__
44 #if !defined(__OpenBSD__) && !defined(__QNX__)
4545 ASSERT(strstr(msg, path) != NULL);
4646 #endif
4747 ASSERT(strstr(msg, dlerror_no_error) == NULL);
4949 /* Should return the same error twice in a row. */
5050 msg = uv_dlerror(&lib);
5151 ASSERT(msg != NULL);
52 #ifndef __OpenBSD__
52 #if !defined(__OpenBSD__) && !defined(__QNX__)
5353 ASSERT(strstr(msg, path) != NULL);
5454 #endif
5555 ASSERT(strstr(msg, dlerror_no_error) == NULL);
2424 #if defined(__unix__) || defined(__POSIX__) || \
2525 defined(__APPLE__) || defined(__sun) || \
2626 defined(_AIX) || defined(__MVS__) || \
27 defined(__HAIKU__)
27 defined(__HAIKU__) || defined(__QNX__)
2828 #include <unistd.h> /* unlink, etc. */
2929 #else
3030 # include <direct.h>