3 #ifndef INCLUDE_NN_NLIB_PLATFORM_H_ 4 #define INCLUDE_NN_NLIB_PLATFORM_H_ 7 # error Sorry, ILP64 not supported 11 #define NLIB_VERSION_YEAR 2016 12 #define NLIB_VERSION_YEAR_SHORT 16 13 #define NLIB_VERSION_DATE 0920 14 #define NLIB_VERSION 20160920 17 # ifndef __STDC_LIMIT_MACROS 19 # pragma message(__FILE__ ": __STDC_LIMIT_MACROS not defined, compile may fail") 20 # elif !defined(NN_PLATFORM_CTR) && !defined(CAFE) 21 # warning __STDC_LIMIT_MACROS not defined, compile may fail 23 # define __STDC_LIMIT_MACROS 25 # ifndef __STDC_CONSTANT_MACROS 27 # pragma message(__FILE__ ": __STDC_CONSTANT_MACROS not defined, compile may fail") 28 # elif !defined(NN_PLATFORM_CTR) && !defined(CAFE) 29 # warning __STDC_CONSTANT_MACROS not defined, compile may fail 31 # define __STDC_CONSTANT_MACROS 33 # ifndef __STDC_FORMAT_MACROS 35 # pragma message(__FILE__ ": __STDC_FORMAT_MACROS not defined, compile may fail") 36 # elif !defined(NN_PLATFORM_CTR) && !defined(CAFE) 37 # warning __STDC_FORMAT_MACROS not defined, compile may fail 39 # define __STDC_FORMAT_MACROS 42 #ifndef __STDC_WANT_LIB_EXT1__ 43 # define __STDC_WANT_LIB_EXT1__ 1 47 # define NLIB_UNUSED(x) (void)(x) 51 # define __has_builtin(x) 0 55 # define __has_feature(x) 0 58 #ifndef __has_cpp_attribute 59 # define __has_cpp_attribute(x) 0 62 #ifndef __has_attribute 63 # define __has_attribute(x) 0 66 #ifndef __has_declspec_attribute 67 # define __has_declspec_attribute(x) 0 71 # define __has_include(x) 0 74 #if __has_feature(thread_sanitizer) 75 # define NLIB_NO_TSAN __attribute__((no_sanitize("thread"))) 80 #if __has_feature(address_sanitizer) 81 # define NLIB_NO_ASAN __attribute__((no_sanitize("address"))) 86 #if __has_feature(memory_sanitizer) 87 # define NLIB_NO_MSAN __attribute__((no_sanitize("memory"))) 96 #if !defined(NLIB_THREAD_AA_) && defined(__clang__) && \ 97 (!defined(SWIG)) && __has_attribute(capability) 98 #define NLIB_THREAD_AA_(x) __attribute__((x)) 100 #ifdef NLIB_THREAD_AA_ 101 #undef NLIB_THREAD_AA_ 103 #define NLIB_THREAD_AA_(x) 106 #define NLIB_CAPABILITY(x) NLIB_THREAD_AA_(capability(x)) 107 #define NLIB_SCOPED_CAPABILITY NLIB_THREAD_AA_(scoped_lockable) 108 #define NLIB_GUARDED_BY(x) NLIB_THREAD_AA_(guarded_by(x)) 109 #define NLIB_PT_GUARDED_BY(x) NLIB_THREAD_AA_(pt_guarded_by(x)) 110 #define NLIB_ACQUIRED_BEFORE(...) NLIB_THREAD_AA_(acquired_before(__VA_ARGS__)) 111 #define NLIB_ACQUIRED_AFTER(...) NLIB_THREAD_AA_(acquired_after(__VA_ARGS__)) 112 #define NLIB_REQUIRES(...) NLIB_THREAD_AA_(requires_capability(__VA_ARGS__)) 113 #define NLIB_REQUIRES_SHARED(...) NLIB_THREAD_AA_(requires_shared_capability(__VA_ARGS__)) 114 #define NLIB_ACQUIRE(...) NLIB_THREAD_AA_(acquire_capability(__VA_ARGS__)) 115 #define NLIB_ACQUIRE_SHARED(...) NLIB_THREAD_AA_(acquire_shared_capability(__VA_ARGS__)) 116 #define NLIB_RELEASE(...) NLIB_THREAD_AA_(release_capability(__VA_ARGS__)) 117 #define NLIB_RELEASE_SHARED(...) NLIB_THREAD_AA_(release_shared_capability(__VA_ARGS__)) 118 #define NLIB_TRY_ACQUIRE(...) NLIB_THREAD_AA_(try_acquire_capability(__VA_ARGS__)) 119 #define NLIB_TRY_ACQUIRE_SHARED(...) NLIB_THREAD_AA_(try_acquire_shared_capability(__VA_ARGS__)) 120 #define NLIB_EXCLUDES(...) NLIB_THREAD_AA_(locks_excluded(__VA_ARGS__)) 121 #define NLIB_ASSERT_CAPABILITY(x) NLIB_THREAD_AA_(assert_capability(x)) 122 #define NLIB_ASSERT_SHARED_CAPABILITY(x) NLIB_THREAD_AA_(assert_shared_capability(x)) 123 #define NLIB_RETURN_CAPABILITY(x) NLIB_THREAD_AA_(lock_returned(x)) 124 #define NLIB_NO_THREAD_SAFETY_ANALYSIS NLIB_THREAD_AA_(no_thread_safety_analysis) 132 #if defined(NLIB_RENAME_CAPI) && !defined(_MSC_VER) 133 #ifndef NLIB_CFUNC_PREFIX 134 # define NLIB_CFUNC_PREFIX mypfx 137 # define NLIB_CAPI__(p, q) p ## q 138 # define NLIB_CAPI_(p, q) NLIB_CAPI__(p, q) 139 # define NLIB_CAPI(x) NLIB_CAPI_(NLIB_CFUNC_PREFIX, x) 142 #define nlib_error_string NLIB_CAPI(nlib_error_string) 143 #define nlib_get_native_last_error NLIB_CAPI(nlib_get_native_last_error) 144 #define nlib_getversion NLIB_CAPI(nlib_getversion) 145 #define nlib_compiler_version NLIB_CAPI(nlib_compiler_version) 146 #define nlib_crc32 NLIB_CAPI(nlib_crc32) 147 #define nlib_crc32c NLIB_CAPI(nlib_crc32c) 148 #define nlib_epochtime NLIB_CAPI(nlib_epochtime) 149 #define nlib_ticktime NLIB_CAPI(nlib_ticktime) 150 #define nlib_sleep NLIB_CAPI(nlib_sleep) 151 #define nlib_gen_random NLIB_CAPI(nlib_gen_random) 152 #define nlib_mempagesize NLIB_CAPI(nlib_mempagesize) 153 #define nlib_virtual_alloc NLIB_CAPI(nlib_virtual_alloc) 154 #define nlib_virtual_free NLIB_CAPI(nlib_virtual_free) 155 #define nlib_physical_alloc NLIB_CAPI(nlib_physical_alloc) 156 #define nlib_physical_free NLIB_CAPI(nlib_physical_free) 157 #define nlib_mlock NLIB_CAPI(nlib_mlock) 158 #define nlib_munlock NLIB_CAPI(nlib_munlock) 159 #define nlib_tls_alloc NLIB_CAPI(nlib_tls_alloc) 160 #define nlib_tls_free NLIB_CAPI(nlib_tls_free) 161 #define nlib_tls_setvalue NLIB_CAPI(nlib_tls_setvalue) 162 #define nlib_tls_getvalue NLIB_CAPI(nlib_tls_getvalue) 163 #define nlib_mutex_init NLIB_CAPI(nlib_mutex_init) 164 #define nlib_mutex_recursive_init NLIB_CAPI(nlib_mutex_recursive_init) 165 #define nlib_mutex_recursive_timed_init NLIB_CAPI(nlib_mutex_recursive_timed_init) 166 #define nlib_mutex_lock NLIB_CAPI(nlib_mutex_lock) 167 #define nlib_mutex_trylock NLIB_CAPI(nlib_mutex_trylock) 168 #define nlib_mutex_trylock_for NLIB_CAPI(nlib_mutex_trylock_for) 169 #define nlib_mutex_unlock NLIB_CAPI(nlib_mutex_unlock) 170 #define nlib_mutex_destroy NLIB_CAPI(nlib_mutex_destroy) 171 #define nlib_semaphore_init NLIB_CAPI(nlib_semaphore_init) 172 #define nlib_semaphore_wait NLIB_CAPI(nlib_semaphore_wait) 173 #define nlib_semaphore_trywait NLIB_CAPI(nlib_semaphore_trywait) 174 #define nlib_semaphore_trywait_for NLIB_CAPI(nlib_semaphore_trywait_for) 175 #define nlib_semaphore_post NLIB_CAPI(nlib_semaphore_post) 176 #define nlib_semaphore_post_ex NLIB_CAPI(nlib_semaphore_post_ex) 177 #define nlib_semaphore_destroy NLIB_CAPI(nlib_semaphore_destroy) 178 #define nlib_cond_init NLIB_CAPI(nlib_cond_init) 179 #define nlib_cond_signal NLIB_CAPI(nlib_cond_signal) 180 #define nlib_cond_broadcast NLIB_CAPI(nlib_cond_broadcast) 181 #define nlib_cond_wait NLIB_CAPI(nlib_cond_wait) 182 #define nlib_cond_wait_for NLIB_CAPI(nlib_cond_wait_for) 183 #define nlib_cond_wait_until NLIB_CAPI(nlib_cond_wait_until) 184 #define nlib_cond_destroy NLIB_CAPI(nlib_cond_destroy) 185 #define nlib_rwlock_init NLIB_CAPI(nlib_rwlock_init) 186 #define nlib_rwlock_destroy NLIB_CAPI(nlib_rwlock_destroy) 187 #define nlib_rwlock_rdlock NLIB_CAPI(nlib_rwlock_rdlock) 188 #define nlib_rwlock_tryrdlock NLIB_CAPI(nlib_rwlock_tryrdlock) 189 #define nlib_rwlock_tryrdlock_for NLIB_CAPI(nlib_rwlock_tryrdlock_for) 190 #define nlib_rwlock_tryrdlock_until NLIB_CAPI(nlib_rwlock_tryrdlock_until) 191 #define nlib_rwlock_rdunlock NLIB_CAPI(nlib_rwlock_rdunlock) 192 #define nlib_rwlock_wrlock NLIB_CAPI(nlib_rwlock_wrlock) 193 #define nlib_rwlock_trywrlock NLIB_CAPI(nlib_rwlock_trywrlock) 194 #define nlib_rwlock_trywrlock_for NLIB_CAPI(nlib_rwlock_trywrlock_for) 195 #define nlib_rwlock_trywrlock_until NLIB_CAPI(nlib_rwlock_trywrlock_until) 196 #define nlib_rwlock_wrunlock NLIB_CAPI(nlib_rwlock_wrunlock) 197 #define nlib_condrwlock_init NLIB_CAPI(nlib_condrwlock_init) 198 #define nlib_condrwlock_destroy NLIB_CAPI(nlib_condrwlock_destroy) 199 #define nlib_condrwlock_signal NLIB_CAPI(nlib_condrwlock_signal) 200 #define nlib_condrwlock_broadcast NLIB_CAPI(nlib_condrwlock_broadcast) 201 #define nlib_condrwlock_wait NLIB_CAPI(nlib_condrwlock_wait) 202 #define nlib_condrwlock_wait_for NLIB_CAPI(nlib_condrwlock_wait_for) 203 #define nlib_condrwlock_wait_until NLIB_CAPI(nlib_condrwlock_wait_until) 204 #define nlib_barrier_init NLIB_CAPI(nlib_barrier_init) 205 #define nlib_barrier_destroy NLIB_CAPI(nlib_barrier_destroy) 206 #define nlib_barrier_wait NLIB_CAPI(nlib_barrier_wait) 207 #define nlib_once NLIB_CAPI(nlib_once) 208 #define nlib_tryonce NLIB_CAPI(nlib_tryonce) 209 #define nlib_mq_open NLIB_CAPI(nlib_mq_open) 210 #define nlib_mq_getattr NLIB_CAPI(nlib_mq_getattr) 211 #define nlib_mq_close NLIB_CAPI(nlib_mq_close) 212 #define nlib_mq_readonly NLIB_CAPI(nlib_mq_readonly) 213 #define nlib_mq_send NLIB_CAPI(nlib_mq_send) 214 #define nlib_mq_send_until NLIB_CAPI(nlib_mq_send_until) 215 #define nlib_mq_receive NLIB_CAPI(nlib_mq_receive) 216 #define nlib_mq_receive_until NLIB_CAPI(nlib_mq_receive_until) 217 #define nlib_mq_drop NLIB_CAPI(nlib_mq_drop) 218 #define nlib_yield NLIB_CAPI(nlib_yield) 219 #define nlib_thread_create NLIB_CAPI(nlib_thread_create) 220 #define nlib_thread_join NLIB_CAPI(nlib_thread_join) 221 #define nlib_thread_detach NLIB_CAPI(nlib_thread_detach) 222 #define nlib_thread_self NLIB_CAPI(nlib_thread_self) 223 #define nlib_thread_getconcurrency NLIB_CAPI(nlib_thread_getconcurrency) 224 #define nlib_thread_getid NLIB_CAPI(nlib_thread_getid) 225 #define nlib_thread_equal NLIB_CAPI(nlib_thread_equal) 226 #define nlib_thread_getcpu NLIB_CAPI(nlib_thread_getcpu) 227 #define nlib_thread_setaffinity NLIB_CAPI(nlib_thread_setaffinity) 228 #define nlib_thread_setname NLIB_CAPI(nlib_thread_setname) 229 #define nlib_thread_getname NLIB_CAPI(nlib_thread_getname) 230 #define nlib_thread_attr_init NLIB_CAPI(nlib_thread_attr_init) 231 #define nlib_thread_attr_setint NLIB_CAPI(nlib_thread_attr_setint) 232 #define nlib_thread_attr_getint NLIB_CAPI(nlib_thread_attr_getint) 233 #define nlib_thread_attr_setptr NLIB_CAPI(nlib_thread_attr_setptr) 234 #define nlib_thread_attr_getptr NLIB_CAPI(nlib_thread_attr_getptr) 235 #define nlib_thread_attr_setstack NLIB_CAPI(nlib_thread_attr_setstack) 236 #define nlib_thread_attr_getstack NLIB_CAPI(nlib_thread_attr_getstack) 237 #define nlib_thread_attr_destroy NLIB_CAPI(nlib_thread_attr_destroy) 238 #define nlib_thread_getpriority NLIB_CAPI(nlib_thread_getpriority) 239 #define nlib_thread_setpriority NLIB_CAPI(nlib_thread_setpriority) 240 #define nlib_thread_priority_min NLIB_CAPI(nlib_thread_priority_min) 241 #define nlib_thread_priority_max NLIB_CAPI(nlib_thread_priority_max) 242 #define nlib_thread_priority_default NLIB_CAPI(nlib_thread_priority_default) 243 #define nlib_thread_exit NLIB_CAPI(nlib_thread_exit) 244 #define nlib_thread_exit_cpp NLIB_CAPI(nlib_thread_exit_cpp) 245 #define nlib_thread_cleanup_push_ NLIB_CAPI(nlib_thread_cleanup_push_) 246 #define nlib_thread_cleanup_pop_ NLIB_CAPI(nlib_thread_cleanup_pop_) 247 #define nlib_write_stdout NLIB_CAPI(nlib_write_stdout) 248 #define nlib_write_stderr NLIB_CAPI(nlib_write_stderr) 249 #define nlib_debug_break NLIB_CAPI(nlib_debug_break) 250 #define nlib_debug_backtrace NLIB_CAPI(nlib_debug_backtrace) 251 #define nlib_debug_backtrace_gettext NLIB_CAPI(nlib_debug_backtrace_gettext) 252 #define nlib_getenv NLIB_CAPI(nlib_getenv) 253 #define nlib_log_print NLIB_CAPI(nlib_log_print) 254 #define nlib_log_vprint NLIB_CAPI(nlib_log_vprint) 255 #define nlib_log_attr_setint NLIB_CAPI(nlib_log_attr_setint) 256 #define nlib_fd_open NLIB_CAPI(nlib_fd_open) 257 #define nlib_fd_close NLIB_CAPI(nlib_fd_close) 258 #define nlib_fd_read NLIB_CAPI(nlib_fd_read) 259 #define nlib_fd_write NLIB_CAPI(nlib_fd_write) 260 #define nlib_fd_seek NLIB_CAPI(nlib_fd_seek) 261 #define nlib_fd_pread NLIB_CAPI(nlib_fd_pread) 262 #define nlib_fd_pwrite NLIB_CAPI(nlib_fd_pwrite) 263 #define nlib_fd_truncate NLIB_CAPI(nlib_fd_truncate) 264 #define nlib_fd_getsize NLIB_CAPI(nlib_fd_getsize) 265 #define nlib_fd_flush NLIB_CAPI(nlib_fd_flush) 266 #define nlib_fd_sync NLIB_CAPI(nlib_fd_sync) 267 #define nlib_fd_native_handle NLIB_CAPI(nlib_fd_native_handle) 268 #define nlib_fd_readv NLIB_CAPI(nlib_fd_readv) 269 #define nlib_fd_writev NLIB_CAPI(nlib_fd_writev) 270 #define nlib_fd_preadv NLIB_CAPI(nlib_fd_preadv) 271 #define nlib_fd_pwritev NLIB_CAPI(nlib_fd_pwritev) 272 #define nlib_unlink NLIB_CAPI(nlib_unlink) 273 #define nlib_remove NLIB_CAPI(nlib_remove) 274 #define nlib_mkdir NLIB_CAPI(nlib_mkdir) 275 #define nlib_rmdir NLIB_CAPI(nlib_rmdir) 276 #define nlib_rename NLIB_CAPI(nlib_rename) 277 #define nlib_dir_open NLIB_CAPI(nlib_dir_open) 278 #define nlib_dir_close NLIB_CAPI(nlib_dir_close) 279 #define nlib_dir_read NLIB_CAPI(nlib_dir_read) 280 #define nlib_is_dir NLIB_CAPI(nlib_is_dir) 281 #define nlib_exist_path NLIB_CAPI(nlib_exist_path) 282 #define nlib_disk_freespace NLIB_CAPI(nlib_disk_freespace) 283 #define nlib_basename NLIB_CAPI(nlib_basename) 284 #define nlib_dirname NLIB_CAPI(nlib_dirname) 285 #define nlib_spinlock_lock_ NLIB_CAPI(nlib_spinlock_lock_) 286 #define nlib_spinlock_unlock_ NLIB_CAPI(nlib_spinlock_unlock_) 287 #define nlib_vsnprintf NLIB_CAPI(nlib_vsnprintf) 288 #define nlib_snprintf NLIB_CAPI(nlib_snprintf) 289 #define nlib_vdprintf NLIB_CAPI(nlib_vdprintf) 290 #define nlib_dprintf NLIB_CAPI(nlib_dprintf) 291 #define nlib_printf NLIB_CAPI(nlib_printf) 292 #define nlib_vsnwprintf NLIB_CAPI(nlib_vsnwprintf) 293 #define nlib_snwprintf NLIB_CAPI(nlib_snwprintf) 294 #define nlib_vdwprintf NLIB_CAPI(nlib_vdwprintf) 295 #define nlib_dwprintf NLIB_CAPI(nlib_dwprintf) 296 #define nlib_wprintf NLIB_CAPI(nlib_wprintf) 297 #define nlib_vsnprintf_fallback NLIB_CAPI(nlib_vsnprintf_fallback) 298 #define nlib_snprintf_fallback NLIB_CAPI(nlib_snprintf_fallback) 299 #define nlib_vsnwprintf_fallback NLIB_CAPI(nlib_vsnwprintf_fallback) 300 #define nlib_snwprintf_fallback NLIB_CAPI(nlib_snwprintf_fallback) 301 #define nlib_memcmp NLIB_CAPI(nlib_memcmp) 302 #define nlib_memchr NLIB_CAPI(nlib_memchr) 303 #define nlib_memrchr NLIB_CAPI(nlib_memrchr) 304 #define nlib_memchr_not NLIB_CAPI(nlib_memchr_not) 305 #define nlib_memchr_range_not NLIB_CAPI(nlib_memchr_range_not) 306 #define nlib_memchr_lt NLIB_CAPI(nlib_memchr_lt) 307 #define nlib_memchr_gt NLIB_CAPI(nlib_memchr_gt) 308 #define nlib_memchr_mb NLIB_CAPI(nlib_memchr_mb) 309 #define nlib_memspn NLIB_CAPI(nlib_memspn) 310 #define nlib_memcspn NLIB_CAPI(nlib_memcspn) 311 #define nlib_memccpy NLIB_CAPI(nlib_memccpy) 312 #define nlib_skipws NLIB_CAPI(nlib_skipws) 313 #define nlib_strlen NLIB_CAPI(nlib_strlen) 314 #define nlib_strnlen NLIB_CAPI(nlib_strnlen) 315 #define nlib_strcpy NLIB_CAPI(nlib_strcpy) 316 #define nlib_strncpy NLIB_CAPI(nlib_strncpy) 317 #define nlib_strchr NLIB_CAPI(nlib_strchr) 318 #define nlib_strrchr NLIB_CAPI(nlib_strrchr) 319 #define nlib_strchr_mb NLIB_CAPI(nlib_strchr_mb) 320 #define nlib_wcslen NLIB_CAPI(nlib_wcslen) 321 #define nlib_wcsnlen NLIB_CAPI(nlib_wcsnlen) 322 #define nlib_wcscpy NLIB_CAPI(nlib_wcscpy) 323 #define nlib_wcsncpy NLIB_CAPI(nlib_wcsncpy) 324 #define nlib_strcat NLIB_CAPI(nlib_strcat) 325 #define nlib_strncat NLIB_CAPI(nlib_strncat) 326 #define nlib_wcscat NLIB_CAPI(nlib_wcscat) 327 #define nlib_wcsncat NLIB_CAPI(nlib_wcsncat) 328 #define nlib_strto_int8 NLIB_CAPI(nlib_strto_int8) 329 #define nlib_strto_int16 NLIB_CAPI(nlib_strto_int16) 330 #define nlib_strto_int32 NLIB_CAPI(nlib_strto_int32) 331 #define nlib_strto_int64 NLIB_CAPI(nlib_strto_int64) 332 #define nlib_strto_uint8 NLIB_CAPI(nlib_strto_uint8) 333 #define nlib_strto_uint16 NLIB_CAPI(nlib_strto_uint16) 334 #define nlib_strto_uint32 NLIB_CAPI(nlib_strto_uint32) 335 #define nlib_strto_uint64 NLIB_CAPI(nlib_strto_uint64) 336 #define nlib_strto_double NLIB_CAPI(nlib_strto_double) 337 #define nlib_strto_float NLIB_CAPI(nlib_strto_float) 338 #define nlib_strto_int32_fallback NLIB_CAPI(nlib_strto_int32_fallback) 339 #define nlib_strto_int64_fallback NLIB_CAPI(nlib_strto_int64_fallback) 340 #define nlib_strto_uint32_fallback NLIB_CAPI(nlib_strto_uint32_fallback) 341 #define nlib_strto_uint64_fallback NLIB_CAPI(nlib_strto_uint64_fallback) 342 #define nlib_strto_double_fallback NLIB_CAPI(nlib_strto_double_fallback) 343 #define nlib_strto_float_fallback NLIB_CAPI(nlib_strto_float_fallback) 344 #define nlib_wide_to_utf8 NLIB_CAPI(nlib_wide_to_utf8) 345 #define nlib_utf8_to_wide NLIB_CAPI(nlib_utf8_to_wide) 346 #define nlib_strcplen NLIB_CAPI(nlib_strcplen) 347 #define nlib_memcplen NLIB_CAPI(nlib_memcplen) 348 #define nlib_wcscplen NLIB_CAPI(nlib_wcscplen) 349 #define nlib_swapendian_16 NLIB_CAPI(nlib_swapendian_16) 350 #define nlib_swapendian_32 NLIB_CAPI(nlib_swapendian_32) 351 #define nlib_swapendian_64 NLIB_CAPI(nlib_swapendian_64) 352 #define nlib_malloc NLIB_CAPI(nlib_malloc) 353 #define nlib_free NLIB_CAPI(nlib_free) 354 #define nlib_calloc NLIB_CAPI(nlib_calloc) 355 #define nlib_realloc NLIB_CAPI(nlib_realloc) 356 #define nlib_malloc_size NLIB_CAPI(nlib_malloc_size) 357 #define nlib_free_size NLIB_CAPI(nlib_free_size) 358 #define nlib_memalign NLIB_CAPI(nlib_memalign) 360 #define nlib_utf16cplen_ex_ NLIB_CAPI(nlib_utf16cplen_ex_) 361 #define nlib_utf16cpy_ NLIB_CAPI(nlib_utf16cpy_) 362 #define nlib_utf16len_ NLIB_CAPI(nlib_utf16len_) 363 #define nlib_utf16ncpy_ NLIB_CAPI(nlib_utf16ncpy_) 364 #define nlib_utf16nlen_ NLIB_CAPI(nlib_utf16nlen_) 365 #define nlib_utf16_to_utf32char NLIB_CAPI(nlib_utf16_to_utf32char) 366 #define nlib_utf16_to_utf8 NLIB_CAPI(nlib_utf16_to_utf8) 367 #define nlib_utf32char_to_utf16 NLIB_CAPI(nlib_utf32char_to_utf16) 368 #define nlib_utf32char_to_utf8 NLIB_CAPI(nlib_utf32char_to_utf8) 369 #define nlib_utf32cplen NLIB_CAPI(nlib_utf32cplen) 370 #define nlib_utf32cpy_ NLIB_CAPI(nlib_utf32cpy_) 371 #define nlib_utf32len_ NLIB_CAPI(nlib_utf32len_) 372 #define nlib_utf32ncpy_ NLIB_CAPI(nlib_utf32ncpy_) 373 #define nlib_utf32nlen_ NLIB_CAPI(nlib_utf32nlen_) 374 #define nlib_utf32_to_utf8 NLIB_CAPI(nlib_utf32_to_utf8) 375 #define nlib_utf8_to_utf16 NLIB_CAPI(nlib_utf8_to_utf16) 376 #define nlib_utf8_to_utf32 NLIB_CAPI(nlib_utf8_to_utf32) 377 #define nlib_utf8_to_utf32char NLIB_CAPI(nlib_utf8_to_utf32char) 378 #define nlib_memutf8_to_utf16 NLIB_CAPI(nlib_memutf8_to_utf16) 379 #define nlib_memutf8_to_utf32 NLIB_CAPI(nlib_memutf8_to_utf32) 380 #define nlib_memutf16_to_utf8 NLIB_CAPI(nlib_memutf16_to_utf8) 381 #define nlib_memutf32_to_utf8 NLIB_CAPI(nlib_memutf32_to_utf8) 382 #define nlib_memutf8_to_wide NLIB_CAPI(nlib_memutf8_to_wide) 383 #define nlib_memwide_to_utf8 NLIB_CAPI(nlib_memwide_to_utf8) 385 #define nlib_socket NLIB_CAPI(nlib_socket) 386 #define nlib_bind NLIB_CAPI(nlib_bind) 387 #define nlib_listen NLIB_CAPI(nlib_listen) 388 #define nlib_accept NLIB_CAPI(nlib_accept) 389 #define nlib_accept_for NLIB_CAPI(nlib_accept_for) 390 #define nlib_connect NLIB_CAPI(nlib_connect) 391 #define nlib_connect_for NLIB_CAPI(nlib_connect_for) 392 #define nlib_send NLIB_CAPI(nlib_send) 393 #define nlib_sendto NLIB_CAPI(nlib_sendto) 394 #define nlib_sendmsg NLIB_CAPI(nlib_sendmsg) 395 #define nlib_recv NLIB_CAPI(nlib_recv) 396 #define nlib_recvfrom NLIB_CAPI(nlib_recvfrom) 397 #define nlib_recvmsg NLIB_CAPI(nlib_recvmsg) 398 #define nlib_closesocket NLIB_CAPI(nlib_closesocket) 399 #define nlib_shutdownsocket NLIB_CAPI(nlib_shutdownsocket) 400 #define nlib_inet_pton NLIB_CAPI(nlib_inet_pton) 401 #define nlib_inet_ntop NLIB_CAPI(nlib_inet_ntop) 402 #define nlib_getaddrinfo NLIB_CAPI(nlib_getaddrinfo) 403 #define nlib_freeaddrinfo NLIB_CAPI(nlib_freeaddrinfo) 404 #define nlib_getsockopt NLIB_CAPI(nlib_getsockopt) 405 #define nlib_setsockopt NLIB_CAPI(nlib_setsockopt) 406 #define nlib_select NLIB_CAPI(nlib_select) 407 #define nlib_poll NLIB_CAPI(nlib_poll) 411 #define nlib_utf8_nbytes_table NLIB_CAPI(nlib_utf8_nbytes_table) 412 #define nlib_hex_char_table NLIB_CAPI(nlib_hex_char_table) 413 #define nlib_memcmp_generic NLIB_CAPI(nlib_memcmp_generic) 414 #define nlib_memchr_generic NLIB_CAPI(nlib_memchr_generic) 415 #define nlib_memrchr_generic NLIB_CAPI(nlib_memrchr_generic) 416 #define nlib_memchr_not_generic NLIB_CAPI(nlib_memchr_not_generic) 417 #define nlib_memchr_range_not_generic NLIB_CAPI(nlib_memchr_range_not_generic) 418 #define nlib_memchr_lt_generic NLIB_CAPI(nlib_memchr_lt_generic) 419 #define nlib_memchr_gt_generic NLIB_CAPI(nlib_memchr_gt_generic) 420 #define nlib_memchr_mb_generic NLIB_CAPI(nlib_memchr_mb_generic) 421 #define nlib_strlen_generic NLIB_CAPI(nlib_strlen_generic) 422 #define nlib_skipws_generic NLIB_CAPI(nlib_skipws_generic) 423 #define nlib_strnlen_generic NLIB_CAPI(nlib_strnlen_generic) 424 #define nlib_strchr_generic NLIB_CAPI(nlib_strchr_generic) 425 #define nlib_strrchr_generic NLIB_CAPI(nlib_strrchr_generic) 426 #define nlib_swapendian_16_generic NLIB_CAPI(nlib_swapendian_16_generic) 427 #define nlib_swapendian_32_generic NLIB_CAPI(nlib_swapendian_32_generic) 428 #define nlib_swapendian_64_generic NLIB_CAPI(nlib_swapendian_64_generic) 429 #define nlib_utf16len_generic NLIB_CAPI(nlib_utf16len_generic) 430 #define nlib_utf16nlen_generic NLIB_CAPI(nlib_utf16nlen_generic) 431 #define nlib_utf32len_generic NLIB_CAPI(nlib_utf32len_generic) 432 #define nlib_utf32nlen_generic NLIB_CAPI(nlib_utf32nlen_generic) 433 #define nlib_utf16cplen_ex_generic NLIB_CAPI(nlib_utf16cplen_ex_generic) 434 #define nlib_fd_impl NLIB_CAPI(nlib_fd_impl) 436 #define utf16chr_mb_simd NLIB_CAPI(utf16chr_mb_simd) 437 #define nlib_strchr_simd NLIB_CAPI(nlib_strchr_simd) 438 #define nlib_strrchr_simd NLIB_CAPI(nlib_strrchr_simd) 439 #define nlib_memchr_simd NLIB_CAPI(nlib_memchr_simd) 440 #define nlib_memrchr_simd NLIB_CAPI(nlib_memrchr_simd) 441 #define nlib_memchr_not_simd NLIB_CAPI(nlib_memchr_not_simd) 442 #define nlib_memchr_range_not_simd NLIB_CAPI(nlib_memchr_range_not_simd) 443 #define nlib_memchr_lt_simd NLIB_CAPI(nlib_memchr_lt_simd) 444 #define nlib_memchr_gt_simd NLIB_CAPI(nlib_memchr_gt_simd) 445 #define nlib_memchr_mb_simd NLIB_CAPI(nlib_memchr_mb_simd) 446 #define nlib_skipws_simd NLIB_CAPI(nlib_skipws_simd) 447 #define nlib_strlen_simd NLIB_CAPI(nlib_strlen_simd) 448 #define nlib_strnlen_simd NLIB_CAPI(nlib_strnlen_simd) 449 #define nlib_utf16len_simd NLIB_CAPI(nlib_utf16len_simd) 450 #define nlib_utf16nlen_simd NLIB_CAPI(nlib_utf16nlen_simd) 451 #define nlib_utf16cplen_ex_simd NLIB_CAPI(nlib_utf16cplen_ex_simd) 452 #define nlib_memcmp_simd NLIB_CAPI(nlib_memcmp_simd) 453 #define nlib_swapendian_16_simd NLIB_CAPI(nlib_swapendian_16_simd) 454 #define nlib_swapendian_32_simd NLIB_CAPI(nlib_swapendian_32_simd) 455 #define nlib_swapendian_64_simd NLIB_CAPI(nlib_swapendian_64_simd) 458 #define nlib_mount_host_nx NLIB_CAPI(nlib_mount_host_nx) 463 #define NLIB_STRINGIFY_(s) #s 464 #define NLIB_STRINGIFY(s) NLIB_STRINGIFY_(s) 466 #if defined(_MSC_VER) 467 # include "nn/nlib/Platform_win32.h" 468 #elif defined(__linux__) || \ 469 defined(__FreeBSD__) || \ 470 defined(__CYGWIN__) || \ 471 (defined(__APPLE__) && defined(__MACH__)) 475 # include "nn/nlib/Platform_unix.h" 476 #elif defined(NN_PLATFORM_CTR) 477 # include "nn/nlib/Platform_ctr.h" 479 # include "nn/nlib/Platform_cafe.h" 480 #elif defined(__NX__) 481 # include "nn/nlib/Platform_nx.h" 484 #if defined(_MSC_VER) && defined(n_EXPORTS) 485 #undef NLIB_VIS_PUBLIC 486 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT 489 #ifndef __analysis_assume 490 # define __analysis_assume(expr) 493 #ifndef _Printf_format_string_ 494 # define _Printf_format_string_ 497 #if defined(__ARM_NEON__) || defined(__aarch64__) 518 #if defined(NLIB_SSE41) || defined(NLIB_NEON) 521 # include <arm_neon.h> 524 # include <smmintrin.h> 527 # include <nmmintrin.h> 531 #if defined(__ARM_ACLE) 532 #include <arm_acle.h> 539 # define RSIZE_MAX 0x7FFFFFFFL 541 # define RSIZE_MAX 0x7FFFFFFFFFFFFFFFLL 546 # define NLIB_WARN(exp) ("WARNING: " exp) 556 #ifndef __PRIS_PREFIX 557 # define __PRIS_PREFIX "z" 561 # define PRIdS __PRIS_PREFIX "d" 565 # define PRIxS __PRIS_PREFIX "x" 569 # define PRIuS __PRIS_PREFIX "u" 573 # define PRIXS __PRIS_PREFIX "X" 577 # define PRIoS __PRIS_PREFIX "o" 581 # define NLIB_ASSUME(cond) switch (0) case 0: default: if (cond) ; else __builtin_unreachable() 584 #ifdef NLIB_NONNULL_ENABLED 585 # define NLIB_EINVAL_IFNULL(p) 587 # define NLIB_EINVAL_IFNULL(p) if (!p) return EINVAL 590 #ifndef NLIB_C_INLINE 591 # define NLIB_C_INLINE __inline 602 #ifdef NLIB_HAS_STDHEADER_STDINT 606 #ifdef NLIB_HAS_STDHEADER_INTTYPES 607 # include <inttypes.h> 610 #if defined(__LP64__) && __LP64__ == 1 620 #ifndef NLIB_VIS_PUBLIC_ALT 621 #define NLIB_VIS_PUBLIC_ALT NLIB_VIS_PUBLIC 624 #ifndef NLIB_EXPIMP_TEMPLATE 625 # define NLIB_EXPIMP_TEMPLATE(x) NLIB_STATIC_ASSERT(sizeof(char) == 1) 655 #if defined(__INTELLISENSE__) 656 #define NLIB_ATOMIC_RELAXED (0) 657 #define NLIB_ATOMIC_ACQUIRE (1) 658 #define NLIB_ATOMIC_RELEASE (2) 659 #define NLIB_ATOMIC_ACQ_REL (3) 660 #define NLIB_ATOMIC_SEQ_CST (7) 666 int32_t val,
int memorder);
672 int success_memorder,
673 int failure_memorder);
701 int64_t desired,
int weak,
702 int success_memorder,
int failure_memorder);
728 int weak,
int success_memorder,
int failure_memorder);
736 #ifndef NLIB_TIMESPEC_HAS_NATIVE 755 #define NLIB_TO_TIMESPEC(tm, t) \ 756 (tm)->tv_sec = (time_t)((t) / (1000 * 10000)); \ 757 (tm)->tv_nsec = ((long)((t) % (1000 * 10000)) * 100) // NOLINT 759 #define NLIB_FROM_TIMESPEC(tm, t) \ 760 t = (int64_t)((tm)->tv_sec) * (1000 * 10000) + ((tm)->tv_nsec / 100) 766 NLIB_TO_TIMESPEC(tm, t);
774 NLIB_TO_TIMESPEC(tm, d);
780 NLIB_FROM_TIMESPEC(tm, d);
802 #define NLIB_PHYSICAL_ALLOC_PROT_NONE 0 803 #define NLIB_PHYSICAL_ALLOC_PROT_READ 1 804 #define NLIB_PHYSICAL_ALLOC_PROT_WRITE 2 805 #define NLIB_PHYSICAL_ALLOC_PROT_EXEC 4 812 #ifdef NLIB_PTHREAD_nlib_tls_alloc 831 #ifdef NLIB_PTHREAD_nlib_tls_alloc 833 return pthread_key_create(tls, destr);
836 #ifdef NLIB_PTHREAD_nlib_tls_free 838 return pthread_key_delete(tls);
843 #ifdef NLIB_PTHREAD_nlib_tls_setvalue 849 #ifdef NLIB_PTHREAD_nlib_tls_setvalue 851 return pthread_setspecific(tls, value);
855 #ifdef NLIB_PTHREAD_nlib_tls_getvalue 862 #ifdef NLIB_PTHREAD_nlib_tls_getvalue 864 *value = pthread_getspecific(tls);
873 #ifdef NLIB_PTHREAD_nlib_mutex_init 881 #ifdef NLIB_PTHREAD_nlib_mutex_init 883 return pthread_mutex_init(mutex, NULL);
889 NLIB_NONNULL NLIB_EXCLUDES(*mutex);
892 NLIB_NONNULL NLIB_EXCLUDES(*mutex);
894 #ifdef NLIB_PTHREAD_nlib_mutex_lock 907 #ifdef NLIB_PTHREAD_nlib_mutex_lock 909 return pthread_mutex_lock(mutex);
914 #ifdef NLIB_PTHREAD_nlib_mutex_trylock 921 #ifdef NLIB_PTHREAD_nlib_mutex_trylock 923 return pthread_mutex_trylock(mutex);
929 nlib_duration delta) NLIB_NONNULL NLIB_TRY_ACQUIRE(0, *mutex);
930 #ifdef NLIB_PTHREAD_nlib_mutex_unlock 936 #ifdef NLIB_PTHREAD_nlib_mutex_unlock 938 return pthread_mutex_unlock(mutex);
942 #ifdef NLIB_PTHREAD_nlib_mutex_destroy 949 #ifdef NLIB_PTHREAD_nlib_mutex_destroy 951 return pthread_mutex_destroy(mutex);
956 const struct timespec* tm)
957 NLIB_TRY_ACQUIRE(0, *mutex) {
959 NLIB_FROM_TIMESPEC(tm, delta);
982 nlib_duration duration;
983 NLIB_FROM_TIMESPEC(tm, duration);
991 #ifdef NLIB_PTHREAD_nlib_cond_init 999 #ifdef NLIB_PTHREAD_nlib_cond_init 1001 return pthread_cond_init(cond, NULL);
1005 #ifdef NLIB_PTHREAD_nlib_cond_signal 1011 #ifdef NLIB_PTHREAD_nlib_cond_signal 1013 return pthread_cond_signal(cond);
1017 #ifdef NLIB_PTHREAD_nlib_cond_broadcast 1023 #ifdef NLIB_PTHREAD_nlib_cond_broadcast 1025 return pthread_cond_broadcast(cond);
1029 #ifdef NLIB_PTHREAD_nlib_cond_wait 1056 NLIB_NONNULL NLIB_REQUIRES(*mutex);
1057 #ifdef NLIB_PTHREAD_nlib_cond_wait 1058 static NLIB_C_INLINE
1060 return pthread_cond_wait(cond, mutex);
1068 nlib_duration duration) NLIB_NONNULL NLIB_REQUIRES(*mutex);
1073 nlib_time abstime) NLIB_NONNULL NLIB_REQUIRES(*mutex);
1075 #ifdef NLIB_PTHREAD_nlib_cond_destroy 1081 #ifdef NLIB_PTHREAD_nlib_cond_destroy 1083 return pthread_cond_destroy(cond);
1087 static NLIB_C_INLINE
1089 NLIB_REQUIRES(*mutex) {
1091 NLIB_FROM_TIMESPEC(tm, d);
1095 static NLIB_C_INLINE
1097 const struct timespec* tm) NLIB_REQUIRES(*mutex) {
1099 NLIB_FROM_TIMESPEC(tm, d);
1106 #ifndef NLIB_RWLOCK_HAS_NATIVE 1107 struct nlib_rwlock_ {
1112 NLIB_CAPABILITY(
"mutex")
1115 #define NLIB_RWLOCK_INITIALIZER { \ 1117 { NLIB_RECURSIVE_TIMED_MUTEX_INITIALIZER, NLIB_RECURSIVE_TIMED_MUTEX_INITIALIZER }, \ 1118 NLIB_COND_INITIALIZER } 1121 #ifdef NLIB_PTHREAD_nlib_rwlock_init 1128 #ifdef NLIB_PTHREAD_nlib_rwlock_init 1130 return pthread_rwlock_init(rwlock, NULL);
1134 #ifdef NLIB_PTHREAD_nlib_rwlock_destroy 1140 #ifdef NLIB_PTHREAD_nlib_rwlock_destroy 1142 return pthread_rwlock_destroy(rwlock);
1146 #ifdef NLIB_PTHREAD_nlib_rwlock_rdlock 1152 #ifdef NLIB_PTHREAD_nlib_rwlock_rdlock 1154 NLIB_NO_THREAD_SAFETY_ANALYSIS {
1155 return pthread_rwlock_rdlock(rwlock);
1159 #ifdef NLIB_PTHREAD_nlib_rwlock_tryrdlock 1165 NLIB_NONNULL NLIB_TRY_ACQUIRE_SHARED(0, *rwlock);
1166 #ifdef NLIB_PTHREAD_nlib_rwlock_tryrdlock 1168 NLIB_NO_THREAD_SAFETY_ANALYSIS {
1169 return pthread_rwlock_tryrdlock(rwlock);
1175 NLIB_NONNULL NLIB_TRY_ACQUIRE_SHARED(0, *rwlock);
1178 NLIB_NONNULL NLIB_TRY_ACQUIRE_SHARED(0, *rwlock);
1180 #ifdef NLIB_PTHREAD_nlib_rwlock_rdunlock 1186 NLIB_NONNULL NLIB_RELEASE_SHARED(*rwlock);
1187 #ifdef NLIB_PTHREAD_nlib_rwlock_rdunlock 1189 NLIB_NO_THREAD_SAFETY_ANALYSIS {
1190 return pthread_rwlock_unlock(rwlock);
1194 #ifdef NLIB_PTHREAD_nlib_rwlock_wrlock 1200 #ifdef NLIB_PTHREAD_nlib_rwlock_wrlock 1202 NLIB_NO_THREAD_SAFETY_ANALYSIS {
1203 return pthread_rwlock_wrlock(rwlock);
1207 #ifdef NLIB_PTHREAD_nlib_rwlock_trywrlock 1213 #ifdef NLIB_PTHREAD_nlib_rwlock_trywrlock 1215 NLIB_NO_THREAD_SAFETY_ANALYSIS {
1216 return pthread_rwlock_trywrlock(rwlock);
1222 NLIB_NONNULL NLIB_TRY_ACQUIRE(0, *rwlock);
1225 NLIB_NONNULL NLIB_TRY_ACQUIRE(0, *rwlock);
1227 #ifdef NLIB_PTHREAD_nlib_rwlock_wrunlock 1233 #ifdef NLIB_PTHREAD_nlib_rwlock_wrunlock 1235 NLIB_NO_THREAD_SAFETY_ANALYSIS {
1236 return pthread_rwlock_unlock(rwlock);
1240 static NLIB_C_INLINE
1242 NLIB_TRY_ACQUIRE_SHARED(0, *rwlock) {
1244 NLIB_FROM_TIMESPEC(tm, d);
1248 static NLIB_C_INLINE
1250 NLIB_TRY_ACQUIRE_SHARED(0, *rwlock) {
1252 NLIB_FROM_TIMESPEC(tm, d);
1256 static NLIB_C_INLINE
1258 NLIB_TRY_ACQUIRE(0, *rwlock) {
1260 NLIB_FROM_TIMESPEC(tm, d);
1264 static NLIB_C_INLINE
1266 NLIB_TRY_ACQUIRE(0, *rwlock) {
1268 NLIB_FROM_TIMESPEC(tm, d);
1273 #if defined(_MSC_VER) && defined(NLIB_RWLOCK_HAS_NATIVE) 1274 typedef struct nlib_condrwlock_ {
1275 CONDITION_VARIABLE cond;
1277 #define NLIB_CONDRWLOCK_INITIALIZER { CONDITION_VARIABLE_INIT } 1279 typedef struct nlib_condrwlock_ {
1283 #define NLIB_CONDRWLOCK_INITIALIZER { NLIB_COND_INITIALIZER, NLIB_MUTEX_INITIALIZER } 1291 nlib_rwlock* __restrict rwlock,
1294 nlib_rwlock* __restrict rwlock,
1295 nlib_duration duration,
1298 nlib_rwlock* __restrict rwlock,
1303 nlib_rwlock* rwlock,
1304 const struct timespec* tm,
1307 NLIB_FROM_TIMESPEC(tm, d);
1312 nlib_rwlock* rwlock,
1313 const struct timespec* tm,
1316 NLIB_FROM_TIMESPEC(tm, d);
1323 #ifndef NLIB_BARRIER_HAS_NATIVE 1324 struct nlib_barrier_ {
1332 #ifdef NLIB_PTHREAD_nlib_barrier_init 1338 #ifdef NLIB_PTHREAD_nlib_barrier_init 1340 return pthread_barrier_init(barrier, NULL, count);
1344 #ifdef NLIB_PTHREAD_nlib_barrier_destroy 1350 #ifdef NLIB_PTHREAD_nlib_barrier_destroy 1352 return pthread_barrier_destroy(barrier);
1361 struct nlib_onceflag_ {
1365 #define NLIB_ONCE_INIT { 0 } 1384 typedef struct nlib_mq_ {
1390 #define NLIB_MQ_BLOCK 0 1391 #define NLIB_MQ_NONBLOCK 1 1392 #define NLIB_MQ_LOCKFREE 2 1403 typedef struct nlib_mq_attr_ {
1432 #define NLIB_THREAD_INVALID (nlib_thread)(0) // NOLINT 1434 #ifndef NLIB_SPINLOCK_HAS_NATIVE 1438 #ifndef NLIB_THREAD_ATTR_HAS_NATIVE 1439 struct nlib_thread_attr_ {
1450 struct nlib_thread_attr_ {
1451 pthread_attr_t attr;
1468 #ifdef NLIB_PTHREAD_nlib_thread_join 1474 #ifdef NLIB_PTHREAD_nlib_thread_join 1476 return pthread_join(thread, NULL);
1480 #ifdef NLIB_PTHREAD_nlib_thread_detach 1486 #ifdef NLIB_PTHREAD_nlib_thread_detach 1488 return pthread_detach(thread);
1492 #ifdef NLIB_PTHREAD_nlib_thread_self 1498 #ifdef NLIB_PTHREAD_nlib_thread_self 1500 *thread = pthread_self();
1508 #ifdef NLIB_PTHREAD_nlib_thread_equal 1514 #ifdef NLIB_PTHREAD_nlib_thread_equal 1516 return pthread_equal(th1, th2);
1524 #ifdef NLIB_PTHREAD_nlib_thread_getname 1530 #ifdef NLIB_PTHREAD_nlib_thread_getname 1532 return pthread_getname_np(thread, name, len);
1557 void** __restrict stack_addr,
size_t* __restrict stack_size)
1561 #define NLIB_THREAD_ATTR_KEY_DETACHSTATE (1) 1562 #define NLIB_THREAD_ATTR_KEY_STACKSIZE (2) 1563 #define NLIB_THREAD_ATTR_KEY_PRIORITY (4) 1564 #define NLIB_THREAD_ATTR_KEY_AFFINITY (5) 1565 #define NLIB_THREAD_ATTR_KEY_EXPLICIT_SCHED (6) 1573 #ifndef NN_PLATFORM_CTR 1581 #elif defined(pthread_cleanup_push) 1582 # define nlib_thread_cleanup_push(fn, arg) pthread_cleanup_push(fn, arg) 1583 # define nlib_thread_cleanup_pop(exec) pthread_cleanup_pop(exec) 1584 #elif !defined(NN_PLATFORM_CTR) 1585 struct nlib_thread_cleanup_handler_ {
1586 void (*func)(
void*);
1588 struct nlib_thread_cleanup_handler_* next;
1590 #define nlib_thread_cleanup_push(fn, arg) switch (0) case 0: default: { \ 1591 struct nlib_thread_cleanup_handler_ _thread_cleanup_handler = { fn, arg, NULL }; \ 1592 nlib_thread_cleanup_push_(&_thread_cleanup_handler) 1593 #define nlib_thread_cleanup_pop(exec) nlib_thread_cleanup_pop_(exec); } 1595 NLIB_VIS_PUBLIC void nlib_thread_cleanup_push_(
struct nlib_thread_cleanup_handler_* handler);
1617 void*
const* __restrict buf,
size_t count)
NLIB_NONNULL;
1623 NLIB_LOG_UNKNOWN = 0,
1637 typedef enum nlib_log_key {
1638 NLIB_LOG_ATTR_UNKNOWN = 0,
1639 NLIB_LOG_ATTR_STDOUT,
1640 NLIB_LOG_ATTR_STDERR,
1641 NLIB_LOG_ATTR_MSVC_TRACE,
1642 NLIB_LOG_ATTR_SYSLOG,
1643 NLIB_LOG_ATTR_NLIB_FD,
1647 #ifndef NLIB_ATTRIBUTE_PRINTF 1648 # define NLIB_ATTRIBUTE_PRINTF(x, y) __attribute__((format(printf, x, y))) 1652 const char* __restrict fmt, ...)
1661 #ifndef NLIB_FD_O_RDONLY 1665 # define NLIB_FD_O_RDONLY O_RDONLY 1668 #ifndef NLIB_FD_O_WRONLY 1672 # define NLIB_FD_O_WRONLY O_WRONLY 1675 #ifndef NLIB_FD_O_RDWR 1679 # define NLIB_FD_O_RDWR O_RDWR 1682 #ifndef NLIB_FD_O_APPEND 1686 # define NLIB_FD_O_APPEND O_APPEND 1689 #ifndef NLIB_FD_O_CREAT 1693 # define NLIB_FD_O_CREAT O_CREAT 1696 #ifndef NLIB_FD_O_TRUNC 1700 # define NLIB_FD_O_TRUNC O_TRUNC 1703 #ifndef NLIB_FD_O_EXCL 1707 # define NLIB_FD_O_EXCL O_EXCL 1710 #ifndef NLIB_SEEK_SET 1714 # define NLIB_SEEK_SET SEEK_SET 1717 #ifndef NLIB_SEEK_CUR 1721 # define NLIB_SEEK_CUR SEEK_CUR 1729 #define NLIB_FD_INVALID (-1) 1736 errno_t nlib_fd_open(nlib_fd* fd,
const char* native_path,
unsigned int flags, ...) NLIB_NONNULL_1;
1745 errno_t nlib_fd_read(
size_t* __restrict result, nlib_fd fd,
void* __restrict buf,
size_t count)
1770 #if !defined(NLIB_IOVEC_HAS_NATIVE) 1771 struct nlib_fd_iovec_ {
1775 typedef struct nlib_fd_iovec_ nlib_fd_iovec;
1777 typedef struct iovec nlib_fd_iovec;
1780 errno_t nlib_fd_readv(
size_t* __restrict result, nlib_fd fd,
const nlib_fd_iovec* __restrict iov,
1795 unsigned int flags);
1799 errno_t nlib_rename(
const char* __restrict old_path,
const char* __restrict new_path);
1804 typedef struct nlib_dir_ nlib_dir;
1805 typedef struct nlib_dirent_ {
1826 uint64_t* __restrict free_bytes_available,
1827 uint64_t* __restrict total_bytes,
1828 uint64_t* __restrict total_free_bytes);
1836 #if defined(_MSC_VER) || defined(NLIB_UNIX) 1837 #define NLIB_SOCKET_ENABLED 1841 typedef int nlib_sock;
1842 #define NLIB_SOCKET_INVALID (nlib_sock)(-1) // NOLINT 1844 #if defined(_MSC_VER) 1845 #define NLIB_SOCK_NONBLOCK 0x8000 1846 #elif defined(SOCK_NONBLOCK) 1847 #define NLIB_SOCK_NONBLOCK SOCK_NONBLOCK 1849 #define NLIB_SOCK_NONBLOCK O_NONBLOCK 1854 typedef struct sockaddr nlib_sockaddr;
1855 typedef struct sockaddr_in nlib_sockaddr_in;
1856 typedef struct sockaddr_in6 nlib_sockaddr_in6;
1858 struct nlib_msghdr_ {
1860 uint32_t msg_namelen;
1861 nlib_fd_iovec* msg_iov;
1864 size_t msg_controllen;
1867 typedef struct nlib_msghdr_ nlib_msghdr;
1868 #define NLIB_CMSG_FIRSTHDR(msgh) \ 1869 ((msgh)->msg_controllen >= sizeof(WSACMSGHDR) ? \ 1870 (LPWSACMSGHDR)(msgh)->msg_control : (LPWSACMSGHDR)NULL) 1871 #define NLIB_CMSG_NXTHDR(msg, cmsg) \ 1872 ( ((cmsg) == NULL) ? NLIB_CMSG_FIRSTHDR(msg) \ 1873 : ( ( ((PUCHAR)(cmsg) + \ 1874 WSA_CMSGHDR_ALIGN((cmsg)->cmsg_len) + \ 1875 sizeof(WSACMSGHDR) ) > \ 1876 (PUCHAR)((msg)->msg_control) + \ 1877 (msg)->msg_controllen) \ 1878 ? (LPWSACMSGHDR)NULL \ 1879 : (LPWSACMSGHDR)((PUCHAR)(cmsg) + \ 1880 WSA_CMSGHDR_ALIGN((cmsg)->cmsg_len)) ) ) 1881 #define NLIB_CMSG_SPACE(length) WSA_CMSG_SPACE(length) 1882 #define NLIB_CMSG_LEN(length) WSA_CMSG_LEN(length) 1883 #define NLIB_CMSG_DATA(cmsg) WSA_CMSG_DATA(cmsg) 1885 typedef struct msghdr nlib_msghdr;
1886 #define NLIB_CMSG_FIRSTHDR(msgh) CMSG_FIRSTHDR(msgh) 1887 #define NLIB_CMSG_NXTHDR(msgh, cmsg) CMSG_NXTHDR(msgh, cmsg) 1889 #define NLIB_CMSG_SPACE(length) CMSG_SPACE(length) 1890 #define NLIB_CMSG_LEN(length) CMSG_LEN(length) 1891 #define NLIB_CMSG_DATA(cmsg) CMSG_DATA(cmsg) 1893 typedef struct cmsghdr nlib_cmsghdr;
1897 errno_t nlib_accept(nlib_sock* __restrict s, nlib_sock sockfd, nlib_sockaddr* __restrict addr,
1898 uint32_t* __restrict addrlen,
int flags);
1900 errno_t nlib_accept_for(nlib_sock* __restrict s, nlib_sock sockfd, nlib_sockaddr* __restrict addr,
1901 uint32_t* __restrict addrlen,
int flags, nlib_duration timeout);
1903 errno_t nlib_connect(nlib_sock sockfd,
const nlib_sockaddr* addr, uint32_t addrlen);
1905 errno_t nlib_connect_for(nlib_sock sockfd,
const nlib_sockaddr* addr, uint32_t addrlen,
1906 int flags, nlib_duration timeout);
1909 errno_t nlib_sendto(
size_t* __restrict size, nlib_sock sockfd,
const void* __restrict buf,
1910 size_t len,
int flags,
const nlib_sockaddr* __restrict dest_addr,
1913 errno_t nlib_sendmsg(
size_t* __restrict size, nlib_sock sockfd,
const nlib_msghdr* msg,
int flags);
1914 static NLIB_C_INLINE
1915 errno_t nlib_send(
size_t* __restrict size, nlib_sock sockfd,
const void* __restrict buf,
1916 size_t len,
int flags) {
1917 return nlib_sendto(size, sockfd, buf, len, flags, NULL, 0);
1921 errno_t nlib_recvfrom(
size_t* __restrict size, nlib_sock sockfd,
1922 void* __restrict buf,
size_t len,
int flags,
1923 nlib_sockaddr* __restrict dest_addr,
1924 uint32_t* __restrict addrlen);
1926 errno_t nlib_recvmsg(
size_t* __restrict size, nlib_sock sockfd, nlib_msghdr* msg,
int flags);
1927 static NLIB_C_INLINE
1928 errno_t nlib_recv(
size_t* __restrict size, nlib_sock sockfd,
void* __restrict buf,
size_t len,
1930 return nlib_recvfrom(size, sockfd, buf, len, flags, NULL, NULL);
1936 # define SHUT_RD SD_RECEIVE 1937 # define SHUT_WR SD_SEND 1938 # define SHUT_RDWR SD_BOTH 1943 #ifndef NLIB_LITTLE_ENDIAN 1944 static NLIB_C_INLINE uint32_t nlib_htonl(uint32_t hostlong) {
return hostlong; }
1945 static NLIB_C_INLINE uint16_t nlib_htons(uint16_t hostshort) {
return hostshort; }
1946 static NLIB_C_INLINE uint32_t nlib_ntohl(uint32_t netlong) {
return netlong; }
1947 static NLIB_C_INLINE uint16_t nlib_ntohs(uint16_t netshort) {
return netshort; }
1949 static NLIB_C_INLINE uint32_t nlib_htonl(uint32_t hostlong) {
1951 return _byteswap_ulong(hostlong);
1953 return __builtin_bswap32(hostlong);
1956 static NLIB_C_INLINE uint16_t nlib_htons(uint16_t hostshort) {
1958 return _byteswap_ushort(hostshort);
1960 return ((hostshort & 0xFF) << 8) | ((hostshort >> 8) & 0xFF);
1963 static NLIB_C_INLINE uint32_t nlib_ntohl(uint32_t netlong) {
1965 return _byteswap_ulong(netlong);
1967 return __builtin_bswap32(netlong);
1970 static NLIB_C_INLINE uint16_t nlib_ntohs(uint16_t netshort) {
1972 return _byteswap_ushort(netshort);
1974 return ((netshort & 0xFF) << 8) | ((netshort >> 8) & 0xFF);
1979 typedef struct in_addr nlib_in_addr;
1980 typedef struct in6_addr nlib_in6_addr;
2003 typedef int eai_error_t;
2004 typedef struct addrinfo nlib_addrinfo;
2006 eai_error_t nlib_getaddrinfo(
const char* __restrict node,
const char* __restrict service,
2007 const nlib_addrinfo* __restrict hints,
2008 nlib_addrinfo** __restrict res);
2010 eai_error_t nlib_getnameinfo(
const nlib_sockaddr* __restrict sa, uint32_t salen,
2011 char* __restrict host, uint32_t hostlen,
2012 char* __restrict serv, uint32_t servlen,
int flags);
2016 errno_t nlib_getsockopt(nlib_sock sockfd,
int level,
int optname,
void* __restrict optval,
2017 uint32_t* __restrict optlen);
2019 errno_t nlib_setsockopt(nlib_sock sockfd,
int level,
int optname,
const void* optval,
2022 typedef fd_set nlib_fd_set;
2024 errno_t nlib_select(
size_t* __restrict n,
int nfds, nlib_fd_set* __restrict readfds,
2025 nlib_fd_set* __restrict writefds,
2026 nlib_fd_set* __restrict exceptfds, nlib_duration timeout);
2028 #define NLIB_FD_CLR FD_CLR 2029 #define NLIB_FD_ISSET FD_ISSET 2031 #define NLIB_FD_SET(fd, set) FD_SET((SOCKET)fd, set) 2033 #define NLIB_FD_SET FD_SET 2035 #define NLIB_FD_ZERO FD_ZERO 2037 #if defined(_MSC_VER) 2038 struct nlib_pollfd_ {
2043 typedef struct nlib_pollfd_ nlib_pollfd;
2045 typedef struct pollfd nlib_pollfd;
2048 errno_t nlib_poll(
size_t* __restrict n, nlib_pollfd* __restrict fds, uint32_t nfds,
2049 nlib_duration timeout);
2052 #define NLIB_MSG_DONTWAIT (0x4000) 2054 #define NLIB_MSG_DONTWAIT MSG_DONTWAIT 2059 errno_t nlib_getsockname(nlib_sock sockfd, nlib_sockaddr* __restrict addr,
2060 uint32_t* __restrict addrlen);
2062 errno_t nlib_getpeername(nlib_sock sockfd, nlib_sockaddr* __restrict addr,
2063 uint32_t* __restrict addrlen);
2076 # warning Do not define EDQUOT. nlib may not work correctly. 2093 #ifndef NLIB_SKIP_ERRNO_DEFINE 2095 #define NLIB_E_BASE 2000 2109 # define EACCES 9973 2115 # define EADDRINUSE 9902 2120 #ifndef EADDRNOTAVAIL 2121 # define EADDRNOTAVAIL 9903 2126 #ifndef EAFNOSUPPORT 2127 # define EAFNOSUPPORT 9901 2133 # define EAGAIN 9976 2139 # define EALREADY 9907 2151 # define EBADMSG 9905 2163 # define ECANCELED 9927 2169 # define ECHILD 9963 2174 #ifndef ECONNABORTED 2175 # define ECONNABORTED 9906 2180 #ifndef ECONNREFUSED 2181 # define ECONNREFUSED 9908 2187 # define ECONNRESET 9909 2193 # define EDEADLK 9975 2198 #ifndef EDESTADDRREQ 2199 # define EDESTADDRREQ 9910 2211 # define EDQUOT (NLIB_E_BASE + 19) 2217 # define EEXIST 9955 2223 # define EFAULT 9948 2234 #ifndef EHOSTUNREACH 2235 # define EHOSTUNREACH 9911 2247 # define EILSEQ 9945 2253 # define EINPROGRESS 9928 2265 # define EINVAL 9943 2277 # define EISCONN 9904 2283 # define EISDIR 9962 2295 # define EMFILE 9978 2301 # define EMLINK 9979 2307 # define EMSGSIZE 9913 2313 # define EMULTIHOP (NLIB_E_BASE + 36) 2318 #ifndef ENAMETOOLONG 2319 # define ENAMETOOLONG 9957 2325 # define ENETDOWN 9914 2331 # define ENETRESET 9915 2337 # define ENETUNREACH 9916 2343 # define ENFILE 9977 2349 # define ENOBUFS 9917 2355 # define ENODATA 9919 2361 # define ENODEV 9967 2367 # define ENOENT 9968 2373 # define ENOEXEC 9954 2379 # define ENOLCK 9964 2385 # define ENOLINK 9918 2391 # define ENOMEM 9971 2397 # define ENOMSG 9920 2403 # define ENOPROTOOPT 9921 2409 # define ENOSPC 9965 2421 # define ENOSTR 9924 2427 # define ENOSYS 9942 2433 # define ENOTCONN 9925 2439 # define ENOTDIR 9970 2445 # define ENOTEMPTY 9953 2450 #ifndef ENOTRECOVERABLE 2451 # define ENOTRECOVERABLE 9934 2457 # define ENOTSOCK 9923 2463 # define ENOTSUP 9926 2469 # define ENOTTY 9958 2481 # define EOPNOTSUPP 9929 2487 # define EOVERFLOW 9940 2493 # define EOWNERDEAD 9931 2511 # define EPROTO 9932 2516 #ifndef EPROTONOSUPPORT 2517 # define EPROTONOSUPPORT 9933 2523 # define EPROTOTYPE 9941 2529 # define ERANGE 9944 2541 # define ESPIPE 9960 2553 # define ESTALE (NLIB_E_BASE + 75) 2565 # define ETIMEDOUT 9938 2571 # define ETXTBSY 9936 2577 # define EWOULDBLOCK 9930 2585 #endif // NLIB_SKIP_ERRNO_DEFINE 2590 #ifndef NLIB_SPINLOCK_HAS_NATIVE 2591 #define NLIB_SPINLOCK_INITIALIZER (0) 2593 #ifndef NN_PLATFORM_CTR 2606 #if defined(__arm__) 2607 #if __has_builtin(__builtin_arm_ldrex) 2608 int R5 = __builtin_arm_ldrex(lock);
2610 int R5 = __ldrex(lock);
2613 #if __has_builtin(__builtin_arm_strex) 2614 if (__builtin_arm_strex(1, lock) == 0) {
2616 if (__strex(1, lock) == 0) {
2618 #if !defined(NN_PLATFORM_CTR) 2626 nlib_spinlock_lock_(lock);
2628 int32_t expected = 0;
2631 nlib_spinlock_lock_(lock);
2636 #if defined(__arm__) 2637 #if __has_builtin(__builtin_arm_ldrex) 2638 int R5 = __builtin_arm_ldrex(lock);
2640 int R5 = __ldrex(lock);
2643 #if __has_builtin(__builtin_arm_strex) 2644 if (__builtin_arm_strex(1, lock) == 0) {
2646 if (__strex(1, lock) == 0) {
2648 #if !defined(NN_PLATFORM_CTR) 2658 int32_t expected = 0;
2667 #if defined(NN_PLATFORM_CTR) 2670 int32_t expected = 1;
2674 nlib_spinlock_unlock_(lock);
2676 #if defined(__arm__) 2688 _Printf_format_string_
const char* __restrict fmt, va_list args)
2692 _Printf_format_string_
const char* __restrict fmt, ...)
2696 _Printf_format_string_
const char* __restrict fmt, va_list args)
2700 _Printf_format_string_
const char* __restrict fmt, ...)
2704 int nlib_printf(_Printf_format_string_
const char* fmt, ...)
2709 _Printf_format_string_
const wchar_t* __restrict fmt, va_list args)
2713 _Printf_format_string_
const wchar_t* __restrict fmt, ...)
2717 _Printf_format_string_
const wchar_t* __restrict fmt, va_list args)
2721 _Printf_format_string_
const wchar_t* __restrict fmt, ...)
NLIB_NONNULL_3;
2726 errno_t nlib_vsnprintf_fallback(
size_t* __restrict count,
char* __restrict buf,
size_t size,
2727 _Printf_format_string_
const char* __restrict fmt, va_list args)
2730 errno_t nlib_snprintf_fallback(
size_t* __restrict count,
char* __restrict buf,
2731 size_t size, _Printf_format_string_
const char* __restrict fmt, ...)
2734 errno_t nlib_vsnwprintf_fallback(
size_t* __restrict count,
wchar_t* __restrict buf,
size_t size,
2735 _Printf_format_string_
const wchar_t* __restrict fmt, va_list args)
2738 errno_t nlib_snwprintf_fallback(
size_t* __restrict count,
wchar_t* __restrict buf,
size_t size,
2739 _Printf_format_string_
const wchar_t* __restrict fmt, ...)
2747 static errno_t nlib_memcpy(
void* __restrict s1,
size_t s1max,
const void* __restrict s2,
size_t n)
2752 void*
nlib_memccpy(
void* __restrict dest,
size_t dest_size,
const void* __restrict src,
2755 #ifdef NLIB_LIBC_nlib_memcmp 2761 #ifdef NLIB_LIBC_nlib_memcmp 2762 static NLIB_C_INLINE
int nlib_memcmp(
const void* buf1,
const void* buf2,
size_t n) {
2763 return memcmp(buf1, buf2, n);
2767 NLIB_VIS_PUBLIC_ALT
const void*
nlib_memchr(
const void* s,
int c,
size_t n)
2769 NLIB_VIS_PUBLIC_ALT
const void*
nlib_memrchr(
const void* s,
int c,
size_t n)
2771 NLIB_VIS_PUBLIC_ALT
const void*
nlib_memchr_not(
const void* s,
int c,
size_t n)
2776 NLIB_VIS_PUBLIC_ALT
const void*
nlib_memchr_lt(
const void* s,
int c,
size_t n)
2778 NLIB_VIS_PUBLIC_ALT
const void*
nlib_memchr_gt(
const void* s,
int c,
size_t n)
2781 NLIB_VIS_PUBLIC_ALT
const void*
nlib_memchr_mb(
const void* s,
size_t n)
2784 const char* __restrict
set,
size_t n)
2787 const char* __restrict
set,
size_t n)
2792 const char*
nlib_skipws(
size_t* __restrict cnt_lf,
const char** __restrict last_lf,
2795 #ifdef NLIB_LIBC_nlib_strlen 2801 #ifdef NLIB_LIBC_nlib_strlen 2802 static NLIB_C_INLINE
size_t nlib_strlen(
const char* s) {
return strlen(s); }
2805 #ifdef NLIB_LIBC_nlib_strnlen 2811 #ifdef NLIB_LIBC_nlib_strnlen 2812 static NLIB_C_INLINE
size_t nlib_strnlen(
const char* s,
size_t maxsize) {
2813 #if defined(_MSC_VER) || defined(__STDC_LIB_EXT1__) 2814 return strnlen_s(s, maxsize);
2816 return strnlen(s, maxsize);
2821 #ifdef NLIB_LIBC_nlib_strcpy 2827 #ifdef NLIB_LIBC_nlib_strcpy 2828 static NLIB_C_INLINE
2830 #if defined(_MSC_VER) || defined(__STDC_LIB_EXT1__) 2831 return strcpy_s(s1, s1max, s2);
2838 #ifdef NLIB_LIBC_nlib_strncpy 2843 errno_t nlib_strncpy(
char* __restrict s1,
size_t s1max,
const char* __restrict s2,
size_t n)
2845 #ifdef NLIB_LIBC_nlib_strncpy 2846 static NLIB_C_INLINE
2847 errno_t nlib_strncpy(
char* __restrict s1,
size_t s1max,
const char* __restrict s2,
size_t n) {
2848 #if defined(_MSC_VER) || defined(__STDC_LIB_EXT1__) 2849 return strncpy_s(s1, s1max, s2, n);
2856 #ifdef NLIB_LIBC_nlib_strchr 2862 #ifdef NLIB_LIBC_nlib_strchr 2863 static NLIB_C_INLINE
const char*
nlib_strchr(
const char* s,
int c) {
return strchr(s, c); }
2866 #ifdef NLIB_LIBC_nlib_strrchr 2872 #ifdef NLIB_LIBC_nlib_strrchr 2873 static NLIB_C_INLINE
const char*
nlib_strrchr(
const char* s,
int c) {
return strrchr(s, c); }
2882 return (
const char*)p;
2888 #ifdef NLIB_LIBC_nlib_wcslen 2894 #ifdef NLIB_LIBC_nlib_wcslen 2895 static NLIB_C_INLINE
size_t nlib_wcslen(
const wchar_t* s) {
return wcslen(s); }
2898 #ifdef NLIB_LIBC_nlib_wcsnlen 2904 #ifdef NLIB_LIBC_nlib_wcsnlen 2905 static NLIB_C_INLINE
size_t nlib_wcsnlen(
const wchar_t* s,
size_t maxsize) {
2906 #if defined(_MSC_VER) || defined(__STDC_LIB_EXT1__) 2907 return wcsnlen_s(s, maxsize);
2909 return wcsnlen(s, maxsize);
2914 #ifdef NLIB_LIBC_nlib_wcscpy 2919 errno_t nlib_wcscpy(
wchar_t* __restrict s1,
size_t s1max,
const wchar_t* __restrict s2)
2921 #ifdef NLIB_LIBC_nlib_wcscpy 2922 static NLIB_C_INLINE
2923 errno_t nlib_wcscpy(
wchar_t* __restrict s1,
size_t s1max,
const wchar_t* __restrict s2) {
2924 #if defined(_MSC_VER) || defined(__STDC_LIB_EXT1__) 2925 return wcscpy_s(s1, s1max, s2);
2932 #ifdef NLIB_LIBC_nlib_wcsncpy 2937 errno_t nlib_wcsncpy(
wchar_t* __restrict s1,
size_t s1max,
const wchar_t* __restrict s2,
size_t n)
2939 #ifdef NLIB_LIBC_nlib_wcsncpy 2940 static NLIB_C_INLINE
2941 errno_t nlib_wcsncpy(
wchar_t* __restrict s1,
size_t s1max,
const wchar_t* __restrict s2,
size_t n) {
2942 #if defined(_MSC_VER) || defined(__STDC_LIB_EXT1__) 2943 return wcsncpy_s(s1, s1max, s2, n);
2986 static NLIB_C_INLINE
2991 if (e != 0 && e != ERANGE)
return e;
2992 if (tmp > 127 || tmp < -128) {
2993 *result = tmp < 0 ? -128 : 127;
2996 *result = (int8_t)tmp;
2999 static NLIB_C_INLINE
3004 if (e != 0 && e != ERANGE)
return e;
3005 if (tmp > 32767 || tmp < -32768) {
3006 *result = tmp < 0 ? -32768 : 32767;
3009 *result = (int16_t)tmp;
3012 static NLIB_C_INLINE
3017 if (e != 0 && e != ERANGE)
return e;
3022 *result = (uint8_t)tmp;
3025 static NLIB_C_INLINE
3030 if (e != 0 && e != ERANGE)
return e;
3035 *result = (uint16_t)tmp;
3047 char* __restrict to,
size_t to_size,
3048 const wchar_t* __restrict from,
size_t from_size)
3052 wchar_t* __restrict to,
size_t to_size,
3053 const char* __restrict from,
size_t from_size)
3060 size_t* __restrict supplementary_codepoint_count,
3061 size_t* __restrict len,
3063 #define nlib_strcplen2 nlib_strcplen 3066 size_t* __restrict supplementary_codepoint_count,
3067 size_t* __restrict from_read,
3068 const char* __restrict from,
3089 NLIB_VIS_PUBLIC_ALT
void nlib_free(
void* ptr);
3112 # define NLIB_MEMCPY(a, b, c) memcpy((a), (b), (c)) 3115 #ifndef NLIB_MEMMOVE 3116 # define NLIB_MEMMOVE(a, b, c) memmove((a), (b), (c)) 3120 # define NLIB_MEMSET(a, b, c) memset((a), (b), (c)) 3140 return (
'0' <= ch && ch <=
'9') || (
'A' <= ch && ch <=
'Z') || (
'a' <= ch && ch <=
'z');
3143 return (
'A' <= ch && ch <=
'Z') || (
'a' <= ch && ch <=
'z');
3145 static NLIB_C_INLINE
int nlib_isblank(
int ch) {
return ch ==
' ' || ch ==
'\t'; }
3146 static NLIB_C_INLINE
int nlib_iscntrl(
int ch) {
return (ch >= 0 && ch <= 0x1F) || ch == 0x7F; }
3147 static NLIB_C_INLINE
int nlib_isdigit(
int ch) {
return (
'0' <= ch && ch <=
'9'); }
3148 static NLIB_C_INLINE
int nlib_isgraph(
int ch) {
return ch >= 0x21 && ch <= 0x7E; }
3149 static NLIB_C_INLINE
int nlib_islower(
int ch) {
return (ch >=
'a' && ch <=
'z'); }
3150 static NLIB_C_INLINE
int nlib_isprint(
int ch) {
return ch >= 0x20 && ch <= 0x7E; }
3151 static NLIB_C_INLINE
int nlib_ispunct(
int ch) {
return (ch >= 0x00 && ch <= 0x20) || ch == 0x7F; }
3153 return ((ch) ==
' ' || (ch) ==
'\t' || (ch) ==
'\n');
3155 static NLIB_C_INLINE
int nlib_isupper(
int ch) {
return (ch >=
'A' && ch <=
'Z'); }
3157 return (
unsigned int)(ch -
'0') < 10u ||
3158 (
unsigned int)((ch | 0x20) -
'a') < 6u;
3161 return (ch >=
'A' && ch <=
'Z') ? ch + (
'a' -
'A') : ch;
3164 return (ch >=
'a' && ch <=
'z') ? ch - (
'a' -
'A') : ch;
3169 static NLIB_C_INLINE
3171 #if defined(_MSC_VER) || defined(__STDC_LIB_EXT1__) 3172 return memcpy_s(s1, s1max, s2, n);
3174 #ifndef NLIB_NONNULL_ENABLED 3175 if (!s1 || !s2)
return ERANGE;
3178 NLIB_MEMSET(s1, 0, s1max);
3181 NLIB_MEMCPY(s1, s2, n);
3187 static NLIB_C_INLINE
3189 #if defined(_MSC_VER) || defined(__STDC_LIB_EXT1__) 3190 return memmove_s(s1, s1max, s2, n);
3192 #ifndef NLIB_NONNULL_ENABLED 3193 if (!s1 || !s2)
return ERANGE;
3195 if (s1max < n)
return ERANGE;
3196 NLIB_MEMMOVE(s1, s2, n);
3201 static NLIB_C_INLINE
3203 NLIB_EINVAL_IFNULL(buf);
3204 NLIB_MEMSET(buf, ch, n);
3211 #if defined(NLIB_SSE42) 3213 return _mm_popcnt_u32(x);
3216 return _mm_popcnt_u32(x);
3220 return (
int)_mm_popcnt_u64(x);
3222 uint32_t lo = (uint32_t)(x & 0xFFFFFFFFU);
3223 uint32_t hi = (uint32_t)((x >> 32) & 0xFFFFFFFFU);
3224 return _mm_popcnt_u32(lo) + _mm_popcnt_u32(hi);
3227 #elif defined(NLIB_NEON) 3229 uint8x8_t x0 = vcnt_u8(vreinterpret_u8_u64(vcreate_u64(x)));
3231 return vaddv_u8(x0);
3233 uint8x8_t x1 = vpadd_u8(x0, x0);
3234 return vget_lane_u8(x1, 0);
3238 uint8x8_t x0 = vcnt_u8(vreinterpret_u8_u64(vcreate_u64(x)));
3240 return vaddv_u8(x0);
3242 uint8x8_t x1 = vpadd_u8(x0, x0);
3243 uint8x8_t x2 = vpadd_u8(x1, x1);
3244 return vget_lane_u8(x2, 0);
3248 uint8x8_t x0 = vcnt_u8(vreinterpret_u8_u64(vcreate_u64(x)));
3250 return vaddv_u8(x0);
3252 uint8x8_t x1 = vpadd_u8(x0, x0);
3253 uint8x8_t x2 = vpadd_u8(x1, x1);
3254 uint8x8_t x3 = vpadd_u8(x2, x2);
3255 return vget_lane_u8(x3, 0);
3261 return _nlib_popcnt_array[(x >> 24) & 0xFF] + _nlib_popcnt_array[(x >> 16) & 0xFF] +
3262 _nlib_popcnt_array[(x >> 8) & 0xFF] + _nlib_popcnt_array[(x)& 0xFF];
3265 return _nlib_popcnt_array[(x >> 56) & 0xFF] + _nlib_popcnt_array[(x >> 48) & 0xFF] +
3266 _nlib_popcnt_array[(x >> 40) & 0xFF] + _nlib_popcnt_array[(x >> 32) & 0xFF] +
3267 _nlib_popcnt_array[(x >> 24) & 0xFF] + _nlib_popcnt_array[(x >> 16) & 0xFF] +
3268 _nlib_popcnt_array[(x >> 8) & 0xFF] + _nlib_popcnt_array[(x)& 0xFF];
3271 return _nlib_popcnt_array[(x >> 8) & 0xFF] + _nlib_popcnt_array[(x)& 0xFF];
3274 #define nlib_popcnt(x) nlib_popcnt32(x) 3284 #if defined(_MSC_VER) 3287 return _BitScanReverse(&cnt, x) ? (int)(31 - cnt) : 32;
3292 return _BitScanForward(&cnt, x) ? cnt : 32;
3297 return _BitScanReverse64(&cnt, x) ? (int)(63 - cnt) : 64;
3301 DWORD dw = (DWORD)(x >> 32);
3302 if (_BitScanReverse(&cnt, dw)) {
3303 return (
int)(31 - cnt);
3306 return _BitScanReverse(&cnt, dw) ?
3307 (int)(63 - cnt) : 64;
3314 return _BitScanForward64(&cnt, x) ? cnt : 64;
3317 DWORD dw = (DWORD)(x);
3318 if (_BitScanForward(&cnt, dw)) {
3321 dw = (DWORD)(x >> 32);
3322 return _BitScanForward(&cnt, dw) ?
3323 (int)(32 + cnt) : 64;
3332 unsigned int dw = (
unsigned int)(x >> 32);
3337 dw = (
unsigned int)(x);
3343 #elif defined(NN_PLATFORM_CTR) 3354 #define nlib_clz(x) nlib_clz32(x) 3355 #define nlib_ctz(x) nlib_ctz32(x) 3357 static size_t nlib_strlcpy(
char* __restrict s1,
const char* __restrict s2,
size_t s1max)
3359 static NLIB_C_INLINE
3360 size_t nlib_strlcpy(
char* __restrict s1,
const char* __restrict s2,
size_t s1max) {
3361 #if defined(__FreeBSD__) 3362 return strlcpy(s1, s2, s1max);
3366 NLIB_MEMCPY(s1, s2, len + 1);
3368 NLIB_MEMCPY(s1, s2, s1max - 1);
3369 s1[s1max - 1] =
'\0';
3379 #if __has_builtin(__builtin_bitreverse32) 3380 return __builtin_bitreverse32(x);
3381 #elif __has_builtin(__builtin_arm_rbit) 3382 return __builtin_arm_rbit(x);
3383 #elif defined(__arm__) && !defined(NN_PLATFORM_CTR) 3386 x = ((x & 0x55555555UL) << 1) | ((x >> 1) & 0x55555555UL);
3387 x = ((x & 0x33333333UL) << 2) | ((x >> 2) & 0x33333333UL);
3388 x = ((x & 0x0F0F0F0FUL) << 4) | ((x >> 4) & 0x0F0F0F0FUL);
3390 x = _byteswap_ulong(x);
3391 #elif defined(CAFE) || defined(NN_PLATFORM_CTR) 3392 x = (x << 24) | ((x & 0xFF00) << 8) |
3393 ((x >> 8) & 0xFF00) | (x >> 24);
3395 x = __builtin_bswap32(x);
3402 #if __has_builtin(__builtin_bitreverse64) 3403 return __builtin_bitreverse64(x);
3404 #elif __has_builtin(__builtin_arm_rbit64) 3405 return __builtin_arm_rbit64(x);
3406 #elif __has_builtin(__builtin_arm_rbit) 3407 return __builtin_arm_rbit(x >> 32) |
3408 (((uint64_t)__builtin_arm_rbit(x)) << 32);
3409 #elif defined(__arm__) && !defined(NN_PLATFORM_CTR) 3410 return __rbit(x >> 32) |
3411 (((uint64_t)__rbit(x)) << 32);
3413 x = ((x & 0x5555555555555555ULL) << 1) | ((x >> 1) & 0x5555555555555555ULL);
3414 x = ((x & 0x3333333333333333ULL) << 2) | ((x >> 2) & 0x3333333333333333ULL);
3415 x = ((x & 0x0F0F0F0F0F0F0F0FULL) << 4) | ((x >> 4) & 0x0F0F0F0F0F0F0F0FULL);
3417 x = _byteswap_uint64(x);
3418 #elif defined(CAFE) || defined(NN_PLATFORM_CTR) 3421 ((x & 0xFF00U) << 40) |
3422 ((x & 0xFF0000U) << 24) |
3423 ((x & 0xFF000000U) << 8) |
3424 ((x >> 8) & 0xFF000000U) |
3425 ((x >> 24) & 0xFF0000U) |
3426 ((x >> 40) & 0xFF00U) |
3429 x = __builtin_bswap64(x);
3443 #if defined(_MSC_VER) 3444 #if defined(n_EXPORTS) 3445 #undef NLIB_VIS_PUBLIC 3446 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT 3447 #elif defined(nx_misc_EXPORTS) 3448 # undef NLIB_VIS_PUBLIC 3449 # define NLIB_VIS_PUBLIC NLIB_WINEXPORT 3453 #endif // INCLUDE_NN_NLIB_PLATFORM_H_
メッセージキューの設定や現在の状態を格納する構造体です。