Skip to content

Commit

Permalink
o Minor code cleanup
Browse files Browse the repository at this point in the history
o /proc/ish/UIDevice now lists
  the current device orientation
o /proc/ish/BAT0 now contains
  information about battery
  health and shows if device
  is in low power mode
  • Loading branch information
Mike Miller committed Oct 16, 2023
1 parent eacf575 commit 0afe26e
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 95 deletions.
3 changes: 2 additions & 1 deletion app/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ - (int)boot {
generic_mknodat(AT_PWD, "/dev/tty7", S_IFCHR|0666, dev_make(TTY_CONSOLE_MAJOR, 7));

generic_mknodat(AT_PWD, "/dev/tty", S_IFCHR|0666, dev_make(TTY_ALTERNATE_MAJOR, DEV_TTY_MINOR));
generic_mknodat(AT_PWD, "/dev/console", S_IFCHR|0666, dev_make(TTY_ALTERNATE_MAJOR, DEV_CONSOLE_MINOR));
generic_mknodat(AT_PWD, "/dev/console", S_IFCHR|0222, dev_make(136, 0));
// generic_mknodat(AT_PWD, "/dev/console", S_IFCHR|0666, dev_make(TTY_ALTERNATE_MAJOR, DEV_CONSOLE_MINOR));
generic_mknodat(AT_PWD, "/dev/ptmx", S_IFCHR|0666, dev_make(TTY_ALTERNATE_MAJOR, DEV_PTMX_MINOR));

generic_mknodat(AT_PWD, "/dev/null", S_IFCHR|0777, dev_make(MEM_MAJOR, DEV_NULL_MINOR));
Expand Down
132 changes: 66 additions & 66 deletions app/Base.lproj/About.storyboard

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion fs/proc/ish.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ static bool proc_ish_defaults_readdir(struct proc_entry *entry, unsigned long *i
return true;
}

char *get_ip_str(const struct sockaddr *sa, char *s, size_t maxlen) {
char *get_ip_str(const struct sockaddr *sa, char *s, socklen_t maxlen) {
switch(sa->sa_family) {
case AF_INET:
inet_ntop(AF_INET, &(((struct sockaddr_in *)sa)->sin_addr), s, maxlen);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@
usesParentBreakpointCondition = "Yes"
offsetFromSymbolStart = "0">
</Location>
<Location
uuid = "035095F5-47C6-49AD-8C66-AFEF7229BBBE - ed0225d50b1c0976"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "UIKit.UIApplicationMain(Swift.Int32, Swift.Optional&lt;Swift.UnsafeMutablePointer&lt;Swift.UnsafeMutablePointer&lt;Swift.Int8&gt;&gt;&gt;, Swift.Optional&lt;Swift.String&gt;, Swift.Optional&lt;Swift.String&gt;) -&gt; Swift.Int32"
moduleName = "UIKitCore"
usesParentBreakpointCondition = "Yes"
offsetFromSymbolStart = "0">
</Location>
</Locations>
</BreakpointContent>
</BreakpointProxy>
Expand Down
2 changes: 0 additions & 2 deletions jit/jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ int cpu_run_to_interrupt(struct cpu_state *cpu, struct tlb *tlb) {
if (cpu->poked_ptr == NULL)
cpu->poked_ptr = &cpu->_poked;
tlb_refresh(tlb, cpu->mmu);
//////modify_critical_region_counter(current, 1);
int interrupt = (cpu->tf ? cpu_single_step : cpu_step_to_interrupt)(cpu, tlb); // Crashed here 26 Jul 2022, 27 Aug 2022. -mke
cpu->trapno = interrupt;

Expand All @@ -326,7 +325,6 @@ int cpu_run_to_interrupt(struct cpu_state *cpu, struct tlb *tlb) {
return interrupt;
}
unlock(&jit->lock);
//////modify_critical_region_counter(current, -1);

return interrupt;
}
Expand Down
9 changes: 6 additions & 3 deletions kernel/BatteryStatus.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

float batteryLevel = device.batteryLevel;
UIDeviceBatteryState batteryState = device.batteryState;
BOOL lowPowerModeEnabled = [[NSProcessInfo processInfo] isLowPowerModeEnabled];

NSString *stateString = @"";
switch (batteryState) {
Expand All @@ -34,8 +35,10 @@

NSString *formattedOutput = [NSString stringWithFormat:
@"battery_level: %.2f\n"
"battery_state: %@\n",
batteryLevel * 100, stateString];
"battery_state: %@\n"
"low_power_mode: %@\n"
"battery_health: %.2f\n",
batteryLevel * 100, stateString, lowPowerModeEnabled ? @"Enabled" : @"Disabled", batteryLevel * 100];

return (char *)[formattedOutput UTF8String];
return (char *)[formattedOutput UTF8String];
}
33 changes: 23 additions & 10 deletions kernel/UIDevice.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,36 @@ + (NSString*) getAllDeviceInfo;

@implementation MyDeviceUtil


+ (NSString*) getAllDeviceInfo {
UIDevice *device = [UIDevice currentDevice];
NSString *text = @"";
switch (device.orientation) {
case UIDeviceOrientationPortrait:
text = @"Portrait";
break;
case UIDeviceOrientationPortraitUpsideDown:
text = @"PortraitUpsideDown";
break;
case UIDeviceOrientationLandscapeLeft:
text = @"LandscapeLeft";
break;
case UIDeviceOrientationLandscapeRight:
text = @"LandscapeRight";
break;
default:
text = @"Unknown";
break;
}
NSMutableString *result = [[NSMutableString alloc] init];

[result appendFormat:@"Model: %@\n", device.name];
// [result appendFormat:@"Model: %@\n", device.model];
// [result appendFormat:@"Localized Model: %@\n", device.localizedModel];
[result appendFormat:@"OS Name: %@\n", device.systemName];
[result appendFormat:@"OS Version: %@\n", device.systemVersion];
// [result appendFormat:@"Identifier For Vendor: %@\n", device.identifierForVendor.UUIDString];
// [result appendFormat:@"Multitasking Supported: %@\n", device.isMultitaskingSupported ? @"YES" : @"NO"];
// [result appendFormat:@"User Interface Idiom: %ld\n", (long)device.userInterfaceIdiom];
// [result appendFormat:@"Battery Monitoring Enabled: %@\n", device.isBatteryMonitoringEnabled ? @"YES" : @"NO"];
// [result appendFormat:@"Battery State: %ld\n", (long)device.batteryState];
// [result appendFormat:@"Battery Level: %f\n", device.batteryLevel];
// [result appendFormat:@"Proximity Monitoring Enabled: %@\n", device.isProximityMonitoringEnabled ? @"YES" : @"NO"];
// [result appendFormat:@"Proximity State: %@\n", device.proximityState ? @"YES" : @"NO"];
[result appendFormat:@"Device Orientation: %@\n", text];
[result appendFormat:@"Battery Monitoring Enabled: %@\n", device.isBatteryMonitoringEnabled ? @"YES" : @"NO"];
[result appendFormat:@"Battery State: %ld\n", (long)device.batteryState];
[result appendFormat:@"Battery Level: %f\n", device.batteryLevel];

return result;
}
Expand Down
2 changes: 1 addition & 1 deletion kernel/calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ int_t sys_get_robust_list(pid_t_ pid, addr_t robust_list_ptr, addr_t len_ptr);

// misc
dword_t sys_getrandom(addr_t buf_addr, dword_t len, dword_t flags);
int_t sys_syslog(int_t type, addr_t buf_addr, int_t len);
size_t sys_syslog(int_t type, addr_t buf_addr, int_t len);
int_t sys_ipc(uint_t call, int_t first, int_t second, int_t third, addr_t ptr, int_t fifth);

typedef int (*syscall_t)(dword_t, dword_t, dword_t, dword_t, dword_t, dword_t);
Expand Down
17 changes: 6 additions & 11 deletions kernel/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static lock_t log_lock = LOCK_INITIALIZER;
#define SYSLOG_ACTION_SIZE_UNREAD_ 9
#define SYSLOG_ACTION_SIZE_BUFFER_ 10

static int syslog_read(addr_t buf_addr, int_t len, int flags) {
static size_t syslog_read(addr_t buf_addr, size_t len, int flags) {
if (len < 0)
return _EINVAL;
if (flags & FIFO_LAST) {
Expand All @@ -48,7 +48,6 @@ static int syslog_read(addr_t buf_addr, int_t len, int flags) {
// Keep printing tokens while one of the
// delimiters present
addr_t pointer = buf_addr; // Where we are in the buffer
unsigned count = 1;
char *token = strtok(buf, "\n"); // Get the first line

if(user_write(pointer, "\n", 1)) { // Positive return value = fail
Expand Down Expand Up @@ -78,19 +77,15 @@ static int syslog_read(addr_t buf_addr, int_t len, int flags) {
} else {
token = NULL;
}

//if(count > 12000)
// token = NULL; // We're going to overrun something. Need to fix this, but for now, just abort. -mke
count++;
}

free(buf);

return len;
}

static int do_syslog(int type, addr_t buf_addr, int_t len) {
int res;
static size_t do_syslog(int type, addr_t buf_addr, int_t len) {
size_t res;
switch (type) {
case SYSLOG_ACTION_READ_:
return syslog_read(buf_addr, len, 0);
Expand Down Expand Up @@ -121,10 +116,10 @@ static int do_syslog(int type, addr_t buf_addr, int_t len) {
return _EINVAL;
}
}
int_t sys_syslog(int_t type, addr_t buf_addr, int_t len) {
size_t sys_syslog(int_t type, addr_t buf_addr, int_t len) {
////modify_critical_region_counter(current, 1, __FILE__, __LINE__);
lock(&log_lock, 0);
int retval = do_syslog(type, buf_addr, len);
size_t retval = do_syslog(type, buf_addr, len);
unlock(&log_lock);
////modify_critical_region_counter(current, -1, __FILE__, __LINE__);
return retval;
Expand Down Expand Up @@ -231,7 +226,7 @@ void die(const char *msg, ...) {
char buf[4096];
vsprintf(buf, msg, args);
die_handler(buf);
abort();
abort();
va_end(args);
}

Expand Down

0 comments on commit 0afe26e

Please sign in to comment.