Skip to content

Commit 6028ba8

Browse files
authored
Merge pull request #165 from emkey1/check
Merge Changes from B506 Release candidate
2 parents d573330 + 083aec8 commit 6028ba8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1470
-1357
lines changed

app/AppDelegate.m

+23-19
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "fs/devices.h"
2929
#include "fs/path.h"
3030
#include "app/RTCDevice.h"
31+
#include "util/sync.h"
3132

3233
#if ISH_LINUX
3334
#import "LinuxInterop.h"
@@ -44,24 +45,28 @@ @interface AppDelegate ()
4445
static void ios_handle_exit(struct task *task, int code) {
4546
// we are interested in init and in children of init
4647
// this is called with pids_lock as an implementation side effect, please do not cite as an example of good API design
47-
complex_lockt(&pids_lock, 0, __FILE__, __LINE__);
48+
task_ref_cnt_mod(task, 1);
49+
lock(&task->general_lock, 0);
50+
// complex_lockt(&pids_lock, 0);
4851
if(task->pid > MAX_PID) {// Corruption
4952
printk("ERROR: Insane PID in ios_handle_exit(%d)\n", task->pid);
50-
unlock(&pids_lock);
53+
// unlock(&pids_lock);
54+
// No reason to unlock the task, it has already been freed. :-(
55+
//unlock(&task->general_lock);
5156
return;
5257
}
5358
if (task->parent != NULL && task->parent->parent != NULL) {
54-
unlock(&pids_lock);
59+
// unlock(&pids_lock);
60+
unlock(&task->general_lock);
61+
task_ref_cnt_mod(task, -1);
5562
return;
5663
}
5764
// pid should be saved now since task would be freed
5865
pid_t pid = task->pid;
59-
// if(pids_lock.pid == pid)
60-
// unlock(&pids_lock);
61-
// while((critical_region_count(task)) || (locks_held_count(task))) { // Wait for now, task is in one or more critical sections, and/or has locks
62-
// nanosleep(&lock_pause, NULL);
63-
// }
64-
unlock(&pids_lock);
66+
67+
//unlock(&pids_lock);
68+
unlock(&task->general_lock);
69+
task_ref_cnt_mod(task, -1);
6570
dispatch_async(dispatch_get_main_queue(), ^{
6671
[[NSNotificationCenter defaultCenter] postNotificationName:ProcessExitedNotification
6772
object:nil
@@ -70,16 +75,13 @@ static void ios_handle_exit(struct task *task, int code) {
7075
});
7176
}
7277

73-
const char* getCurrentTimestamp(void);
74-
75-
const char* getCurrentTimestamp(void) {
78+
const char* getRenameRunDirString(void) {
7679
NSDate *currentDate = [NSDate date];
7780
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
78-
[dateFormatter setDateFormat:@"yyyy-MM-dd_HH:mm:ss"];
81+
[dateFormatter setDateFormat:@"yyyy-MM-dd_HH-mm-ss"];
7982
NSString *timestamp = [dateFormatter stringFromDate:currentDate];
8083

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

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

151-
// Create a unique directory in /tmp and link to /var/run
152-
const char *timestamp = getCurrentTimestamp();
153-
generic_mkdirat(AT_PWD, timestamp, 0755);
153+
// mv current /run to /tmp/run-old/[timestamp], create new /run and link to /var/run
154+
generic_mkdirat(AT_PWD, "/tmp/old-run", 0755);
155+
const char *rename = getRenameRunDirString();
156+
generic_renameat(AT_PWD, "/run", AT_PWD, rename);
157+
generic_mkdirat(AT_PWD, "/run", 0755);
154158
generic_unlinkat(AT_PWD, "/var/run");
155-
generic_symlinkat(timestamp, AT_PWD, "/var/run");
159+
generic_symlinkat("/run", AT_PWD, "/var/run");
156160

157161
// Create directories/links to simulate /sys stuff for battery monitoring
158162
generic_mkdirat(AT_PWD, "/sys/class", 0755);

app/PasteboardDevice.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ static int clipboard_close(clip_fd *fd) {
223223
return 0;
224224
}
225225

226-
static intptr_t clipboard_open(int major, int minor, clip_fd *fd) {
226+
static int clipboard_open(int major, int minor, clip_fd *fd) {
227227
// Zero fd_priv data
228228
memset(&fd_priv(fd), 0, sizeof(fd_priv(fd)));
229229

app/RTCDevice.m

+12-39
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
//
2-
// RTCDevice.m
3-
// iSH-AOK
4-
//
5-
// Created by Michael Miller on 11/24/23.
6-
//
7-
8-
#import <Foundation/Foundation.h>
1+
#include <Foundation/Foundation.h>
92
#include "fs/poll.h"
103
#include "fs/dyndev.h"
114
#include "kernel/errno.h"
@@ -26,35 +19,23 @@
2619
} rtc_time;
2720

2821
// Get the time, put it in the appropriate structure
29-
static rtc_time *get_current_time(rtc_fd *fd, size_t *len) {
22+
static rtc_time get_current_time(rtc_fd *fd) {
3023
// Obtain the current date
3124
NSDate *currentDate = [NSDate date];
3225
NSCalendar *calendar = [NSCalendar currentCalendar];
3326

3427
// Define the desired date components
35-
NSDateComponents *components = [calendar components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond)
36-
fromDate:currentDate];
37-
38-
// Allocate and populate the rtc_time structure
39-
rtc_time *timeStruct = malloc(sizeof(rtc_time));
40-
if (!timeStruct) {
41-
// Handle memory allocation failure
42-
*len = 0;
43-
return NULL;
44-
}
28+
NSDateComponents *components = [calendar components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond) fromDate:currentDate];
4529

4630
// Populate the structure
4731
// Note: tm_mon is 0-based (0 for January) and tm_year is years since 1900
48-
timeStruct->tm_sec = (int)[components second];
49-
timeStruct->tm_min = (int)[components minute];
50-
timeStruct->tm_hour = (int)[components hour];
51-
timeStruct->tm_mday = (int)[components day];
52-
timeStruct->tm_mon = (int)[components month] - 1; // Adjust for tm_mon
53-
timeStruct->tm_year = (int)[components year] - 1900; // Adjust for tm_year
54-
55-
// Update the size
56-
*len = sizeof(rtc_time);
57-
32+
rtc_time timeStruct;
33+
timeStruct.tm_sec = (int)[components second];
34+
timeStruct.tm_min = (int)[components minute];
35+
timeStruct.tm_hour = (int)[components hour];
36+
timeStruct.tm_mday = (int)[components day];
37+
timeStruct.tm_mon = (int)[components month] - 1; // Adjust for tm_mon
38+
timeStruct.tm_year = (int)[components year] - 1900; // Adjust for tm_year
5839
return timeStruct;
5940
}
6041

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

77-
#define RTC_RD_TIME 0x80247009 // Example definition, adjust as necessary
58+
#define RTC_RD_TIME 0x80247009
7859

7960
static ssize_t rtc_ioctl_size(int cmd) {
8061
switch (cmd) {
@@ -89,15 +70,7 @@ static int rtc_ioctl(struct fd *fd, int cmd, void *arg) {
8970
@autoreleasepool {
9071
switch (cmd) {
9172
case RTC_RD_TIME: { // On a real Linux, there are a number of other possible ioctl()'s. We don't really need them
92-
size_t length = 0;
93-
rtc_time *data = get_current_time(fd, &length);
94-
95-
if (arg == NULL) {
96-
return _EFAULT; // Null pointer argument
97-
}
98-
99-
*(rtc_time *) arg = *data; // This is the magic that gets the value back to the "kernel"
100-
73+
*(rtc_time *) arg = get_current_time(fd); // This is the magic that gets the value back to the "kernel"
10174
return 0; // Success
10275
}
10376
default:

app/Terminal.m

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "fs/devices.h"
1313
#include "fs/tty.h"
1414
#include "fs/devices.h"
15+
#include "util/ro_locks.h"
1516

1617
extern struct tty_driver ios_pty_driver;
1718

app/UpgradeRootViewController.m

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "kernel/calls.h"
1313
#include "kernel/init.h"
1414
#include "fs/devices.h"
15+
#include "util/sync.h"
1516

1617
@interface UpgradeRootViewController ()
1718

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

33-
complex_lockt(&pids_lock, 0, __FILE__, __LINE__);
34+
complex_lockt(&pids_lock, 0);
3435
current = pid_get_task(1); // pray
3536
unlock(&pids_lock);
3637
self.terminal = [Terminal createPseudoTerminal:&self->_tty];
@@ -74,7 +75,7 @@ - (void)processExited:(NSNotification *)notif {
7475
if (code != 0) {
7576
[self showAlertWithTitle:@"Upgrade failed" message:@"exit status %d", code];
7677
} else {
77-
complex_lockt(&pids_lock, 0, __FILE__, __LINE__);
78+
complex_lockt(&pids_lock, 0);
7879
current = pid_get_task(1); // pray
7980
unlock(&pids_lock);
8081
FsUpdateRepositories();

app/UserPreferences.m

+3-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
#import "UserPreferences.h"
99
#import "fs/proc/ish.h"
10-
#include "sync.h"
1110
#include "task.h"
1211

1312
// Stuff to allow for cleaning up when doEnableExtraLocking is disabled. -mke
@@ -455,9 +454,9 @@ - (void)setShouldEnableExtraLocking:(BOOL)dim {
455454
- (BOOL)validateShouldEnableExtraLocking:(id *)value error:(NSError **)error {
456455
// Should set task->critical_region.count to 0 for all active processes when this is set to false. Otherwise stuff blows up. -mke
457456
if(doEnableExtraLocking == true) { // This needs to be the opposite of what you would expect because of reasons. -mke
458-
complex_lockt(&pids_lock, 0, __FILE__, __LINE__);
459-
zero_critical_regions_count();
460-
unlock(&pids_lock);
457+
// complex_lockt(&pids_lock, 0, __FILE__, __LINE__);
458+
// zero_critical_regions_count();
459+
// unlock(&pids_lock);
461460
}
462461
return [*value isKindOfClass:NSNumber.class];
463462
}

app/iOSFS.m

+5-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212
#include "iOSFS.h"
1313
#include "kernel/fs.h"
1414
#include "kernel/errno.h"
15+
#include "kernel/task.h"
1516
#include "fs/path.h"
1617
#include "fs/real.h"
1718

19+
extern inline void task_ref_cnt_mod(struct task *task, int value);
20+
1821
const NSFileCoordinatorWritingOptions NSFileCoordinatorWritingForCreating = NSFileCoordinatorWritingForMerging;
1922

2023
@interface DirectoryPicker : NSObject <UIDocumentPickerDelegate, UIAdaptivePresentationControllerDelegate>
@@ -239,7 +242,7 @@ static int combine_error(NSError *coordinatorError, int err) {
239242
__block NSError *error = nil;
240243
__block struct fd *fd;
241244
__block dispatch_semaphore_t file_opened = dispatch_semaphore_create(0);
242-
modify_critical_region_counter_wrapper(1, __FILE__, __LINE__);
245+
task_ref_cnt_mod(current, 1);
243246
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
244247
void (^operation)(NSURL *url) = ^(NSURL *url) {
245248
fd = realfs_open(mount, path_for_url_in_mount(mount, url, path), flags, mode);
@@ -265,7 +268,7 @@ static int combine_error(NSError *coordinatorError, int err) {
265268
}
266269
[coordinator coordinateReadingItemAtURL:url options:options error:&error byAccessor:operation];
267270
});
268-
modify_critical_region_counter_wrapper(-1, __FILE__, __LINE__);
271+
task_ref_cnt_mod(current, -1);
269272

270273
dispatch_semaphore_wait(file_opened, DISPATCH_TIME_FOREVER);
271274

debug.h

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ extern void (*die_handler)(const char *msg);
7979
_Noreturn void die(const char *msg, ...);
8080

8181
#define STRACE(msg, ...) TRACE_(strace, msg, ##__VA_ARGS__)
82+
// #define STRACE(fmt, ...) printk(fmt, ##__VA_ARGS__)
8283

8384
#if defined(__i386__) || defined(__x86_64__)
8485
#define debugger __asm__("int3")

emu/decode.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "emu/cpu.h"
33
#include "emu/modrm.h"
44
#include "emu/interrupt.h"
5+
#include "kernel/task.h"
56

67
#undef oz
78
#define oz OP_SIZE
@@ -13,9 +14,10 @@
1314
#undef DEFAULT_CHANNEL
1415
#define DEFAULT_CHANNEL instr
1516
#define TRACEI(msg, ...) TRACE(msg "\t", ##__VA_ARGS__)
16-
extern int current_pid(void);
17-
extern char* curent_comm(void);
18-
#define TRACEIP() TRACE("%d %08x\t", current_pid(), state->ip)
17+
//extern int current_pid(struct task *task);
18+
//extern char* curent_comm(void);
19+
//#define TRACEIP() TRACE("%d %08x\t", current_pid(current), state->ip)
20+
//#define TRACEIP() TRACE("%d %08x\t", current_pid(), state->ip)
1921

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

3638
restart:
37-
TRACEIP();
39+
// TRACEIP(current);
3840
READINSN;
3941
switch (insn) {
4042
#define MAKE_OP(x, OP, op) \

0 commit comments

Comments
 (0)