Created
September 7, 2022 07:54
-
-
Save Lessica/ecfc5816467dcbaac41c50fd9074b8e9 to your computer and use it in GitHub Desktop.
iOS Daemon without Jetsam
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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