@@ -15,23 +15,34 @@ in the source distribution for its full text.
1515#include <math.h>
1616#include <stdlib.h>
1717#include <unistd.h>
18- #include <net/if.h>
19- #include <net/if_types.h>
20- #include <net/route.h>
2118#include <sys/socket.h>
19+ #include <sys/sysctl.h>
20+ #include <net/if.h>
2221#include <mach/port.h>
2322
23+ /* iOS 6.1 SDK doesn't have net/if_types.h and net/route.h, define constants manually */
24+ #ifndef IFT_LOOP
25+ #define IFT_LOOP 24 /* Software loopback network */
26+ #endif
27+
28+ #ifndef RTM_IFINFO2
29+ #define RTM_IFINFO2 0x12
30+ #endif
31+
2432#include <CoreFoundation/CFBase.h>
2533#include <CoreFoundation/CFDictionary.h>
2634#include <CoreFoundation/CFNumber.h>
2735#include <CoreFoundation/CFString.h>
2836#include <CoreFoundation/CoreFoundation.h>
2937
38+ /* IOKit is not available on iOS */
39+ #if !TARGET_OS_IPHONE
3040#include <IOKit/IOKitLib.h>
3141#include <IOKit/IOTypes.h>
3242#include <IOKit/ps/IOPowerSources.h>
3343#include <IOKit/ps/IOPSKeys.h>
3444#include <IOKit/storage/IOBlockStorageDriver.h>
45+ #endif
3546
3647#include "ClockMeter.h"
3748#include "CPUMeter.h"
@@ -158,7 +169,9 @@ static uint64_t Platform_nanosecondsPerMachTickDenom = 1;
158169
159170static double Platform_nanosecondsPerSchedulerTick = -1 ;
160171
172+ #if !TARGET_OS_IPHONE
161173static mach_port_t iokit_port ; // the mach port used to initiate communication with IOKit
174+ #endif
162175
163176static void Platform_calculateNanosecondsPerMachTick (uint64_t * numer , uint64_t * denom ) {
164177 // Check if we can determine the timebase used on this system.
@@ -351,6 +364,12 @@ void Platform_setGPUValues(Meter* mtr, double* totalUsage, unsigned long long* t
351364 mtr -> curItems = 1 ;
352365 mtr -> values [0 ] = NAN ;
353366
367+ #if TARGET_OS_IPHONE
368+ /* IOKit not available on iOS */
369+ (void )host ;
370+ (void )dhost ;
371+ return ;
372+ #else
354373 if (!dhost -> GPUService )
355374 return ;
356375
@@ -390,6 +409,7 @@ void Platform_setGPUValues(Meter* mtr, double* totalUsage, unsigned long long* t
390409 CFRelease (properties );
391410
392411 mtr -> values [0 ] = * totalUsage ;
412+ #endif
393413}
394414
395415void Platform_setMemoryValues (Meter * mtr ) {
@@ -403,16 +423,26 @@ void Platform_setMemoryValues(Meter* mtr) {
403423
404424 mtr -> total = dhost -> host_info .max_mem / 1024 ;
405425#ifdef HAVE_STRUCT_VM_STATISTICS64
426+ #if !TARGET_OS_IPHONE /* iOS 6.1 SDK doesn't have compressor_page_count and external_page_count */
406427 natural_t used = vm -> active_count + vm -> inactive_count +
407428 vm -> speculative_count + vm -> wire_count +
408429 vm -> compressor_page_count - vm -> purgeable_count - vm -> external_page_count ;
409430 mtr -> values [MEMORY_METER_USED ] = (double )(used - vm -> compressor_page_count ) * page_K ;
431+ #else
432+ natural_t used = vm -> active_count + vm -> inactive_count +
433+ vm -> speculative_count + vm -> wire_count - vm -> purgeable_count ;
434+ mtr -> values [MEMORY_METER_USED ] = (double )used * page_K ;
435+ #endif
410436#else
411437 mtr -> values [MEMORY_METER_USED ] = (double )(vm -> active_count + vm -> wire_count ) * page_K ;
412438#endif
413439 // mtr->values[MEMORY_METER_SHARED] = "shared memory, like tmpfs and shm"
414440#ifdef HAVE_STRUCT_VM_STATISTICS64
441+ #if !TARGET_OS_IPHONE
415442 mtr -> values [MEMORY_METER_COMPRESSED ] = (double )vm -> compressor_page_count * page_K ;
443+ #else
444+ // mtr->values[MEMORY_METER_COMPRESSED] = "compressed memory not available on iOS 6.1"
445+ #endif
416446#else
417447 // mtr->values[MEMORY_METER_COMPRESSED] = "compressed memory, like zswap on linux"
418448#endif
@@ -506,7 +536,11 @@ void Platform_getFileDescriptors(double* used, double* max) {
506536}
507537
508538bool Platform_getDiskIO (DiskIOData * data ) {
509-
539+ #if TARGET_OS_IPHONE
540+ /* IOKit not available on iOS */
541+ (void )data ;
542+ return false;
543+ #else
510544 io_iterator_t drive_list ;
511545
512546 /* Get the list of all drives */
@@ -589,6 +623,7 @@ bool Platform_getDiskIO(DiskIOData* data) {
589623 IOObjectRelease (drive_list );
590624
591625 return true;
626+ #endif
592627}
593628
594629/* Caution: Given that interfaces are dynamic, and it is not possible to get statistics on interfaces that no longer exist,
@@ -656,6 +691,7 @@ void Platform_getBattery(double* percent, ACPresence* isOnAC) {
656691 * percent = NAN ;
657692 * isOnAC = AC_ERROR ;
658693
694+ #if !TARGET_OS_IPHONE
659695 CFArrayRef list = NULL ;
660696
661697 CFTypeRef power_sources = IOPSCopyPowerSourcesInfo ();
@@ -705,6 +741,7 @@ void Platform_getBattery(double* percent, ACPresence* isOnAC) {
705741
706742 if (power_sources )
707743 CFRelease (power_sources );
744+ #endif
708745}
709746
710747void Platform_gettime_monotonic (uint64_t * msec ) {
0 commit comments