1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#include "include/platform_shims.h"
#if __has_include(<crt_externs.h>)
#include <crt_externs.h>
#elif defined(_WIN32)
#include <stdlib.h>
#elif __has_include(<unistd.h>)
#include <unistd.h>
extern char **environ;
#endif
#if __wasi__
#include <wasi/libc-environ.h> // for __wasilibc_get_environ
#endif
#if __has_include(<libc_private.h>)
#import <libc_private.h>
void _platform_shims_lock_environ(void) {
environ_lock_np();
}
void _platform_shims_unlock_environ(void) {
environ_unlock_np();
}
#else
void _platform_shims_lock_environ(void) { /* noop */ }
void _platform_shims_unlock_environ(void) { /* noop */ }
#endif
char ** _platform_shims_get_environ(void) {
#if __has_include(<crt_externs.h>)
return *_NSGetEnviron();
#elif defined(_WIN32)
return _environ;
#elif TARGET_OS_WASI
return __wasilibc_get_environ();
#elif __has_include(<unistd.h>)
return environ;
#endif
}
#if __has_include(<libkern/OSThermalNotification.h>)
const char * _platform_shims_kOSThermalNotificationPressureLevelName(void) {
return kOSThermalNotificationPressureLevelName;
}
#endif
#if __has_include(<mach/vm_page_size.h>)
vm_size_t _platform_shims_vm_size(void) {
// This shim exists because vm_page_size is not marked const, and therefore looks like global mutable state to Swift.
return vm_page_size;
}
#endif
#if __has_include(<mach/mach.h>)
mach_port_t _platform_mach_task_self(void) {
// This shim exists because mach_task_self_ is not marked const, and therefore looks like global mutable state to Swift.
return mach_task_self();
}
#endif
|