Skip to content

Commit

Permalink
Fixed elock so that it doesn't crash the app when toggled
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Miller committed Oct 30, 2022
1 parent e98aefd commit 50eaba1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
13 changes: 13 additions & 0 deletions app/UserPreferences.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@

#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
extern bool doEnableExtraLocking;
extern lock_t pids_lock;
extern struct list alive_pids_list;

// IMPORTANT: If you add a constant here and expose it via UserPreferences,
// consider if it also needs to be exposed as a friendly preference and included
Expand Down Expand Up @@ -438,6 +445,12 @@ - (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__);
dword_t res = zero_critical_regions_count();
unlock(&pids_lock);
}
return [*value isKindOfClass:NSNumber.class];
}

Expand Down
15 changes: 12 additions & 3 deletions kernel/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ dword_t get_count_of_blocked_tasks() {
return res;
}

dword_t zero_critical_regions_count(void) { // If doEnableExtraLocking is changed to false, we need to zero out critical_region.count for active processes
dword_t res = 0;
struct pid *pid_entry;
list_for_each_entry(&alive_pids_list, pid_entry, alive) {
pid_entry->task->critical_region.count = 0; // Bad things happen if this isn't done. -mke
}
return 0;
}

dword_t get_count_of_alive_tasks() {
complex_lockt(&pids_lock, 0, __FILE__, __LINE__);
dword_t res = 0;
Expand Down Expand Up @@ -191,16 +200,16 @@ void task_destroy(struct task *task) {
}
list_remove(&pid->alive);

if(Ishould)
unlock(&pids_lock);

signal_pending = !!(current->pending & ~current->blocked);

while((critical_region_count(task) >1) || (locks_held_count(task)) || (signal_pending)) { // Wait for now, task is in one or more critical sections, and/or has locks
nanosleep(&lock_pause, NULL);
signal_pending = !!(current->blocked); // Be less stringent -mke
}

if(Ishould)
unlock(&pids_lock);

free(task);
}

Expand Down
1 change: 1 addition & 0 deletions kernel/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ struct task *pid_get_task_zombie(dword_t id); // don't return null if the task e

dword_t get_count_of_blocked_tasks(void);
dword_t get_count_of_alive_tasks(void);
dword_t zero_critical_regions_count(void);

#define MAX_PID (1 << 15) // oughta be enough

Expand Down

0 comments on commit 50eaba1

Please sign in to comment.