Ejemplo n.º 1
0
void test_move()
{

        move_seg(SEG_LENGTH, SEG_LENGTH+1);

        Segment t1 = get_seg(SEG_LENGTH);
        Segment t2 = get_seg(SEG_LENGTH+1);

        for (unsigned i = 0; i < SEG_LENGTH; i++) {

                uint32_t *w = Seq_get(t1->data, i);
                uint32_t *w2 = Seq_get(t2->data, i);
                if (w != w2)
                        printf("TEST MOVE IS A FAIL!!!!!\n");
        }

        printf("TEST MOVE IS A FAIL!!!!!\n");

}
Ejemplo n.º 2
0
static void
pager (void)
{
    L4_ThreadId_t tid;
    L4_MsgTag_t tag;
    L4_Msg_t msg;

    L4_Send(master_tid);
    for (;;) {
        tag = L4_Wait(&tid);

        for (;;) {
            L4_Word_t faddr, fip;
            L4_MsgStore(tag, &msg);

            if (L4_UntypedWords (tag) != 2 ||
                !L4_IpcSucceeded (tag)) {
                printf ("Malformed pagefault IPC from %p (tag=%p)\n",
                        (void *) tid.raw, (void *) tag.raw);
                L4_KDB_Enter ("malformed pf");
                break;
            }

            faddr = L4_MsgWord(&msg, 0);
            fip   = L4_MsgWord (&msg, 1);
            L4_MsgClear(&msg);
            {
                L4_MapItem_t map;
                L4_SpaceId_t space;
                L4_Word_t seg, offset, cache, rwx, size;
                int r;

                seg = get_seg(KBENCH_SPACE, faddr, &offset, &cache, &rwx);
                assert(seg != ~0UL);

                size = L4_GetMinPageBits();
                faddr &= ~((1ul << size)-1);
                offset &= ~((1ul << size)-1);

                space.raw = __L4_TCR_SenderSpace();

                L4_MapItem_Map(&map, seg, offset, faddr, size,
                               cache, rwx);
                r = L4_ProcessMapItem(space, map);
                assert(r == 1);
            }
            L4_MsgLoad(&msg);
//            tag = L4_ReplyWait (tid, &tid);
            tag = L4_MsgTag();
            L4_Set_SendBlock(&tag);
            L4_Set_ReceiveBlock(&tag);
            tag = L4_Ipc(tid, L4_anythread, tag, &tid);
        }
    }
}
Ejemplo n.º 3
0
void test_get_words_in_seg(Segment s)
{
        int n = get_num_segs(s);

        for (int i = 0; i < n; i++) {
                if (get_words_in_seg(get_seg(s, i), i) != NUM_WORDS) {
                        fprintf(stderr, "num words does not match\n");
                }
        }

        return;
}
Ejemplo n.º 4
0
void test_clear()
{
        clear_seg(SEG_LENGTH);

        Segment t = get_seg(SEG_LENGTH);
        if ( t->length != 0 || t->data != NULL) {
                printf("CLEAR IS A FAILURE!!!\n");
        }

        printf("CLEAR IS A SUCCESS!!!\n");

}
Ejemplo n.º 5
0
/* The sregs has been synced with HAX kernel already before this call */
static int hax_get_segments(CPUArchState *env, struct vcpu_state_t *sregs)
{
    get_seg(&env->segs[R_CS], &sregs->_cs);
    get_seg(&env->segs[R_DS], &sregs->_ds);
    get_seg(&env->segs[R_ES], &sregs->_es);
    get_seg(&env->segs[R_FS], &sregs->_fs);
    get_seg(&env->segs[R_GS], &sregs->_gs);
    get_seg(&env->segs[R_SS], &sregs->_ss);

    get_seg(&env->tr, &sregs->_tr);
    get_seg(&env->ldt, &sregs->_ldt);
    env->idt.limit = sregs->_idt.limit;
    env->idt.base = sregs->_idt.base;
    env->gdt.limit = sregs->_gdt.limit;
    env->gdt.base = sregs->_gdt.base;
    return 0;
}
Ejemplo n.º 6
0
void* mem_pool::malloc(size_t size, size_t n/*=1*/)
{
    size_t real_size;
    if(n==1)
        real_size=size;
    else{
        real_size=size*n;

        if(n!=0 && real_size/n!=size){
            PROTON_LOG(0, "size overflow:"<<size<<"*"<<n);
            return NULL;
        }
    }
    seg_pool* meta=get_seg(real_size);
    // [TODO] optimize to use malloc_one
    return meta->malloc(real_size);
}
Ejemplo n.º 7
0
/* assumes add_seg works correctly */
void test_get_seg()
{
        Segment test = get_seg(SEG_LENGTH);

        for (unsigned i = 0; i < test->length; i++) {

                uint32_t *word = Seq_get(test->data, i);
                if (*word != i)
                        printf("GET SEG IS A FAIL!!!!!\n");
        }

        printf("GET SEG IS A SUCCESS!!!\n");

        printf("\n");

        


}
Ejemplo n.º 8
0
bool load(FILE *file, int size)
{
    UArray_T s0 = get_seg(um->memory, 0);
    assert(s0);

    resize(um->memory, 0, (size/4) + 1);

    for (int i=0; i < (size/4); i++) {
        uint32_t word = 0;

        for (int j = 1; j <= 4; j++) {
            //word = Bitpack_newu(word, 8, 32- (j*8), getc(file));
            int hi = 8 + (32 - (j*8));

            word = shl(shr(word, hi), hi)                 /* high part */
                | shr(shl(word, 64 - (32- (j*8))), 64 - (32- (j*8)))  /* low part  */
                | (getc(file) << (32- (j*8)));
        }

        put_word(um->memory, 0, i, word);
    }
    
    return true;
}
Ejemplo n.º 9
0
static void
pager (void)
{
    L4_ThreadId_t tid;
    L4_MsgTag_t tag;
    L4_Msg_t msg;
    int count = 0;

    for (;;) {
        tag = L4_Wait(&tid);

        for (;;) { 
            L4_Word_t faddr, fip;
            L4_MsgStore(tag, &msg);

            if (L4_Label(tag) == START_LABEL) {
                // Startup notification, start ping and pong thread
                void (*start_addr)(void);
                void (*pong_start_addr)(void);
                L4_Word_t *pong_stack_addr = pong_stack;
                if (pagertimer) {
                    start_addr = ping_thread_pager;
                } else if (pagertimer_simulated) {
                    start_addr = ping_thread_simulated;
                } else if (fass_buffer) {
                    start_addr = ping_thread_buffer;
                } else if (fault_test) {
                    count = 0;
                    start_addr = NULL;
                } else if (intra_close) {
                    start_addr = ping_thread_close;
                } else if (intra_open) {
                    start_addr = ping_thread_open;
                } else if (intra_rpc) {
                    start_addr = ping_thread_rpc_server;
                } else if (intra_ovh) {
                    start_addr = ping_thread_ovh;
                } else if (intra_async) {
                    start_addr = ping_thread_async;
                } else if (intra_async_ovh) {
                    start_addr = ping_thread_async_ovh;
                } else {
                    start_addr = ping_thread;
                }

                if (start_addr != NULL) {
                    /*printf("ping_start_addr: %lx ping_stack_addr: %lx\n",
                           START_ADDR (start_addr), (L4_Word_t) ping_stack);*/
                    send_startup_ipc (ping_tid,
                              START_ADDR(start_addr),
                              (L4_Word_t) ping_stack +
                              sizeof (ping_stack) - 32);
                    L4_ThreadSwitch(ping_tid);
                }

                if (fass_buffer) {
                    pong_start_addr = pong_thread_buffer;
                    pong_stack_addr = pong_stack_fass;
                } else if (fass) {
                    pong_start_addr = pong_thread_fass;
                    pong_stack_addr = pong_stack_fass;
                } else if (fault_test) {
                    pong_stack_addr = pong_stack_fass;
                    pong_start_addr = pong_thread_faulter;
                } else if (intra_close) {
                    pong_start_addr = pong_thread_close;
                } else if (intra_open) {
                    pong_start_addr = pong_thread_open;
                } else if (intra_rpc) {
                    pong_start_addr = pong_thread_close;
                } else if (intra_ovh) {
                    pong_start_addr = pong_thread_ovh;
                } else if (intra_async) {
                    pong_start_addr = pong_thread_async;
                } else if (intra_async_ovh) {
                    pong_start_addr = pong_thread_async_ovh;
                } else {
                    pong_start_addr = pong_thread;
                }

                if (!pagertimer) {
                    /*printf("pong_start_addr: %lx pong_stack_addr: %lx\n",
                           START_ADDR (pong_start_addr), (L4_Word_t) pong_stack_addr);*/
                    L4_Set_Priority(ping_tid, 100);
                    L4_Set_Priority(pong_tid, 99);
                    send_startup_ipc (pong_tid, 
                              START_ADDR (pong_start_addr),
                              (L4_Word_t) pong_stack_addr + sizeof (ping_stack) - 32);
                }
                break;
            }


            if (L4_UntypedWords (tag) != 2 ||
                !L4_IpcSucceeded (tag)) {
                printf ("pingpong: malformed pagefault IPC from %p (tag=%p)\n",
                    (void *) tid.raw, (void *) tag.raw);
                L4_KDB_Enter ("malformed pf");
                break;
            }

            faddr = L4_MsgWord(&msg, 0);
            fip   = L4_MsgWord (&msg, 1);
            L4_MsgClear(&msg);

            if (fault_test && (faddr == (uintptr_t) fault_area)) {
                if (count < num_iterations) {
                    count++;
                } else {
                    /* Tell master that we're finished */
                    L4_Set_MsgTag (L4_Niltag);
                    L4_Send (master_tid);
                    break;
                }
            } else {
                L4_MapItem_t map;
                L4_SpaceId_t space;
                L4_Word_t seg, offset, cache, rwx, size;
                int r;

                seg = get_seg(KBENCH_SPACE, faddr, &offset, &cache, &rwx);
                //if can not find mapping, must be page fault test,
                //just map any valid address, since fault address is dummy.
                if (seg == ~0UL)
                    seg = get_seg(KBENCH_SPACE, (L4_Word_t) fault_area,
                                  &offset, &cache, &rwx);

                if (tid.raw == ping_th.raw)
                    space = ping_space;
                else if (tid.raw == pong_th.raw)
                {
                    if (pong_space.raw != L4_nilspace.raw)
                        space = pong_space;
                    else //pong_space is not created, only ping_space is used.
                        space = ping_space;
                }
                else
                    space = KBENCH_SPACE;

                size = L4_GetMinPageBits();
                faddr &= ~((1ul << size)-1);
                offset &= ~((1ul << size)-1);

                L4_MapItem_Map(&map, seg, offset, faddr, size,
                               cache, rwx);
                r = L4_ProcessMapItem(space, map);
                assert(r == 1);
            }
            L4_MsgLoad(&msg);
            tag = L4_ReplyWait (tid, &tid);
        }
    }
}
Ejemplo n.º 10
0
    } else {
        return createThread(func);
    }
}

#define PAGESIZE (1 << USER_MIN_PAGE_BITS)
#define PARTIAL_SIZE            (PAGESIZE*2)
#define PARTIAL_SIZE_UNMAPPED   4 /* umapped size from PARTIAL_SIZE */
/*
 * map mapped_address to physical address of partial_buffer_physmem
 */
static void prepare_mapped_address(void)
{
    ALIGNED(PARTIAL_SIZE) static char partial_buffer_physmem[PARTIAL_SIZE] = {1};
    word_t offset, cache, rwx, size;
    uintptr_t seg = get_seg(KTEST_SPACE, (uintptr_t)partial_buffer_physmem, &offset, &cache, &rwx, &size);
    int res;
    uintptr_t virt = (uintptr_t)mapped_address;
    uintptr_t base = virt;
    L4_MapItem_t map;
    size = L4_GetMinPageBits();

    offset = offset & ~((1UL << size)-1);
    virt = virt & ~((1UL << size)-1);

    while (virt < base + PARTIAL_SIZE) {
        L4_MapItem_Map(&map, seg, offset, virt,
                size, cache, rwx);

        res = L4_ProcessMapItem(KTEST_SPACE, map);
        fail_unless(res == 1, "L4_Map failed");