Changeset eadaeae8 in mainline for uspace/app/trace


Ignore:
Timestamp:
2018-03-21T20:58:49Z (8 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3be9d10
Parents:
874381a
Message:

Make capability handles type-safe

Define distinct pointer types for the handles of the supported
capability types and use them instead of integer handles. This makes it
virtually impossible to pass a non-handle or a handle of different type
instead of the proper handle. Also turn cap_handle_t into an "untyped"
capability handle that can be assigned to and from the "typed" handles.

This commit also fixes a bug in msim-con driver, which wrongly used the
IRQ number instead of the IRQ capability handle to unregister the IRQ.

This commit also fixes the wrong use of the capability handle instead
of error code in libusbhost.

Location:
uspace/app/trace
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/trace/ipcp.c

    r874381a readaeae8  
    4646
    4747typedef struct {
    48         sysarg_t phone_hash;
     48        cap_phone_handle_t phone_handle;
    4949        ipc_call_t question;
    5050        oper_t *oper;
    5151
    52         ipc_callid_t call_hash;
     52        cap_call_handle_t call_handle;
    5353
    5454        ht_link_t link;
     
    7575static size_t pending_call_key_hash(void *key)
    7676{
    77         ipc_callid_t *call_id = (ipc_callid_t *)key;
    78         return *call_id;
     77        cap_call_handle_t *chandle = (cap_call_handle_t *) key;
     78        return CAP_HANDLE_RAW(*chandle);
    7979}
    8080
     
    8282{
    8383        pending_call_t *hs = hash_table_get_inst(item, pending_call_t, link);
    84         return hs->call_hash;
     84        return CAP_HANDLE_RAW(hs->call_handle);
    8585}
    8686
    8787static bool pending_call_key_equal(void *key, const ht_link_t *item)
    8888{
    89         ipc_callid_t *call_id = (ipc_callid_t *)key;
     89        cap_call_handle_t *chandle = (cap_call_handle_t *) key;
    9090        pending_call_t *hs = hash_table_get_inst(item, pending_call_t, link);
    9191
    92         return *call_id == hs->call_hash;
     92        return *chandle == hs->call_handle;
    9393}
    9494
     
    102102
    103103
    104 void ipcp_connection_set(int phone, int server, proto_t *proto)
    105 {
    106         if (phone <0 || phone >= MAX_PHONE) return;
    107         connections[phone].server = server;
    108         connections[phone].proto = proto;
    109         have_conn[phone] = 1;
    110 }
    111 
    112 void ipcp_connection_clear(int phone)
    113 {
    114         have_conn[phone] = 0;
    115         connections[phone].server = 0;
    116         connections[phone].proto = NULL;
     104void ipcp_connection_set(cap_phone_handle_t phone, int server, proto_t *proto)
     105{
     106        // XXX: there is no longer a limit on the number of phones as phones are
     107        // now handled using capabilities
     108        if (CAP_HANDLE_RAW(phone) < 0 || CAP_HANDLE_RAW(phone) >= MAX_PHONE)
     109            return;
     110        connections[CAP_HANDLE_RAW(phone)].server = server;
     111        connections[CAP_HANDLE_RAW(phone)].proto = proto;
     112        have_conn[CAP_HANDLE_RAW(phone)] = 1;
     113}
     114
     115void ipcp_connection_clear(cap_phone_handle_t phone)
     116{
     117        have_conn[CAP_HANDLE_RAW(phone)] = 0;
     118        connections[CAP_HANDLE_RAW(phone)].server = 0;
     119        connections[CAP_HANDLE_RAW(phone)].proto = NULL;
    117120}
    118121
     
    174177}
    175178
    176 void ipcp_call_out(int phone, ipc_call_t *call, ipc_callid_t hash)
     179void ipcp_call_out(cap_phone_handle_t phandle, ipc_call_t *call,
     180    cap_call_handle_t chandle)
    177181{
    178182        pending_call_t *pcall;
     
    182186        int i;
    183187
    184         if (have_conn[phone]) proto = connections[phone].proto;
    185         else proto = NULL;
     188        if (have_conn[CAP_HANDLE_RAW(phandle)])
     189                proto = connections[CAP_HANDLE_RAW(phandle)].proto;
     190        else
     191                proto = NULL;
    186192
    187193        args = call->args;
    188194
    189195        if ((display_mask & DM_IPC) != 0) {
    190                 printf("Call ID: %d, phone: %d, proto: %s, method: ",
    191                     hash, phone,
    192                     (proto ? proto->name : "n/a"));
     196                printf("Call ID: %p, phone: %p, proto: %s, method: ",
     197                    chandle, phandle, (proto ? proto->name : "n/a"));
    193198                ipc_m_print(proto, IPC_GET_IMETHOD(*call));
    194199                printf(" args: (%" PRIun ", %" PRIun ", %" PRIun ", "
     
    208213                if (oper != NULL) {
    209214
    210                         printf("%s(%d).%s", (proto ? proto->name : "n/a"),
    211                             phone, (oper ? oper->name : "unknown"));
     215                        printf("%s(%p).%s", (proto ? proto->name : "n/a"),
     216                            phandle, (oper ? oper->name : "unknown"));
    212217
    213218                        putchar('(');
     
    236241
    237242        pcall = malloc(sizeof(pending_call_t));
    238         pcall->phone_hash = phone;
     243        pcall->phone_handle = phandle;
    239244        pcall->question = *call;
    240         pcall->call_hash = hash;
     245        pcall->call_handle = chandle;
    241246        pcall->oper = oper;
    242247
     
    244249}
    245250
    246 static void parse_answer(ipc_callid_t hash, pending_call_t *pcall,
     251static void parse_answer(cap_call_handle_t call_handle, pending_call_t *pcall,
    247252    ipc_call_t *answer)
    248253{
    249         sysarg_t phone;
     254        cap_phone_handle_t phone;
    250255        sysarg_t method;
    251256        sysarg_t service;
    252257        errno_t retval;
    253258        proto_t *proto;
    254         int cphone;
     259        cap_phone_handle_t cphone;
    255260
    256261        sysarg_t *resp;
     
    258263        int i;
    259264
    260         phone = pcall->phone_hash;
     265        phone = pcall->phone_handle;
    261266        method = IPC_GET_IMETHOD(pcall->question);
    262267        retval = IPC_GET_RETVAL(*answer);
     
    265270
    266271        if ((display_mask & DM_IPC) != 0) {
    267                 printf("Response to %d: retval=%s, args = (%" PRIun ", "
     272                printf("Response to %p: retval=%s, args = (%" PRIun ", "
    268273                    "%" PRIun ", %" PRIun ", %" PRIun ", %" PRIun ")\n",
    269                     hash, str_error_name(retval), IPC_GET_ARG1(*answer),
     274                    call_handle, str_error_name(retval), IPC_GET_ARG1(*answer),
    270275                    IPC_GET_ARG2(*answer), IPC_GET_ARG3(*answer),
    271276                    IPC_GET_ARG4(*answer), IPC_GET_ARG5(*answer));
     
    307312                        proto = proto_unknown;
    308313
    309                 cphone = IPC_GET_ARG5(*answer);
     314                cphone = (cap_phone_handle_t) IPC_GET_ARG5(*answer);
    310315                if ((display_mask & DM_SYSTEM) != 0) {
    311                         printf("Registering connection (phone %d, protocol: %s)\n", cphone,
     316                        printf("Registering connection (phone %p, protocol: %s)\n", cphone,
    312317                    proto->name);
    313318                }
     
    317322}
    318323
    319 void ipcp_call_in(ipc_call_t *call, ipc_callid_t hash)
     324void ipcp_call_in(ipc_call_t *call, cap_call_handle_t chandle)
    320325{
    321326        ht_link_t *item;
     
    325330                /* Not a response */
    326331                if ((display_mask & DM_IPC) != 0) {
    327                         printf("Not a response (hash %d)\n", hash);
     332                        printf("Not a response (handle %p)\n", chandle);
    328333                }
    329334                return;
    330335        }
    331336
    332         item = hash_table_find(&pending_calls, &hash);
     337        item = hash_table_find(&pending_calls, &chandle);
    333338        if (item == NULL)
    334339                return; /* No matching question found */
     
    339344
    340345        pcall = hash_table_get_inst(item, pending_call_t, link);
    341         hash_table_remove(&pending_calls, &hash);
    342 
    343         parse_answer(hash, pcall, call);
     346        hash_table_remove(&pending_calls, &chandle);
     347
     348        parse_answer(chandle, pcall, call);
    344349        free(pcall);
    345350}
    346351
    347 void ipcp_hangup(int phone, errno_t rc)
     352void ipcp_hangup(cap_phone_handle_t phone, errno_t rc)
    348353{
    349354        if ((display_mask & DM_SYSTEM) != 0) {
    350                 printf("Hang phone %d up -> %s\n", phone, str_error_name(rc));
     355                printf("Hang up phone %p -> %s\n", phone, str_error_name(rc));
    351356                ipcp_connection_clear(phone);
    352357        }
  • uspace/app/trace/ipcp.h

    r874381a readaeae8  
    4141void ipcp_cleanup(void);
    4242
    43 void ipcp_call_out(int phone, ipc_call_t *call, ipc_callid_t hash);
    44 void ipcp_call_sync(int phone, ipc_call_t *call, ipc_call_t *answer);
    45 void ipcp_call_in(ipc_call_t *call, ipc_callid_t hash);
    46 void ipcp_hangup(int phone, errno_t rc);
     43void ipcp_call_out(cap_phone_handle_t, ipc_call_t *, cap_call_handle_t);
     44void ipcp_call_sync(cap_phone_handle_t, ipc_call_t *call, ipc_call_t *answer);
     45void ipcp_call_in(ipc_call_t *call, cap_call_handle_t);
     46void ipcp_hangup(cap_phone_handle_t, errno_t);
    4747
    48 void ipcp_connection_set(int phone, int server, proto_t *proto);
    49 void ipcp_connection_clear(int phone);
     48void ipcp_connection_set(cap_phone_handle_t, int server, proto_t *proto);
     49void ipcp_connection_clear(cap_phone_handle_t);
    5050
    5151#endif
  • uspace/app/trace/trace.c

    r874381a readaeae8  
    282282{
    283283        ipc_call_t call;
    284         sysarg_t phoneid;
     284        cap_phone_handle_t phandle;
    285285
    286286        if (sc_rc != EOK)
    287287                return;
    288288
    289         phoneid = sc_args[0];
     289        phandle = (cap_phone_handle_t) sc_args[0];
    290290
    291291        IPC_SET_IMETHOD(call, sc_args[1]);
     
    296296        IPC_SET_ARG5(call, 0);
    297297
    298         ipcp_call_out(phoneid, &call, 0);
     298        ipcp_call_out(phandle, &call, 0);
    299299}
    300300
     
    311311
    312312        if (rc == EOK) {
    313                 ipcp_call_out(sc_args[0], &call, 0);
    314         }
    315 }
    316 
    317 static void sc_ipc_wait(sysarg_t *sc_args, int sc_rc)
     313                ipcp_call_out((cap_phone_handle_t) sc_args[0], &call, 0);
     314        }
     315}
     316
     317static void sc_ipc_wait(sysarg_t *sc_args, cap_call_handle_t sc_rc)
    318318{
    319319        ipc_call_t call;
     
    390390                break;
    391391        case SYS_IPC_WAIT:
    392                 sc_ipc_wait(sc_args, sc_rc);
     392                sc_ipc_wait(sc_args, (cap_call_handle_t) sc_rc);
    393393                break;
    394394        default:
Note: See TracChangeset for help on using the changeset viewer.