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
145 | 145 | list(APPEND uv_test_sources src/win/snprintf.c test/runner-win.c) |
146 | 146 | else() |
147 | 147 | 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") | |
149 | 149 | # TODO: This should be replaced with find_package(Threads) if possible |
150 | 150 | # Android has pthread as part of its c library, not as a separate |
151 | 151 | # libpthread.so. |
307 | 307 | src/unix/no-proctitle.c |
308 | 308 | src/unix/posix-hrtime.c |
309 | 309 | 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) | |
310 | 322 | endif() |
311 | 323 | |
312 | 324 | if(APPLE OR CMAKE_SYSTEM_NAME MATCHES "DragonFly|FreeBSD|Linux|NetBSD|OpenBSD") |
67 | 67 | defined(__GNU__) |
68 | 68 | # include "uv/posix.h" |
69 | 69 | #elif defined(__HAIKU__) |
70 | # include "uv/posix.h" | |
71 | #elif defined(__QNX__) | |
70 | 72 | # include "uv/posix.h" |
71 | 73 | #endif |
72 | 74 |
32 | 32 | |
33 | 33 | #if defined(__PASE__) |
34 | 34 | rc = uv__random_readpath("/dev/urandom", buf, buflen); |
35 | #elif defined(_AIX) | |
35 | #elif defined(_AIX) || defined(__QNX__) | |
36 | 36 | rc = uv__random_readpath("/dev/random", buf, buflen); |
37 | 37 | #elif defined(__APPLE__) || defined(__OpenBSD__) || \ |
38 | 38 | (defined(__ANDROID_API__) && __ANDROID_API__ >= 28) |
112 | 112 | address->address.address4 = *((struct sockaddr_in*) ent->ifa_addr); |
113 | 113 | } |
114 | 114 | |
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) { | |
116 | 118 | address->netmask.netmask6 = *((struct sockaddr_in6*) ent->ifa_netmask); |
117 | 119 | } else { |
118 | 120 | address->netmask.netmask4 = *((struct sockaddr_in*) ent->ifa_netmask); |
78 | 78 | defined(__NetBSD__) |
79 | 79 | # include <sys/param.h> |
80 | 80 | # 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__) | |
82 | 86 | # include <sys/statvfs.h> |
83 | 87 | #else |
84 | 88 | # include <sys/statfs.h> |
628 | 632 | |
629 | 633 | static int uv__fs_statfs(uv_fs_t* req) { |
630 | 634 | 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__) | |
632 | 640 | struct statvfs buf; |
633 | 641 | |
634 | 642 | if (0 != statvfs(req->path, &buf)) |
645 | 653 | return -1; |
646 | 654 | } |
647 | 655 | |
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__) | |
649 | 662 | stat_fs->f_type = 0; /* f_type is not supported. */ |
650 | 663 | #else |
651 | 664 | 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 | } |
850 | 850 | } |
851 | 851 | |
852 | 852 | |
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__) | |
854 | 858 | static int uv__udp_set_source_membership4(uv_udp_t* handle, |
855 | 859 | const struct sockaddr_in* multicast_addr, |
856 | 860 | const char* interface_addr, |
1038 | 1042 | const char* interface_addr, |
1039 | 1043 | const char* source_addr, |
1040 | 1044 | 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__) | |
1042 | 1050 | int err; |
1043 | 1051 | union uv__sockaddr mcast_addr; |
1044 | 1052 | union uv__sockaddr src_addr; |
1145 | 1153 | * and use the general uv__setsockopt_maybe_char call on other platforms. |
1146 | 1154 | */ |
1147 | 1155 | #if defined(__sun) || defined(_AIX) || defined(__OpenBSD__) || \ |
1148 | defined(__MVS__) | |
1156 | defined(__MVS__) || defined(__QNX__) | |
1149 | 1157 | |
1150 | 1158 | return uv__setsockopt(handle, |
1151 | 1159 | IP_TTL, |
1154 | 1162 | sizeof(ttl)); |
1155 | 1163 | |
1156 | 1164 | #else /* !(defined(__sun) || defined(_AIX) || defined (__OpenBSD__) || |
1157 | defined(__MVS__)) */ | |
1165 | defined(__MVS__) || defined(__QNX__)) */ | |
1158 | 1166 | |
1159 | 1167 | return uv__setsockopt_maybe_char(handle, |
1160 | 1168 | IP_TTL, |
1162 | 1170 | ttl); |
1163 | 1171 | |
1164 | 1172 | #endif /* defined(__sun) || defined(_AIX) || defined (__OpenBSD__) || |
1165 | defined(__MVS__) */ | |
1173 | defined(__MVS__) || defined(__QNX__) */ | |
1166 | 1174 | } |
1167 | 1175 | |
1168 | 1176 | |
1174 | 1182 | * and use the general uv__setsockopt_maybe_char call otherwise. |
1175 | 1183 | */ |
1176 | 1184 | #if defined(__sun) || defined(_AIX) || defined(__OpenBSD__) || \ |
1177 | defined(__MVS__) | |
1185 | defined(__MVS__) || defined(__QNX__) | |
1178 | 1186 | if (handle->flags & UV_HANDLE_IPV6) |
1179 | 1187 | return uv__setsockopt(handle, |
1180 | 1188 | IP_MULTICAST_TTL, |
1182 | 1190 | &ttl, |
1183 | 1191 | sizeof(ttl)); |
1184 | 1192 | #endif /* defined(__sun) || defined(_AIX) || defined(__OpenBSD__) || \ |
1185 | defined(__MVS__) */ | |
1193 | defined(__MVS__) || defined(__QNX__) */ | |
1186 | 1194 | |
1187 | 1195 | return uv__setsockopt_maybe_char(handle, |
1188 | 1196 | IP_MULTICAST_TTL, |
1199 | 1207 | * and use the general uv__setsockopt_maybe_char call otherwise. |
1200 | 1208 | */ |
1201 | 1209 | #if defined(__sun) || defined(_AIX) || defined(__OpenBSD__) || \ |
1202 | defined(__MVS__) | |
1210 | defined(__MVS__) || defined(__QNX__) | |
1203 | 1211 | if (handle->flags & UV_HANDLE_IPV6) |
1204 | 1212 | return uv__setsockopt(handle, |
1205 | 1213 | IP_MULTICAST_LOOP, |
1207 | 1215 | &on, |
1208 | 1216 | sizeof(on)); |
1209 | 1217 | #endif /* defined(__sun) || defined(_AIX) ||defined(__OpenBSD__) || |
1210 | defined(__MVS__) */ | |
1218 | defined(__MVS__) || defined(__QNX__) */ | |
1211 | 1219 | |
1212 | 1220 | return uv__setsockopt_maybe_char(handle, |
1213 | 1221 | IP_MULTICAST_LOOP, |
41 | 41 | |
42 | 42 | msg = uv_dlerror(&lib); |
43 | 43 | ASSERT(msg != NULL); |
44 | #ifndef __OpenBSD__ | |
44 | #if !defined(__OpenBSD__) && !defined(__QNX__) | |
45 | 45 | ASSERT(strstr(msg, path) != NULL); |
46 | 46 | #endif |
47 | 47 | ASSERT(strstr(msg, dlerror_no_error) == NULL); |
49 | 49 | /* Should return the same error twice in a row. */ |
50 | 50 | msg = uv_dlerror(&lib); |
51 | 51 | ASSERT(msg != NULL); |
52 | #ifndef __OpenBSD__ | |
52 | #if !defined(__OpenBSD__) && !defined(__QNX__) | |
53 | 53 | ASSERT(strstr(msg, path) != NULL); |
54 | 54 | #endif |
55 | 55 | ASSERT(strstr(msg, dlerror_no_error) == NULL); |