void testTryAllocThread(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); int result = sceKernelTryAllocateVpl(vpl, requestBytes, &data); 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; sceKernelTryAllocateVpl(vpl, 0x08, (void **) &data1); sceKernelTryAllocateVpl(vpl, 0x10, (void **) &data2); sceKernelTryAllocateVpl(vpl, 0x01, (void **) &data3); schedf("Three 0x08s: diff=%x, %x\n", data1 - data2, data2 - data3); flushschedf(); sceKernelDeleteVpl(vpl); }
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; }
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(¶ms, 0, sizeof(pspUtilityHtmlViewerParam)); params.base.size = sizeof(pspUtilityHtmlViewerParam); sceUtilityGetSystemParamInt(PSP_SYSTEMPARAM_ID_INT_LANGUAGE, ¶ms.base.language); sceUtilityGetSystemParamInt(PSP_SYSTEMPARAM_ID_INT_UNKNOWN, ¶ms.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, ¶ms.memaddr, NULL); if (res < 0) throwError(6000, "Error 0x%08X allocating browser memory.\n", res); res = sceUtilityHtmlViewerInitStart(¶ms); if (res < 0) throwError(6000, "Error 0x%08X initing browser.\n", res); }
int main(int argc, char **argv) { SceUID vpl = sceKernelCreateVpl("vpl", PSP_MEMORY_PARTITION_USER, 0, 0x10000, NULL); void *data; testTryAlloc("More than free", vpl, 0xFFE1, 1); testTryAlloc("0 bytes", vpl, 0, 1); testTryAlloc("1 byte", vpl, 1, 1); testTryAlloc("-1 bytes", vpl, -1, 1); testTryAlloc("16 bytes", vpl, 16, 1); testTryAlloc("8 bytes", vpl, 8, 1); // Crashes. //testTryAlloc("Into NULL", vpl, 8, 0); testTryAlloc("Most remaining", vpl, 0xFF00, 1); testTryAlloc("More than remaining", vpl, 0xA1, 1); testTryAlloc("All remaining", vpl, 0xA0, 1); testTryAlloc("All remaining - 7", vpl, 0xA0 - 7, 1); testTryAlloc("All remaining - 8", vpl, 0xA0 - 8, 1); testTryAlloc("1 byte (none left)", vpl, 1, 1); sceKernelDeleteVpl(vpl); testTryAlloc("NULL", 0, 0x100, 1); testTryAlloc("NULL with invalid", 0, 0, 0); testTryAlloc("Invalid", 0xDEADBEEF, 0x100, 1); testTryAlloc("Deleted", vpl, 0x100, 1); flushschedf(); 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]); testTryAllocThread(" Alloc 0x20 of 0x00/0xE0", attrs[i], 0x20, 0xE0 - 0x08); testTryAllocThread(" Alloc 0x20 of 0x20/0xE0", attrs[i], 0x20, 0xE0 - 0x08 - (0x20 + 0x08)); testTryAllocThread(" Alloc 0x20 of 0x40/0xE0", attrs[i], 0x20, 0xE0 - 0x08 - (0x20 + 0x08) * 2); schedf("\n"); } BASIC_SCHED_TEST("Zero", result = sceKernelTryAllocateVpl(vpl1, 0, &data); );
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; }
void vpl_init(void) { g_vpl_uid = sceKernelCreateVpl("SateliteVPL", 2, 0, VPL_POOL_SIZE, NULL); }
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); );