void testAllocThread(const char *title, u32 attr, u32 requestBytes, u32 initialBytes) {
	schedf("%s: ", title);

	SceUID vpl = sceKernelCreateVpl("vpl", PSP_MEMORY_PARTITION_USER, attr, 0x100, NULL);

	// This way we have some allocated + free.
	void *data;
	sceKernelAllocateVpl(vpl, initialBytes, &data, NULL);

	SceUID allocThread = sceKernelCreateThread("allocThread", &allocFunc, 0x12, 0x1000, 0, NULL);
	sceKernelStartThread(allocThread, sizeof(SceUID), &vpl);
	sceKernelDelayThread(400);

	unsigned int timeout = 1000;
	int result = sceKernelAllocateVpl(vpl, requestBytes, &data, &timeout);
	schedf("L2 ");
	sceKernelDelayThread(600);

	sceKernelDeleteVpl(vpl);
	sceKernelWaitThreadEnd(allocThread, NULL);
	sceKernelTerminateDeleteThread(allocThread);

	if (result == 0) {
		schedf("OK (thread=%08X)\n", schedulingResult);
	} else {
		schedf("Failed (thread=%08X, main=%08X)\n", schedulingResult, result);
	}
}
void testDiff() {
	SceUID vpl = sceKernelCreateVpl("vpl", PSP_MEMORY_PARTITION_USER, 0, 0x10000, NULL);
	char *data1, *data2, *data3;
	sceKernelAllocateVpl(vpl, 0x08, (void **) &data1, NULL);
	sceKernelAllocateVpl(vpl, 0x10, (void **) &data2, NULL);
	sceKernelAllocateVpl(vpl, 0x01, (void **) &data3, NULL);

	schedf("Three 0x08s: diff=%x, %x\n\n", data1 - data2, data2 - data3);
	flushschedf();

	sceKernelDeleteVpl(vpl);
}
Esempio n. 3
0
static int allocFunc(SceSize argSize, void* argPointer) {
	SceUInt timeout = 1000;
	void *data;
	schedulingResult = sceKernelAllocateVpl(*(SceUID *) argPointer, 0x20, &data, &timeout);
	schedf("L1 ");
	sceKernelDelayThread(1000);
	sceKernelFreeVpl(*(SceUID *) argPointer, data);
	return 0;
}
Esempio n. 4
0
int thread1(SceSize argc, void *argv) {
	void *data;
	SceUInt t = 200;

	checkpoint("thread1 start");
	int result = sceKernelAllocateVpl(vpl, 0x800, &data, &t);
	checkpoint("thread1 end: %08x", result);

	return 0;
}
Esempio n. 5
0
void *vpl_alloc(int size)
{
	void *p;
	int ret;

	ret = sceKernelAllocateVpl(g_vpl_uid, size, &p, NULL);

	if(ret == 0)
		return p;

	return NULL;
}
void *testAlloc(const char *title, SceUID vpl, unsigned int size, int with_data) {
	void *data = (void *) 0xDEADBEEF;
	int result = sceKernelAllocateVpl(vpl, size, with_data ? &data : NULL, NULL);
	if (result == 0) {
		schedf("%s: OK ", title);
		schedfVpl(vpl);
	} else {
		schedf("%s: Failed (%08X) ", title, result);
		schedfVpl(vpl);
	}

	return data;
}
void *testAllocTimeout(const char *title, SceUID vpl, unsigned int size, unsigned int timeout, int with_data) {
	void *data = (void *) 0xDEADBEEF;
	int result = sceKernelAllocateVpl(vpl, size, with_data ? &data : NULL, &timeout);
	if (result == 0) {
		schedf("%s: OK (%dms left) ", title, timeout);
		schedfVpl(vpl);
	} else {
		schedf("%s: Failed (%08X, %dms left) ", title, result, timeout);
		schedfVpl(vpl);
	}

	return data;
}
Esempio n. 8
0
extern "C" int main(int argc, char **argv) {
	SceUID th1 = sceKernelCreateThread("thread1", &thread1, 0x21, 0x1000, 0, NULL);
	SceUID th2 = sceKernelCreateThread("thread2", &thread2, 0x21, 0x1000, 0, NULL);
	vpl = sceKernelCreateVpl("vpl", PSP_MEMORY_PARTITION_USER, 0, 0x1000 + 0x20, NULL);
	void *data;
	sceKernelAllocateVpl(vpl, 0x800, &data, NULL);
	checkpoint("starting");
	sceKernelStartThread(th1, 0, NULL);
	sceKernelStartThread(th2, 0, NULL);
	checkpoint("waiting");
	sceKernelDelayThread(10000);
	checkpoint("deleting");
	sceKernelDeleteVpl(vpl);
	checkpoint("done, waiting");
	sceKernelDelayThread(10000);

	return 0;
}
Esempio n. 9
0
File: main.c Progetto: CDragu/pspsdk
void htmlViewerInit(char *url)
{
	int res;
	
	vpl = sceKernelCreateVpl("BrowserVpl", PSP_MEMORY_PARTITION_USER, 0, BROWSER_MEMORY + 256, NULL);
	
	if (vpl < 0) 
		throwError(6000, "Error 0x%08X creating vpl.\n", vpl);

	memset(&params, 0, sizeof(pspUtilityHtmlViewerParam));
	
	params.base.size = sizeof(pspUtilityHtmlViewerParam);
	
	sceUtilityGetSystemParamInt(PSP_SYSTEMPARAM_ID_INT_LANGUAGE, &params.base.language);
	sceUtilityGetSystemParamInt(PSP_SYSTEMPARAM_ID_INT_UNKNOWN, &params.base.buttonSwap);
	
	params.base.graphicsThread = 17;
	params.base.accessThread = 19;
	params.base.fontThread = 18;
	params.base.soundThread = 16;	
	params.memsize = BROWSER_MEMORY;
	params.initialurl = url;
	params.numtabs = 1;
	params.cookiemode = PSP_UTILITY_HTMLVIEWER_COOKIEMODE_DEFAULT;
	params.homeurl = url;
	params.textsize = PSP_UTILITY_HTMLVIEWER_TEXTSIZE_NORMAL;
	params.displaymode = PSP_UTILITY_HTMLVIEWER_DISPLAYMODE_SMART_FIT;
	params.options = PSP_UTILITY_HTMLVIEWER_DISABLE_STARTUP_LIMITS|PSP_UTILITY_HTMLVIEWER_ENABLE_FLASH;
	params.interfacemode = PSP_UTILITY_HTMLVIEWER_INTERFACEMODE_FULL;
	params.connectmode = PSP_UTILITY_HTMLVIEWER_CONNECTMODE_MANUAL_ALL;
	
	// Note the lack of 'ms0:' on the paths	
	params.dldirname = "/PSP/PHOTO";
	
	res = sceKernelAllocateVpl(vpl, params.memsize, &params.memaddr, NULL);
	
	if (res < 0) 
		throwError(6000, "Error 0x%08X allocating browser memory.\n", res);

	res = sceUtilityHtmlViewerInitStart(&params);
	
	if (res < 0)
		throwError(6000, "Error 0x%08X initing browser.\n", res);
}
Esempio n. 10
0
extern "C" int main(int argc, char *argv[]) {
    int result;
    void *addr;
    void *addr1;
    void *addr3;
    void *addrs[50];

    SceUID uid1 = sceKernelCreateVpl("bottom", 2, 0x4300, 0x100, NULL);
    SceUID uid2 = sceKernelCreateVpl("middle", 2, 0x4300, 0x100, NULL);
    SceUID uid3 = sceKernelCreateVpl("top", 2, 0x4300, 0x100, NULL);

    result = sceKernelAllocateVpl(uid1, 0x10, &addr1, NULL);
    result = sceKernelAllocateVpl(uid3, 0x10, &addr3, NULL);

    VplAccounting *acct = (VplAccounting *)((char *)addr3 + 0x18);
    schedfAcct(acct);
    schedfVpl(uid2);

    result = sceKernelAllocateVpl(uid2, 0x10, &addrs[0], NULL);
    checkpoint("alloc 0");
    schedfAcct(acct);
    schedfVpl(uid2);

    result = sceKernelAllocateVpl(uid2, 0x10, &addrs[1], NULL);
    checkpoint("alloc 1");
    schedfAcct(acct);
    schedfVpl(uid2);

    result = sceKernelAllocateVpl(uid2, 0x10, &addrs[2], NULL);
    checkpoint("alloc 2");
    schedfAcct(acct);
    schedfVpl(uid2);

    checkpoint("free 1: %08x", sceKernelFreeVpl(uid2, addrs[1]));
    schedfAcct(acct);
    schedfVpl(uid2);

    checkpoint("free 0: %08x", sceKernelFreeVpl(uid2, addrs[0]));
    schedfAcct(acct);
    schedfVpl(uid2);

    checkpoint("free 2: %08x", sceKernelFreeVpl(uid2, addrs[2]));
    schedfAcct(acct);
    schedfVpl(uid2);

    result = sceKernelAllocateVpl(uid2, 0x10, &addrs[0], NULL);
    checkpoint("alloc 0");
    schedfAcct(acct);
    schedfVpl(uid2);

    result = sceKernelAllocateVpl(uid2, 0x10, &addrs[1], NULL);
    checkpoint("alloc 1");
    schedfAcct(acct);
    schedfVpl(uid2);

    checkpoint("free 1: %08x", sceKernelFreeVpl(uid2, addrs[1]));
    schedfAcct(acct);
    schedfVpl(uid2);

    checkpoint("free 0: %08x", sceKernelFreeVpl(uid2, addrs[0]));
    schedfAcct(acct);
    schedfVpl(uid2);

    result = sceKernelAllocateVpl(uid2, 0x10, &addrs[0], NULL);
    result = sceKernelAllocateVpl(uid2, 0x10, &addrs[1], NULL);
    result = sceKernelAllocateVpl(uid2, 0x10, &addrs[2], NULL);
    result = sceKernelAllocateVpl(uid2, 0x10, &addrs[3], NULL);
    result = sceKernelAllocateVpl(uid2, 0x10, &addrs[4], NULL);
    void *addr2 = addrs[4];
    result = sceKernelAllocateVpl(uid2, 0x10, &addrs[5], NULL);
    result = sceKernelAllocateVpl(uid2, 0x10, &addrs[6], NULL);
    result = sceKernelAllocateVpl(uid2, 0x10, &addrs[7], NULL);
    result = sceKernelAllocateVpl(uid2, 0x18, &addrs[8], NULL);

    schedfAcct(acct);
    schedfVpl(uid2);

    checkpoint("free 4: %08x", sceKernelFreeVpl(uid2, addr2));
    schedfAcct(acct);
    schedfVpl(uid2);

    for (int i = 0; i <= 8; i += 2) {
        sceKernelFreeVpl(uid2, addrs[i]);
        checkpoint("free %d", i);
        schedfAcct(acct);
        schedfVpl(uid2);
    }
    checkpoint("free every other");
    schedfAcct(acct);
    schedfVpl(uid2);

    for (int i = 8; i >= 0; --i) {
        sceKernelFreeVpl(uid2, addrs[i]);
    }
    checkpoint("free all");
    schedfAcct(acct);
    schedfVpl(uid2);

    result = sceKernelAllocateVpl(uid2, 0x10, &addrs[0], NULL);
    checkpoint("alloc 1");
    schedfAcct(acct);
    schedfVpl(uid2);

    result = sceKernelFreeVpl(uid2, addrs[0]);
    checkpoint("free 1");
    schedfAcct(acct);
    schedfVpl(uid2);

    return 0;
}
Esempio n. 11
0
int main(int argc, char **argv) {
	SceUID vpl = sceKernelCreateVpl("vpl", PSP_MEMORY_PARTITION_USER, 0, 0x10000, NULL);
	void *data;

	schedf("No timeout:\n");
	testAlloc("  More than free", vpl, 0xFFE1, 1);
	testAlloc("  0 bytes", vpl, 0, 1);
	testAlloc("  1 byte", vpl, 1, 1);
	testAlloc("  -1 bytes", vpl, -1, 1);
	testAlloc("  16 bytes", vpl, 16, 1);
	testAlloc("  8 bytes", vpl, 8, 1);

	schedf("\nWith timeout:\n");
	testAllocTimeout("  More than free", vpl, 0xFFE1, 500, 1);
	testAllocTimeout("  0 bytes", vpl, 0, 500, 1);
	testAllocTimeout("  1 byte", vpl, 1, 500, 1);
	testAllocTimeout("  -1 bytes", vpl, -1, 500, 1);
	testAllocTimeout("  16 bytes", vpl, 16, 500, 1);
	testAllocTimeout("  8 bytes", vpl, 8, 500, 1);
	
	schedf("\nErrors:\n");
	// Crashes.
	//testAllocTimeout("Into NULL", vpl, 8, 500, 0);
	testAllocTimeout("  Into NULL", vpl, 0xFFE0, 500, 0);

	testAllocTimeout("  Most remaining", vpl, 0xFF00, 500, 1);
	testAllocTimeout("  More than remaining", vpl, 0xA1, 500, 1);
	testAllocTimeout("  All remaining", vpl, 0x68, 500, 1);
	testAllocTimeout("  All remaining - 7", vpl, 0x68 - 7, 500, 1);
	testAllocTimeout("  All remaining - 8", vpl, 0x68 - 8, 500, 1);
	testAllocTimeout("  1 byte (none left)", vpl, 1, 500, 1);
	testAllocTimeout("  1 byte (none left, 0 timeout)", vpl, 1, 0, 1);

	sceKernelDeleteVpl(vpl);

	testAllocTimeout("  NULL", 0, 0x100, 500, 1);
	testAllocTimeout("  NULL with invalid", 0, 0, 500, 0);
	testAllocTimeout("  Invalid", 0xDEADBEEF, 0x100, 500, 1);
	testAllocTimeout("  Deleted", vpl, 0x100, 500, 1);
	schedf("\n");

	testDiff();

	u32 attrs[] = {PSP_VPL_ATTR_FIFO, PSP_VPL_ATTR_PRIORITY, PSP_VPL_ATTR_SMALLEST, PSP_VPL_ATTR_HIGHMEM};
	int i;
	for (i = 0; i < sizeof(attrs) / sizeof(attrs[0]); ++i) {
		schedf("Attr %x:\n", attrs[i]);
		testAllocThread("  Alloc 0x10 of 0x00/0xE0", attrs[i], 0x20, 0xE0 - 0x08);
		testAllocThread("  Alloc 0x10 of 0x20/0xE0", attrs[i], 0x20, 0xE0 - 0x08 - (0x20 + 0x08));
		testAllocThread("  Alloc 0x10 of 0x40/0xE0", attrs[i], 0x20, 0xE0 - 0x08 - (0x20 + 0x08) * 2);
		schedf("\n");
	}
	flushschedf();

	SceUID deleteThread = CREATE_SIMPLE_THREAD(deleteMeFunc);
	vpl = sceKernelCreateVpl("vpl", PSP_MEMORY_PARTITION_USER, 0, 0x10000, NULL);
	sceKernelAllocateVpl(vpl, 0x10000 - 0x20 - 0x08, &data, NULL);
	sceKernelStartThread(deleteThread, sizeof(SceUID), &vpl);
	sceKernelDeleteVpl(vpl);
	flushschedf();

	unsigned int timeout;
	BASIC_SCHED_TEST("Zero",
		timeout = 500;
		result = sceKernelAllocateVpl(vpl1, 0, &data, &timeout);
	);
Esempio n. 12
0
static int deleteMeFunc(SceSize argSize, void* argPointer) {
	void *data;
	int result = sceKernelAllocateVpl(*(SceUID *) argPointer, 1, &data, NULL);
	printf("After delete: %08X\n\n", result);
	return 0;
}
Esempio n. 13
0
	SceUID deleteThread = CREATE_SIMPLE_THREAD(deleteMeFunc);
	vpl = sceKernelCreateVpl("vpl", PSP_MEMORY_PARTITION_USER, 0, 0x10000, NULL);
	sceKernelAllocateVpl(vpl, 0x10000 - 0x20 - 0x08, &data, NULL);
	sceKernelStartThread(deleteThread, sizeof(SceUID), &vpl);
	sceKernelDeleteVpl(vpl);
	flushschedf();

	unsigned int timeout;
	BASIC_SCHED_TEST("Zero",
		timeout = 500;
		result = sceKernelAllocateVpl(vpl1, 0, &data, &timeout);
	);
	BASIC_SCHED_TEST("Alloc same",
		timeout = 500;
		result = sceKernelAllocateVpl(vpl1, 0x6000, &data, &timeout);
	);
	BASIC_SCHED_TEST("Alloc other",
		timeout = 500;
		result = sceKernelAllocateVpl(vpl2, 0x6000, &data, &timeout);
	);
	schedf("\n");
	flushschedf();

	schedf("Callbacks:\n");

	SceUID cb = sceKernelCreateCallback("cb", callbackFunc, 0);
	vpl = sceKernelCreateVpl("vpl", PSP_MEMORY_PARTITION_USER, 0, 0x10000, NULL);

	sceKernelNotifyCallback(cb, 1);
	schedf("  Invalid: ");