Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#90 closed defect (fixed)

Crash on complex nesting

Reported by: Thierry Delisle Owned by: Rob Schluntz <rschlunt@…>
Priority: major Component: cfa-cc
Version: 1.0 Keywords:
Cc:

Description

This code craches the compiler:

#include <stddef.h>

struct thread_desc{};
struct __spinlock_t{};

enum FinishOpCode { No_Action, Release, Schedule, Release_Schedule, Release_Multi, Release_Multi_Schedule, Callback };

typedef void (*__finish_callback_fptr_t)(void);

//TODO use union, many of these fields are mutually exclusive (i.e. MULTI vs NOMULTI)
struct FinishAction {
	FinishOpCode action_code;
	//*
	// Union of possible actions
	union {
		// Option 1 : locks and threads
		struct {
			// 1 thread or N thread
			union {
				thread_desc * thrd;
				struct {
					thread_desc ** thrds;
					unsigned short thrd_count;
				};
			};
			// 1 lock or N lock
			union {
				__spinlock_t * lock;
				struct {
					__spinlock_t ** locks;
					unsigned short lock_count;
				};
			};
		};
		// Option 2 : action pointer
		__finish_callback_fptr_t callback;
	};
	/*/
	thread_desc * thrd;
	thread_desc ** thrds;
	unsigned short thrd_count;
	__spinlock_t * lock;
	__spinlock_t ** locks;
	unsigned short lock_count;
	__finish_callback_fptr_t callback;
	//*/
};
static inline void ?{}(FinishAction & this) {
	this.action_code = No_Action;
	this.thrd = NULL;
	this.lock = NULL;
}
static inline void ^?{}(FinishAction & this) {}

struct processor {
	FinishAction finish;
};

void finishRunning(processor * this) with( this->finish ) {
	verify( ! kernelTLS.preemption_state.enabled );
	choose( action_code ) {
	case No_Action:
		break;
	case Release:
		unlock( *lock );
	case Schedule:
		ScheduleThread( thrd );
	case Release_Schedule:
		unlock( *lock );
		ScheduleThread( thrd );
	case Release_Multi:
		for(int i = 0; i < lock_count; i++) {
			unlock( *locks[i] );
		}
	case Release_Multi_Schedule:
		for(int i = 0; i < lock_count; i++) {
			unlock( *locks[i] );
		}
		for(int i = 0; i < thrd_count; i++) {
			ScheduleThread( thrds[i] );
		}
	case Callback:
		callback();
	default:
		abort("KERNEL ERROR: Unexpected action to run after thread");
	}
}

Change History (3)

comment:1 Changed 6 years ago by Rob Schluntz <rschlunt@…>

Owner: set to Rob Schluntz <rschlunt@…>
Resolution: fixed
Status: newclosed

In 5de1e2c:

Fix memory error from caused by vector::push_back [fixes #90]

comment:2 Changed 6 years ago by Rob Schluntz <rschlunt@…>

In 5de1e2c:

Fix memory error from caused by vector::push_back [fixes #90]

comment:3 Changed 6 years ago by Rob Schluntz <rschlunt@…>

In 5de1e2c:

Fix memory error from caused by vector::push_back [fixes #90]

Note: See TracTickets for help on using tickets.