Skip to content

Commit

Permalink
Added Jason Conway's Re Ordering patch (upstream PR ish-app#1944. Fix…
Browse files Browse the repository at this point in the history
…ed a bunch of compiler complaints about uncast variables, removed "easter egg" for now.
  • Loading branch information
Mike Miller committed Nov 2, 2022
1 parent 02b6bd0 commit 6cdefc1
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 23 deletions.
1 change: 1 addition & 0 deletions jit/gadgets-aarch64/gadgets.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ _xaddr .req x3
.endm
.macro gret pop=0
ldr x8, [_ip, \pop*8]!
dmb ishld /* Jason Conway's Re Ordering patch (upstream PR #1944 */
add _ip, _ip, 8 /* TODO get rid of this */
br x8
.endm
Expand Down
1 change: 1 addition & 0 deletions kernel/calls.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ syscall_t syscall_table[] = {
[384] = (syscall_t) sys_arch_prctl,
[403] = (syscall_t) syscall_stub, // clock_gettime64
[407] = (syscall_t) syscall_stub, // clock_nanosleep_time64
[412] = (syscall_t) syscall_stub, // utimensat_time64
[436] = (syscall_t) syscall_stub,
[439] = (syscall_t) sys_faccessat, // faccessat2
};
Expand Down
1 change: 1 addition & 0 deletions kernel/resource_locking.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ extern unsigned critical_region_count(struct task*);
extern void modify_critical_region_counter(struct task*, int, char*, int);
extern unsigned locks_held_count(struct task*);
extern void modify_locks_held_count(struct task*, int);
extern bool current_is_valid(void);

37 changes: 19 additions & 18 deletions kernel/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ static struct timer_spec timer_spec_to_real(struct itimerspec_ itspec) {

static struct itimerspec_ timer_spec_from_real(struct timer_spec spec) {
struct itimerspec_ itspec = {
.value.sec = spec.value.tv_sec,
.value.nsec = spec.value.tv_nsec,
.interval.sec = spec.interval.tv_sec,
.interval.nsec = spec.interval.tv_nsec,
.value.sec = (dword_t)spec.value.tv_sec,
.value.nsec = (dword_t)spec.value.tv_nsec,
.interval.sec = (dword_t)spec.interval.tv_sec,
.interval.nsec = (dword_t)spec.interval.tv_nsec,
};
return itspec;
};

dword_t sys_time(addr_t time_out) {
dword_t now = time(NULL);
dword_t now = (dword_t)time(NULL);
if (time_out != 0)
if (user_put(time_out, now))
return _EFAULT;
Expand Down Expand Up @@ -73,8 +73,9 @@ dword_t sys_clock_gettime(dword_t clock, addr_t tp) {
return errno_map();
}
struct timespec_ t;
t.sec = ts.tv_sec;
t.nsec = ts.tv_nsec;
t.sec = (dword_t)ts.tv_sec;
t.nsec = (dword_t)ts.tv_nsec;

if (user_put(tp, t))
return _EFAULT;
STRACE(" {%lds %ldns}", t.sec, t.nsec);
Expand All @@ -91,8 +92,8 @@ dword_t sys_clock_getres(dword_t clock, addr_t res_addr) {
if (err < 0)
return errno_map();
struct timespec_ t;
t.sec = res.tv_sec;
t.nsec = res.tv_nsec;
t.sec = (dword_t)res.tv_sec;
t.nsec = (dword_t)res.tv_nsec;
if (user_put(res_addr, t))
return _EFAULT;
return 0;
Expand Down Expand Up @@ -150,10 +151,10 @@ int_t sys_setitimer(int_t which, addr_t new_val_addr, addr_t old_val_addr) {

if (old_val_addr != 0) {
struct itimerval_ old_val;
old_val.interval.sec = old_spec.interval.tv_sec;
old_val.interval.usec = old_spec.interval.tv_nsec / 1000;
old_val.value.sec = old_spec.value.tv_sec;
old_val.value.usec = old_spec.value.tv_nsec / 1000;
old_val.interval.sec = (dword_t)old_spec.interval.tv_sec;
old_val.interval.usec = (dword_t)old_spec.interval.tv_nsec / 1000;
old_val.value.sec = (dword_t)old_spec.value.tv_sec;
old_val.value.usec = (dword_t)old_spec.value.tv_nsec / 1000;
if (user_put(old_val_addr, old_val))
return _EFAULT;
}
Expand All @@ -176,7 +177,7 @@ uint_t sys_alarm(uint_t seconds) {
return err;

// Round up, and make sure to not return 0 if old_spec is > 0
seconds = old_spec.value.tv_sec;
seconds = (dword_t)old_spec.value.tv_sec;
if (old_spec.value.tv_nsec >= 500000000)
seconds++;
if (seconds == 0 && !timespec_is_zero(old_spec.value))
Expand All @@ -203,8 +204,8 @@ dword_t sys_nanosleep(addr_t req_addr, addr_t rem_addr) {
return errno_map();
if (rem_addr != 0) {
struct timespec_ rem_ts;
rem_ts.sec = rem.tv_sec;
rem_ts.nsec = rem.tv_nsec;
rem_ts.sec = (dword_t)rem.tv_sec;
rem_ts.nsec = (dword_t)rem.tv_nsec;
if (user_put(rem_addr, rem_ts))
return _EFAULT;
}
Expand Down Expand Up @@ -235,8 +236,8 @@ dword_t sys_gettimeofday(addr_t tv, addr_t tz) {
}
struct timeval_ tv_;
struct timezone_ tz_;
tv_.sec = timeval.tv_sec;
tv_.usec = timeval.tv_usec;
tv_.sec = (dword_t)timeval.tv_sec;
tv_.usec = (dword_t)timeval.tv_usec;
tz_.minuteswest = timezone.tz_minuteswest;
tz_.dsttime = timezone.tz_dsttime;
if ((tv && user_put(tv, tv_)) || (tz && user_put(tz, tz_))) {
Expand Down
24 changes: 19 additions & 5 deletions util/sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,17 @@ void modify_critical_region_counter(struct task *task, int value, __attribute__(
if(!task->critical_region.count && (value < 0)) { // Prevent our unsigned value attempting to go negative. -mke
//int skipme = strcmp(task->comm, "init");
//if((task->pid > 2) && (skipme != 0)) // Why ask why? -mke
printk("ERROR: Attempt to decrement critical_region count when it is already zero, ignoring(%s:%d) (%s:%d)\n", task->comm, task->pid, file, line);
if(task->pid > 10)
printk("ERROR: Attempt to decrement critical_region count when it is already zero, ignoring(%s:%d) (%s:%d)\n", task->comm, task->pid, file, line);
return;
}


if((strcmp(task->comm, "easter_egg") == 0) && ( !noprintk)) { // Extra logging for the some command
/* if((strcmp(task->comm, "easter_egg") == 0) && ( !noprintk)) { // Extra logging for the some command
noprintk = 1; // Avoid recursive logging -mke
printk("INFO: MCRC(%d(%s):%s:%d:%d:%d)\n", task->pid, task->comm, file, line, value, task->critical_region.count + value);
noprintk = 0;
}
} */

task->critical_region.count = task->critical_region.count + value;

Expand Down Expand Up @@ -139,7 +140,8 @@ int wait_for_ignore_signals(cond_t *cond, lock_t *lock, struct timespec *timeout
current->waiting_lock = NULL;
unlock(&current->waiting_cond_lock);
//return _ETIMEDOUT;
printk("ERROR: Locking PID is gone in wait_for_ignore_signals() (%s:%d). Attempting recovery\n", current->comm, current->pid);
if(!strcmp("go", current->comm)) // go causes this a lot. To no particularly positive effect -mke
printk("ERROR: Locking PID is gone in wait_for_ignore_signals() (%s:%d). Attempting recovery\n", current->comm, current->pid);
unlock(lock);
modify_critical_region_counter(current, -1,__FILE__, __LINE__);
return 0;
Expand All @@ -152,7 +154,11 @@ int wait_for_ignore_signals(cond_t *cond, lock_t *lock, struct timespec *timeout
if((lock->pid == -1) && (lock->comm[0] == 0)) { // Something has gone wrong. -mke
goto AGAIN; // Ugh. -mke
}
rc = pthread_cond_timedwait_relative_np(&cond->cond, &lock->m, &trigger_time);
if(lock->pid != -1) {
rc = pthread_cond_timedwait_relative_np(&cond->cond, &lock->m, &trigger_time);
} else {
return 0; // More Kludgery. -mke
}
if(rc == ETIMEDOUT) {
attempts++;
if(attempts <= 6) // We are likely deadlocked if more than ten attempts -mke
Expand Down Expand Up @@ -232,6 +238,14 @@ unsigned critical_region_count(struct task *task) {
unsigned critical_region_count_wrapper() { // sync.h can't know about the definition of struct due to recursive include files. -mke
return(critical_region_count(current));
}

bool current_is_valid(void) {
if(current != NULL)
return true;

return false;
}

unsigned locks_held_count(struct task *task) {
// return 0; // Short circuit for now
if(task->pid < 10) // Here be monsters. -mke
Expand Down
1 change: 1 addition & 0 deletions util/sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ extern void modify_critical_region_counter_wrapper(int, const char*, int);
extern unsigned locks_held_count_wrapper(void);
extern void modify_locks_held_count_wrapper(int);
extern struct pid *pid_get(dword_t id);
extern bool current_is_valid(void);

extern struct timespec lock_pause;

Expand Down

0 comments on commit 6cdefc1

Please sign in to comment.