Beispiel #1
0
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;
}
Beispiel #2
0
void hidExit()
{
	if(!hidInitialised) return;

	// Unmap HID sharedmem and close handles.
	u8 val=0;
	int i; for(i=0; i<5; i++)svcCloseHandle(hidEvents[i]);
	svcUnmapMemoryBlock(hidMemHandle, (u32)hidSharedMem);
	svcCloseHandle(hidMemHandle);
	svcCloseHandle(hidHandle);

	APT_CheckNew3DS(NULL, &val);

	if(val)
	{
		irrstExit();
	}

	if(hidSharedMem != NULL)
	{
		mappableFree((void*) hidSharedMem);
		hidSharedMem = NULL;
	}
	
	hidInitialised = false;
}
Beispiel #3
0
Result hidInit(void)
{
	u8 val=0;
	Result ret=0;

	if (AtomicPostIncrement(&hidRefCount)) return 0;

	// Request service.
	ret = srvGetServiceHandle(&hidHandle, "hid:USER");
	if (R_FAILED(ret)) ret = srvGetServiceHandle(&hidHandle, "hid:SPVR");
	if (R_FAILED(ret)) goto cleanup0;

	// Get sharedmem handle.
	if(R_FAILED(ret=HIDUSER_GetHandles(&hidMemHandle, &hidEvents[HIDEVENT_PAD0], &hidEvents[HIDEVENT_PAD1], &hidEvents[HIDEVENT_Accel], &hidEvents[HIDEVENT_Gyro], &hidEvents[HIDEVENT_DebugPad]))) goto cleanup1;

	// Map HID shared memory.
	hidSharedMem=(vu32*)mappableAlloc(0x2b0);
	if(!hidSharedMem)
	{
		ret = -1;
		goto cleanup1;
	}

	if(R_FAILED(ret=svcMapMemoryBlock(hidMemHandle, (u32)hidSharedMem, MEMPERM_READ, 0x10000000)))goto cleanup2;

	APT_CheckNew3DS(&val);

	if(val)
	{
		ret = irrstInit();
	}

	// Reset internal state.
	kOld = kHeld = kDown = kUp = 0;
	return ret;

cleanup2:
	svcCloseHandle(hidMemHandle);
	if(hidSharedMem != NULL)
	{
		mappableFree((void*) hidSharedMem);
		hidSharedMem = NULL;
	}
cleanup1:
	svcCloseHandle(hidHandle);
cleanup0:
	AtomicDecrement(&hidRefCount);
	return ret;
}
Beispiel #4
0
void irrstExit(void)
{
	if (AtomicDecrement(&irrstRefCount)) return;

	svcCloseHandle(irrstEvent);
	// Unmap ir:rst sharedmem and close handles.
	svcUnmapMemoryBlock(irrstMemHandle, (u32)irrstSharedMem);
	if(envGetHandle("ir:rst") == 0) IRRST_Shutdown();
	svcCloseHandle(irrstMemHandle);
	svcCloseHandle(irrstHandle);

	if(irrstSharedMem != NULL)
	{
		mappableFree((void*) irrstSharedMem);
		irrstSharedMem = NULL;
	}
}
Beispiel #5
0
Result irrstInit(void)
{
	if (AtomicPostIncrement(&irrstRefCount)) return 0;

	Result ret=0;

	// Request service.
	if(R_FAILED(ret=srvGetServiceHandle(&irrstHandle, "ir:rst"))) goto cleanup0;

	// Get sharedmem handle.
	if(R_FAILED(ret=IRRST_GetHandles(&irrstMemHandle, &irrstEvent))) goto cleanup1;

	// Initialize ir:rst
	if(envGetHandle("ir:rst") == 0) ret = IRRST_Initialize(10, 0);

	// Map ir:rst shared memory.
	irrstSharedMem=(vu32*)mappableAlloc(0x98);
	if(!irrstSharedMem)
	{
		ret = -1;
		goto cleanup1;
	}

	if(R_FAILED(ret = svcMapMemoryBlock(irrstMemHandle, (u32)irrstSharedMem, MEMPERM_READ, 0x10000000))) goto cleanup2;

	// Reset internal state.
	kHeld = 0;
	return 0;

cleanup2:
	svcCloseHandle(irrstMemHandle);
	if(irrstSharedMem != NULL)
	{
		mappableFree((void*) irrstSharedMem);
		irrstSharedMem = NULL;
	}
cleanup1:
	svcCloseHandle(irrstHandle);
cleanup0:
	AtomicDecrement(&irrstRefCount);
	return ret;
}
Beispiel #6
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;
}
Beispiel #7
0
void hidExit(void)
{
	if (AtomicDecrement(&hidRefCount)) return;

	// Unmap HID sharedmem and close handles.
	u8 val=0;
	int i; for(i=0; i<5; i++)svcCloseHandle(hidEvents[i]);
	svcUnmapMemoryBlock(hidMemHandle, (u32)hidSharedMem);
	svcCloseHandle(hidMemHandle);
	svcCloseHandle(hidHandle);

	APT_CheckNew3DS(&val);

	if(val)
	{
		irrstExit();
	}

	if(hidSharedMem != NULL)
	{
		mappableFree((void*) hidSharedMem);
		hidSharedMem = NULL;
	}
}
Result http_haxx(char *requrl, u8 *cert, u32 certsize, targeturlctx *first_targeturlctx)
{
	Result ret=0;
	httpcContext context;
	u32 *linearaddr = NULL;
	Handle httpheap_sharedmem_handle=0;
	Handle ropvmem_sharedmem_handle=0;
	Handle httpc_sslc_handle = 0;
	u32 i;

	ret = httpcOpenContext(&context, HTTPC_METHOD_POST, requrl, 1);
	if(ret!=0)return ret;

	ret = httpcAddPostDataAscii(&context, "form_name", "form_value");
	if(ret!=0)
	{
		httpcCloseContext(&context);
		return ret;
	}

	//Locate the physmem for the httpc sharedmem. With the current cmpblock, there can only be one POST struct that was ever written into sharedmem, with the name/value from above.
	printf("Searching for the httpc sharedmem in physmem...\n");
	ret = locate_sharedmem_linearaddr(&linearaddr);
	if(ret!=0)
	{
		printf("Failed to locate the sharedmem in physmem.\n");
		httpcCloseContext(&context);
		return ret;
	}

	printf("Writing the haxx to physmem...\n");
	ret = writehax_sharedmem_physmem(linearaddr);
	if(ret!=0)
	{
		printf("Failed to setup the haxx.\n");
		httpcCloseContext(&context);
		return ret;
	}

	printf("Triggering the haxx...\n");
	ret = _httpcCloseContext(&context, &httpheap_sharedmem_handle, &ropvmem_sharedmem_handle, &httpc_sslc_handle);
	if(R_FAILED(ret))
	{
		printf("httpcCloseContext returned 0x%08x.\n", (unsigned int)ret);
		return ret;
	}

	httpheap_sharedmem = (vu32*)mappableAlloc(httpheap_size);
	if(httpheap_sharedmem==NULL)
	{
		ret = -2;
		svcCloseHandle(httpheap_sharedmem_handle);
		svcCloseHandle(ropvmem_sharedmem_handle);
		svcCloseHandle(httpc_sslc_handle);
		return ret;
	}

	ropvmem_sharedmem = (vu32*)mappableAlloc(ropvmem_size);
	if(ropvmem_sharedmem==NULL)
	{
		ret = -3;
		mappableFree((void*)httpheap_sharedmem);
		svcCloseHandle(httpheap_sharedmem_handle);
		svcCloseHandle(ropvmem_sharedmem_handle);
		svcCloseHandle(httpc_sslc_handle);
		return ret;
	}

	if(R_FAILED(ret=svcMapMemoryBlock(httpheap_sharedmem_handle, (u32)httpheap_sharedmem, MEMPERM_READ | MEMPERM_WRITE, MEMPERM_READ | MEMPERM_WRITE)))
	{
		svcCloseHandle(httpheap_sharedmem_handle);
		mappableFree((void*)httpheap_sharedmem);
		httpheap_sharedmem = NULL;

		svcCloseHandle(ropvmem_sharedmem_handle);
		mappableFree((void*)ropvmem_sharedmem);
		ropvmem_sharedmem = NULL;

		svcCloseHandle(httpc_sslc_handle);

		printf("svcMapMemoryBlock with the httpheap sharedmem failed: 0x%08x.\n", (unsigned int)ret);
		return ret;
	}

	if(R_FAILED(ret=svcMapMemoryBlock(ropvmem_sharedmem_handle, (u32)ropvmem_sharedmem, MEMPERM_READ | MEMPERM_WRITE, MEMPERM_READ | MEMPERM_WRITE)))
	{
		svcUnmapMemoryBlock(httpheap_sharedmem_handle, (u32)httpheap_sharedmem);
		svcCloseHandle(httpheap_sharedmem_handle);
		mappableFree((void*)httpheap_sharedmem);
		httpheap_sharedmem = NULL;

		svcCloseHandle(ropvmem_sharedmem_handle);
		mappableFree((void*)ropvmem_sharedmem);
		ropvmem_sharedmem = NULL;

		svcCloseHandle(httpc_sslc_handle);

		printf("svcMapMemoryBlock with the ropvmem sharedmem failed: 0x%08x.\n", (unsigned int)ret);
		return ret;
	}

	printf("Finishing haxx setup with sysmodule memory...\n");
	ret = setuphaxx_httpheap_sharedmem(first_targeturlctx);

	if(R_FAILED(ret))
	{
		printf("Failed to finish haxx setup: 0x%08x.\n", (unsigned int)ret);
	}
	else
	{
		printf("Finalizing...\n");
	}

	svcUnmapMemoryBlock(httpheap_sharedmem_handle, (u32)httpheap_sharedmem);
	svcCloseHandle(httpheap_sharedmem_handle);
	mappableFree((void*)httpheap_sharedmem);
	httpheap_sharedmem = NULL;

	svcUnmapMemoryBlock(ropvmem_sharedmem_handle, (u32)ropvmem_sharedmem);
	svcCloseHandle(ropvmem_sharedmem_handle);
	mappableFree((void*)ropvmem_sharedmem);
	ropvmem_sharedmem = NULL;

	if(R_FAILED(ret))
	{
		svcCloseHandle(httpc_sslc_handle);
		return ret;
	}

	printf("Running setup with sslc...\n");
	ret = setuphax_http_sslc(httpc_sslc_handle, cert, certsize);

	svcCloseHandle(httpc_sslc_handle);//Normally sslcExit should close this, but close it here too just in case.

	if(R_FAILED(ret))
	{
		printf("Setup failed with sslc: 0x%08x.\n", (unsigned int)ret);
		return ret;
	}

	printf("Testing httpc with non-targeted URLs...\n");

	for(i=0; i<2; i++)
	{
		ret = httpcOpenContext(&context, HTTPC_METHOD_POST, requrl, 1);
		if(R_FAILED(ret))
		{
			printf("httpcOpenContext returned 0x%08x, i=%u.\n", (unsigned int)ret, (unsigned int)i);
			return ret;
		}

		ret = httpcAddRequestHeaderField(&context, "User-Agent", "ctr-httpwn/"VERSION);
		if(R_FAILED(ret))
		{
			printf("httpcAddRequestHeaderField returned 0x%08x, i=%u.\n", (unsigned int)ret, (unsigned int)i);
			httpcCloseContext(&context);
			return ret;
		}

		ret = httpcAddPostDataAscii(&context, "form_name", "form_value");
		if(R_FAILED(ret))
		{
			printf("httpcAddPostDataAscii returned 0x%08x, i=%u.\n", (unsigned int)ret, (unsigned int)i);
			httpcCloseContext(&context);
			return ret;
		}

		ret = httpcCloseContext(&context);
		if(R_FAILED(ret))
		{
			printf("httpcCloseContext returned 0x%08x, i=%u.\n", (unsigned int)ret, (unsigned int)i);
			return ret;
		}
	}

	return 0;
}