コード例 #1
0
ファイル: dispatch.c プロジェクト: Raimoo/pspautotests
void checkSema(int doDispatch) {
	SceUID sema = sceKernelCreateSema("sema", 0, 0, 1, NULL);
	dispatchCheckpoint("sceKernelCreateSema: %08x", sema >= 0 ? 1 : sema);
	dispatchCheckpoint("sceKernelSignalSema: %08x", sceKernelSignalSema(sema, 1));
	dispatchCheckpoint("sceKernelWaitSema: %08x", sceKernelWaitSema(sema, 1, NULL));
	dispatchCheckpoint("sceKernelWaitSema too much: %08x", sceKernelWaitSema(sema, 9, NULL));
	dispatchCheckpoint("sceKernelDeleteSema: %08x", sceKernelDeleteSema(sema));
	sema = sceKernelCreateSema("test", 0, 1, 2, NULL);
	dispatchCheckpoint("sceKernelCreateSema: %08x", sema >= 0 ? 1 : sema);
	startLockThreadSema(sema);
	int state;
	if (doDispatch) {
		++ignoreResched;
		state = sceKernelSuspendDispatchThread();
		dispatchCheckpoint("sceKernelSuspendDispatchThread: %08x", state);
	}
	SceUInt timeout = 300;
	dispatchCheckpoint("sceKernelWaitSema: %08x", sceKernelWaitSema(sema, 1, &timeout));
	dispatchCheckpoint("sceKernelSignalSema: %08x", sceKernelSignalSema(sema, 1));
	if (doDispatch) {
		dispatchCheckpoint("sceKernelResumeDispatchThread: %08x", sceKernelResumeDispatchThread(state));
		--ignoreResched;
	}
	endLockThreadSema(sema);
	dispatchCheckpoint("sceKernelPollSema: %08x", sceKernelPollSema(sema, 1));
	dispatchCheckpoint("sceKernelDeleteSema: %08x", sceKernelDeleteSema(sema));
}
コード例 #2
0
ファイル: pmp_play.c プロジェクト: DavisDev/pmplayer-advance
static int pmp_wait(volatile struct pmp_play_struct *p, SceUID s, char *e)
	{
	SceUInt t = 1000000;
	

	while (1)
		{
		int result = sceKernelWaitSema(s, 1, &t);

		if (result == SCE_KERNEL_ERROR_OK)
			{
			break;
			}
		else if (result == SCE_KERNEL_ERROR_WAIT_TIMEOUT)
			{
			sceKernelDelayThread(1);

			if (p->return_request == 1)
				{
				return(0);
				}
			}
		else
			{
			p->return_result  = e;
			p->return_request = 1;
			return(0);
			}
		}


	return(1);
	}
コード例 #3
0
ファイル: ddrdb.c プロジェクト: fanzzbbs/uofw
/* Subroutine sceDdrdb_driver_B8218473 - Address 0x000028D8 */
s32 sceDdrdbPrngen(u8 *pDstData) 
{
    s32 status;
    s32 tmpStatus;
    u32 i;

    status = SCE_DNAS_ERROR_OPERATION_FAILED; //0x000028FC
    
    status = sceKernelWaitSema(g_semaId, 1, NULL); //0x00002908
    if (status != SCE_ERROR_OK)
        return SCE_ERROR_SEMAPHORE;

    /* Compute a pseudorandom number. */
    tmpStatus = sceUtilsBufferCopyWithRange(g_pWorkData, KIRK_PRN_LEN, NULL, 0, KIRK_CMD_PRN_GEN); //0x00002950
    if (tmpStatus == SCE_ERROR_OK) { //0x00002958

        /* Copy computed number into provided buffer. */
        for (i = 0; i < KIRK_PRN_LEN; i++) //0x00002960 - 0x00002980
            pDstData[i] = g_pWorkData[i]; //0x00002980

        status = SCE_ERROR_OK;
    }
    
    /* Clear the work area. */
    for (i = 0; i < KIRK_PRN_LEN; i++) // 0x00002988 - 0x000029A0
        g_pWorkData[i] = 0; 

    tmpStatus = sceKernelSignalSema(g_semaId, 1); //0x000029A8
    return (tmpStatus != SCE_ERROR_OK) ? SCE_ERROR_SEMAPHORE : status; //0x000029B0 - 0x000029BC
}
コード例 #4
0
ファイル: SDL_syssem.c プロジェクト: GWRon/sdl.mod
/* TODO: This routine is a bit overloaded.
 * If the timeout is 0 then just poll the semaphore; if it's SDL_MUTEX_MAXWAIT, pass
 * NULL to sceKernelWaitSema() so that it waits indefinitely; and if the timeout
 * is specified, convert it to microseconds. */
int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
{
    Uint32 *pTimeout;
    int res;

    if (sem == NULL) {
        SDL_SetError("Passed a NULL sem");
        return 0;
    }

    if (timeout == 0) {
        res = sceKernelPollSema(sem->semid, 1);
        if (res < 0) {
            return SDL_MUTEX_TIMEDOUT;
        }
        return 0;
    }

    if (timeout == SDL_MUTEX_MAXWAIT) {
        pTimeout = NULL;
    } else {
        timeout *= 1000;  /* Convert to microseconds. */
        pTimeout = &timeout;
    }

    res = sceKernelWaitSema(sem->semid, 1, pTimeout);
       switch (res) {
               case SCE_KERNEL_ERROR_OK:
                       return 0;
               case SCE_KERNEL_ERROR_WAIT_TIMEOUT:
                       return SDL_MUTEX_TIMEDOUT;
               default:
                       return SDL_SetError("sceKernelWaitSema() failed");
    }
}
コード例 #5
0
ファイル: ddrdb.c プロジェクト: fanzzbbs/uofw
/* Subroutine sceDdrdb_driver_370F456A - Address 0x00002494 */
s32 sceDdrdbCertvry(u8 *pCert) 
{
    s32 status;
    s32 tmpStatus;
    u32 i;
    
    status = sceKernelWaitSema(g_semaId, 1, NULL); //0x000024C4
    if (status != SCE_ERROR_OK)
        return SCE_ERROR_SEMAPHORE; 

    /* Set up the work area. */
    for (i = 0; i < KIRK_CERT_LEN; i++) //0x000024D4 & 0x000024F4
        g_pWorkData[i] = pCert[i]; //0x000024F4

    /* Verify the provided certificate. */
    tmpStatus = sceUtilsBufferCopyWithRange(NULL, 0, g_pWorkData, KIRK_CERT_LEN, KIRK_CMD_CERT_VER); //0x0000250C
    status = (tmpStatus != SCE_ERROR_OK) ? SCE_DNAS_ERROR_OPERATION_FAILED : SCE_ERROR_OK; //0x00002510 - 0x00002518

    /* Clear the work area. */
    for (i = 0; i < KIRK_CERT_LEN; i++) //0x0000251C - 0x00002534
        g_pWorkData[i] = 0;

    tmpStatus = sceKernelSignalSema(g_semaId, 1); //0x0000253C
    return (tmpStatus != SCE_ERROR_OK) ? SCE_ERROR_SEMAPHORE : status;
}
コード例 #6
0
ファイル: ddrdb.c プロジェクト: fanzzbbs/uofw
/* Subroutine sceDdrdb_driver_E27CE4CB - Address 0x00002358 */
s32 sceDdrdbSigvry(u8 *pPubKey, u8 *pData, u8 *pSig) 
{
    s32 status;
    s32 tmpStatus;
    SceSize workSize;
    u32 i;
    
    tmpStatus = sceKernelWaitSema(g_semaId, 1, NULL); // 0x00002398
    if (tmpStatus != SCE_ERROR_OK)
        return SCE_ERROR_SEMAPHORE;

    /* Set up the work area. */
    for (i = 0; i < KIRK_ECDSA_PUBLIC_KEY_LEN; i++) // 0x000023AC - 0x000023C8
        g_pWorkData[i] = pPubKey[i]; // 0x000023C8

    for (i = 0; i < KIRK_ECDSA_SRC_DATA_LEN; i++) // 0x000023CC - 0x000023EC
        g_pWorkData[KIRK_ECDSA_PUBLIC_KEY_LEN + i] = pData[i]; // 0x000023EC

    for (i = 0; i < KIRK_ECDSA_SIG_LEN; i++) // 0x000023CC - 0x000023EC
        g_pWorkData[KIRK_ECDSA_PUBLIC_KEY_LEN + KIRK_ECDSA_SRC_DATA_LEN + i] = pSig[i]; // 0x00002410

    workSize = KIRK_ECDSA_PUBLIC_KEY_LEN + KIRK_ECDSA_SRC_DATA_LEN + KIRK_ECDSA_SIG_LEN;

    /* Verify the provided signature. */
    tmpStatus = sceUtilsBufferCopyWithRange(NULL, 0, g_pWorkData, workSize, KIRK_CMD_SIG_VER_ECDSA); //0x00002428
    status = (tmpStatus != SCE_ERROR_OK) ? SCE_DNAS_ERROR_OPERATION_FAILED : SCE_ERROR_OK; //0x0000242C - 0x00002434

    /* Clear the work area. */
    for (i = 0; i < workSize; i++) //0x00002438 - 0x00002450
        g_pWorkData[i] = 0;

    tmpStatus = sceKernelSignalSema(g_semaId, 1); //0x00002458
    return (tmpStatus != SCE_ERROR_OK) ? SCE_ERROR_SEMAPHORE : status; //0x00002460 - 0x00002468
}
コード例 #7
0
ファイル: ddrdb.c プロジェクト: fanzzbbs/uofw
/* Subroutine sceDdrdb_driver_F970D54E - Address 0x00002570 */
s32 sceDdrdbMul1(u8 *pKeyData) 
{
    s32 status;
    s32 tmpStatus;
    SceSize workSize;
    u32 i;
    
    tmpStatus = sceKernelWaitSema(g_semaId, 1, NULL); //0x000025A0
    if (tmpStatus != SCE_ERROR_OK)
        return SCE_ERROR_SEMAPHORE;

    status = SCE_DNAS_ERROR_OPERATION_FAILED; // 0x00002598
    workSize = KIRK_ECDSA_PUBLIC_KEY_LEN + KIRK_ECDSA_PRIVATE_KEY_LEN;

    /* Compute a (public, private) key pair. */
    tmpStatus = sceUtilsBufferCopyWithRange(g_pWorkData, workSize, NULL, 0, KIRK_CMD_KEY_GEN_ECDSA); //0x000025E8
    if (tmpStatus == SCE_ERROR_OK) { // 0x000025F0

        /* Copy the computed key pair into the provided buffer. */
        for (i = 0; i < workSize; i++) // 0x000025F8 & 0x00002618
            pKeyData[i] = g_pWorkData[i]; //0x00002618

        status = SCE_ERROR_OK;
    }

    /* Clear the work area. */
    for (i = 0; i < workSize; i++) // 0x00002620 - 0x00002638
        g_pWorkData[i] = 0;

    tmpStatus = sceKernelSignalSema(g_semaId, 1); //0x00002640
    return (tmpStatus != SCE_ERROR_OK) ? SCE_ERROR_SEMAPHORE : status; //0x00002648 & 0x0000264C & 0x00002654
}
コード例 #8
0
ファイル: threadmgr.c プロジェクト: himanshugoel2797/VHL
int terminateDeleteAllUserThreads()
{
        SceKernelSemaInfo semaInfo;
        SceKernelThreadInfo threadInfo;
        globals_t *globals;
        int res;

        globals = getGlobals();
        sceKernelLockMutex(globals->threadmgrMutex, 1, NULL);

        semaInfo.size = sizeof(semaInfo);
        res = sceKernelGetSemaInfo(globals->threadmgrSema, &semaInfo);
        if (res)
                return res;

        while (semaInfo.currentCount < semaInfo.maxCount) {
                res = sceKernelGetThreadInfo(globals->threadmgrTable[semaInfo.currentCount].uid, &threadInfo);
                if (res == 0 && (threadInfo.status == PSP2_THREAD_STOPPED
                                  || threadInfo.status == PSP2_THREAD_KILLED))
                        sceKernelDeleteThread(globals->threadmgrTable[semaInfo.currentCount].uid);
                else
                        sceKernelNotifyCallback(globals->threadmgrTable[semaInfo.currentCount].exitDeleteCb, 0);

                semaInfo.currentCount++;
        }

        sceKernelUnlockMutex(globals->threadmgrMutex, 1);

        sceKernelWaitSema(globals->threadmgrSema, MAX_THREADS_NUM, NULL);
        sceKernelSignalSema(globals->threadmgrSema, MAX_THREADS_NUM);

        return 0;
}
コード例 #9
0
ファイル: dispatch.c プロジェクト: Raimoo/pspautotests
int lockThreadSema(SceSize argc, void *argp) {
	SceUID sema = *(SceUID *)argp;
	dispatchCheckpoint("T sceKernelWaitSema: %08x", sceKernelWaitSema(sema, 2, NULL));
	dispatchCheckpoint("T sceKernelDelayThread: %08x", sceKernelDelayThread(3000));
	dispatchCheckpoint("T sceKernelSignalSema: %08x", sceKernelSignalSema(sema, 1));
	return 0;
}
コード例 #10
0
ファイル: kermit.c プロジェクト: DaveeFTW/vita_kermit
int sceKermit_driver_9160841C(int pin_n, int allow_callbacks)
{
	/* lock the power source, no shutdown */
	int res = sceKernelPowerLock(0);
	
	/* check if valid */
	if (res == 0)
	{
		/* wait? */
		sub_00000908();
		
		/* suspend interrupts */
		int intr = sceKernelCpuSuspendIntr();
		
		PIN_HIGH(0xBC300038, pin_n);
		PIN_LOW(0xBC300050, pin_n);
		PIN_HIGH(0xBC300050, pin_n);
		
		/* resume all the interrupts */
		sceKernelCpuResumeIntr(intr);
		
		/* wait on work sema */
		if (allow_callbacks)	sceKernelWaitSemaCB(g_work_sema[pin_n], 1, NULL);
		else					sceKernelWaitSema(g_work_sema[pin_n], 1, NULL);
		
		/* unlock power */
		res = sceKernelPowerUnlock(0);
		
		/* resolve +ve res to 0 */
		if (res > 0) res = 0;
	}
	
	/* return the result */
	return res;
}
コード例 #11
0
static int streamThread(unsigned int args, void* arg){

	int vol, dec_vol;

	for(;;) {

		// A pretty bad way to close thread
		if(termStream){
			termStream = false;
			if (bgm_chn != 0xDEAD){
				sceAudioOutReleasePort(bgm_chn);
				bgm_chn = 0xDEAD;
			}
			sceKernelExitDeleteThread(0);
		}

		sceKernelWaitSema(BGM_Mutex, 1, NULL);
		if (BGM == NULL || (!BGM->isPlaying)){
			sceKernelSignalSema(BGM_Mutex, 1);
			continue;
		}

		// Seems like audio ports are thread dependant on PSVITA :/
		if (BGM->isNewTrack){
			uint8_t audio_mode = BGM->isStereo ? SCE_AUDIO_OUT_MODE_STEREO : SCE_AUDIO_OUT_MODE_MONO;
			int nsamples = AUDIO_BUFSIZE / ((audio_mode+1)<<1);
			if (bgm_chn == 0xDEAD) bgm_chn = sceAudioOutOpenPort(SCE_AUDIO_OUT_PORT_TYPE_MAIN, nsamples, 48000, audio_mode);
			sceAudioOutSetConfig(bgm_chn, nsamples, 48000, audio_mode);
			vol = BGM->vol * 327;
			int vol_stereo[] = {vol, vol};
			sceAudioOutSetVolume(bgm_chn, SCE_AUDIO_VOLUME_FLAG_L_CH | SCE_AUDIO_VOLUME_FLAG_R_CH, vol_stereo);
			BGM->isNewTrack = false;
		}

		// Volume changes support
		dec_vol = audio_decoder->GetVolume();
		if (dec_vol != vol){
			vol = dec_vol * 327;
			int vol_stereo[] = {vol, vol};
			sceAudioOutSetVolume(bgm_chn, SCE_AUDIO_VOLUME_FLAG_L_CH | SCE_AUDIO_VOLUME_FLAG_R_CH, vol_stereo);
			vol = dec_vol;
		}


		// Audio streaming feature
		if (BGM->handle != NULL){
			if (BGM->cur_audiobuf == BGM->audiobuf) BGM->cur_audiobuf = BGM->audiobuf2;
			else BGM->cur_audiobuf = BGM->audiobuf;
			audio_decoder->Decode(BGM->cur_audiobuf, AUDIO_BUFSIZE);
			if (audio_decoder->GetLoopCount() > 0){ // EoF
				BGM->endedOnce = true;
			}
			int res = sceAudioOutOutput(bgm_chn, BGM->cur_audiobuf);
			if (res < 0) Output::Error("An error occurred in audio thread (0x%lX)", res);
		}

		sceKernelSignalSema(BGM_Mutex, 1);

	}
}
コード例 #12
0
ファイル: cd_psp2.cpp プロジェクト: Rinnegatamante/vitaQuake
void CDAudio_Stop(void)
{
	if (BGM != NULL){
		BGM->closeTrigger = true;
		BGM->pauseTrigger = true;
		sceKernelWaitSema(Talk_Mutex, 1, NULL);
	}
}
コード例 #13
0
ファイル: nodrm.c プロジェクト: AnnaKozlowska/procfw
static inline void lock(void)
{
	u32 k1;

	k1 = pspSdkSetK1(0);
	sceKernelWaitSema(g_nodrm_sema, 1, 0);
	pspSdkSetK1(k1);
}
コード例 #14
0
ファイル: fifo.cpp プロジェクト: achurch/pspautotests
int thread1(SceSize argc, void *argv) {
	SceUInt t = 200;

	checkpoint("thread1 start");
	int result = sceKernelWaitSema(sema, 5, &t);
	checkpoint("thread1 end: %08x", result);

	return 0;
}
コード例 #15
0
int main(int argc, char **argv) {
	SceUID sema = sceKernelCreateSema("wait1", 0, 1, 1, NULL);

	WAIT_TEST_SIMPLE("Signaled", sema, 1);
	WAIT_TEST_SIMPLE("Greater than max", sema, 100);
	WAIT_TEST_SIMPLE("Negative", sema, -1);

	sceKernelSignalSema(sema, 1);
	WAIT_TEST_SIMPLE_TIMEOUT("Signaled", sema, 1, 500);
	WAIT_TEST_SIMPLE_TIMEOUT("Never signaled", sema, 1, 500);
	WAIT_TEST_SIMPLE_TIMEOUT("Greater than max", sema, 100, 500);
	WAIT_TEST_SIMPLE_TIMEOUT("Zero", sema, 0, 500);
	WAIT_TEST_SIMPLE_TIMEOUT("Negative", sema, -1, 500);
	WAIT_TEST_SIMPLE_TIMEOUT("Zero timeout", sema, 1, 0);
	
	// Signaled off thread.
	printf("Wait timeout: ");
	schedulingPlacement = 1;
	SCHED_LOG(A, 1);
	SceUInt timeout = 5000;
	SceUID thread = sceKernelCreateThread("waitTest", (void *)&waitTestFunc, 0x12, 0x10000, 0, NULL);
	sceKernelStartThread(thread, sizeof(int), &sema);
	SCHED_LOG(B, 1);
	int result = sceKernelWaitSema(sema, 1, &timeout);
	SCHED_LOG(E, 1);
	schedf(" (thread=%08X, main=%08X, remaining=%d)\n", schedulingResult, result, timeout / 1000);
	flushschedf();

	sceKernelDeleteSema(sema);

	SceUID deleteThread = CREATE_SIMPLE_THREAD(deleteMeFunc);
	sema = sceKernelCreateSema("wait1", 0, 0, 1, NULL);
	sceKernelStartThread(deleteThread, sizeof(int), &sema);
	sceKernelDelayThread(500);
	sceKernelDeleteSema(sema);
	flushschedf();

	WAIT_TEST_SIMPLE("NULL", 0, 1);
	WAIT_TEST_SIMPLE("Invalid", 0xDEADBEEF, 1);
	WAIT_TEST_SIMPLE("Deleted", sema, 1);
	
	BASIC_SCHED_TEST("NULL",
		result = sceKernelWaitSema(0, 1, NULL);
	);
コード例 #16
0
ファイル: MusicEngine.c プロジェクト: Oize/pspstacklesspython
int Load(const char* musicfile) {
    endofstream = 0;                      // set the endofsong flag to 0.
	sceKernelWaitSema(mutex, 1, 0);		// wait for thread to be open.
	sprintf(Song, "%s", musicfile);		// Song is not used by another thread so we can change it
	SongIsChanged = 1;					// Mark status that the song is changed
	sceKernelSignalSema(mutex, 1);		// free the lock of this thread.
	printf("Music file %s loaded.\n", Song);

	return 1;
};
コード例 #17
0
ファイル: psp2_ui.cpp プロジェクト: EasyRPG/Player
static int renderThread(unsigned int args, void* arg){
	
	for (;;){
	
		sceKernelWaitSema(GPU_Mutex, 1, NULL);
		memcpy(vita2d_texture_get_datap(gpu_texture), vita2d_texture_get_datap(next_texture), vita2d_texture_get_stride(gpu_texture)*240);
		sceKernelSignalSema(GPU_Mutex, 1);
		
		sceKernelWaitSema(GPU_Cleanup_Mutex, 1, NULL);
		
		if (main_texture == NULL) sceKernelExitDeleteThread(0); // Exit procedure
		
		vita2d_start_drawing();
   
		if (set_shader){
			Output::Post("Shader set to %s.",shader_names[in_use_shader]);
			set_shader = false;
			vita2d_texture_set_program(shaders[in_use_shader]->vertexProgram, shaders[in_use_shader]->fragmentProgram);
			vita2d_texture_set_wvp(shaders[in_use_shader]->wvpParam);
			vita2d_texture_set_vertexInput(&shaders[in_use_shader]->vertexInput);
			vita2d_texture_set_fragmentInput(&shaders[in_use_shader]->fragmentInput);
		}
   
		vita2d_clear_screen();
		switch (zoom_state){
			case 0: // 640x480
				vita2d_draw_texture_scale(gpu_texture, 160, 32, 2.0, 2.0);
				break;
			case 1: // 725x544
				vita2d_draw_texture_scale(gpu_texture, 117, 0, 2.266, 2.266);
				break;
			case 2: // 960x544
				vita2d_draw_texture_scale(gpu_texture, 0, 0, 3, 2.266);
				break;
		}
		vita2d_end_drawing();
		vita2d_wait_rendering_done();
		vita2d_swap_buffers();
		sceKernelSignalSema(GPU_Cleanup_Mutex, 1);
	
	}
	
}
コード例 #18
0
ファイル: stdio.c プロジェクト: 173210/psplink
static int io_read(PspIoDrvFileArg *arg, char *data, int len)
{
	int ret = 0;

	(void) sceKernelWaitSema(g_in_sema, 1, 0);
	if((arg->fs_num == STDIN_FILENO) && (g_stdin_handler != NULL))
	{
		ret = g_stdin_handler(data, len);
	}
	(void) sceKernelSignalSema(g_in_sema, 1);

	return ret;
}
コード例 #19
0
ファイル: ddrdb.c プロジェクト: fanzzbbs/uofw
/* Subroutine sceDdrdb_driver_40CB752A - Address 0x000029C0 */
s32 sceDdrdbHash(u8 *pSrcData, SceSize size, u8 *pDigest) 
{
    s32 status;
    s32 tmpStatus;
    SceSize workSize;
    u32 i;
    
    tmpStatus = sceKernelWaitSema(g_semaId, 1, NULL); //0x00002A04
    if (tmpStatus != SCE_ERROR_OK)
        return SCE_ERROR_SEMAPHORE;

    workSize = size + sizeof(KirkSHA1Hdr); //0x00002A20
    if (size <= SCE_DNAS_USER_DATA_MAX_LEN) { //0x00002A1C

        /* Set up the work area for KIRK. */
        KirkSHA1Hdr *pSha1Hdr = (KirkSHA1Hdr *)g_pWorkData;
        pSha1Hdr->dataSize = size; // 0x00002A28 
        
        /* Copy data used for hash computation to work area. */
        u8 *pData = g_pWorkData + sizeof(KirkSHA1Hdr);
        for (i = 0; i < size; i++)
            pData[i] = pSrcData[i]; //0x00002A54

        workSize = size + sizeof(KirkSHA1Hdr); //0x00002A5C
        status = SCE_DNAS_ERROR_OPERATION_FAILED; //0x00002A74 & 0x00002A7C

        /* Compute the SHA-1 hash value of the specified data. */
        tmpStatus = sceUtilsBufferCopyWithRange(g_pWorkData, KIRK_SHA1_DIGEST_LEN, g_pWorkData, workSize, KIRK_CMD_HASH_GEN_SHA1); //0x00002A70
        if (tmpStatus == SCE_ERROR_OK) { //0x00002A9C

            /* Copy hash value into provided buffer. */
            for (i = 0; i < KIRK_SHA1_DIGEST_LEN; i++) //0x00002A80 - 0x00002AA0
                pDigest[i] = g_pWorkData[i];

            status = SCE_ERROR_OK; //0x00002AA4
        }
    }

    /* Clear at least <KIRK_SHA1_DIGEST_LEN> bits of the working area. */
    for (i = 0; i < KIRK_SHA1_DIGEST_LEN; i++) // 0x00002AAC
        g_pWorkData[i] = 0; //0x00002B30

    /* Use casts here to handle potential underflow situation. */
    for (i = 0; (s32)i < (s32)(workSize - KIRK_SHA1_DIGEST_LEN); i++) // 0x00002B1C - 0x00002B30
        g_pWorkData[KIRK_SHA1_DIGEST_LEN + i] = 0;

    tmpStatus = sceKernelSignalSema(g_semaId, 1); //0x00002AD4
    return (tmpStatus != SCE_ERROR_OK) ? SCE_ERROR_SEMAPHORE : tmpStatus; //0x00002ADC & 0x00002AE0 & 0x00002AE4
}
コード例 #20
0
ファイル: main.c プロジェクト: bensaraceno/PSP
int ball_thread(int size, Ball *b) {
	int inPlay = 1;
	// Loop until game ends or until ball is no longer in play.
	while (_gameState != GAME_OVER && inPlay) {
		if (_gameState == GAME_PAUSED) {
			sceKernelWaitSema(_pauseSem, 1, 0); // Block on semaphore
			sceKernelSignalSema(_pauseSem, 1); // Once awake, signal semaphore so next in line wakes up 
		}
		inPlay = DrawBall(b);
		sceKernelDelayThread(10000);
	}
	_activeBalls[b->ballId] = 0; // Remove this ball from array of active balls
	sceKernelExitThread(0);
	return 0;
}
コード例 #21
0
ファイル: psp2_ui.cpp プロジェクト: EasyRPG/Player
Psp2Ui::~Psp2Ui() {
	sceKernelWaitSema(GPU_Cleanup_Mutex, 1, NULL);
	for (int i = 0; i < SHADERS_NUM; i++){
		vita2d_free_shader(shaders[i]);
	}
	vita2d_free_texture(main_texture);
	main_texture = NULL;
	sceKernelSignalSema(GPU_Cleanup_Mutex, 1);
	sceKernelWaitThreadEnd(GPU_Thread, NULL, NULL);
	vita2d_free_texture(next_texture);
	vita2d_free_texture(gpu_texture);
	sceKernelDeleteSema(GPU_Mutex);
	sceKernelDeleteSema(GPU_Cleanup_Mutex);
	vita2d_fini();
}
コード例 #22
0
ファイル: ddrdb.c プロジェクト: fanzzbbs/uofw
// Name: sceDdrdbSigvryForUser ?
s32 sceDdrdb_F013F8BF(u8 *pData, u8 *pSig) 
{
    s32 status;
    s32 tmpStatus;
    SceSize workSize;
    s32 oldK1;
    u32 i;
    
    oldK1 = pspShiftK1();

    /* Check if the provided buffers are located in userland. */
    if (!pspK1StaBufOk(pData, KIRK_SHA1_DIGEST_LEN) || !pspK1StaBufOk(pSig, KIRK_ECDSA_SIG_LEN)) { // 0x00002E68 & 0x00002E7C
        pspSetK1(oldK1);
        return SCE_ERROR_PRIV_REQUIRED;
    }
         
    tmpStatus = sceKernelWaitSema(g_semaId, 1, NULL); //0x00002EC4
    if (tmpStatus != SCE_ERROR_OK) {
        pspSetK1(oldK1);
        return SCE_ERROR_SEMAPHORE;
    }

    /* Set up the work area. */
    for (i = 0; i < KIRK_ECDSA_PUBLIC_KEY_LEN; i++) // 0x00002ED4 - 0x00002F00
        g_pWorkData[i] = g_pubKeySigForUser[i]; // 0x00002F00

    for (i = 0; i < KIRK_SHA1_DIGEST_LEN; i++) //0x00002F04 - 0x00002F24
        g_pWorkData[KIRK_ECDSA_PUBLIC_KEY_LEN + i] = pData[i];

    for (i = 0; i < KIRK_ECDSA_SIG_LEN; i++) //0x00002F28 - 0x00002F48
        g_pWorkData[KIRK_ECDSA_PUBLIC_KEY_LEN + KIRK_SHA1_DIGEST_LEN + i] = pSig[i]; //0x00002F48

    workSize = KIRK_ECDSA_PUBLIC_KEY_LEN + KIRK_SHA1_DIGEST_LEN + KIRK_ECDSA_SIG_LEN;

    /* Verify the provided signature. */
    tmpStatus = sceUtilsBufferCopyWithRange(NULL, 0, g_pWorkData, workSize, KIRK_CMD_SIG_VER_ECDSA); //0x00002F60
    status = (tmpStatus != SCE_ERROR_OK) ? SCE_ERROR_INVALID_VALUE : SCE_ERROR_OK; //0x00002F64 - 0x00002F6C
    
    /* Clear the work area. */
    for (i = 0; i < workSize; i++) //0x00002F70 - 0x00002F88
        g_pWorkData[i] = 0; //0x00002F88

    tmpStatus = sceKernelSignalSema(g_semaId, 1); //0x00002F90

    pspSetK1(oldK1);
    return (tmpStatus != SCE_ERROR_OK) ? SCE_ERROR_SEMAPHORE : status; //0x00002F98 - 0x00002FA4
}
コード例 #23
0
ファイル: stdio.c プロジェクト: 173210/psplink
static int io_write(PspIoDrvFileArg *arg, const char *data, int len)
{
	int ret = 0;

	(void) sceKernelWaitSema(g_out_sema, 1, 0);
	if((arg->fs_num == STDOUT_FILENO) && (g_stdout_handler != NULL))
	{
		ret = g_stdout_handler(data, len);
	}
	else if((arg->fs_num == STDERR_FILENO) && (g_stderr_handler != NULL))
	{
		ret = g_stderr_handler(data, len);
	}
	(void) sceKernelSignalSema(g_out_sema, 1);

	return ret;
}
コード例 #24
0
ファイル: Memory.cpp プロジェクト: Fighter19/PSPMania
static void LockAlloc()
{
	if( g_Mutex < 0 )
		InitAlloc();

	SceUID thid = sceKernelGetThreadId();

	if( thid != g_MutexOwner )
	{
		sceKernelWaitSema( g_Mutex, 1, NULL );
		g_MutexOwner = thid;
	}
	else
	{
		g_MutexCount++;
	}
}
コード例 #25
0
ファイル: mutexutils.c プロジェクト: mafu9/dxlibp-kai
int dxpMutexLock(DXPMUTEX *pHnd, int tryFlag)
{
	int ret;
	const SceUID thid = sceKernelGetThreadId();
	if(thid != pHnd->ownerThid)
	{
		SceUInt timeout = 0;
		ret = sceKernelWaitSema(pHnd->semaid, 1, tryFlag ? &timeout : NULL);
		pHnd->ownerThid = thid;
	}
	else
	{
		pHnd->count++;
		ret = 0;
	}
	return ret;
}
コード例 #26
0
ファイル: ddrdb.c プロジェクト: fanzzbbs/uofw
/* Subroutine sceDdrdb_driver_EC05300A - Address 0x00002658 */
s32 sceDdrdbMul2(u8 *pPrivKey, u8 *pBasePoint, u8 *pNewPoint) 
{
    s32 status;
    s32 tmpStatus;
    SceSize workSize;
    u32 i;
    
    tmpStatus = sceKernelWaitSema(g_semaId, 1, NULL); // 0x00002698
    if (tmpStatus != SCE_ERROR_OK)
        return SCE_ERROR_SEMAPHORE;

    /* Set up the work area. */
    for (i = 0; i < KIRK_ECDSA_PRIVATE_KEY_LEN; i++) // 0x000026A4 - 0x000026C8
        g_pWorkData[i] = pPrivKey[i]; //0x000026C8

    for (i = 0; i < KIRK_ECDSA_POINT_LEN; i++) // 0x000026CC - 0x000026EC
        g_pWorkData[KIRK_ECDSA_PRIVATE_KEY_LEN + i] = pBasePoint[i]; //0x000026EC

    status = SCE_DNAS_ERROR_OPERATION_FAILED; //0x00002708 & 0x00002710

    /* Compute a new point on the elliptic curve using the provided key and curve base point. */
    tmpStatus = sceUtilsBufferCopyWithRange(g_pWorkData, KIRK_ECDSA_POINT_LEN,
        g_pWorkData, KIRK_ECDSA_PRIVATE_KEY_LEN, 
        KIRK_CMD_POINT_MULTIPLICATION_ECDSA
        ); //0x00002704
    if (tmpStatus == SCE_ERROR_OK) { //0x0000270C

        /* Copy the computed point into the provided buffer. */
        for (i = 0; i < KIRK_ECDSA_POINT_LEN; i++) //0x00002714 - 0x00002734
            pNewPoint[i] = g_pWorkData[i];

        status = SCE_ERROR_OK;
    }
    workSize = KIRK_ECDSA_PRIVATE_KEY_LEN + KIRK_ECDSA_POINT_LEN;
    
    /* Clear the work area. */
    for (i = 0; i < workSize; i++) //0x00002740 - 0x00002754
        g_pWorkData[i] = 0;

    tmpStatus = sceKernelSignalSema(g_semaId, 1); //0x0000275C
    return (tmpStatus != SCE_ERROR_OK) ? SCE_ERROR_SEMAPHORE : status; //0x00002764 & 0x00002764 & 0x0000276C
}
コード例 #27
0
ファイル: mutex.c プロジェクト: Falaina/cspspemu
static int multipleTestThread(int argsize, void* argdata) {
	int n = *(int *)argdata;
	printf("multipleTest_t%d:[0]\n", n);
	sceKernelWaitSema(semaid, 1, NULL);

	sceKernelLockMutex(mutexid, 1, NULL);
	{
		sceKernelLockMutex(mutexid, 1, NULL);
		{
			printf("multipleTest_t%d:[A]\n", n);
			{
				sceKernelDelayThread(3000);
			}
			printf("multipleTest_t%d:[B]\n", n);
		}
		sceKernelUnlockMutex(mutexid, 1);
	}
	sceKernelUnlockMutex(mutexid, 1);
	//printf("multipleTest_t%d:[3]\n", n);
	return 0;
}
コード例 #28
0
ファイル: ddrdb.c プロジェクト: fanzzbbs/uofw
/* sceDdrdb_driver_B24E1391 - Address 0x00002798 */
s32 sceDdrdbSiggen(u8 *pPrivKey, u8 *pSrcData, u8 *pSig) 
{
    s32 status;
    s32 tmpStatus; 
    SceSize workSize;
    u32 i;
    
    tmpStatus = sceKernelWaitSema(g_semaId, 1, NULL); //0x000027D8
    if (tmpStatus != SCE_ERROR_OK)
        return SCE_ERROR_SEMAPHORE;
    
    /* Setup the work area. */
    for (i = 0; i < 32; i++) //0x000027E4 - 0x00002808
        g_pWorkData[i] = pPrivKey[i];
    
    for (i = 0; i < KIRK_ECDSA_SRC_DATA_LEN; i++) //0x0000280C - 0x0000282C
        g_pWorkData[i] = pSrcData[i];

    workSize = 32 + KIRK_ECDSA_SRC_DATA_LEN;
    status = SCE_DNAS_ERROR_OPERATION_FAILED; //0x00002848 & 0x00002850

    /* Compute the signature for the provided data. */
    tmpStatus = sceUtilsBufferCopyWithRange(g_pWorkData, workSize, g_pWorkData, workSize, KIRK_CMD_SIG_GEN_ECDSA); //0x00002844
    if (tmpStatus == SCE_ERROR_OK) { //0x0000284C

        /* Copy the computed signature into the provided buffer. */
        for (i = 0; i < KIRK_ECDSA_SIG_LEN; i++) //0x00002854 - 0x00002874
            pSig[i] = g_pWorkData[i]; //0x00002874

        status = SCE_ERROR_OK;
    }
    
    /* Clear the work area. */
    for (i = 0; i < workSize; i++) //0x00002880 - 0x00002894
        g_pWorkData[i] = 0;

    tmpStatus = sceKernelSignalSema(g_semaId, 1); //0x0000289C
    return (tmpStatus != SCE_ERROR_OK) ? SCE_ERROR_SEMAPHORE : status; //0x000028A4 - 0x000028AC
}
コード例 #29
0
ファイル: threads.c プロジェクト: mrcmunir/cspspemu
void testThreads() {
	int n;

	// Create a semaphore for waiting both threads to execute.
	semaphore = sceKernelCreateSema("Semaphore", 0, 0, 2, NULL);
	
	for (n = 0; n < 2; n++) {
		// Create and start a new thread passing a stack local variable as parameter.
		// When sceKernelStartThread, thread is executed immediately, so in a while it has access
		// to the unmodified stack of the thread that created this one and can access n,
		// before it changes its value.
		sceKernelStartThread(
			sceKernelCreateThread("Test Thread", (void *)&threadFunction, 0x12, 0x10000, 0, NULL),
			n, &n
		);
	}

	// Wait until semaphore have been signaled two times (both new threads have been executed).
	sceKernelWaitSema(semaphore, 2, NULL);

	// After both threads have been executed, we will emit a -1 to check that semaphores work fine.
	printf("%d\n", -1);
}
コード例 #30
0
ファイル: virtual_pbp.c プロジェクト: sseary/procfw-chn
static inline void lock(void)
{
    sceKernelWaitSema(g_sema, 1, 0);
}