| 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 | #elif defined(GATE_SYS_WASM) | ||
| 45 | # define GATE_SYSTEM_OS_WASM_IMPL 1 | ||
| 46 | #else | ||
| 47 | # define GATE_SYSTEM_OS_NO_IMPL 1 | ||
| 48 | #endif | ||
| 49 | |||
| 50 | |||
| 51 | /* generic */ | ||
| 52 | |||
| 53 | 2 | char const* gate_os_get_platform_label(gate_uint32_t platform) | |
| 54 | { | ||
| 55 | 2 | char const* ret = NULL; | |
| 56 |
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) |
| 57 | { | ||
| 58 | ✗ | case GATE_OS_PLATFORM_WINDOWS_3X: ret = "Windows 3.x"; break; | |
| 59 | ✗ | case GATE_OS_PLATFORM_WINDOWS_9X: ret = "Windows 9x"; break; | |
| 60 | ✗ | case GATE_OS_PLATFORM_WINDOWS_NT: ret = "Windows NT"; break; | |
| 61 | ✗ | case GATE_OS_PLATFORM_WINDOWS_CE: ret = "Windows CE"; break; | |
| 62 | ✗ | case GATE_OS_PLATFORM_WINDOWS_IOT: ret = "Windows IoT"; break; | |
| 63 | ✗ | case GATE_OS_PLATFORM_BSD_NETBSD: ret = "NetBSD"; break; | |
| 64 | ✗ | case GATE_OS_PLATFORM_BSD_FREEBSD: ret = "FreeBSD"; break; | |
| 65 | ✗ | case GATE_OS_PLATFORM_BSD_OPENBSD: ret = "OpenBSD"; break; | |
| 66 | ✗ | case GATE_OS_PLATFORM_LINUX_DEBIAN: ret = "Debian Linux"; break; | |
| 67 | ✗ | case GATE_OS_PLATFORM_LINUX_UBUNTU: ret = "Ubuntu Linux"; break; | |
| 68 | ✗ | case GATE_OS_PLATFORM_LINUX_SUSE: ret = "SUSE Linux"; break; | |
| 69 | ✗ | case GATE_OS_PLATFORM_LINUX_ARCH: ret = "Arch Linux"; break; | |
| 70 | ✗ | case GATE_OS_PLATFORM_LINUX_GENTOO: ret = "Gentoo Linux"; break; | |
| 71 | ✗ | case GATE_OS_PLATFORM_LINUX_REDHAT: ret = "Redhat Linux"; break; | |
| 72 | ✗ | case GATE_OS_PLATFORM_LINUX_FEDORA: ret = "Fedora Linux"; break; | |
| 73 | ✗ | case GATE_OS_PLATFORM_LINUX_SLACKWARE: ret = "Slackware Linux"; break; | |
| 74 | ✗ | case GATE_OS_PLATFORM_LINUX_EMBEDDED: ret = "Linux Embedded"; break; | |
| 75 | ✗ | case GATE_OS_PLATFORM_DARWIN_MACOS: ret = "MacOS X"; break; | |
| 76 | ✗ | case GATE_OS_PLATFORM_DARWIN_IOS: ret = "Apple iOS"; break; | |
| 77 | 2 | default: | |
| 78 | { | ||
| 79 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (GATE_FLAG_ENABLED(platform, GATE_OS_PLATFORM_WINDOWS)) |
| 80 | { | ||
| 81 | ✗ | ret = "Windows"; | |
| 82 | } | ||
| 83 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | else if (GATE_FLAG_ENABLED(platform, GATE_OS_PLATFORM_BSD)) |
| 84 | { | ||
| 85 | ✗ | ret = "BSD"; | |
| 86 | } | ||
| 87 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | else if (GATE_FLAG_ENABLED(platform, GATE_OS_PLATFORM_LINUX)) |
| 88 | { | ||
| 89 | 2 | ret = "Linux"; | |
| 90 | } | ||
| 91 | ✗ | else if (GATE_FLAG_ENABLED(platform, GATE_OS_PLATFORM_DARWIN)) | |
| 92 | { | ||
| 93 | ✗ | ret = "Darwin"; | |
| 94 | } | ||
| 95 | ✗ | else if (GATE_FLAG_ENABLED(platform, GATE_OS_PLATFORM_LINUX)) | |
| 96 | { | ||
| 97 | ✗ | ret = "Linux"; | |
| 98 | } | ||
| 99 | ✗ | else if (GATE_FLAG_ENABLED(platform, GATE_OS_PLATFORM_RTOS)) | |
| 100 | { | ||
| 101 | ✗ | ret = "Real-Time OS"; | |
| 102 | } | ||
| 103 | ✗ | else if (GATE_FLAG_ENABLED(platform, GATE_OS_PLATFORM_EFI)) | |
| 104 | { | ||
| 105 | ✗ | ret = "EFI"; | |
| 106 | } | ||
| 107 | ✗ | else if (GATE_FLAG_ENABLED(platform, GATE_OS_PLATFORM_DOS)) | |
| 108 | { | ||
| 109 | ✗ | ret = "DOS"; | |
| 110 | } | ||
| 111 | ✗ | else if (GATE_FLAG_ENABLED(platform, GATE_OS_PLATFORM_MCU)) | |
| 112 | { | ||
| 113 | ✗ | ret = "Microcontroller"; | |
| 114 | } | ||
| 115 | ✗ | else if (GATE_FLAG_ENABLED(platform, GATE_OS_PLATFORM_WASM)) | |
| 116 | { | ||
| 117 | ✗ | ret = "WebAssembly"; | |
| 118 | } | ||
| 119 | } | ||
| 120 | } | ||
| 121 | 2 | return ret; | |
| 122 | } | ||
| 123 | |||
| 124 | 1 | char const* gate_os_get_cpu_architecture_label(gate_enumint_t arch) | |
| 125 | { | ||
| 126 | 1 | char const* ret = NULL; | |
| 127 | |||
| 128 |
1/14✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ 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.
|
1 | switch (arch) |
| 129 | { | ||
| 130 | ✗ | case GATE_OS_ARCH_X86_16: ret = "X86-16"; break; | |
| 131 | ✗ | case GATE_OS_ARCH_X86_32: ret = "X86-32"; break; | |
| 132 | 1 | case GATE_OS_ARCH_X86_64: ret = "X86-64"; break; | |
| 133 | ✗ | case GATE_OS_ARCH_ITANIUM: ret = "Itanium"; break; | |
| 134 | ✗ | case GATE_OS_ARCH_ARM_32: ret = "ARM-32"; break; | |
| 135 | ✗ | case GATE_OS_ARCH_ARM_64: ret = "ARM-64"; break; | |
| 136 | ✗ | case GATE_OS_ARCH_MIPS: ret = "MIPS"; break; | |
| 137 | ✗ | case GATE_OS_ARCH_ALPHA: ret = "ALPHA"; break; | |
| 138 | ✗ | case GATE_OS_ARCH_ALPHA_64: ret = "ALPHA-64"; break; | |
| 139 | ✗ | case GATE_OS_ARCH_PPC: ret = "PPC"; break; | |
| 140 | ✗ | case GATE_OS_ARCH_SHX: ret = "SHX"; break; | |
| 141 | ✗ | case GATE_OS_ARCH_RISCV: ret = "RISC-V"; break; | |
| 142 | ✗ | case GATE_OS_ARCH_WASM: ret = "WASM"; break; | |
| 143 | } | ||
| 144 | 1 | return ret; | |
| 145 | } | ||
| 146 | |||
| 147 | ✗ | gate_result_t gate_os_get_hostname(gate_string_t* hostname) | |
| 148 | { | ||
| 149 | char buffer[4096]; | ||
| 150 | gate_size_t used; | ||
| 151 | ✗ | gate_result_t ret = gate_os_get_hostname_str(buffer, sizeof(buffer), &used); | |
| 152 | ✗ | if (GATE_SUCCEEDED(ret)) | |
| 153 | { | ||
| 154 | ✗ | if (NULL == gate_string_create(hostname, buffer, used)) | |
| 155 | { | ||
| 156 | ✗ | ret = GATE_RESULT_OUTOFMEMORY; | |
| 157 | } | ||
| 158 | } | ||
| 159 | ✗ | return ret; | |
| 160 | } | ||
| 161 | ✗ | gate_result_t gate_os_get_hostdomainname(gate_string_t* domainname) | |
| 162 | { | ||
| 163 | char buffer[4096]; | ||
| 164 | gate_size_t used; | ||
| 165 | ✗ | gate_result_t ret = gate_os_get_hostdomainname_str(buffer, sizeof(buffer), &used); | |
| 166 | ✗ | if (GATE_SUCCEEDED(ret)) | |
| 167 | { | ||
| 168 | ✗ | if (NULL == gate_string_create(domainname, buffer, used)) | |
| 169 | { | ||
| 170 | ✗ | ret = GATE_RESULT_OUTOFMEMORY; | |
| 171 | } | ||
| 172 | } | ||
| 173 | ✗ | return ret; | |
| 174 | } | ||
| 175 | |||
| 176 | ✗ | gate_bool_t gate_os_cpu_get_activation(gate_os_cpu_activation_t const* activation, gate_size_t id) | |
| 177 | { | ||
| 178 | gate_size_t byte_pos; | ||
| 179 | gate_size_t bit_pos; | ||
| 180 | gate_uint8_t mask; | ||
| 181 | |||
| 182 | ✗ | if (id >= sizeof(activation->core_bits)) | |
| 183 | { | ||
| 184 | ✗ | return 0; | |
| 185 | } | ||
| 186 | else | ||
| 187 | { | ||
| 188 | ✗ | byte_pos = id / 8; | |
| 189 | ✗ | bit_pos = 7 - id % 8; | |
| 190 | ✗ | mask = (gate_uint8_t)1 << bit_pos; | |
| 191 | ✗ | return (activation->core_bits[byte_pos] & mask) == mask; | |
| 192 | } | ||
| 193 | } | ||
| 194 | ✗ | gate_result_t gate_os_cpu_set_activation(gate_os_cpu_activation_t* activation, gate_size_t id, gate_bool_t activated) | |
| 195 | { | ||
| 196 | gate_size_t byte_pos; | ||
| 197 | gate_size_t bit_pos; | ||
| 198 | gate_uint8_t mask; | ||
| 199 | |||
| 200 | ✗ | if (id >= sizeof(activation->core_bits)) | |
| 201 | { | ||
| 202 | ✗ | return GATE_RESULT_OUTOFBOUNDS; | |
| 203 | } | ||
| 204 | else | ||
| 205 | { | ||
| 206 | ✗ | byte_pos = id / 8; | |
| 207 | ✗ | bit_pos = 7 - id % 8; | |
| 208 | ✗ | mask = (gate_uint8_t)1 << bit_pos; | |
| 209 | ✗ | if (activated) | |
| 210 | { | ||
| 211 | ✗ | activation->core_bits[byte_pos] |= mask; | |
| 212 | } | ||
| 213 | else | ||
| 214 | { | ||
| 215 | ✗ | activation->core_bits[byte_pos] &= ~mask; | |
| 216 | } | ||
| 217 | ✗ | return GATE_RESULT_OK; | |
| 218 | } | ||
| 219 | } | ||
| 220 | |||
| 221 | |||
| 222 | |||
| 223 | #if defined(GATE_SYSTEM_OS_WINAPI_IMPL) | ||
| 224 | |||
| 225 | #endif /* defined(GATE_SYSTEM_OS_WINAPI_IMPL) */ | ||
| 226 | |||
| 227 | |||
| 228 | |||
| 229 | #if defined(GATE_SYSTEM_OS_POSIX_IMPL) | ||
| 230 | |||
| 231 | #endif /* defined(GATE_SYSTEM_OS_POSIX_IMPL) */ | ||
| 232 | |||
| 233 | |||
| 234 | |||
| 235 | #if defined(GATE_SYSTEM_OS_EFI_IMPL) | ||
| 236 | |||
| 237 | #endif /* GATE_SYSTEM_OS_EFI_IMPL */ | ||
| 238 | |||
| 239 | |||
| 240 | |||
| 241 | #if defined(GATE_SYSTEM_OS_DOS_IMPL) | ||
| 242 | |||
| 243 | #endif /* GATE_SYSTEM_OS_DOS_IMPL */ | ||
| 244 | |||
| 245 | |||
| 246 | |||
| 247 | #if defined(GATE_SYSTEM_OS_NO_IMPL) | ||
| 248 | |||
| 249 | gate_result_t gate_os_get_platform(gate_uint32_t* ptr_platform) | ||
| 250 | { | ||
| 251 | (void)ptr_platform; | ||
| 252 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 253 | } | ||
| 254 | gate_uint32_t gate_os_address_space() | ||
| 255 | { | ||
| 256 | return 32; | ||
| 257 | } | ||
| 258 | gate_uint32_t gate_os_up_time_seconds() | ||
| 259 | { | ||
| 260 | return 0; | ||
| 261 | } | ||
| 262 | gate_result_t gate_os_print_osname(char* buffer, gate_size_t buffer_len, gate_size_t* buffer_used) | ||
| 263 | { | ||
| 264 | (void)buffer; | ||
| 265 | (void)buffer_len; | ||
| 266 | (void)buffer_used; | ||
| 267 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 268 | } | ||
| 269 | gate_result_t gate_os_print_productname(char* buffer, gate_size_t buffer_len, gate_size_t* buffer_used) | ||
| 270 | { | ||
| 271 | (void)buffer; | ||
| 272 | (void)buffer_len; | ||
| 273 | (void)buffer_used; | ||
| 274 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 275 | } | ||
| 276 | gate_result_t gate_os_get_version(gate_version_t* ptr_version) | ||
| 277 | { | ||
| 278 | (void)ptr_version; | ||
| 279 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 280 | } | ||
| 281 | |||
| 282 | gate_result_t gate_os_get_hostname_str(char* buffer, gate_size_t buffer_len, gate_size_t* buffer_used) | ||
| 283 | { | ||
| 284 | (void)buffer; | ||
| 285 | (void)buffer_len; | ||
| 286 | (void)buffer_used; | ||
| 287 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 288 | } | ||
| 289 | gate_result_t gate_os_set_hostname(gate_string_t const* hostname) | ||
| 290 | { | ||
| 291 | (void)hostname; | ||
| 292 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 293 | } | ||
| 294 | gate_result_t gate_os_get_hostdomainname_str(char* buffer, gate_size_t buffer_len, gate_size_t* buffer_used) | ||
| 295 | { | ||
| 296 | (void)buffer; | ||
| 297 | (void)buffer_len; | ||
| 298 | (void)buffer_used; | ||
| 299 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 300 | } | ||
| 301 | gate_result_t gate_os_set_hostdomainname(gate_string_t const* domainname) | ||
| 302 | { | ||
| 303 | (void)domainname; | ||
| 304 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 305 | } | ||
| 306 | gate_result_t gate_os_get_uid(gate_uint8_t* buffer, gate_size_t buffer_len, gate_size_t* buffer_used) | ||
| 307 | { | ||
| 308 | (void)buffer; | ||
| 309 | (void)buffer_len; | ||
| 310 | (void)buffer_used; | ||
| 311 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 312 | } | ||
| 313 | |||
| 314 | gate_result_t gate_os_shutdown() | ||
| 315 | { | ||
| 316 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 317 | } | ||
| 318 | gate_result_t gate_os_reboot() | ||
| 319 | { | ||
| 320 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 321 | } | ||
| 322 | |||
| 323 | gate_result_t gate_os_get_cpu_architecture(gate_enumint_t* ptr_arch) | ||
| 324 | { | ||
| 325 | (void)ptr_arch; | ||
| 326 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 327 | } | ||
| 328 | gate_result_t gate_os_get_cpu_info(gate_os_cpuinfo_t* info) | ||
| 329 | { | ||
| 330 | (void)info; | ||
| 331 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 332 | } | ||
| 333 | gate_result_t gate_os_enum_cpu_features(gate_os_cpu_feature_callback_t callback, void* param) | ||
| 334 | { | ||
| 335 | (void)callback; | ||
| 336 | (void)param; | ||
| 337 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 338 | } | ||
| 339 | gate_result_t gate_os_get_process_cpu_affinity(gate_os_cpu_activation_t* affinity) | ||
| 340 | { | ||
| 341 | (void)affinity; | ||
| 342 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 343 | } | ||
| 344 | gate_result_t gate_os_set_process_cpu_affinity(gate_os_cpu_activation_t const* affinity) | ||
| 345 | { | ||
| 346 | (void)affinity; | ||
| 347 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 348 | } | ||
| 349 | |||
| 350 | gate_result_t gate_os_cpu_load_init(gate_os_cpu_load_state_t* state) | ||
| 351 | { | ||
| 352 | (void)state; | ||
| 353 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 354 | } | ||
| 355 | gate_result_t gate_os_cpu_load_update(gate_os_cpu_load_state_t* state, gate_uint16_t* load65535) | ||
| 356 | { | ||
| 357 | (void)state; | ||
| 358 | (void)load65535; | ||
| 359 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 360 | } | ||
| 361 | gate_result_t gate_os_cpu_load_uninit(gate_os_cpu_load_state_t* state) | ||
| 362 | { | ||
| 363 | (void)state; | ||
| 364 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 365 | } | ||
| 366 | |||
| 367 | gate_result_t gate_os_get_physical_memory(gate_uint64_t* ptr_total, gate_uint64_t* ptr_available) | ||
| 368 | { | ||
| 369 | (void)ptr_total; | ||
| 370 | (void)ptr_available; | ||
| 371 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 372 | } | ||
| 373 | gate_result_t gate_os_get_virtual_memory(gate_uint64_t* ptr_total, gate_uint64_t* ptr_available) | ||
| 374 | { | ||
| 375 | (void)ptr_total; | ||
| 376 | (void)ptr_available; | ||
| 377 | return GATE_RESULT_NOTIMPLEMENTED; | ||
| 378 | } | ||
| 379 | |||
| 380 | #endif /* GATE_SYSTEM_OS_NO_IMPL */ | ||
| 381 |