Skip to content

Commit

Permalink
Merge pull request #165 from emkey1/check
Browse files Browse the repository at this point in the history
Merge Changes from B506 Release candidate
  • Loading branch information
emkey1 authored Dec 24, 2023
2 parents d573330 + 083aec8 commit 6028ba8
Show file tree
Hide file tree
Showing 65 changed files with 1,470 additions and 1,357 deletions.
42 changes: 23 additions & 19 deletions app/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "fs/devices.h"
#include "fs/path.h"
#include "app/RTCDevice.h"
#include "util/sync.h"

#if ISH_LINUX
#import "LinuxInterop.h"
Expand All @@ -44,24 +45,28 @@ @interface AppDelegate ()
static void ios_handle_exit(struct task *task, int code) {
// we are interested in init and in children of init
// this is called with pids_lock as an implementation side effect, please do not cite as an example of good API design
complex_lockt(&pids_lock, 0, __FILE__, __LINE__);
task_ref_cnt_mod(task, 1);
lock(&task->general_lock, 0);
// complex_lockt(&pids_lock, 0);
if(task->pid > MAX_PID) {// Corruption
printk("ERROR: Insane PID in ios_handle_exit(%d)\n", task->pid);
unlock(&pids_lock);
// unlock(&pids_lock);
// No reason to unlock the task, it has already been freed. :-(
//unlock(&task->general_lock);
return;
}
if (task->parent != NULL && task->parent->parent != NULL) {
unlock(&pids_lock);
// unlock(&pids_lock);
unlock(&task->general_lock);
task_ref_cnt_mod(task, -1);
return;
}
// pid should be saved now since task would be freed
pid_t pid = task->pid;
// if(pids_lock.pid == pid)
// unlock(&pids_lock);
// while((critical_region_count(task)) || (locks_held_count(task))) { // Wait for now, task is in one or more critical sections, and/or has locks
// nanosleep(&lock_pause, NULL);
// }
unlock(&pids_lock);

//unlock(&pids_lock);
unlock(&task->general_lock);
task_ref_cnt_mod(task, -1);
dispatch_async(dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:ProcessExitedNotification
object:nil
Expand All @@ -70,16 +75,13 @@ static void ios_handle_exit(struct task *task, int code) {
});
}

const char* getCurrentTimestamp(void);

const char* getCurrentTimestamp(void) {
const char* getRenameRunDirString(void) {
NSDate *currentDate = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd_HH:mm:ss"];
[dateFormatter setDateFormat:@"yyyy-MM-dd_HH-mm-ss"];
NSString *timestamp = [dateFormatter stringFromDate:currentDate];

// Prepending "/tmp/" to the timestamp
NSString *prefixedTimestamp = [NSString stringWithFormat:@"/tmp/%@", timestamp];
NSString *prefixedTimestamp = [NSString stringWithFormat:@"/tmp/old-run/%@", timestamp];

// Convert to const char* and return
return [prefixedTimestamp UTF8String];
Expand Down Expand Up @@ -148,11 +150,13 @@ - (intptr_t)boot {
// Permissions on / have been broken for a while, let's fix them
generic_setattrat(AT_PWD, "/", (struct attr) {.type = attr_mode, .mode = 0755}, false);

// Create a unique directory in /tmp and link to /var/run
const char *timestamp = getCurrentTimestamp();
generic_mkdirat(AT_PWD, timestamp, 0755);
// mv current /run to /tmp/run-old/[timestamp], create new /run and link to /var/run
generic_mkdirat(AT_PWD, "/tmp/old-run", 0755);
const char *rename = getRenameRunDirString();
generic_renameat(AT_PWD, "/run", AT_PWD, rename);
generic_mkdirat(AT_PWD, "/run", 0755);
generic_unlinkat(AT_PWD, "/var/run");
generic_symlinkat(timestamp, AT_PWD, "/var/run");
generic_symlinkat("/run", AT_PWD, "/var/run");

// Create directories/links to simulate /sys stuff for battery monitoring
generic_mkdirat(AT_PWD, "/sys/class", 0755);
Expand Down
2 changes: 1 addition & 1 deletion app/PasteboardDevice.m
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ static int clipboard_close(clip_fd *fd) {
return 0;
}

static intptr_t clipboard_open(int major, int minor, clip_fd *fd) {
static int clipboard_open(int major, int minor, clip_fd *fd) {
// Zero fd_priv data
memset(&fd_priv(fd), 0, sizeof(fd_priv(fd)));

Expand Down
51 changes: 12 additions & 39 deletions app/RTCDevice.m
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
//
// RTCDevice.m
// iSH-AOK
//
// Created by Michael Miller on 11/24/23.
//

#import <Foundation/Foundation.h>
#include <Foundation/Foundation.h>
#include "fs/poll.h"
#include "fs/dyndev.h"
#include "kernel/errno.h"
Expand All @@ -26,35 +19,23 @@
} rtc_time;

// Get the time, put it in the appropriate structure
static rtc_time *get_current_time(rtc_fd *fd, size_t *len) {
static rtc_time get_current_time(rtc_fd *fd) {
// Obtain the current date
NSDate *currentDate = [NSDate date];
NSCalendar *calendar = [NSCalendar currentCalendar];

// Define the desired date components
NSDateComponents *components = [calendar components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond)
fromDate:currentDate];

// Allocate and populate the rtc_time structure
rtc_time *timeStruct = malloc(sizeof(rtc_time));
if (!timeStruct) {
// Handle memory allocation failure
*len = 0;
return NULL;
}
NSDateComponents *components = [calendar components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond) fromDate:currentDate];

// Populate the structure
// Note: tm_mon is 0-based (0 for January) and tm_year is years since 1900
timeStruct->tm_sec = (int)[components second];
timeStruct->tm_min = (int)[components minute];
timeStruct->tm_hour = (int)[components hour];
timeStruct->tm_mday = (int)[components day];
timeStruct->tm_mon = (int)[components month] - 1; // Adjust for tm_mon
timeStruct->tm_year = (int)[components year] - 1900; // Adjust for tm_year

// Update the size
*len = sizeof(rtc_time);

rtc_time timeStruct;
timeStruct.tm_sec = (int)[components second];
timeStruct.tm_min = (int)[components minute];
timeStruct.tm_hour = (int)[components hour];
timeStruct.tm_mday = (int)[components day];
timeStruct.tm_mon = (int)[components month] - 1; // Adjust for tm_mon
timeStruct.tm_year = (int)[components year] - 1900; // Adjust for tm_year
return timeStruct;
}

Expand All @@ -74,7 +55,7 @@ static int rtc_close(rtc_fd *fd) {
return 0;
}

#define RTC_RD_TIME 0x80247009 // Example definition, adjust as necessary
#define RTC_RD_TIME 0x80247009

static ssize_t rtc_ioctl_size(int cmd) {
switch (cmd) {
Expand All @@ -89,15 +70,7 @@ static int rtc_ioctl(struct fd *fd, int cmd, void *arg) {
@autoreleasepool {
switch (cmd) {
case RTC_RD_TIME: { // On a real Linux, there are a number of other possible ioctl()'s. We don't really need them
size_t length = 0;
rtc_time *data = get_current_time(fd, &length);

if (arg == NULL) {
return _EFAULT; // Null pointer argument
}

*(rtc_time *) arg = *data; // This is the magic that gets the value back to the "kernel"

*(rtc_time *) arg = get_current_time(fd); // This is the magic that gets the value back to the "kernel"
return 0; // Success
}
default:
Expand Down
1 change: 1 addition & 0 deletions app/Terminal.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "fs/devices.h"
#include "fs/tty.h"
#include "fs/devices.h"
#include "util/ro_locks.h"

extern struct tty_driver ios_pty_driver;

Expand Down
5 changes: 3 additions & 2 deletions app/UpgradeRootViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "kernel/calls.h"
#include "kernel/init.h"
#include "fs/devices.h"
#include "util/sync.h"

@interface UpgradeRootViewController ()

Expand All @@ -30,7 +31,7 @@ - (void)viewDidLoad {
#if !ISH_LINUX
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(processExited:) name:ProcessExitedNotification object:nil];

complex_lockt(&pids_lock, 0, __FILE__, __LINE__);
complex_lockt(&pids_lock, 0);
current = pid_get_task(1); // pray
unlock(&pids_lock);
self.terminal = [Terminal createPseudoTerminal:&self->_tty];
Expand Down Expand Up @@ -74,7 +75,7 @@ - (void)processExited:(NSNotification *)notif {
if (code != 0) {
[self showAlertWithTitle:@"Upgrade failed" message:@"exit status %d", code];
} else {
complex_lockt(&pids_lock, 0, __FILE__, __LINE__);
complex_lockt(&pids_lock, 0);
current = pid_get_task(1); // pray
unlock(&pids_lock);
FsUpdateRepositories();
Expand Down
7 changes: 3 additions & 4 deletions app/UserPreferences.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#import "UserPreferences.h"
#import "fs/proc/ish.h"
#include "sync.h"
#include "task.h"

// Stuff to allow for cleaning up when doEnableExtraLocking is disabled. -mke
Expand Down Expand Up @@ -455,9 +454,9 @@ - (void)setShouldEnableExtraLocking:(BOOL)dim {
- (BOOL)validateShouldEnableExtraLocking:(id *)value error:(NSError **)error {
// Should set task->critical_region.count to 0 for all active processes when this is set to false. Otherwise stuff blows up. -mke
if(doEnableExtraLocking == true) { // This needs to be the opposite of what you would expect because of reasons. -mke
complex_lockt(&pids_lock, 0, __FILE__, __LINE__);
zero_critical_regions_count();
unlock(&pids_lock);
// complex_lockt(&pids_lock, 0, __FILE__, __LINE__);
// zero_critical_regions_count();
// unlock(&pids_lock);
}
return [*value isKindOfClass:NSNumber.class];
}
Expand Down
7 changes: 5 additions & 2 deletions app/iOSFS.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
#include "iOSFS.h"
#include "kernel/fs.h"
#include "kernel/errno.h"
#include "kernel/task.h"
#include "fs/path.h"
#include "fs/real.h"

extern inline void task_ref_cnt_mod(struct task *task, int value);

const NSFileCoordinatorWritingOptions NSFileCoordinatorWritingForCreating = NSFileCoordinatorWritingForMerging;

@interface DirectoryPicker : NSObject <UIDocumentPickerDelegate, UIAdaptivePresentationControllerDelegate>
Expand Down Expand Up @@ -239,7 +242,7 @@ static int combine_error(NSError *coordinatorError, int err) {
__block NSError *error = nil;
__block struct fd *fd;
__block dispatch_semaphore_t file_opened = dispatch_semaphore_create(0);
modify_critical_region_counter_wrapper(1, __FILE__, __LINE__);
task_ref_cnt_mod(current, 1);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
void (^operation)(NSURL *url) = ^(NSURL *url) {
fd = realfs_open(mount, path_for_url_in_mount(mount, url, path), flags, mode);
Expand All @@ -265,7 +268,7 @@ static int combine_error(NSError *coordinatorError, int err) {
}
[coordinator coordinateReadingItemAtURL:url options:options error:&error byAccessor:operation];
});
modify_critical_region_counter_wrapper(-1, __FILE__, __LINE__);
task_ref_cnt_mod(current, -1);

dispatch_semaphore_wait(file_opened, DISPATCH_TIME_FOREVER);

Expand Down
1 change: 1 addition & 0 deletions debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ extern void (*die_handler)(const char *msg);
_Noreturn void die(const char *msg, ...);

#define STRACE(msg, ...) TRACE_(strace, msg, ##__VA_ARGS__)
// #define STRACE(fmt, ...) printk(fmt, ##__VA_ARGS__)

#if defined(__i386__) || defined(__x86_64__)
#define debugger __asm__("int3")
Expand Down
10 changes: 6 additions & 4 deletions emu/decode.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "emu/cpu.h"
#include "emu/modrm.h"
#include "emu/interrupt.h"
#include "kernel/task.h"

#undef oz
#define oz OP_SIZE
Expand All @@ -13,9 +14,10 @@
#undef DEFAULT_CHANNEL
#define DEFAULT_CHANNEL instr
#define TRACEI(msg, ...) TRACE(msg "\t", ##__VA_ARGS__)
extern int current_pid(void);
extern char* curent_comm(void);
#define TRACEIP() TRACE("%d %08x\t", current_pid(), state->ip)
//extern int current_pid(struct task *task);
//extern char* curent_comm(void);
//#define TRACEIP() TRACE("%d %08x\t", current_pid(current), state->ip)
//#define TRACEIP() TRACE("%d %08x\t", current_pid(), state->ip)

// this will be the next PyEval_EvalFrameEx
__no_instrument DECODER_RET glue(DECODER_NAME, OP_SIZE)(DECODER_ARGS) {
Expand All @@ -34,7 +36,7 @@ __no_instrument DECODER_RET glue(DECODER_NAME, OP_SIZE)(DECODER_ARGS) {
#define READMODRM_NOMEM READMODRM; if (modrm.type != modrm_reg) UNDEFINED

restart:
TRACEIP();
// TRACEIP(current);
READINSN;
switch (insn) {
#define MAKE_OP(x, OP, op) \
Expand Down
Loading

0 comments on commit 6028ba8

Please sign in to comment.