GCC Code Coverage Report


Directory: src/gate/
File: src/gate/system/os.c
Date: 2025-09-14 13:10:38
Exec Total Coverage
Lines: 9 90 10.0%
Functions: 1 6 16.7%
Branches: 4 68 5.9%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright(c) 2018-2025, Stefan Meislinger |
4 | All rights reserved. |
5 | |
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met:|
8 | |
9 | 1. Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. |
11 | 2. Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"|
16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | THE POSSIBILITY OF SUCH DAMAGE. |
26 +----------------------------------------------------------------------------+
27 */
28
29 #include "gate/system/os.h"
30 #include "gate/results.h"
31 #include "gate/streams.h"
32 #include "gate/environments.h"
33
34 #if defined(GATE_SYS_WIN) && !defined(GATE_SYS_WIN16)
35 # define GATE_SYSTEM_OS_WINAPI_IMPL 1
36 #elif defined(GATE_SYS_BEOS)
37 # define GATE_SYSTEM_OS_NO_IMPL 1
38 #elif defined(GATE_SYS_POSIX)
39 # define GATE_SYSTEM_OS_POSIX_IMPL 1
40 #elif defined(GATE_SYS_EFI)
41 # define GATE_SYSTEM_OS_EFI_IMPL 1
42 #elif defined(GATE_SYS_DOS)
43 # define GATE_SYSTEM_OS_DOS_IMPL 1
44 #else
45 # define GATE_SYSTEM_OS_NO_IMPL 1
46 #endif
47
48
49 /* generic */
50
51 2 char const* gate_os_get_platform_label(gate_uint32_t platform)
52 {
53 2 char const* ret = NULL;
54
1/20
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 2 times.
2 switch (platform)
55 {
56 case GATE_OS_PLATFORM_WINDOWS_3X: ret = "Windows 3.x"; break;
57 case GATE_OS_PLATFORM_WINDOWS_9X: ret = "Windows 9x"; break;
58 case GATE_OS_PLATFORM_WINDOWS_NT: ret = "Windows NT"; break;
59 case GATE_OS_PLATFORM_WINDOWS_CE: ret = "Windows CE"; break;
60 case GATE_OS_PLATFORM_WINDOWS_IOT: ret = "Windows IoT"; break;
61 case GATE_OS_PLATFORM_BSD_NETBSD: ret = "NetBSD"; break;
62 case GATE_OS_PLATFORM_BSD_FREEBSD: ret = "FreeBSD"; break;
63 case GATE_OS_PLATFORM_BSD_OPENBSD: ret = "OpenBSD"; break;
64 case GATE_OS_PLATFORM_LINUX_DEBIAN: ret = "Debian Linux"; break;
65 case GATE_OS_PLATFORM_LINUX_UBUNTU: ret = "Ubuntu Linux"; break;
66 case GATE_OS_PLATFORM_LINUX_SUSE: ret = "SUSE Linux"; break;
67 case GATE_OS_PLATFORM_LINUX_ARCH: ret = "Arch Linux"; break;
68 case GATE_OS_PLATFORM_LINUX_GENTOO: ret = "Gentoo Linux"; break;
69 case GATE_OS_PLATFORM_LINUX_REDHAT: ret = "Redhat Linux"; break;
70 case GATE_OS_PLATFORM_LINUX_FEDORA: ret = "Fedora Linux"; break;
71 case GATE_OS_PLATFORM_LINUX_SLACKWARE: ret = "Slackware Linux"; break;
72 case GATE_OS_PLATFORM_LINUX_EMBEDDED: ret = "Linux Embedded"; break;
73 case GATE_OS_PLATFORM_DARWIN_MACOS: ret = "MacOS X"; break;
74 case GATE_OS_PLATFORM_DARWIN_IOS: ret = "Apple iOS"; break;
75 2 default:
76 {
77
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (GATE_FLAG_ENABLED(platform, GATE_OS_PLATFORM_WINDOWS))
78 {
79 ret = "Windows";
80 }
81
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 else if (GATE_FLAG_ENABLED(platform, GATE_OS_PLATFORM_BSD))
82 {
83 ret = "BSD";
84 }
85
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 else if (GATE_FLAG_ENABLED(platform, GATE_OS_PLATFORM_LINUX))
86 {
87 2 ret = "Linux";
88 }
89 else if (GATE_FLAG_ENABLED(platform, GATE_OS_PLATFORM_DARWIN))
90 {
91 ret = "Darwin";
92 }
93 else if (GATE_FLAG_ENABLED(platform, GATE_OS_PLATFORM_LINUX))
94 {
95 ret = "Linux";
96 }
97 else if (GATE_FLAG_ENABLED(platform, GATE_OS_PLATFORM_RTOS))
98 {
99 ret = "Real-Time OS";
100 }
101 else if (GATE_FLAG_ENABLED(platform, GATE_OS_PLATFORM_EFI))
102 {
103 ret = "EFI";
104 }
105 else if (GATE_FLAG_ENABLED(platform, GATE_OS_PLATFORM_DOS))
106 {
107 ret = "DOS";
108 }
109 else if (GATE_FLAG_ENABLED(platform, GATE_OS_PLATFORM_MCU))
110 {
111 ret = "Microcontroller";
112 }
113 else if (GATE_FLAG_ENABLED(platform, GATE_OS_PLATFORM_WASM))
114 {
115 ret = "WebAssembly";
116 }
117 }
118 }
119 2 return ret;
120 }
121
122 char const* gate_os_get_cpu_architecture_label(gate_enumint_t arch)
123 {
124 char const* ret = NULL;
125
126 switch (arch)
127 {
128 case GATE_OS_ARCH_X86_16: ret = "X86-16"; break;
129 case GATE_OS_ARCH_X86_32: ret = "X86-32"; break;
130 case GATE_OS_ARCH_X86_64: ret = "X86-64"; break;
131 case GATE_OS_ARCH_ITANIUM: ret = "Itanium"; break;
132 case GATE_OS_ARCH_ARM_32: ret = "ARM-32"; break;
133 case GATE_OS_ARCH_ARM_64: ret = "ARM-64"; break;
134 case GATE_OS_ARCH_MIPS: ret = "MIPS"; break;
135 case GATE_OS_ARCH_ALPHA: ret = "ALPHA"; break;
136 case GATE_OS_ARCH_ALPHA_64: ret = "ALPHA-64"; break;
137 case GATE_OS_ARCH_PPC: ret = "PPC"; break;
138 case GATE_OS_ARCH_SHX: ret = "SHX"; break;
139 case GATE_OS_ARCH_RISCV: ret = "RISC-V"; break;
140 case GATE_OS_ARCH_WASM: ret = "WASM"; break;
141 }
142 return ret;
143 }
144
145 gate_result_t gate_os_get_hostname(gate_string_t* hostname)
146 {
147 char buffer[4096];
148 gate_size_t used;
149 gate_result_t ret = gate_os_get_hostname_str(buffer, sizeof(buffer), &used);
150 if (GATE_SUCCEEDED(ret))
151 {
152 if (NULL == gate_string_create(hostname, buffer, used))
153 {
154 ret = GATE_RESULT_OUTOFMEMORY;
155 }
156 }
157 return ret;
158 }
159 gate_result_t gate_os_get_hostdomainname(gate_string_t* domainname)
160 {
161 char buffer[4096];
162 gate_size_t used;
163 gate_result_t ret = gate_os_get_hostdomainname_str(buffer, sizeof(buffer), &used);
164 if (GATE_SUCCEEDED(ret))
165 {
166 if (NULL == gate_string_create(domainname, buffer, used))
167 {
168 ret = GATE_RESULT_OUTOFMEMORY;
169 }
170 }
171 return ret;
172 }
173
174 gate_bool_t gate_os_cpu_get_activation(gate_os_cpu_activation_t const* activation, gate_size_t id)
175 {
176 gate_size_t byte_pos;
177 gate_size_t bit_pos;
178 gate_uint8_t mask;
179
180 if (id >= sizeof(activation->core_bits))
181 {
182 return 0;
183 }
184 else
185 {
186 byte_pos = id / 8;
187 bit_pos = 7 - id % 8;
188 mask = (gate_uint8_t)1 << bit_pos;
189 return (activation->core_bits[byte_pos] & mask) == mask;
190 }
191 }
192 gate_result_t gate_os_cpu_set_activation(gate_os_cpu_activation_t* activation, gate_size_t id, gate_bool_t activated)
193 {
194 gate_size_t byte_pos;
195 gate_size_t bit_pos;
196 gate_uint8_t mask;
197
198 if (id >= sizeof(activation->core_bits))
199 {
200 return GATE_RESULT_OUTOFBOUNDS;
201 }
202 else
203 {
204 byte_pos = id / 8;
205 bit_pos = 7 - id % 8;
206 mask = (gate_uint8_t)1 << bit_pos;
207 if (activated)
208 {
209 activation->core_bits[byte_pos] |= mask;
210 }
211 else
212 {
213 activation->core_bits[byte_pos] &= ~mask;
214 }
215 return GATE_RESULT_OK;
216 }
217 }
218
219
220
221 #if defined(GATE_SYSTEM_OS_WINAPI_IMPL)
222
223 #endif /* defined(GATE_SYSTEM_OS_WINAPI_IMPL) */
224
225
226
227 #if defined(GATE_SYSTEM_OS_POSIX_IMPL)
228
229 #endif /* defined(GATE_SYSTEM_OS_POSIX_IMPL) */
230
231
232
233 #if defined(GATE_SYSTEM_OS_EFI_IMPL)
234
235 #endif /* GATE_SYSTEM_OS_EFI_IMPL */
236
237
238
239 #if defined(GATE_SYSTEM_OS_DOS_IMPL)
240
241 #endif /* GATE_SYSTEM_OS_DOS_IMPL */
242
243
244
245 #if defined(GATE_SYSTEM_OS_NO_IMPL)
246
247 gate_result_t gate_os_get_platform(gate_uint32_t* ptr_platform)
248 {
249 (void)ptr_platform;
250 return GATE_RESULT_NOTIMPLEMENTED;
251 }
252 gate_uint32_t gate_os_address_space()
253 {
254 return 32;
255 }
256 gate_uint32_t gate_os_up_time_seconds()
257 {
258 return 0;
259 }
260 gate_result_t gate_os_print_osname(char* buffer, gate_size_t buffer_len, gate_size_t* buffer_used)
261 {
262 (void)buffer;
263 (void)buffer_len;
264 (void)buffer_used;
265 return GATE_RESULT_NOTIMPLEMENTED;
266 }
267 gate_result_t gate_os_print_productname(char* buffer, gate_size_t buffer_len, gate_size_t* buffer_used)
268 {
269 (void)buffer;
270 (void)buffer_len;
271 (void)buffer_used;
272 return GATE_RESULT_NOTIMPLEMENTED;
273 }
274 gate_result_t gate_os_get_version(gate_version_t* ptr_version)
275 {
276 (void)ptr_version;
277 return GATE_RESULT_NOTIMPLEMENTED;
278 }
279
280 gate_result_t gate_os_get_hostname_str(char* buffer, gate_size_t buffer_len, gate_size_t* buffer_used)
281 {
282 (void)buffer;
283 (void)buffer_len;
284 (void)buffer_used;
285 return GATE_RESULT_NOTIMPLEMENTED;
286 }
287 gate_result_t gate_os_set_hostname(gate_string_t const* hostname)
288 {
289 (void)hostname;
290 return GATE_RESULT_NOTIMPLEMENTED;
291 }
292 gate_result_t gate_os_get_hostdomainname_str(char* buffer, gate_size_t buffer_len, gate_size_t* buffer_used)
293 {
294 (void)buffer;
295 (void)buffer_len;
296 (void)buffer_used;
297 return GATE_RESULT_NOTIMPLEMENTED;
298 }
299 gate_result_t gate_os_set_hostdomainname(gate_string_t const* domainname)
300 {
301 (void)domainname;
302 return GATE_RESULT_NOTIMPLEMENTED;
303 }
304 gate_result_t gate_os_get_uid(gate_uint8_t* buffer, gate_size_t buffer_len, gate_size_t* buffer_used)
305 {
306 (void)buffer;
307 (void)buffer_len;
308 (void)buffer_used;
309 return GATE_RESULT_NOTIMPLEMENTED;
310 }
311
312 gate_result_t gate_os_shutdown()
313 {
314 return GATE_RESULT_NOTIMPLEMENTED;
315 }
316 gate_result_t gate_os_reboot()
317 {
318 return GATE_RESULT_NOTIMPLEMENTED;
319 }
320
321 gate_result_t gate_os_get_cpu_architecture(gate_enumint_t* ptr_arch)
322 {
323 (void)ptr_arch;
324 return GATE_RESULT_NOTIMPLEMENTED;
325 }
326 gate_result_t gate_os_get_cpu_info(gate_os_cpuinfo_t* info)
327 {
328 (void)info;
329 return GATE_RESULT_NOTIMPLEMENTED;
330 }
331 gate_result_t gate_os_enum_cpu_features(gate_os_cpu_feature_callback_t callback, void* param)
332 {
333 (void)callback;
334 (void)param;
335 return GATE_RESULT_NOTIMPLEMENTED;
336 }
337 gate_result_t gate_os_get_process_cpu_affinity(gate_os_cpu_activation_t* affinity)
338 {
339 (void)affinity;
340 return GATE_RESULT_NOTIMPLEMENTED;
341 }
342 gate_result_t gate_os_set_process_cpu_affinity(gate_os_cpu_activation_t const* affinity)
343 {
344 (void)affinity;
345 return GATE_RESULT_NOTIMPLEMENTED;
346 }
347
348 gate_result_t gate_os_cpu_load_init(gate_os_cpu_load_state_t* state)
349 {
350 (void)state;
351 return GATE_RESULT_NOTIMPLEMENTED;
352 }
353 gate_result_t gate_os_cpu_load_update(gate_os_cpu_load_state_t* state, gate_uint16_t* load65535)
354 {
355 (void)state;
356 (void)load65535;
357 return GATE_RESULT_NOTIMPLEMENTED;
358 }
359 gate_result_t gate_os_cpu_load_uninit(gate_os_cpu_load_state_t* state)
360 {
361 (void)state;
362 return GATE_RESULT_NOTIMPLEMENTED;
363 }
364
365 gate_result_t gate_os_get_physical_memory(gate_uint64_t* ptr_total, gate_uint64_t* ptr_available)
366 {
367 (void)ptr_total;
368 (void)ptr_available;
369 return GATE_RESULT_NOTIMPLEMENTED;
370 }
371 gate_result_t gate_os_get_virtual_memory(gate_uint64_t* ptr_total, gate_uint64_t* ptr_available)
372 {
373 (void)ptr_total;
374 (void)ptr_available;
375 return GATE_RESULT_NOTIMPLEMENTED;
376 }
377
378 #endif /* GATE_SYSTEM_OS_NO_IMPL */
379