Skip to content

Instantly share code, notes, and snippets.

@Lessica
Created September 7, 2022 07:54
Show Gist options
  • Save Lessica/ecfc5816467dcbaac41c50fd9074b8e9 to your computer and use it in GitHub Desktop.
Save Lessica/ecfc5816467dcbaac41c50fd9074b8e9 to your computer and use it in GitHub Desktop.
iOS Daemon without Jetsam
#import <Foundation/Foundation.h>
#import <dlfcn.h>
#import <sys/proc.h>
// these headers can be found at https://github.com/apple/darwin-xnu
#import "libproc.h"
#import "kern_memorystatus.h"
static __attribute__ ((constructor(101), visibility("hidden")))
void BypassJetsam(void) {
pid_t me = getpid();
int rc; memorystatus_priority_properties_t props = {JETSAM_PRIORITY_CRITICAL, 0};
rc = memorystatus_control(MEMORYSTATUS_CMD_SET_PRIORITY_PROPERTIES, me, 0, &props, sizeof(props));
if (rc < 0) { perror ("memorystatus_control"); exit(rc);}
rc = memorystatus_control(MEMORYSTATUS_CMD_SET_JETSAM_HIGH_WATER_MARK, me, -1, NULL, 0);
if (rc < 0) { perror ("memorystatus_control"); exit(rc);}
rc = memorystatus_control(MEMORYSTATUS_CMD_SET_PROCESS_IS_MANAGED, me, 0, NULL, 0);
if (rc < 0) { perror ("memorystatus_control"); exit(rc);}
rc = memorystatus_control(MEMORYSTATUS_CMD_SET_PROCESS_IS_FREEZABLE, me, 0, NULL, 0);
if (rc < 0) { perror ("memorystatus_control"); exit(rc); }
rc = proc_track_dirty(me, 0);
if (rc != 0) { perror("proc_track_dirty"); exit(rc); }
}
#pragma mark -
int main(int argc, char *argv[])
{
// https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingLaunchdJobs.html
CFRunLoopRun();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment