/* share dataspaces with executable file sections * with a client task */ int share_sections (unsigned long hmod, l4_threadid_t client) { IXFModule *ixf; IXFSYSDEP *sysdep; l4exec_section_t *section; l4_uint32_t rights; slist_t *s; unsigned long imp_hmod; int index; int rc; ixf = (IXFModule *)hmod; sysdep = (IXFSYSDEP *)(ixf->hdlSysDep); s = sysdep->seclist; while (s) { section = s->section; rights = 0; if (section->info.type & L4_DSTYPE_READ) rights |= L4DM_READ; if (section->info.type & L4_DSTYPE_WRITE) rights |= L4DM_WRITE; rc = l4dm_share(§ion->ds, client, rights); if (rc) { LOG("error sharing dataspace %x with task %x.%x", section->ds, client.id.task, client.id.lthread); return rc; } LOG("dataspace %x shared", section->ds); s = s->next; } index = 0; while (!(rc = getimp (hmod, &index, &imp_hmod))) { if (!imp_hmod) continue; // DL, no sections to share rc = share_sections(imp_hmod, client); LOG("module %x sections shared", imp_hmod); if (rc) break; } if (rc == ERROR_MOD_NOT_FOUND) return 0; return rc; }
int32_t ferret_monitor_attach_component(CORBA_Object _dice_corba_obj, uint16_t major, uint16_t minor, uint16_t instance, l4dm_dataspace_t *ds, CORBA_Server_Environment *_dice_corba_env) { local_object_id_t id; l4vfs_th_node_t * node; char path[MAX_PATH]; int ret; if (major == FERRET_TBUF_MAJOR && minor == FERRET_TBUF_MINOR) { LOGd(verbose, "Request for trace buffer"); return -2; // not found } snprintf(path, MAX_PATH, "/%d/%d/%d", major, minor, instance); id = l4vfs_th_resolve(0, path); if (id == L4VFS_ILLEGAL_OBJECT_ID) { LOGd(verbose, "Request for unknown sensor"); return -1; // not found } node = l4vfs_th_node_for_id(id); *ds = ((sensor_entry_t *)(node->data))->ds; LOGd(verbose, "Found id = %d.", id); ret = l4dm_share(ds, *_dice_corba_obj, L4DM_RO); if (ret) { LOG("Cannot share access rights for ds: ret = %d", ret); return -1; } node->usage_count++; return 0; }
int32_t ferret_client_create_component(CORBA_Object _dice_corba_obj, uint16_t major, uint16_t minor, uint16_t instance, uint16_t type, uint32_t flags, const char* config, l4dm_dataspace_t *ds, CORBA_Server_Environment *_dice_corba_env) { int ret; void * temp; char * data; ssize_t size = 0; char path[MAX_PATH]; l4vfs_th_node_t * node; local_object_id_t id; sensor_entry_t * se; LOGd(verbose, "create: %hd:%hd:%hd:%hd", major, minor, instance, type); // fixme: - check flags // - care for shared opens // - care for usage count on reopens /* 1. check of we have this node -> reopen * yes ? -> as usual + increment usage count * no ? -> create directories on demand and finally create the * corresponding node itself */ snprintf(path, MAX_PATH, "/%d/%d/%d", major, minor, instance); id = l4vfs_th_resolve(0, path); if (id != L4VFS_ILLEGAL_OBJECT_ID) { node = l4vfs_th_node_for_id(id); se = (sensor_entry_t *)(node->data); // check some properties, reopen works only with similar properties if (type != se->type) { LOG("Given type '%d' does not match old one '%d' on reopen!", type, se->type); return -1; } if (flags != se->flags) { LOG("Given flags '%d' do not match old ones '%d' on reopen!", type, se->flags); return -1; } if (strcmp(config, se->config) != 0) { LOG("Given config '%s' does not match old one '%s' on reopen!", config, se->config); return -1; } *ds = se->ds; ret = l4dm_share(ds, *_dice_corba_obj, L4DM_RW); if (ret) { LOG("Cannot share access rights for ds: ret = %d", ret); return -1; } node->usage_count++; } else { unsigned dm_flags = L4DM_PINNED + L4RM_MAP + L4DM_CONTIGUOUS; // create ds switch (type) { case FERRET_SCALAR: size = ferret_scalar_size_config(config); break; case FERRET_HISTO: size = ferret_histo_size_config(config); break; case FERRET_HISTO64: size = ferret_histo64_size_config(config); break; case FERRET_LIST: size = ferret_list_size_config(config); break; case FERRET_DPLIST: size = ferret_dplist_size_config(config); break; case FERRET_SLIST: size = ferret_slist_size_config(config); break; case FERRET_ULIST: size = ferret_ulist_size_config(config); break; case FERRET_ALIST: size = ferret_alist_size_config(config); break; case FERRET_TBUF: LOG("The tracebuffer sensor can not be instantiated, it exists" " in the kernel!"); return -1; default: LOG("Unknown sensor type requested: %d", type); return -1; } LOGd(verbose, "Size: %d", (int)size); // %z in not printf compatible if (flags & FERRET_SUPERPAGES && size > L4_PAGESIZE) dm_flags += L4DM_MEMPHYS_SUPERPAGES; temp = l4dm_mem_ds_allocate(size, dm_flags, ds); if (! temp) return -1; ferret_common_init((ferret_common_t *)temp, major, minor, instance, type, *ds); switch (type) { case FERRET_SCALAR: ret = ferret_scalar_init((ferret_scalar_t *) temp, config); if (ret != 0) { LOG("Something wrong in scalar_init: %d, %s", ret, config); // fixme: free allocated memory return -2; } break; case FERRET_HISTO: ret = ferret_histo_init((ferret_histo_t *) temp, config); if (ret != 0) { LOG("Something wrong in histo_init: %d, %s", ret, config); // fixme: free allocated memory return -2; } break; case FERRET_HISTO64: ret = ferret_histo64_init((ferret_histo64_t *) temp, config); if (ret != 0) { LOG("Something wrong in histo64_init: %d, %s", ret, config); // fixme: free allocated memory return -2; } break; case FERRET_LIST: ret = ferret_list_init((ferret_list_t *) temp, config); if (ret != 0) { LOG("Something wrong in list_init: %d, %s", ret, config); // fixme: free allocated memory return -2; } break; case FERRET_ALIST: ret = ferret_alist_init((ferret_alist_t *) temp, config); if (ret != 0) { LOG("Something wrong in alist_init: %d, %s", ret, config); // fixme: free allocated memory return -2; } break; case FERRET_DPLIST: ret = ferret_dplist_init((ferret_dplist_t *) temp, config, &data); if (ret != 0) { LOG("Something wrong in dplist_init: %d, %s", ret, config); // fixme: free allocated memory return -2; } break; case FERRET_SLIST: ret = ferret_slist_init((ferret_slist_t *) temp, config, &data); if (ret != 0) { LOG("Something wrong in slist_init: %d, %s", ret, config); // fixme: free allocated memory return -2; } break; case FERRET_ULIST: ret = ferret_ulist_init((ferret_ulist_t *) temp, config, &data); if (ret != 0) { LOG("Something wrong in ulist_init: %d, %s", ret, config); // fixme: free allocated memory return -2; } break; default: LOG("Unknown sensor type requested: %d", type); return -1; } LOGd(verbose, "Size: %d", (int)size); // %z in not printf compatible se = sensors_new_entry(ds, major, minor, instance, type, flags, config, data); if (! se) { return -1; } id = se->node->id; LOGd(verbose, "Registered with id = %d.", id); ret = l4dm_share(ds, *_dice_corba_obj, L4DM_RW); if (ret) { // free ds l4dm_mem_release(temp); LOG("Cannot share access rights for ds: ret = %d", ret); return -1; } } return 0; }