예제 #1
0
int init_signal (void)
{
    DkSetExceptionHandler(&divzero_upcall,     PAL_EVENT_DIVZERO,      0);
    DkSetExceptionHandler(&memfault_upcall,    PAL_EVENT_MEMFAULT,     0);
    DkSetExceptionHandler(&illegal_upcall,     PAL_EVENT_ILLEGAL,      0);
    DkSetExceptionHandler(&quit_upcall,        PAL_EVENT_QUIT,         0);
    DkSetExceptionHandler(&suspend_upcall,     PAL_EVENT_SUSPEND,      0);
    DkSetExceptionHandler(&resume_upcall,      PAL_EVENT_RESUME,       0);
    return 0;
}
예제 #2
0
파일: Failure.c 프로젝트: oscarlab/graphene
int main (int argc, char ** argv, char ** envp)
{
    pal_printf("Enter Main Thread\n");

    DkSetExceptionHandler(FailureHandler, PAL_EVENT_FAILURE);

    PAL_HANDLE out = DkStreamOpen("foo:unknown", PAL_ACCESS_WRONLY, 0, 0, 0);

    if (!out && !handled) {
        pal_printf("DkStreamOpen failed\n");
        return -1;
    }

    pal_printf("Leave Main Thread\n");
    return 0;
}
예제 #3
0
int main (int argc, char ** argv, char ** envp)
{
    volatile int c;
    DkSetExceptionHandler(handler, PAL_EVENT_MEMFAULT, 0);

    void * mem1 = (void *) DkVirtualMemoryAlloc(NULL, UNIT * 4, 0,
                                                PAL_PROT_READ|PAL_PROT_WRITE);

    if (mem1)
        pal_printf("Memory Allocation OK\n");

    void * mem2 = (void *) DkVirtualMemoryAlloc(NULL, UNIT, 0,
                                                PAL_PROT_READ|PAL_PROT_WRITE);

    if (mem2) {
        c = count;
        *(volatile int *) mem2 = 0;
        pal_printf("(int *) %p = %d\n", mem2, *(volatile int *) mem2);
        if (c == count)
            pal_printf("Memory Allocation Protection (RW) OK\n");

        DkVirtualMemoryProtect(mem2, UNIT, PAL_PROT_READ);
        c = count;
        *(volatile int *) mem2 = 0;
        asm volatile("nop");
        if (c == count - 1)
            pal_printf("Memory Protection (R) OK\n");

        DkVirtualMemoryFree(mem2, UNIT);
        c = count;
        *(volatile int *) mem2 = 0;
        asm volatile("nop");
        if (c == count - 1)
            pal_printf("Memory Deallocation OK\n");
    }

    void * mem3 = (void *) pal_control.user_address.start;
    void * mem4 = (void *) pal_control.user_address.end - UNIT;

    if (mem3 >= pal_control.executable_range.start &&
        mem3 < pal_control.executable_range.end)
        mem3 = (void *) (((PAL_NUM) pal_control.executable_range.end + UNIT - 1) & ~(UNIT - 1));

    mem3 = (void *) DkVirtualMemoryAlloc(mem3, UNIT, 0,
                                         PAL_PROT_READ|PAL_PROT_WRITE);
    mem4 = (void *) DkVirtualMemoryAlloc(mem4, UNIT, 0,
                                         PAL_PROT_READ|PAL_PROT_WRITE);

    if (mem3 && mem4)
        pal_printf("Memory Allocation with Address OK\n");

    /* total memory */
    pal_printf("Total Memory: %llu\n", pal_control.mem_info.mem_total);

    unsigned long before = DkMemoryAvailableQuota();
    void * mem5 = (void *) DkVirtualMemoryAlloc(NULL, UNIT * 1000, 0,
                                                PAL_PROT_READ|PAL_PROT_WRITE);

    if (mem5) {
        unsigned long after = before;

        for (int i = 0 ; i < 10000 ; i++) {
            for (void * ptr = mem5 ; ptr < mem5 + UNIT * 1000 ; ptr += UNIT)
                *(volatile int *) ptr = 0;

            unsigned long quota = DkMemoryAvailableQuota();
            if (quota < after)
                after = quota;
        }

        pal_printf("Memory Qouta Before Allocation: %ld\n", before);
        pal_printf("Memory Qouta After  Allocation: %ld\n", after);

        /* chance are some pages are evicted, so at least 80% accuracy */
        if (before >= after + UNIT * 800)
            pal_printf("Get Memory Available Quota OK\n");
    }

    return 0;
}
예제 #4
0
파일: Ipc.c 프로젝트: oscarlab/graphene
int main (int argc, char ** argv, char ** envp)
{
    char gipc_uri[20];
    int ret;

    DkSetExceptionHandler(handler, PAL_EVENT_MEMFAULT);

    if (argc > 1 && !memcmp(argv[1], "Child", 6)) {
        /* private memory */

        ret = DkStreamRead(pal_control.parent_process, 0, 20, gipc_uri,
                           NULL, 0);

        if (ret > 0) {
            PAL_HANDLE ipc1 = DkStreamOpen(gipc_uri, 0, 0, 0, 0);

            if (ipc1) {
                pal_printf("Join Physical Memory Store OK\n");

                PAL_PTR mem_addr = 0;
                PAL_NUM mem_size = UNIT;
                PAL_FLG mem_prot = PAL_PROT_READ|PAL_PROT_WRITE;

                ret = DkPhysicalMemoryMap(ipc1, 1, &mem_addr, &mem_size,
                                          &mem_prot);

                if (ret > 0) {
                    pal_printf("[Test 1] Physical Memory Map   : %s\n",
                               (char *) mem_addr);
                    memcpy((void *) mem_addr, "Hello World, Bob", 20);
                    pal_printf("[Test 1] Receiver After  Map   : %s\n",
                               (char *) mem_addr);
                }

                ret = 0;
                DkStreamWrite(pal_control.parent_process, 0, sizeof(int),
                              &ret, NULL);
                DkObjectClose(ipc1);
            }
        }

        /* private untouched memory */

        ret = DkStreamRead(pal_control.parent_process, 0, 20, gipc_uri,
                           NULL, 0);

        if (ret > 0) {
            PAL_HANDLE ipc2 = DkStreamOpen(gipc_uri, 0, 0, 0, 0);

            if (ipc2) {
                pal_printf("Join Physical Memory Store OK\n");

                PAL_PTR mem_addr = 0;
                PAL_NUM mem_size = UNIT;
                PAL_FLG mem_prot = PAL_PROT_READ|PAL_PROT_WRITE;

                ret = DkPhysicalMemoryMap(ipc2, 1, &mem_addr, &mem_size,
                                          &mem_prot);

                if (ret > 0) {
                    pal_printf("[Test 2] Physical Memory Map   : %s\n",
                               (char *) mem_addr);
                    memcpy((void *) mem_addr, "Hello World, Bob", 20);
                    pal_printf("[Test 2] Receiver After  Map   : %s\n",
                               (char *) mem_addr);
                }

                ret = 0;
                DkStreamWrite(pal_control.parent_process, 0, sizeof(int),
                              &ret, NULL);
                DkStreamDelete(ipc2, 0);
                DkObjectClose(ipc2);
            }
        }

        /* file-backed memory */

        ret = DkStreamRead(pal_control.parent_process, 0, 20, gipc_uri,
                           NULL, 0);

        if (ret > 0) {
            PAL_HANDLE ipc3 = DkStreamOpen(gipc_uri, 0, 0, 0, 0);

            if (ipc3) {
                pal_printf("Join Physical Memory Store OK\n");

                PAL_PTR mem_addr = 0;
                PAL_NUM mem_size = UNIT;
                PAL_FLG mem_prot = PAL_PROT_READ|PAL_PROT_WRITE;

                ret = DkPhysicalMemoryMap(ipc3, 1, &mem_addr, &mem_size,
                                          &mem_prot);

                if (ret > 0) {
                    pal_printf("[Test 3] Physical Memory Map   : %s\n",
                               (char *) mem_addr);
                    memcpy((void *) mem_addr, "Hello World, Bob", 20);
                    pal_printf("[Test 3] Receiver After  Map   : %s\n",
                               (char *) mem_addr);
                }

                ret = 0;
                DkStreamWrite(pal_control.parent_process, 0, sizeof(int),
                              &ret, NULL);
                DkObjectClose(ipc3);
            }
        }

        /* file-backed memory beyond file size */

        ret = DkStreamRead(pal_control.parent_process, 0, 20, gipc_uri,
                           NULL, 0);

        if (ret > 0) {
            PAL_HANDLE ipc4 = DkStreamOpen(gipc_uri, 0, 0, 0, 0);

            if (ipc4) {
                pal_printf("Join Physical Memory Store OK\n");

                PAL_PTR mem_addr = 0;
                PAL_NUM mem_size = UNIT;
                PAL_FLG mem_prot = PAL_PROT_READ|PAL_PROT_WRITE;

                ret = DkPhysicalMemoryMap(ipc4, 1, &mem_addr, &mem_size,
                                          &mem_prot);

                if (ret > 0) {
                    message = "[Test 4] Physical Memory Map   : Memory Fault\n";
                    *(volatile int *) mem_addr;
                    __asm__ volatile("nop");
                    message = NULL;
                }

                ret = 0;
                DkStreamWrite(pal_control.parent_process, 0, sizeof(int),
                              &ret, NULL);
                DkObjectClose(ipc4);
            }