Skip to content

Commit 0b64c08

Browse files
committed
Add support for iOS 6.1.x.
1 parent 33fa6e0 commit 0b64c08

File tree

6 files changed

+110
-4
lines changed

6 files changed

+110
-4
lines changed

Compat.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ in the source distribution for its full text.
2424
# define PATH_MAX 4096
2525
#endif
2626

27+
/* iOS 6.1 SDK does not have these constants */
28+
#ifndef AT_FDCWD
29+
# define AT_FDCWD -100
30+
#endif
31+
32+
#ifndef AT_SYMLINK_NOFOLLOW
33+
# define AT_SYMLINK_NOFOLLOW 0x100
34+
#endif
35+
2736

2837
int Compat_faccessat(int dirfd,
2938
const char* pathname,

darwin/DarwinMachine.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,22 @@ Machine* Machine_new(UsersTable* usersTable, uid_t userId) {
105105
openzfs_sysctl_init(&this->zfs);
106106
openzfs_sysctl_updateArcStats(&this->zfs);
107107

108+
#if !TARGET_OS_IPHONE
108109
this->GPUService = IOServiceGetMatchingService(kIOMainPortDefault, IOServiceMatching("IOGPU"));
109110
if (!this->GPUService) {
110111
CRT_debug("Cannot initialize IOGPU service");
111112
}
113+
#endif
112114

113115
return super;
114116
}
115117

116118
void Machine_delete(Machine* super) {
117119
DarwinMachine* this = (DarwinMachine*) super;
118120

121+
#if !TARGET_OS_IPHONE
119122
IOObjectRelease(this->GPUService);
123+
#endif
120124

121125
DarwinMachine_freeCPULoadInfo(&this->prev_load);
122126

darwin/DarwinMachine.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ Released under the GNU GPLv2+, see the COPYING file
77
in the source distribution for its full text.
88
*/
99

10+
#if !TARGET_OS_IPHONE
1011
#include <IOKit/IOKitLib.h>
12+
#endif
1113
#include <mach/mach_host.h>
1214
#include <sys/sysctl.h>
1315

@@ -27,7 +29,9 @@ typedef struct DarwinMachine_ {
2729
processor_cpu_load_info_t prev_load;
2830
processor_cpu_load_info_t curr_load;
2931

32+
#if !TARGET_OS_IPHONE
3033
io_service_t GPUService;
34+
#endif
3135

3236
ZfsArcStats zfs;
3337
} DarwinMachine;

darwin/DarwinProcess.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,63 @@ in the source distribution for its full text.
99

1010
#include "darwin/DarwinProcess.h"
1111

12+
#if !TARGET_OS_IPHONE
1213
#include <libproc.h>
14+
#endif
1315
#include <stdio.h>
1416
#include <stdlib.h>
1517
#include <string.h>
1618
#include <mach/mach.h>
1719
#include <sys/dirent.h>
1820

21+
/* iOS 6.1 SDK doesn't have libproc.h, define stubs */
22+
#if TARGET_OS_IPHONE
23+
#define PROC_PIDVNODEPATHINFO 9
24+
#define PROC_PIDTASKINFO 4
25+
#define PROC_PIDTASKINFO_SIZE sizeof(struct proc_taskinfo)
26+
#define PROC_PIDPATHINFO_MAXSIZE 4096
27+
28+
struct proc_taskinfo {
29+
uint64_t pti_virtual_size;
30+
uint64_t pti_resident_size;
31+
uint64_t pti_total_user;
32+
uint64_t pti_total_system;
33+
uint64_t pti_threads_user;
34+
uint64_t pti_threads_system;
35+
int32_t pti_policy;
36+
int32_t pti_faults;
37+
int32_t pti_pageins;
38+
int32_t pti_cow_faults;
39+
int32_t pti_messages_sent;
40+
int32_t pti_messages_received;
41+
int32_t pti_syscalls_mach;
42+
int32_t pti_syscalls_unix;
43+
int32_t pti_csw;
44+
int32_t pti_threadnum;
45+
int32_t pti_numrunning;
46+
int32_t pti_priority;
47+
};
48+
49+
struct vnode_info_path {
50+
char vip_path[1024];
51+
};
52+
53+
struct proc_vnodepathinfo {
54+
struct vnode_info_path pvi_cdir;
55+
struct vnode_info_path pvi_rdir;
56+
};
57+
58+
static inline int proc_pidpath(int pid, void *buffer, uint32_t buffersize) {
59+
(void)pid; (void)buffer; (void)buffersize;
60+
return -1;
61+
}
62+
63+
static inline int proc_pidinfo(int pid, int flavor, uint64_t arg, void *buffer, int buffersize) {
64+
(void)pid; (void)flavor; (void)arg; (void)buffer; (void)buffersize;
65+
return -1;
66+
}
67+
#endif
68+
1969
#include "CRT.h"
2070
#include "Process.h"
2171
#include "darwin/DarwinMachine.h"

darwin/DarwinProcessTable.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ in the source distribution for its full text.
88
#include "darwin/DarwinProcessTable.h"
99

1010
#include <errno.h>
11+
#if !TARGET_OS_IPHONE
1112
#include <libproc.h>
13+
#endif
1214
#include <stdbool.h>
1315
#include <stdio.h>
1416
#include <stdlib.h>

darwin/Platform.c

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

159170
static double Platform_nanosecondsPerSchedulerTick = -1;
160171

172+
#if !TARGET_OS_IPHONE
161173
static mach_port_t iokit_port; // the mach port used to initiate communication with IOKit
174+
#endif
162175

163176
static 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

395415
void 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

508538
bool 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

710747
void Platform_gettime_monotonic(uint64_t* msec) {

0 commit comments

Comments
 (0)