Skip to content

Commit

Permalink
o Rename mofify_critical_region_counter() to mofify_critical_region_c…
Browse files Browse the repository at this point in the history
…ount(), same for wrapper

o Broke critical_region_count() in current_comm(), fix
  • Loading branch information
Mike Miller committed Nov 27, 2023
1 parent 06f2290 commit 73e9d22
Show file tree
Hide file tree
Showing 20 changed files with 129 additions and 129 deletions.
4 changes: 2 additions & 2 deletions app/iOSFS.m
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,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__);
modify_critical_region_count_wrapper(1, __FILE__, __LINE__);
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 +265,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__);
modify_critical_region_count_wrapper(-1, __FILE__, __LINE__);

dispatch_semaphore_wait(file_opened, DISPATCH_TIME_FOREVER);

Expand Down
34 changes: 17 additions & 17 deletions emu/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void mem_destroy(struct mem *mem) {
free(mem->pgdir[i]);
}

//modify_critical_region_counter(current, 1, __FILE__, __LINE__);
//mofify_critical_region_counter(current, 1, __FILE__, __LINE__);

do {
nanosleep(&lock_pause, NULL);
Expand All @@ -79,7 +79,7 @@ void mem_destroy(struct mem *mem) {

write_unlock_and_destroy(&mem->lock);

//modify_critical_region_counter(current, -1, __FILE__, __LINE__);
//mofify_critical_region_counter(current, -1, __FILE__, __LINE__);

}

Expand All @@ -97,52 +97,52 @@ static struct pt_entry *mem_pt_new(struct mem *mem, page_t page) {

struct pt_entry *mem_pt(struct mem *mem, page_t page) {

//modify_critical_region_counter(current, 1, __FILE__, __LINE__);
//mofify_critical_region_counter(current, 1, __FILE__, __LINE__);

if (mem->pgdir[PGDIR_TOP(page)] != NULL) { // Check if defined. Likely still leaves a potential race condition as no locking currently. -MKE FIXME
struct pt_entry *pgdir = mem->pgdir[PGDIR_TOP(page)];
if (pgdir == NULL) {
//modify_critical_region_counter(current, -1, __FILE__, __LINE__);
//mofify_critical_region_counter(current, -1, __FILE__, __LINE__);
return NULL;
}

struct pt_entry *entry = &pgdir[PGDIR_BOTTOM(page)];
if (entry->data == NULL) {
//modify_critical_region_counter(current, -1, __FILE__, __LINE__);
//mofify_critical_region_counter(current, -1, __FILE__, __LINE__);
return NULL;
}

//modify_critical_region_counter(current, -1, __FILE__, __LINE__);
//mofify_critical_region_counter(current, -1, __FILE__, __LINE__);
return entry;
} else {
mem->pgdir[PGDIR_TOP(page)] = NULL;
//modify_critical_region_counter(current, -1, __FILE__, __LINE__);
//mofify_critical_region_counter(current, -1, __FILE__, __LINE__);
return NULL;
}

//modify_critical_region_counter(current, -1, __FILE__, __LINE__);
//mofify_critical_region_counter(current, -1, __FILE__, __LINE__);
}

static void mem_pt_del(struct mem *mem, page_t page) {
//modify_critical_region_counter(current, 1, __FILE__, __LINE__);
//mofify_critical_region_counter(current, 1, __FILE__, __LINE__);
struct pt_entry *entry = mem_pt(mem, page);
if (entry != NULL) {
while(critical_region_count(current) > 4) { // mark
nanosleep(&lock_pause, NULL);
}
entry->data = NULL;
}
//modify_critical_region_counter(current, -1, __FILE__, __LINE__);
//mofify_critical_region_counter(current, -1, __FILE__, __LINE__);
}

void mem_next_page(struct mem *mem, page_t *page) {
(*page)++;
if (*page >= MEM_PAGES)
return;
//modify_critical_region_counter(current, 1, __FILE__, __LINE__);
//mofify_critical_region_counter(current, 1, __FILE__, __LINE__);
while (*page < MEM_PAGES && mem->pgdir[PGDIR_TOP(*page)] == NULL)
*page = (*page - PGDIR_BOTTOM(*page)) + MEM_PGDIR_SIZE;
//modify_critical_region_counter(current, -1, __FILE__, __LINE__);
//mofify_critical_region_counter(current, -1, __FILE__, __LINE__);
}

page_t pt_find_hole(struct mem *mem, pages_t size) {
Expand Down Expand Up @@ -346,7 +346,7 @@ void *mem_ptr(struct mem *mem, addr_t addr, int type) {
if (type != MEM_WRITE_PTRACE && !(entry->flags & P_WRITE))
return NULL;

////modify_critical_region_counter(current, 1, __FILE__, __LINE__);
////mofify_critical_region_counter(current, 1, __FILE__, __LINE__);

if (type == MEM_WRITE_PTRACE) {
// TODO: Is P_WRITE really correct? The page shouldn't be writable without ptrace.
Expand All @@ -361,17 +361,17 @@ void *mem_ptr(struct mem *mem, addr_t addr, int type) {

if (entry->flags & P_COW) {
lock(&current->general_lock, 0); // prevent elf_exec from doing mm_release while we are in flight? -mke
//modify_critical_region_counter(current, 1, __FILE__, __LINE__);
//mofify_critical_region_counter(current, 1, __FILE__, __LINE__);
read_to_write_lock(&mem->lock);
void *copy = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
void *data = (char *) entry->data->data + entry->offset;
//modify_critical_region_counter(current, -1, __FILE__, __LINE__);
//mofify_critical_region_counter(current, -1, __FILE__, __LINE__);

// copy/paste from above
modify_critical_region_counter(current, 1,__FILE__, __LINE__);
modify_critical_region_count(current, 1,__FILE__, __LINE__);
//read_to_write_lock(&mem->lock);
memcpy(copy, data, PAGE_SIZE); //mkemkemke Crashes here a lot when running both the go and parallel make test. 01 June 2022
modify_critical_region_counter(current, -1, __FILE__, __LINE__);
modify_critical_region_count(current, -1, __FILE__, __LINE__);
pt_map(mem, page, 1, copy, 0, entry->flags &~ P_COW);
unlock(&current->general_lock);
write_to_read_lock(&mem->lock, __FILE__, __LINE__);
Expand Down
26 changes: 13 additions & 13 deletions emu/tlb.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
#include "kernel/resource_locking.h"

void tlb_refresh(struct tlb *tlb, struct mmu *mmu) {
//modify_critical_region_counter(current, 1, __FILE__, __LINE__); // WORKING ON -mke
//mofify_critical_region_counter(current, 1, __FILE__, __LINE__); // WORKING ON -mke
if (tlb->mmu == mmu && tlb->mem_changes == mmu->changes) {
//modify_critical_region_counter(current, -1, __FILE__, __LINE__);
//mofify_critical_region_counter(current, -1, __FILE__, __LINE__);
return;
}
tlb->mmu = mmu;
tlb->dirty_page = TLB_PAGE_EMPTY;
tlb->mem_changes = mmu->changes;
tlb_flush(tlb);
//modify_critical_region_counter(current, -1, __FILE__, __LINE__);
//mofify_critical_region_counter(current, -1, __FILE__, __LINE__);
}

void tlb_flush(struct tlb *tlb) {
Expand All @@ -24,48 +24,48 @@ void tlb_flush(struct tlb *tlb) {
}

void tlb_free(struct tlb *tlb) {
////modify_critical_region_counter(current, 1, __FILE__, __LINE__);
////mofify_critical_region_counter(current, 1, __FILE__, __LINE__);
free(tlb);
////modify_critical_region_counter(current, -1, __FILE__, __LINE__);
////mofify_critical_region_counter(current, -1, __FILE__, __LINE__);
}

bool __tlb_read_cross_page(struct tlb *tlb, addr_t addr, char *value, unsigned size) {
////modify_critical_region_counter(current, 1, __FILE__, __LINE__);
////mofify_critical_region_counter(current, 1, __FILE__, __LINE__);
char *ptr1 = __tlb_read_ptr(tlb, addr);
if (ptr1 == NULL) {
////modify_critical_region_counter(current, -1, __FILE__, __LINE__);
////mofify_critical_region_counter(current, -1, __FILE__, __LINE__);
return false;
}
char *ptr2 = __tlb_read_ptr(tlb, (PAGE(addr) + 1) << PAGE_BITS);
if (ptr2 == NULL) {
////modify_critical_region_counter(current, -1, __FILE__, __LINE__);
////mofify_critical_region_counter(current, -1, __FILE__, __LINE__);
return false;
}
size_t part1 = PAGE_SIZE - PGOFFSET(addr);
assert(part1 < size);
memcpy(value, ptr1, part1);
memcpy(value + part1, ptr2, size - part1);
////modify_critical_region_counter(current, -1, __FILE__, __LINE__);
////mofify_critical_region_counter(current, -1, __FILE__, __LINE__);
return true;
}

bool __tlb_write_cross_page(struct tlb *tlb, addr_t addr, const char *value, unsigned size) {
////modify_critical_region_counter(current, 1, __FILE__, __LINE__);
////mofify_critical_region_counter(current, 1, __FILE__, __LINE__);
char *ptr1 = __tlb_write_ptr(tlb, addr);
if (ptr1 == NULL) {
////modify_critical_region_counter(current, -1, __FILE__, __LINE__);
////mofify_critical_region_counter(current, -1, __FILE__, __LINE__);
return false;
}
char *ptr2 = __tlb_write_ptr(tlb, (PAGE(addr) + 1) << PAGE_BITS);
if (ptr2 == NULL) {
////modify_critical_region_counter(current, -1, __FILE__, __LINE__);
////mofify_critical_region_counter(current, -1, __FILE__, __LINE__);
return false;
}
size_t part1 = PAGE_SIZE - PGOFFSET(addr);
assert(part1 < size);
memcpy(ptr1, value, part1);
memcpy(ptr2, value + part1, size - part1);
////modify_critical_region_counter(current, -1, __FILE__, __LINE__);
////mofify_critical_region_counter(current, -1, __FILE__, __LINE__);
return true;
}

Expand Down
6 changes: 3 additions & 3 deletions fs/proc/pid.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static int proc_pid_stat_show(struct proc_entry *entry, struct proc_data *buf) {
if ((task == NULL) || (task->exiting == true))
return _ESRCH;

////modify_critical_region_counter(task, 1, __FILE__, __LINE__);
////mofify_critical_region_counter(task, 1, __FILE__, __LINE__);
if(!strcmp(task->general_lock.lname, "task_creat_gen")) // Work around. Sometimes the general lock is locked when it shouldn't be
unlock(&task->general_lock);
lock(&task->general_lock, 0);
Expand Down Expand Up @@ -117,7 +117,7 @@ static int proc_pid_stat_show(struct proc_entry *entry, struct proc_data *buf) {
//unlock(&task->sighand->lock);
unlock(&task->group->lock);
unlock(&task->general_lock);
////modify_critical_region_counter(task, -1, __FILE__, __LINE__);
////mofify_critical_region_counter(task, -1, __FILE__, __LINE__);
proc_put_task(task);
return 0;
}
Expand Down Expand Up @@ -167,7 +167,7 @@ static int proc_pid_cmdline_show(struct proc_entry *entry, struct proc_data *buf
if ((task == NULL) || (task->exiting == true))
return _ESRCH;

////modify_critical_region_counter(task, 1, __FILE__, __LINE__);
////mofify_critical_region_counter(task, 1, __FILE__, __LINE__);

int err = 0;
lock(&task->general_lock, 0);
Expand Down
6 changes: 3 additions & 3 deletions fs/proc/root.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,19 +328,19 @@ static bool proc_root_readdir(struct proc_entry *UNUSED(entry), unsigned long *i

pid_t_ pid = *index - PROC_ROOT_LEN;
if (pid <= MAX_PID) {
modify_critical_region_counter(current, 1, __FILE__, __LINE__);
modify_critical_region_count(current, 1, __FILE__, __LINE__);
//lock(&pids_lock, 0);
do {
pid++;
} while (pid <= MAX_PID && pid_get_task(pid) == NULL);
//unlock(&pids_lock);
modify_critical_region_counter(current, -1, __FILE__, __LINE__);
modify_critical_region_count(current, -1, __FILE__, __LINE__);
if (pid > MAX_PID) {
return false;
}
*next_entry = (struct proc_entry) {&proc_pid, .pid = pid};
*index = pid + PROC_ROOT_LEN;
//modify_critical_region_counter(current, -1, __FILE__, __LINE__);
//mofify_critical_region_counter(current, -1, __FILE__, __LINE__);
return true;
}

Expand Down
14 changes: 7 additions & 7 deletions jit/jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ void jit_invalidate_page(struct jit *jit, page_t page) {
while(critical_region_count(current) > 4) { // It's all a bit magic, but I think this is doing something useful. -mke
nanosleep(&lock_pause, NULL);
}
//modify_critical_region_counter(current, 1, __FILE__, __LINE__);
//mofify_critical_region_counter(current, 1, __FILE__, __LINE__);
jit_invalidate_range(jit, page, page + 1);
//modify_critical_region_counter(current, -1, __FILE__, __LINE__);
//mofify_critical_region_counter(current, -1, __FILE__, __LINE__);
}

void jit_invalidate_all(struct jit *jit) {
Expand Down Expand Up @@ -227,7 +227,7 @@ static int cpu_step_to_interrupt(struct cpu_state *cpu, struct tlb *tlb) {
addr_t ip = frame->cpu.eip;
size_t cache_index = jit_cache_hash(ip);
struct jit_block *block = cache[cache_index];
//////modify_critical_region_counter(current, 1, __FILE__, __LINE__);
//////mofify_critical_region_counter(current, 1, __FILE__, __LINE__);
if (block == NULL || block->addr != ip) {
lock(&jit->lock, 0);
block = jit_lookup(jit, ip);
Expand All @@ -240,7 +240,7 @@ static int cpu_step_to_interrupt(struct cpu_state *cpu, struct tlb *tlb) {
cache[cache_index] = block;
unlock(&jit->lock);
}
//////modify_critical_region_counter(current, -1, __FILE__, __LINE__);
//////mofify_critical_region_counter(current, -1, __FILE__, __LINE__);
struct jit_block *last_block = frame->last_block;
if (last_block != NULL &&
(last_block->jump_ip[0] != NULL ||
Expand All @@ -253,17 +253,17 @@ static int cpu_step_to_interrupt(struct cpu_state *cpu, struct tlb *tlb) {
if (last_block->jump_ip[i] != NULL &&
(*last_block->jump_ip[i] & 0xffffffff) == block->addr) {
*last_block->jump_ip[i] = (unsigned long) block->code;
//modify_critical_region_counter(current, 1, __FILE__, __LINE__);
//mofify_critical_region_counter(current, 1, __FILE__, __LINE__);
list_add(&block->jumps_from[i], &last_block->jumps_from_links[i]);
//modify_critical_region_counter(current, -1, __FILE__, __LINE__);
//mofify_critical_region_counter(current, -1, __FILE__, __LINE__);
}
}
}

unlock(&jit->lock);
}

//////modify_critical_region_counter(current, -1, __FILE__, __LINE__);
//////mofify_critical_region_counter(current, -1, __FILE__, __LINE__);

frame->last_block = block;

Expand Down
4 changes: 2 additions & 2 deletions kernel/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ static int load_entry(struct prg_header ph, addr_t bias, struct fd *fd) {
if (tail_size != 0) {
// Unlock and lock the mem because the user functions must be
// called without locking mem.
//modify_critical_region_counter(current, 1, __FILE__, __LINE__);
//mofify_critical_region_counter(current, 1, __FILE__, __LINE__);
if(trylockw(&current->mem->lock)) // Test to see if it is actually locked. This is likely masking an underlying problem. -mke
write_unlock(&current->mem->lock, __FILE__, __LINE__);
user_memset(file_end, 0, tail_size);
write_lock(&current->mem->lock);
//modify_critical_region_counter(current, -1, __FILE__, __LINE__);
//mofify_critical_region_counter(current, -1, __FILE__, __LINE__);
}
if (tail_size > bss_size)
tail_size = bss_size;
Expand Down
14 changes: 7 additions & 7 deletions kernel/exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ noreturn void do_exit(int status) {
unlock(&current->group->lock);

// the actual freeing needs pids_lock
modify_critical_region_counter(current, 1, __FILE__, __LINE__);
modify_critical_region_count(current, 1, __FILE__, __LINE__);
complex_lockt(&pids_lock, 0, __FILE__, __LINE__);
// release the sighand
signal_pending = !!(current->pending & ~current->blocked);
Expand Down Expand Up @@ -199,7 +199,7 @@ noreturn void do_exit(int status) {
}

vfork_notify(current);
modify_critical_region_counter(current, -1, __FILE__, __LINE__);
modify_critical_region_count(current, -1, __FILE__, __LINE__);
if(current != leader) {
task_destroy(current, 1);
} else {
Expand Down Expand Up @@ -233,7 +233,7 @@ noreturn void do_exit_group(int status) {
modify_locks_held_count(current, tmpvar); // Reset to zero -mke
}

modify_critical_region_counter(current, 1, __FILE__, __LINE__);
modify_critical_region_count(current, 1, __FILE__, __LINE__);
list_for_each_entry(&group->threads, task, group_links) {
task->exiting = true;
deliver_signal(task, SIGKILL_, SIGINFO_NIL);
Expand All @@ -242,7 +242,7 @@ noreturn void do_exit_group(int status) {
}

unlock(&pids_lock);
modify_critical_region_counter(current, -1, __FILE__, __LINE__);
modify_critical_region_count(current, -1, __FILE__, __LINE__);
unlock(&group->lock);
//if(current->pid <= MAX_PID) // abort if crazy. -mke
do_exit(status);
Expand Down Expand Up @@ -365,7 +365,7 @@ int do_wait(int idtype, pid_t_ id, struct siginfo_ *info, struct rusage_ *rusage
return _EINVAL;

complex_lockt(&pids_lock, 0, __FILE__, __LINE__);
modify_critical_region_counter(current, 1, __FILE__, __LINE__);
modify_critical_region_count(current, 1, __FILE__, __LINE__);
int err;
bool got_signal = false;

Expand Down Expand Up @@ -425,12 +425,12 @@ int do_wait(int idtype, pid_t_ id, struct siginfo_ *info, struct rusage_ *rusage

info->sig = SIGCHLD_;
found_something:
modify_critical_region_counter(current, -1, __FILE__, __LINE__);
modify_critical_region_count(current, -1, __FILE__, __LINE__);
unlock(&pids_lock);
return 0;

error:
modify_critical_region_counter(current, -1, __FILE__, __LINE__);
modify_critical_region_count(current, -1, __FILE__, __LINE__);
unlock(&pids_lock);
return err;
}
Expand Down
4 changes: 2 additions & 2 deletions kernel/futex.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,10 @@ dword_t sys_futex(addr_t uaddr, dword_t op, dword_t val, addr_t timeout_or_val2,
switch (op & FUTEX_CMD_MASK_) {
case FUTEX_WAIT_:
STRACE("futex(FUTEX_WAIT, %#x, %d, 0x%x {%ds %dns}) = ...\n", uaddr, val, timeout_or_val2, timeout.tv_sec, timeout.tv_nsec);
modify_critical_region_counter(current, 1, __FILE__, __LINE__);
modify_critical_region_count(current, 1, __FILE__, __LINE__);
dword_t return_val;
return_val = futex_wait(uaddr, val, timeout_or_val2 ? &timeout : NULL);
modify_critical_region_counter(current, -1, __FILE__, __LINE__);
modify_critical_region_count(current, -1, __FILE__, __LINE__);
return return_val;
case FUTEX_WAKE_:
STRACE("futex(FUTEX_WAKE, %#x, %d)", uaddr, val);
Expand Down
Loading

0 comments on commit 73e9d22

Please sign in to comment.