Fix system memory size of tvOS

use sysctlbyname("hw.memsize") to get sytem memory size instead of host_info,
host_info is not available on tvOS, so we change to sysctlbyname which support all apple platforms

apple document didn't stat this API is available on tvOS though,
https://developer.apple.com/documentation/kernel/1387446-sysctlbyname
This commit is contained in:
karelrooted 2023-12-16 14:33:44 +08:00
parent 2cccfd516e
commit d483d620b6

View File

@ -23,6 +23,7 @@
#include <mach/mach_time.h> #include <mach/mach_time.h>
#include <mach/task.h> #include <mach/task.h>
#include <os/proc.h> #include <os/proc.h>
#include <sys/sysctl.h>
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
@ -100,17 +101,12 @@ double mvkGetEnvVarNumber(const char* varName, double defaultValue) {
#pragma mark System memory #pragma mark System memory
uint64_t mvkGetSystemMemorySize() { uint64_t mvkGetSystemMemorySize() {
#if MVK_MACOS_OR_IOS_OR_VISIONOS uint64_t host_memsize = 0;
mach_msg_type_number_t host_size = HOST_BASIC_INFO_COUNT; size_t size = sizeof(host_memsize);
host_basic_info_data_t info; if (sysctlbyname("hw.memsize", &host_memsize, &size, NULL, 0) == KERN_SUCCESS) {
if (host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&info, &host_size) == KERN_SUCCESS) { return host_memsize;
return info.max_mem;
} }
return 0; return 0;
#endif
#if MVK_TVOS
return 0;
#endif
} }
uint64_t mvkGetAvailableMemorySize() { uint64_t mvkGetAvailableMemorySize() {