Example #1
0
File: rpc.c Project: seL4/refos
void
rpc_sv_release(void *cl)
{
    rpc_client_state_t* c = (rpc_client_state_t*)cl;
    (void)c;

    _rpc_dest_ep = 0;

    if (seL4_MessageInfo_get_extraCaps(c->minfo) > 0) {
        // Flush recieving path of previous recieved caps.
        seL4_CNode_Delete(REFOS_CSPACE, _rpc_recv_cslot, REFOS_CSPACE_DEPTH);
    }
}
Example #2
0
struct srv_client*
srv_ctable_connect_direct_handler(srv_common_t *srv, srv_msg_t *m,
        seL4_CPtr liveness, int* _errno)
{
    assert(srv && srv->magic == SRV_MAGIC && m);

    /* Check that the liveness cap passed in correctly. */
    if(!srv_check_dispatch_caps(m, 0x00000000, 1)) {
        SET_ERRNO_PTR(_errno, EINVALIDPARAM);
        return NULL;
    }
    int error = ENOMEM;

    /* Copyout the liveness cap, create session cap cslot. Do not printf before the copyout. */
    seL4_CPtr livenessCP = rpc_copyout_cptr(liveness);
    if (!liveness || !livenessCP) {
        goto error0;
    }

    /* Allocate the client structure. */
    struct srv_client *c = client_alloc(&srv->clientTable, livenessCP);
    if (!c) {
        goto error1;
    }

    dprintf("Adding new %s client cID = %d. Hi! (:D)\n", srv->config.serverName, c->cID);
    assert(c->session);

    /* Authenticate the client to the process server, using its liveness cap. */
    error = proc_watch_client(c->liveness, srv->notifyClientFaultDeathAsyncEP, &c->deathID);
    if (error != ESUCCESS) {
        goto error2;
    }

    SET_ERRNO_PTR(_errno, ESUCCESS);
    return c;

    /* Exit stack. */
error2:
    client_queue_delete(&srv->clientTable, c->cID);
    client_table_postaction(&srv->clientTable);
error1:
    seL4_CNode_Delete(REFOS_CSPACE, livenessCP, REFOS_CDEPTH);
    csfree(livenessCP);
error0:
    SET_ERRNO_PTR(_errno, error);
    return NULL;

}
Example #3
0
File: rpc.c Project: seL4/refos
void
rpc_init(const char* name_str, int32_t label)
{
    _rpc_label = label;
    _rpc_name = name_str;

	rpc_reset_contents(NULL);

    if (!_rpc_recv_cslot) {
        rpc_setup_recv(REFOS_THREAD_CAP_RECV);
    } else if (seL4_MessageInfo_get_extraCaps(_rpc_minfo) > 0) {
        // Flush recieving path of previous recieved caps.
        seL4_CNode_Delete(REFOS_CSPACE, _rpc_recv_cslot, REFOS_CDEPTH);
    }

    seL4_SetMR(0, label);
}
Example #4
0
static int
test_file_server_connect()
{
    test_start("fs connection");

    /* Find the file server. */
    nsv_mountpoint_t mp = nsv_resolve("fileserv/*");
    test_assert(mp.success == true);
    test_assert(mp.serverAnon != 0);

    seL4_CPtr fileservAnon = mp.serverAnon;
    const int fs_test_repeat = 5;

    /* Attempt to ping the file server. */
    for (int i = 0; i < fs_test_repeat; i++) {
        int error = serv_ping(fileservAnon);
        test_assert(error == ESUCCESS);
    }

    /* Repeatedly connect to and disconnect from the file server. */
    for (int i = 0; i < fs_test_repeat; i++) {
        int error;
        seL4_CPtr fileservSession = serv_connect_direct(fileservAnon, REFOS_LIVENESS, &error);
        test_assert(fileservSession && error == ESUCCESS);

        if (fileservSession) {
            serv_disconnect_direct(fileservSession);
            seL4_CNode_Delete(REFOS_CSPACE, fileservSession, REFOS_CDEPTH);
            csfree(fileservSession);
        }
    }

    /* Release the resources stored in the valid mountpoint. */
    nsv_mountpoint_release(&mp);
    test_assert(mp.success == false);
    test_assert(mp.serverAnon == 0);

    return test_success();
}
Example #5
0
refos_err_t
srv_ctable_set_param_buffer_handler(srv_common_t *srv, struct srv_client *c,
        srv_msg_t *m, seL4_CPtr parambufferDataspace, uint32_t parambufferSize)
{
    assert(srv && srv->magic == SRV_MAGIC);
    assert(c && m);

    /* Special case: unset the parameter buffer. */
    if (!parambufferDataspace && parambufferSize == 0) {
        seL4_CNode_Revoke(REFOS_CSPACE, c->paramBuffer, REFOS_CDEPTH);
        seL4_CNode_Delete(REFOS_CSPACE, c->paramBuffer, REFOS_CDEPTH);
        csfree(c->paramBuffer);
        c->paramBuffer = 0;
        c->paramBufferSize = 0;
        return ESUCCESS;
    }
 
    /* Sanity check parameters. */
    if (!srv_check_dispatch_caps(m, 0x00000000, 1)) {
        return EINVALIDPARAM;
    }
    if (parambufferSize == 0) {
        return EINVALIDPARAM;
    }

    /* Set the parameter buffer by copying out the given dspace cap.
       Do not printf before copyout. */
    c->paramBuffer = rpc_copyout_cptr(parambufferDataspace);
    if (!c->paramBuffer) {
        ROS_ERROR("Failed to copyout the cap.");
        return ENOMEM;
    }
    c->paramBufferSize = parambufferSize;
    dprintf("Set param buffer for client cID = %d...\n", c->cID);

    return ESUCCESS;

}
Example #6
0
void reset_resources(void) {
    simple_t simple;
    camkes_make_simple(&simple);
    int i;
    seL4_CPtr root = simple_get_cnode(&simple);
    int error;
    /* revoke any of our initial untyped resources */
    for (i = 0; i < simple_get_untyped_count(&simple); i++) {
        uint32_t size_bits;
        uint32_t paddr;
        seL4_CPtr ut = simple_get_nth_untyped(&simple, i, &size_bits, &paddr);
        error = seL4_CNode_Revoke(root, ut, 32);
        assert(error == seL4_NoError);
    }
    /* delete anything from any slots that should be empty */
    for (i = simple_last_valid_cap(&simple) + 1; i < BIT(simple_get_cnode_size_bits(&simple)); i++) {
        error = seL4_CNode_Delete(root, i, 32);
    }
    /* save some pieces of the bss that we actually don't want to zero */
    char save_sysinfo[4];
    char save_libc[34];
    char save_morecore_area[4];
    char save_morecore_size[4];
    memcpy(save_libc, __libc, 34);
    memcpy(save_sysinfo, __sysinfo, 4);
    memcpy(save_morecore_area, morecore_area, 4);
    memcpy(save_morecore_size, morecore_size, 4);
    /* zero the bss */
    memset(__bss_start, 0, (uintptr_t)__bss_end - (uintptr_t)__bss_start);
    /* restore these pieces */
    memcpy(__libc, save_libc, 34);
    memcpy(__sysinfo, save_sysinfo, 4);
    memcpy(morecore_area, save_morecore_area, 4);
    memcpy(morecore_size, save_morecore_size, 4);
    mutex_reinitializable_vm_lock_init();
}
Example #7
0
static serv_connection_t
serv_connect_internal(char *serverPath, bool paramBuffer)
{
    _svprintf("Connecting to server [%s]...\n", serverPath);
    serv_connection_t sc;
    memset(&sc, 0, sizeof(serv_connection_t));
    sc.error = EINVALID;

    /* Resolve server path to find the server's anon cap. */
    _svprintf("    Querying nameserv to find anon cap for [%s]....\n", serverPath);
    printf("    Querying nameserv to find anon cap for [%s]....\n", serverPath);
    sc.serverMountPoint = nsv_resolve(serverPath);
    if (!sc.serverMountPoint.success || ROS_ERRNO() != ESUCCESS) {
        _svprintf("    WARNING: Server not found.\n");
        printf("    WARNING: Server not found.\n");
        sc.error = ESERVERNOTFOUND;
        goto exit1;
    }

    _svprintf("    Result path prefix [%s] anon 0x%x dspace [%s]....\n",
        sc.serverMountPoint.nameservPathPrefix, sc.serverMountPoint.serverAnon,
        sc.serverMountPoint.dspaceName);
    printf("    Result path prefix [%s] anon 0x%x dspace [%s]....\n",
        sc.serverMountPoint.nameservPathPrefix, sc.serverMountPoint.serverAnon,
        sc.serverMountPoint.dspaceName);
    if (serv_special_connectless_server(sc.serverMountPoint.serverAnon)) {
        /* Connectionless server. */
        _svprintf("    Known connectionless server detected.\n");
        printf("    Known connectionless server detected.\n");
        sc.connectionLess = true;
        sc.serverSession = sc.serverMountPoint.serverAnon;
        sc.error = ESUCCESS;
        return sc;
    } else {
        /* Make connection request to server using the anon cap. */
        _svprintf("    Make connection request to server [%s] using the anon cap 0x%x...\n",
                serverPath, sc.serverMountPoint.serverAnon);
        printf("    Make connection request to server [%s] using the anon cap 0x%x...\n",
                serverPath, sc.serverMountPoint.serverAnon);
        sc.serverSession = serv_connect_direct(sc.serverMountPoint.serverAnon, REFOS_LIVENESS,
                                               &sc.error);
    }
    if (!sc.serverSession || sc.error != ESUCCESS) {
        _svprintf("    WARNING: Failed to anonymously connect to server.\n");
        printf("    WARNING: Failed to anonymously connect to server.\n");
        goto exit2;
    }

    /* Try pinging the server. */
    int error = serv_ping(sc.serverSession);
    if (error) {
        _svprintf("    WARNING: Failed to ping file server.\n");
        printf("    WARNING: Failed to ping file server.\n");
        sc.error = error;
        goto exit3;
    }

    /* Set up the parameter buffer between client (ie. us) and server. */
    if (paramBuffer) {
        sc.paramBuffer = data_open_map(REFOS_PROCSERV_EP, "anon", 0, 0,
                                       PROCESS_PARAM_DEFAULTSIZE, -1);
        if (sc.paramBuffer.err != ESUCCESS) {
            _svprintf("    WARNING: Failed to create param buffer dspace.\n");
            printf("    WARNING: Failed to create param buffer dspace.\n");
            sc.error = sc.paramBuffer.err;
            goto exit3;
        }
        assert(sc.paramBuffer.window && sc.paramBuffer.dataspace);
        assert(sc.paramBuffer.vaddr != NULL);

        /* Set this parameter buffer on server. */
        error = serv_set_param_buffer(sc.serverSession, sc.paramBuffer.dataspace,
                                      PROCESS_PARAM_DEFAULTSIZE);
        if (error) {
            _svprintf("    Failed to set remote server parameter buffer.");
            printf("    Failed to set remote server parameter buffer.");
            sc.error = error;
            goto exit4;
        }
    } else {
        sc.paramBuffer.err = -1;
    }

    _svprintf("Successfully connected to server [%s]!\n", serverPath);
    printf("Successfully connected to server [%s]!\n", serverPath);
    sc.error = ESUCCESS;
    return sc;

    /* Exit stack. */
exit4:
    assert(sc.paramBuffer.err == ESUCCESS);
    data_mapping_release(sc.paramBuffer);
exit3:
    assert(sc.serverSession);
    if (!sc.connectionLess) {
        serv_disconnect_direct(sc.serverSession);
        seL4_CNode_Delete(REFOS_CSPACE, sc.serverSession, REFOS_CDEPTH);
        csfree(sc.serverSession);
    }
exit2:
    nsv_mountpoint_release(&sc.serverMountPoint);
exit1:
    assert(sc.error != ESUCCESS);
    return sc;
}
Example #8
0
static int
test_file_server_dataspace()
{
    /* ---------- datamap test ------------ */
    test_start("fs cpio dspace datamap");
    int error;

    /* Find the file server. */
    nsv_mountpoint_t mp = nsv_resolve("fileserv/*");
    test_assert(mp.success == true);
    test_assert(mp.serverAnon != 0);
    seL4_CPtr fileservAnon = mp.serverAnon;

    seL4_CPtr fileservSession = serv_connect_direct(fileservAnon, REFOS_LIVENESS, &error);
    test_assert(fileservSession && error == ESUCCESS);

    /* Allocate a temporary window. */
    seL4_CPtr tempWindow = 0;
    seL4_Word tempWindowVaddr = walloc(2, &tempWindow);
    test_assert(tempWindowVaddr && tempWindow);

    /* Open a new dataspace on the fileserver to test with. */
    seL4_CPtr dspace = data_open(fileservSession, "hello.txt", 0, O_RDWR, 0, &error);
    test_assert(dspace && error == ESUCCESS);

    /* Test datamap. */
    error = data_datamap(fileservSession, dspace, tempWindow, 3);
    test_assert(error == ESUCCESS);
    int scmp = strncmp((char*) tempWindowVaddr, "lo world!", 9);
    test_assert(scmp == 0);

    test_success();

    /* ---------- init_data test ------------ */
    test_start("fs cpio dspace init_data");

    /* Open a new anon dataspace to init data on */
    seL4_CPtr anonDS = data_open(REFOS_PROCSERV_EP, "anon", 0, O_RDWR, 0x1000, &error);
    test_assert(anonDS && error == ESUCCESS);

    /* Inititialise content of this anon dataspace with our fileserv CPIO dataspace. */
    error = data_init_data(fileservSession, anonDS, dspace , 3);
    test_assert(error == ESUCCESS);

    /* Allocate another temporary window. */
    seL4_CPtr tempWindowAnon = 0;
    seL4_Word tempWindowVaddrAnon = walloc(2, &tempWindowAnon);
    test_assert(tempWindowVaddrAnon && tempWindowAnon);

    /* Datamap initialised anon dataspace. */
    error = data_datamap(REFOS_PROCSERV_EP, anonDS, tempWindowAnon, 0);
    test_assert(error == ESUCCESS);
    scmp = strncmp((char*) tempWindowVaddrAnon, "lo world!", 9);
    test_assert(scmp == 0);

    /* Clean up. */
    data_dataunmap(fileservSession, tempWindow);
    data_dataunmap(REFOS_PROCSERV_EP, tempWindowAnon);
    if (tempWindow) {
        walloc_free(tempWindowVaddr, 2);
    }
    if (tempWindowAnon) {
        walloc_free(tempWindowVaddrAnon, 2);
    }
    if (fileservSession) {
        serv_disconnect_direct(fileservSession);
        seL4_CNode_Delete(REFOS_CSPACE, fileservSession, REFOS_CDEPTH);
        csfree(fileservSession);
    }

    /* Release the resources stored in the valid mountpoint. */
    nsv_mountpoint_release(&mp);
    test_assert(mp.success == false);
    test_assert(mp.serverAnon == 0);

    return test_success();
}