Beispiel #1
0
void testSysSemaphoreErrors()
{
	sys_semaphore_t sem;              // Working semaphore
	sys_semaphore_t sem_f;            // Broken semaphore
	sys_semaphore_attribute_t attr;   // Initialized semaphore attribute
	sys_semaphore_attribute_t attr_z; // Zeroed semaphore attribute
	sys_semaphore_attribute_initialize(attr);
	memset(&attr_z, 0x00, sizeof(sys_semaphore_attribute_t));
	sys_semaphore_value_t val;

	// Create the working semaphore
	if (sys_semaphore_create(&sem, &attr, 0, 1)) {
		printf("[!] sys_semaphore_create: Something went wrong!\n");
		exit(-1);
	}

	// Error tests
	printf("[*] Checking sys_semaphore_create errors:\n");
	printf("sys_semaphore_create: max_val < 0 returns: 0x%x\n", sys_semaphore_create(&sem_f, &attr, 0, -1));
	printf("sys_semaphore_create: max_val == 0 returns: 0x%x\n", sys_semaphore_create(&sem_f, &attr, 0, 0));
	printf("sys_semaphore_create: initial_val < 0 returns: 0x%x\n", sys_semaphore_create(&sem_f, &attr, -1, 0));
	printf("sys_semaphore_create: initial_val > max_val returns: 0x%x\n", sys_semaphore_create(&sem_f, &attr, 2, 1));
	printf("sys_semaphore_create: &sem == NULL returns: 0x%x\n", sys_semaphore_create(NULL, &attr, 0, 1));
	printf("sys_semaphore_create: &attr == NULL returns: 0x%x\n", sys_semaphore_create(&sem_f, NULL, 0, 1));
	printf("sys_semaphore_create: uninitialized attr returns: 0x%x\n",  sys_semaphore_create(&sem_f, &attr_z, 0, 1));
	
	// Error tests
	printf("\n[*] Checking sys_semaphore_get_value errors:\n");
	printf("sys_semaphore_get_value: &val == NULL returns: 0x%x\n", sys_semaphore_get_value(sem, NULL));
	printf("sys_semaphore_get_value: failed semaphore id returns: 0x%x\n", sys_semaphore_get_value(sem_f, &val));
	printf("sys_semaphore_get_value: invalid semaphore id returns: 0x%x\n", sys_semaphore_get_value(NULL, &val));

	printf("\n[*] Checking sys_semaphore_wait errors:\n");
	printf("sys_semaphore_wait: short timeout returns: 0x%x\n", sys_semaphore_wait(sem, 1ULL));
	printf("sys_semaphore_wait: failed semaphore id returns: 0x%x\n", sys_semaphore_wait(sem_f, 0ULL));
	printf("sys_semaphore_wait: invalid semaphore id returns: 0x%x\n", sys_semaphore_wait(NULL, 0ULL));

	printf("\n[*] Checking sys_semaphore_trywait errors:\n");
	printf("sys_semaphore_trywait: semaphore value <= 0 returns: 0x%x\n", sys_semaphore_trywait(sem));
	printf("sys_semaphore_trywait: failed semaphore id returns: 0x%x\n", sys_semaphore_trywait(sem_f));
	printf("sys_semaphore_trywait: invalid semaphore id returns: 0x%x\n", sys_semaphore_trywait(NULL));

	printf("\n[*] Checking sys_semaphore_post errors:\n");
	printf("sys_semaphore_post: failed semaphore id returns: 0x%x\n", sys_semaphore_post(sem_f, 0));
	printf("sys_semaphore_post: invalid semaphore id returns: 0x%x\n", sys_semaphore_post(NULL, 0));
	printf("sys_semaphore_post: val < 0 returns: 0x%x\n", sys_semaphore_post(sem, -1));
	printf("sys_semaphore_post: val > max_val returns: 0x%x\n", sys_semaphore_post(sem, 2));
	
	// Destroy the working semaphore
	if (sys_semaphore_destroy(sem)) {
		printf("[!] sys_semaphore_destroy: Something went wrong!\n");
		exit(-1);
	}

	// More error tests
	printf("\n[*] Checking sys_semaphore_destroy errors:\n");
	printf("sys_semaphore_destroy: failed semaphore id returns: 0x%x\n", sys_semaphore_destroy(sem_f));
	printf("sys_semaphore_destroy: invalid semaphore id returns: 0x%x\n", sys_semaphore_destroy(NULL));
	printf("sys_semaphore_destroy: destroyed semaphore id returns: 0x%x\n", sys_semaphore_destroy(sem));
}
Beispiel #2
0
void semPost(uint64_t arg) {
	sys_timer_sleep(1);
	if (sys_semaphore_post(g_sem, arg) & ~0x8001000A) {
		printf("[!] sys_semaphore_post: Something went wrong!\n");
		exit(-1);
	}
	sys_ppu_thread_exit(0);
}
Beispiel #3
0
void					CellSemaphore::Post				()
{
	sys_semaphore_post(Semaphore, 1);
}