1/* 2 * Copyright 2016, Data61 3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO) 4 * ABN 41 687 119 230. 5 * 6 * This software may be distributed and modified according to the terms of 7 * the BSD 2-Clause license. Note that NO WARRANTY is provided. 8 * See "LICENSE_BSD2.txt" for details. 9 * 10 * @TAG(D61_BSD) 11 */ 12 13#include "dispatch.h" 14#include <refos-util/serv_connect.h> 15 16 /*! @file 17 @brief Common file server dispatcher helper functions. */ 18 19/*! @brief Special anonymous client structure. 20 21 We use this to temporarily book-keep an anonymous client who has not fully connected yet. This 22 solves the chicken-and-egg problem of needing a rpc_client_t to communicate so the client can 23 communicate to set up real communication session. 24*/ 25static struct srv_client _anonClient; 26 27int 28check_dispatch_interface(srv_msg_t *m, void **userptr, int labelMin, int labelMax) 29{ 30 assert(userptr); 31 if (seL4_MessageInfo_get_label(m->message) != seL4_Fault_NullFault) { 32 /* Not a Syscall, pass onto next dispatcher. */ 33 return DISPATCH_PASS; 34 } 35 36 struct srv_client *c = NULL; 37 if (m->badge) { 38 /* Try to look up client. */ 39 c = client_get_badge(&fileServCommon->clientTable, m->badge); 40 } else { 41 /* Anonymous client, unbadged. */ 42 c = &_anonClient; 43 memset(c, 0, sizeof(struct srv_client)); 44 c->magic = FS_DISPATCH_ANON_CLIENT_MAGIC; 45 } 46 47 if (!c) { 48 /* No client registered here, not our syscall to handle. */ 49 return DISPATCH_PASS; 50 } 51 52 seL4_Word syscallFunc = seL4_GetMR(0); 53 if (syscallFunc <= labelMin || syscallFunc >= labelMax) { 54 /* Not our type of syscall to handle. */ 55 return DISPATCH_PASS; 56 } 57 58 c->rpcClient.userptr = (void*) m; 59 c->rpcClient.minfo = m->message; 60 (*userptr) = (void*) c; 61 return DISPATCH_SUCCESS; 62} 63