Ejemplo n.º 1
0
void test_bad_address (const void* addr)
{
    //Validate user address
    if (!is_user_vaddr(addr))
        exit(-1);

    //Validate unmapped
    kptr(addr);
}
Ejemplo n.º 2
0
void TestProtection()
	{
	test.Next(_L("Test protection"));
	TBool jit=User::JustInTime();
	User::SetJustInTime(EFalse);
	TUint x=0xffffffff;
	TBuf8<64> ubuf;
	TPtrC8 uptrc(ubuf.Ptr(),11);
	TPtr8 uptr((TUint8*)ubuf.Ptr(),1,20);
	TPtrC8 kptrc(Kern,1);
	TPtr8 kptr(Kern,10,256);
	TPtrC8 gptrc(Garbage,1);
	TPtr8 gptr(Garbage,10,256);
	RunTestInThread(GlobalReadThread,&x,&KLitKernExec,EKUDesInfoInvalidType);
	RunTestInThread(GlobalReadThread,&ubuf,NULL,KErrNone);
	RunTestInThread(GlobalReadThread,&uptr,NULL,KErrNone);
	RunTestInThread(GlobalReadThread,&uptrc,&KLitKernExec,EKUDesInfoInvalidType);
	RunTestInThread(GlobalReadThread,&kptrc,&KLitKernExec,EKUDesInfoInvalidType);
	RunTestInThread(GlobalReadThread,&gptrc,&KLitKernExec,EKUDesInfoInvalidType);
	RunTestInThread(GlobalReadThread,&gptr,&KLitKernExec,ECausedException);
	if (KernProt)
		{
		RunTestInThread(GlobalReadThread,Kern,&KLitKernExec,ECausedException);
		RunTestInThread(GlobalReadThread,&kptr,&KLitKernExec,ECausedException);
		}
	RunTestInThread(GlobalWriteThread,&x,&KLitKernExec,EKUDesInfoInvalidType);
	RunTestInThread(GlobalWriteThread,&ubuf,NULL,KErrNone);
	RunTestInThread(GlobalWriteThread,&uptr,NULL,KErrNone);
	RunTestInThread(GlobalWriteThread,&uptrc,NULL,KErrNone);
	RunTestInThread(GlobalWriteThread,&gptrc,&KLitKernExec,ECausedException);
	RunTestInThread(GlobalWriteThread,&gptr,&KLitKernExec,ECausedException);
	if (KernProt)
		{
		RunTestInThread(GlobalWriteThread,Kern,&KLitKernExec,ECausedException);
		RunTestInThread(GlobalWriteThread,&kptrc,&KLitKernExec,ECausedException);
		RunTestInThread(GlobalWriteThread,&kptr,&KLitKernExec,ECausedException);
		}
	User::SetJustInTime(jit);
	}
Ejemplo n.º 3
0
static void
syscall_handler (struct intr_frame *f) 
{
    // Validate call number
    test_bad_address(f->esp);

    //Arguments passed to syscall, can only have 3 at most
    int funcArgs[3]; 
    int* syscall_id = (int*)f->esp;
    switch (*syscall_id) {
        case SYS_EXIT:
        {
            fill_args(f, &funcArgs[0], 1); 
            exit(funcArgs[0]);
            break;
        }
        case SYS_WAIT:
        {
            fill_args(f, &funcArgs[0], 1);
            f->eax = wait(funcArgs[0]);
            break;
        }
        case SYS_HALT:
        {
            halt();
            break;
        }
        case SYS_WRITE:
        {
            fill_args(f, &funcArgs[0], 3);
            void* kp = kptr((const void*)funcArgs[1]);
            f->eax = write(funcArgs[0], (const char*)kp, (unsigned)funcArgs[2]);
            break;
        }
        case SYS_READ:
        {
            fill_args(f, &funcArgs[0], 3);
            void* kp = kptr((const void*)funcArgs[1]);
            f->eax = read(funcArgs[0], kp, (unsigned)funcArgs[2]);
            break;
        }
        case SYS_EXEC:
        {
            fill_args(f, &funcArgs[0], 1);
            void* kp = kptr((const void*)funcArgs[0]);
            f->eax = exec((const char*)kp);
            break;
        }
        case SYS_CREATE:
        {
            fill_args(f, &funcArgs[0], 2);
            void* kp = kptr((const void*)funcArgs[0]);
            f->eax = create((const char*)kp, (unsigned)funcArgs[1]);
            break;
        }
        case SYS_REMOVE:
        {
            fill_args(f, &funcArgs[0], 1);
            void* kp = kptr((const void*)funcArgs[0]);
            f->eax = remove((const char*)kp);
            break;
        }
        case SYS_OPEN:
        {
            fill_args(f, &funcArgs[0], 1);
            void* kp = kptr((const void*)funcArgs[0]);
            f->eax = open((const char*)kp);
            break;
        }
        case SYS_FILESIZE:
        {
            fill_args(f, &funcArgs[0], 1);
            f->eax = filesize(funcArgs[0]);
            break;
        }
        case SYS_SEEK:
        {
            fill_args(f, &funcArgs[0], 2);
            seek(funcArgs[0], (unsigned)funcArgs[1]);
            break;
        }
        case SYS_TELL:
        {
            fill_args(f, &funcArgs[0], 1);
            f->eax = tell(funcArgs[0]);
        }
        default:
            break; 
    }
}