Example #1
0
File: gfx.c Project: Voka/lpp-3ds
void gfxExit(void)
{
	if (screenFree == NULL) return;

	// Exit event handler
	gspExitEventHandler();

	// Free framebuffers
	screenFree(gfxTopRightFramebuffers[1]);
	screenFree(gfxTopRightFramebuffers[0]);
	screenFree(gfxBottomFramebuffers[1]);
	screenFree(gfxBottomFramebuffers[0]);
	screenFree(gfxTopLeftFramebuffers[1]);
	screenFree(gfxTopLeftFramebuffers[0]);

	//unmap GSP shared mem
	svcUnmapMemoryBlock(gspSharedMemHandle, (u32)gfxSharedMemory);

	GSPGPU_UnregisterInterruptRelayQueue();

	svcCloseHandle(gspSharedMemHandle);
	if(gfxSharedMemory != NULL)
	{
		mappableFree(gfxSharedMemory);
		gfxSharedMemory = NULL;
	}

	svcCloseHandle(gspEvent);

	GSPGPU_ReleaseRight();

	gspExit();

	screenFree = NULL;
}
Example #2
0
void gfxExit()
{
	// Exit event handler
	gspExitEventHandler();

	// Free framebuffers
	linearFree(gfxTopRightFramebuffers[1]);
	linearFree(gfxTopRightFramebuffers[0]);
	linearFree(gfxBottomFramebuffers[1]);
	linearFree(gfxBottomFramebuffers[0]);
	linearFree(gfxTopLeftFramebuffers[1]);
	linearFree(gfxTopLeftFramebuffers[0]);

	//unmap GSP shared mem
	svcUnmapMemoryBlock(gspSharedMemHandle, 0x10002000);

	GSPGPU_UnregisterInterruptRelayQueue(NULL);

	svcCloseHandle(gspSharedMemHandle);
	svcCloseHandle(gspEvent);

	GSPGPU_ReleaseRight(NULL);

	gspExit();
}
Example #3
0
File: main.c Project: LITTOMA/HANS
void gspGpuExit()
{
	GSPGPU_UnregisterInterruptRelayQueue(NULL);

	//unmap GSP shared mem
	svc_unmapMemoryBlock(gspSharedMemHandle, 0x10002000);
	svc_closeHandle(gspSharedMemHandle);
	svc_closeHandle(gspEvent);

	//free GSP heap
	svc_controlMemory((u32*)&gspHeap, (u32)gspHeap, 0x0, gspHeap_size, MEMOP_FREE, 0x0);

	GSPGPU_ReleaseRight(NULL);
	
	gspExit();
}
Example #4
0
D3DSDevice::~D3DSDevice()
{
    if (nullptr==dealloc)
        return; // should not happen!

    gspExitEventHandler();

    dealloc( m_FBBottom[0] );
    dealloc( m_FBBottom[1] );
    dealloc( m_FBTop[0] );
    dealloc( m_FBTop[1] );
    if (m_b3DEnabled)
    {
        dealloc( m_FBTop[2] );
        dealloc( m_FBTop[3] );
    }

    svcUnmapMemoryBlock( m_hGSPSharedMemory, 
                         (u32)m_pSharedMemory );

    GSPGPU_UnregisterInterruptRelayQueue();

    svcCloseHandle( m_hGSPSharedMemory );
    if (nullptr!=m_pSharedMemory)
    {
        mappableFree( m_pSharedMemory );
        m_pSharedMemory = nullptr;
    }

    svcCloseHandle( m_hGSPEvent );

    GSPGPU_ReleaseRight();

    gspExit();

    dealloc = nullptr;
}
Example #5
0
void aptReturnToMenu(void)
{
	NS_APPID menu_appid;
	u32 tmp0 = 1, tmp1 = 0;

	if(aptIsCrippled())
	{
		svcClearEvent(aptStatusEvent);
		aptSetStatus(APP_EXITING);
		return;
	}

	// This is only executed when ret-to-menu was triggered via the home-button, not the power-button.
	if(aptGetStatusPower() == 0)
	{
		aptOpenSession();
		APT_AppletUtility(NULL, 0x6, 0x4, (u8*)&tmp0, 0x1, (u8*)&tmp1);
		aptCloseSession();
	}

	// Set status to SUSPENDED.
	__apt_launchapplet_appID = 0;
	svcClearEvent(aptStatusEvent);
	aptSetStatus(APP_SUSPENDED);

	// Prepare for return to menu
	aptOpenSession();
	APT_PrepareToJumpToHomeMenu();
	aptCloseSession();

	// Save Vram
	GSPGPU_SaveVramSysArea();

	// Capture screen.
	memset(__ns_capinfo, 0, 0x20);

	aptInitCaptureInfo(__ns_capinfo);

	menu_appid = aptGetMenuAppID();

	// Send capture-screen info to menu.
	aptOpenSession();
	APT_SendParameter(currentAppId, menu_appid, 0x20, __ns_capinfo, 0x0, 0x10);
	aptCloseSession();

	aptOpenSession();
	APT_SendCaptureBufferInfo(0x20, __ns_capinfo);
	aptCloseSession();

	// Release GSP module.
	GSPGPU_ReleaseRight();

	// Jump to menu!
	aptOpenSession();
	APT_JumpToHomeMenu(0x0, 0x0, 0x0);
	aptCloseSession();

	// Wait for return to application.
	aptOpenSession();
	APT_NotifyToWait(currentAppId);
	aptCloseSession();

	// This is only executed when ret-to-menu was triggered via the home-button, not the power-button.
	if(aptGetStatusPower() == 0)
	{
		tmp0 = 0;
		aptOpenSession();
		APT_AppletUtility(NULL, 0x4, 0x1, (u8*)&tmp0, 0x1, (u8*)&tmp1);
		aptCloseSession();
	}

	aptWaitStatusEvent();
}
Example #6
0
Result APT_LaunchLibraryApplet(NS_APPID appID, Handle inhandle, u32 *parambuf, u32 parambufsize)
{
	Result ret=0;
	u8 tmp=0;

	u8 buf1[4];
	u8 buf2[4];

	aptOpenSession();
	APT_ReplySleepQuery(currentAppId, 0);
	aptCloseSession();

	aptOpenSession();
	ret=APT_PrepareToStartLibraryApplet(appID);
	aptCloseSession();
	if(R_FAILED(ret))return ret;

	memset(buf1, 0, 4);
	aptOpenSession();
	APT_AppletUtility(NULL, 0x4, 0x1, buf1, 0x1, buf2);
	aptCloseSession();

	while(1)
	{
		aptOpenSession();
		ret=APT_IsRegistered(appID, &tmp);
		aptCloseSession();
		if(R_FAILED(ret))return ret;

		if(tmp!=0)break;
	}

	aptCallHook(APTHOOK_ONSUSPEND);

	__apt_launchapplet_appID = appID;
	__apt_launchapplet_inhandle = inhandle;
	__apt_launchapplet_parambuf = parambuf;
	__apt_launchapplet_parambufsize = parambufsize;

	// Set status to SUSPENDED.
	svcClearEvent(aptStatusEvent);
	aptSetStatus(APP_SUSPENDED);

	// Save Vram
	GSPGPU_SaveVramSysArea();

	// Capture screen.
	memset(__ns_capinfo, 0, 0x20);

	aptInitCaptureInfo(__ns_capinfo);

	// Send capture-screen info to the library applet.
	aptOpenSession();
	APT_SendParameter(currentAppId, appID, 0x20, __ns_capinfo, 0x0, 0x2);
	aptCloseSession();

	// Release GSP module.
	GSPGPU_ReleaseRight();

	return 0;
}
Example #7
0
void changeProcess(int processId, u32* argbuf, u32 argbuflength)
{
	initSrv();
	gspGpuInit();

	// free extra data pages if any
	freeDataPages(0x14000000);
	freeDataPages(0x30000000);

	// allocate gsp heap
	svc_controlMemory((u32*)&gspHeap, 0x0, 0x0, 0x01000000, 0x10003, 0x3);

	patchMenuRop(processId, argbuf, argbuflength);

	// grab waitLoop stub
	GSPGPU_FlushDataCache(NULL, (u8*)&gspHeap[0x00200000], 0x100);
	doGspwn((u32*)(MENU_LOADEDROP_BUFADR-0x100), (u32*)&gspHeap[0x00200000], 0x100);
	svc_sleepThread(20*1000*1000);

	// patch it
	u32* patchArea = (u32*)&gspHeap[0x00200000];
	for(int i=0; i<0x100/4; i++)
	{
		if(patchArea[i] == 0xBABEBAD0)
		{
			patchArea[i-1] = patchArea[i+1];
			break;
		}
	}

	// copy it back
	GSPGPU_FlushDataCache(NULL, (u8*)&gspHeap[0x00200000], 0x100);
	doGspwn((u32*)&gspHeap[0x00200000], (u32*)(MENU_LOADEDROP_BUFADR-0x100), 0x100);
	svc_sleepThread(20*1000*1000);

	// ghetto dcache invalidation
	// don't judge me
	int i, j;//, k;
	// for(k=0; k<0x2; k++)
		for(j=0; j<0x4; j++)
			for(i=0; i<0x01000000/0x4; i+=0x4)
				((u32*)gspHeap)[i+j]^=0xDEADBABE;

	//exit to menu
	// _aptExit();

	exitSrv();

	// do that at the end so that release right is one of the last things to happen
	{
		GSPGPU_UnregisterInterruptRelayQueue(NULL);

		//unmap GSP shared mem
		svc_unmapMemoryBlock(gspSharedMemHandle, 0x10002000);
		svc_closeHandle(gspSharedMemHandle);
		svc_closeHandle(gspEvent);

		//free GSP heap
		svc_controlMemory((u32*)&gspHeap, (u32)gspHeap, 0x0, 0x01000000, MEMOP_FREE, 0x0);

		Handle _gspGpuHandle = gspGpuHandle;

		// free heap (has to be the very last thing before jumping to app as contains bss)
		u32 out; svc_controlMemory(&out, (u32)_heap_base, 0x0, _heap_size, MEMOP_FREE, 0x0);

		GSPGPU_ReleaseRight(&_gspGpuHandle);

		svc_closeHandle(_gspGpuHandle);
	}

	svc_exitProcess();
}