static void discover_desc(struct bt_scpp *scpp, GAttrib *attrib, uint16_t start, uint16_t end, bt_uuid_t *uuid, gatt_cb_t func, gpointer user_data) { unsigned int id; id = gatt_discover_desc(attrib, start, end, uuid, func, user_data); if (queue_push_head(scpp->gatt_op, UINT_TO_PTR(id))) return; error("scpp: Could not discover descriptor"); g_attrib_cancel(attrib, id); }
void route_free(Route *route) { if (!route) return; if (route->network) { LIST_REMOVE(routes, route->network->static_routes, route); if (route->section) hashmap_remove(route->network->routes_by_section, UINT_TO_PTR(route->section)); } free(route); }
int route_new_static(Network *network, unsigned section, Route **ret) { _cleanup_route_free_ Route *route = NULL; if (section) { route = hashmap_get(network->routes_by_section, UINT_TO_PTR(section)); if (route) { *ret = route; route = NULL; return 0; } } route = new0(Route, 1); if (!route) return -ENOMEM; route->family = AF_UNSPEC; route->scope = RT_SCOPE_UNIVERSE; route->protocol = RTPROT_STATIC; route->network = network; LIST_PREPEND(routes, network->static_routes, route); if (section) { route->section = section; hashmap_put(network->routes_by_section, UINT_TO_PTR(route->section), route); } *ret = route; route = NULL; return 0; }
bool bt_att_unregister_disconnect(struct bt_att *att, unsigned int id) { struct att_disconn *disconn; if (!att || !id) return false; disconn = queue_remove_if(att->disconn_list, match_disconn_id, UINT_TO_PTR(id)); if (!disconn) return false; destroy_att_disconn(disconn); return true; }
bool bt_uhid_unregister(struct bt_uhid *uhid, unsigned int id) { struct uhid_notify *notify; if (!uhid || !id) return false; notify = queue_remove_if(uhid->notify_list, match_notify_id, UINT_TO_PTR(id)); if (!notify) return false; free(notify); return true; }
static void shutdown_device(void) { uint8_t enable = 0x00; unsigned int id; bt_hci_flush(hci_dev); id = timeout_add(5000, shutdown_timeout, NULL, NULL); bt_hci_send(hci_dev, BT_HCI_CMD_LE_SET_ADV_ENABLE, &enable, 1, NULL, NULL, NULL); bt_hci_send(hci_dev, BT_HCI_CMD_RESET, NULL, 0, shutdown_complete, UINT_TO_PTR(id), NULL); }
bool bt_hci_unregister(struct bt_hci *hci, unsigned int id) { struct evt *evt; if (!hci || !id) return false; evt = queue_remove_if(hci->evt_list, match_evt_id, UINT_TO_PTR(id)); if (!evt) return false; evt_free(evt); return true; }
int route_new_static(Network *network, unsigned section, Route **ret) { _cleanup_route_free_ Route *route = NULL; int r; if (section) { route = hashmap_get(network->routes_by_section, UINT_TO_PTR(section)); if (route) { *ret = route; route = NULL; return 0; } } r = route_new(&route); if (r < 0) return r; route->protocol = RTPROT_STATIC; if (section) { r = hashmap_put(network->routes_by_section, UINT_TO_PTR(route->section), route); if (r < 0) return r; route->section = section; } LIST_PREPEND(routes, network->static_routes, route); route->network = network; *ret = route; route = NULL; return 0; }
static void write_char(struct bt_scpp *scan, GAttrib *attrib, uint16_t handle, const uint8_t *value, size_t vlen, GAttribResultFunc func, gpointer user_data) { unsigned int id; id = gatt_write_char(attrib, handle, value, vlen, func, user_data); if (queue_push_head(scan->gatt_op, UINT_TO_PTR(id))) return; error("scpp: Could not read char"); g_attrib_cancel(attrib, id); }
bool bt_att_unregister(struct bt_att *att, unsigned int id) { struct att_notify *notify; if (!att || !id) return false; notify = queue_remove_if(att->notify_list, match_notify_id, UINT_TO_PTR(id)); if (!notify) return false; destroy_att_notify(notify); return true; }
bool gatt_db_unregister(struct gatt_db *db, unsigned int id) { struct notify *notify; if (!db || !id) return false; notify = queue_find(db->notify_list, match_notify_id, UINT_TO_PTR(id)); if (!notify) return false; queue_remove(db->notify_list, notify); notify_destroy(notify); return true; }
static struct hci_dev *dev_lookup(uint16_t index) { struct hci_dev *dev; dev = queue_find(dev_list, dev_match_index, UINT_TO_PTR(index)); if (!dev) { fprintf(stderr, "Creating new device for unknown index\n"); dev = dev_alloc(index); if (!dev) return NULL; queue_push_tail(dev_list, dev); } return dev; }
void btd_gatt_client_service_removed(struct btd_gatt_client *client, struct gatt_db_attribute *attrib) { uint16_t start_handle, end_handle; if (!client || !attrib || !client->ready) return; gatt_db_attribute_get_service_handles(attrib, &start_handle, &end_handle); DBG("GATT Services Removed - start: 0x%04x, end: 0x%04x", start_handle, end_handle); queue_remove_all(client->services, match_service_handle, UINT_TO_PTR(start_handle), unregister_service); }
bool gatt_db_attribute_write_result(struct gatt_db_attribute *attrib, unsigned int id, int err) { struct pending_write *p; if (!attrib || !id) return false; p = queue_remove_if(attrib->pending_writes, find_pending, UINT_TO_PTR(id)); if (!p) return false; pending_write_result(p, err); return true; }
/* remove and FDB entry. */ void fdb_entry_free(FdbEntry *fdb_entry) { if (!fdb_entry) return; if (fdb_entry->network) { LIST_REMOVE(static_fdb_entries, fdb_entry->network->static_fdb_entries, fdb_entry); if (fdb_entry->section) hashmap_remove(fdb_entry->network->fdb_entries_by_section, UINT_TO_PTR(fdb_entry->section)); } free(fdb_entry->mac_addr); free(fdb_entry); }
void * grub_mmap_malign_and_register (grub_uint64_t align, grub_uint64_t size, int *handle, int type, int flags) { void *ret; if (flags & (GRUB_MMAP_MALLOC_LOW | GRUB_MMAP_MALLOC_HIGH)) { struct grub_mmap_malign_and_register_closure c; c.align = align; c.size = size; c.highestlow = 0; if (flags & GRUB_MMAP_MALLOC_LOW) { c.min = 0; c.max = 0x100000; } else { c.min = grub_mmap_high; c.max = 0x100000000ll; } /* FIXME: use low-memory mm allocation once it's available. */ grub_mmap_iterate (find_hook, &c); ret = UINT_TO_PTR (c.highestlow); } else ret = grub_memalign (align, size); if (! ret) { *handle = 0; return 0; } *handle = grub_mmap_register (PTR_TO_UINT64 (ret), size, type); if (! *handle) { grub_free (ret); return 0; } return ret; }
bool gatt_db_attribute_read_result(struct gatt_db_attribute *attrib, unsigned int id, int err, const uint8_t *value, size_t length) { struct pending_read *p; if (!attrib || !id) return false; p = queue_remove_if(attrib->pending_reads, find_pending, UINT_TO_PTR(id)); if (!p) return false; pending_read_result(p, err, value, length); return true; }
void grub_mmap_free_and_unregister (int handle) { struct grub_mmap_region *cur; grub_uint64_t addr; for (cur = grub_mmap_overlays; cur; cur = cur->next) if (cur->handle == handle) break; if (! cur) return; addr = cur->start; grub_mmap_unregister (handle); if (addr >= 0x100000) grub_free (UINT_TO_PTR (addr)); }
static void bus_match_node_free(struct bus_match_node *node) { assert(node); assert(node->parent); assert(!node->child); assert(node->type != BUS_MATCH_ROOT); assert(node->type < _BUS_MATCH_NODE_TYPE_MAX); if (node->parent->child) { /* We are apparently linked into the parent's child * list. Let's remove us from there. */ if (node->prev) { assert(node->prev->next == node); node->prev->next = node->next; } else { assert(node->parent->child == node); node->parent->child = node->next; } if (node->next) node->next->prev = node->prev; } if (node->type == BUS_MATCH_VALUE) { /* We might be in the parent's hash table, so clean * this up */ if (node->parent->type == BUS_MATCH_MESSAGE_TYPE) hashmap_remove(node->parent->compare.children, UINT_TO_PTR(node->value.u8)); else if (BUS_MATCH_CAN_HASH(node->parent->type) && node->value.str) hashmap_remove(node->parent->compare.children, node->value.str); free(node->value.str); } if (BUS_MATCH_IS_COMPARE(node->type)) { assert(hashmap_isempty(node->compare.children)); hashmap_free(node->compare.children); } free(node); }
void route_free(Route *route) { if (!route) return; if (route->network) { LIST_REMOVE(routes, route->network->static_routes, route); if (route->section) hashmap_remove(route->network->routes_by_section, UINT_TO_PTR(route->section)); } if (route->link) { set_remove(route->link->routes, route); set_remove(route->link->routes_foreign, route); } sd_event_source_unref(route->expire); free(route); }
static void process_response(struct bt_hci *hci, uint16_t opcode, const void *data, size_t size) { struct cmd *cmd; if (opcode == BT_HCI_CMD_NOP) goto done; cmd = queue_remove_if(hci->rsp_queue, match_cmd_opcode, UINT_TO_PTR(opcode)); if (!cmd) return; if (cmd->callback) cmd->callback(data, size, cmd->user_data); cmd_free(cmd); done: wakeup_writer(hci); }
DnsTransaction* dns_transaction_free(DnsTransaction *t) { DnsQuery *q; DnsZoneItem *i; if (!t) return NULL; sd_event_source_unref(t->timeout_event_source); dns_packet_unref(t->sent); dns_packet_unref(t->received); dns_answer_unref(t->cached); sd_event_source_unref(t->dns_udp_event_source); safe_close(t->dns_udp_fd); dns_server_unref(t->server); dns_stream_free(t->stream); if (t->scope) { hashmap_remove(t->scope->transactions, t->key); if (t->id != 0) hashmap_remove(t->scope->manager->dns_transactions, UINT_TO_PTR(t->id)); } dns_resource_key_unref(t->key); while ((q = set_steal_first(t->queries))) set_remove(q->transactions, t); set_free(t->queries); while ((i = set_steal_first(t->zone_items))) i->probe_transaction = NULL; set_free(t->zone_items); free(t); return NULL; }
bool mgmt_unregister(struct mgmt *mgmt, unsigned int id) { struct mgmt_notify *notify; if (!mgmt || !id) return false; notify = queue_remove_if(mgmt->notify_list, match_notify_id, UINT_TO_PTR(id)); if (!notify) return false; if (!mgmt->in_notify) { destroy_notify(notify); return true; } notify->removed = true; mgmt->need_notify_cleanup = true; return true; }
bool bt_att_unregister(struct bt_att *att, unsigned int id) { struct att_notify *notify; if (!att || !id) return false; notify = queue_find(att->notify_list, match_notify_id, UINT_TO_PTR(id)); if (!notify) return false; if (!att->in_notify) { queue_remove(att->notify_list, notify); destroy_att_notify(notify); return true; } notify->removed = true; att->need_notify_cleanup = true; return true; }
static int bus_match_find_compare_value( struct bus_match_node *where, enum bus_match_node_type t, uint8_t value_u8, const char *value_str, struct bus_match_node **ret) { struct bus_match_node *c, *n; assert(where); assert(where->type == BUS_MATCH_ROOT || where->type == BUS_MATCH_VALUE); assert(BUS_MATCH_IS_COMPARE(t)); assert(ret); for (c = where->child; c && c->type != t; c = c->next) ; if (!c) return 0; if (t == BUS_MATCH_MESSAGE_TYPE) n = hashmap_get(c->compare.children, UINT_TO_PTR(value_u8)); else if (BUS_MATCH_CAN_HASH(t)) n = hashmap_get(c->compare.children, value_str); else { for (n = c->child; !value_node_same(n, t, value_u8, value_str); n = n->next) ; } if (n) { *ret = n; return 1; } return 0; }
struct gatt_db_attribute *gatt_db_get_attribute(struct gatt_db *db, uint16_t handle) { struct gatt_db_service *service; int i; if (!db || !handle) return NULL; service = queue_find(db->services, find_service_for_handle, UINT_TO_PTR(handle)); if (!service) return NULL; for (i = 0; i < service->num_handles; i++) { if (!service->attributes[i]) continue; if (service->attributes[i]->handle == handle) return service->attributes[i]; } return NULL; }
t_Error PrsInit(t_FmPcd *p_FmPcd) { t_FmPcdDriverParam *p_Param = p_FmPcd->p_FmPcdDriverParam; t_FmPcdPrsRegs *p_Regs = p_FmPcd->p_FmPcdPrs->p_FmPcdPrsRegs; uint32_t tmpReg; if(p_FmPcd->guestId != NCSW_MASTER_ID) return E_OK; ASSERT_COND(p_FmPcd->guestId == NCSW_MASTER_ID); #ifdef FM_PRS_MEM_ERRATA_FMAN_SW003 { uint32_t i; uint32_t regsToGlobalOffset = 0x840; uint32_t firstPortToGlobalOffset = 0x45800; uint64_t globalAddr = PTR_TO_UINT(p_Regs) - regsToGlobalOffset; uint32_t firstPortAddr = (uint32_t)(globalAddr - (uint64_t)firstPortToGlobalOffset); uint32_t portSize = 0x1000; t_FmRevisionInfo revInfo; FM_GetRevision(p_FmPcd->h_Fm, &revInfo); if ((revInfo.majorRev == 1) && (revInfo.minorRev == 0)) { /* clear all parser memory */ IOMemSet32(UINT_TO_PTR(globalAddr), 0x00000000, 0x800); for(i = 0;i<16;i++) IOMemSet32(UINT_TO_PTR(firstPortAddr+i*portSize), (uint8_t)0x00000000, (uint32_t)0x80); } } #endif /* FM_PRS_MEM_ERRATA_FMAN_SW003 */ /**********************RPCLIM******************/ WRITE_UINT32(p_Regs->rpclim, (uint32_t)p_Param->prsMaxParseCycleLimit); /**********************FMPL_RPCLIM******************/ /* register even if no interrupts enabled, to allow future enablement */ FmRegisterIntr(p_FmPcd->h_Fm, e_FM_MOD_PRS, 0, e_FM_INTR_TYPE_ERR, PcdPrsErrorException, p_FmPcd); /* register even if no interrupts enabled, to allow future enablement */ FmRegisterIntr(p_FmPcd->h_Fm, e_FM_MOD_PRS, 0, e_FM_INTR_TYPE_NORMAL, PcdPrsException, p_FmPcd); /**********************PEVR******************/ WRITE_UINT32(p_Regs->pevr, (FM_PCD_PRS_SINGLE_ECC | FM_PCD_PRS_PORT_IDLE_STS) ); /**********************PEVR******************/ /**********************PEVER******************/ if(p_FmPcd->exceptions & FM_PCD_EX_PRS_SINGLE_ECC) { FmEnableRamsEcc(p_FmPcd->h_Fm); WRITE_UINT32(p_Regs->pever, FM_PCD_PRS_SINGLE_ECC); } else WRITE_UINT32(p_Regs->pever, 0); /**********************PEVER******************/ /**********************PERR******************/ WRITE_UINT32(p_Regs->perr, FM_PCD_PRS_DOUBLE_ECC); /**********************PERR******************/ /**********************PERER******************/ tmpReg = 0; if(p_FmPcd->exceptions & FM_PCD_EX_PRS_DOUBLE_ECC) { FmEnableRamsEcc(p_FmPcd->h_Fm); tmpReg |= FM_PCD_PRS_DOUBLE_ECC; } WRITE_UINT32(p_Regs->perer, tmpReg); /**********************PERER******************/ /**********************PPCS******************/ WRITE_UINT32(p_Regs->ppsc, p_FmPcd->p_FmPcdPrs->fmPcdPrsPortIdStatistics); /**********************PPCS******************/ #ifdef FM_PRS_L4_SHELL_ERRATA_FMANb { uint32_t i, j; t_FmRevisionInfo revInfo; uint8_t swPrsL4Patch[] = SW_PRS_L4_PATCH; FM_GetRevision(p_FmPcd->h_Fm, &revInfo); if ((revInfo.majorRev == 1) && (revInfo.minorRev == 0)) { /* load sw parser L4 patch */ for(i=0;i<sizeof(swPrsL4Patch)/4;i++) { tmpReg = 0; for(j =0;j<4;j++) { tmpReg <<= 8; tmpReg |= swPrsL4Patch[i*4+j]; } WRITE_UINT32(*(p_FmPcd->p_FmPcdPrs->p_SwPrsCode+ FM_PCD_PRS_SW_OFFSET/4 + i), tmpReg); } p_FmPcd->p_FmPcdPrs->p_CurrSwPrs = FM_PCD_PRS_SW_OFFSET/4 + p_FmPcd->p_FmPcdPrs->p_SwPrsCode+sizeof(swPrsL4Patch)/4; } } #endif /* FM_PRS_L4_SHELL_ERRATA_FMANb */ return E_OK; }
static void *server(void *p) { struct context *c = p; sd_bus *bus = NULL; sd_id128_t id; int r; c->quit = false; assert_se(sd_id128_randomize(&id) >= 0); assert_se(sd_bus_new(&bus) >= 0); assert_se(sd_bus_set_fd(bus, c->fds[0], c->fds[0]) >= 0); assert_se(sd_bus_set_server(bus, 1, id) >= 0); assert_se(sd_bus_add_object_vtable(bus, NULL, "/foo", "org.freedesktop.systemd.test", vtable, c) >= 0); assert_se(sd_bus_add_object_vtable(bus, NULL, "/foo", "org.freedesktop.systemd.test2", vtable, c) >= 0); assert_se(sd_bus_add_fallback_vtable(bus, NULL, "/value", "org.freedesktop.systemd.ValueTest", vtable2, NULL, UINT_TO_PTR(20)) >= 0); assert_se(sd_bus_add_node_enumerator(bus, NULL, "/value", enumerator_callback, NULL) >= 0); assert_se(sd_bus_add_node_enumerator(bus, NULL, "/value/a", enumerator2_callback, NULL) >= 0); assert_se(sd_bus_add_object_manager(bus, NULL, "/value") >= 0); assert_se(sd_bus_add_object_manager(bus, NULL, "/value/a") >= 0); assert_se(sd_bus_start(bus) >= 0); log_error("Entering event loop on server"); while (!c->quit) { log_error("Loop!"); r = sd_bus_process(bus, NULL); if (r < 0) { log_error_errno(r, "Failed to process requests: %m"); goto fail; } if (r == 0) { r = sd_bus_wait(bus, (uint64_t) -1); if (r < 0) { log_error_errno(r, "Failed to wait: %m"); goto fail; } continue; } } r = 0; fail: if (bus) { sd_bus_flush(bus); sd_bus_unref(bus); } return INT_TO_PTR(r); }
grub_err_t SUFFIX (grub_freebsd_load_elfmodule) (struct grub_relocator *relocator, grub_file_t file, int argc, char *argv[], grub_addr_t *kern_end) { Elf_Ehdr e; Elf_Shdr *s; char *shdr = 0; grub_addr_t curload, module; grub_err_t err; grub_size_t chunk_size = 0; void *chunk_src; err = read_headers (file, &e, &shdr); if (err) return err; curload = module = ALIGN_PAGE (*kern_end); for (s = (Elf_Shdr *) shdr; s < (Elf_Shdr *) ((char *) shdr + e.e_shnum * e.e_shentsize); s = (Elf_Shdr *) ((char *) s + e.e_shentsize)) { if (s->sh_size == 0) continue; if (! (s->sh_flags & SHF_ALLOC)) continue; if (chunk_size < s->sh_addr + s->sh_size) chunk_size = s->sh_addr + s->sh_size; } if (chunk_size < sizeof (e)) chunk_size = sizeof (e); chunk_size += e.e_phnum * e.e_phentsize; chunk_size += e.e_shnum * e.e_shentsize; { grub_relocator_chunk_t ch; err = grub_relocator_alloc_chunk_addr (relocator, &ch, module, chunk_size); if (err) return err; chunk_src = get_virtual_current_address (ch); } for (s = (Elf_Shdr *) shdr; s < (Elf_Shdr *) ((char *) shdr + e.e_shnum * e.e_shentsize); s = (Elf_Shdr *) ((char *) s + e.e_shentsize)) { if (s->sh_size == 0) continue; if (! (s->sh_flags & SHF_ALLOC)) continue; grub_dprintf ("bsd", "loading section to %x, size %d, align %d\n", (unsigned) curload, (int) s->sh_size, (int) s->sh_addralign); switch (s->sh_type) { default: case SHT_PROGBITS: err = load (file, (grub_uint8_t *) chunk_src + module + s->sh_addr - *kern_end, s->sh_offset, s->sh_size); if (err) return err; break; case SHT_NOBITS: grub_memset ((grub_uint8_t *) chunk_src + module + s->sh_addr - *kern_end, 0, s->sh_size); break; } if (curload < module + s->sh_addr + s->sh_size) curload = module + s->sh_addr + s->sh_size; } load (file, UINT_TO_PTR (module), 0, sizeof (e)); if (curload < module + sizeof (e)) curload = module + sizeof (e); load (file, UINT_TO_PTR (curload), e.e_shoff, e.e_shnum * e.e_shentsize); e.e_shoff = curload - module; curload += e.e_shnum * e.e_shentsize; load (file, UINT_TO_PTR (curload), e.e_phoff, e.e_phnum * e.e_phentsize); e.e_phoff = curload - module; curload += e.e_phnum * e.e_phentsize; *kern_end = curload; grub_freebsd_add_meta_module (argv[0], FREEBSD_MODTYPE_ELF_MODULE, argc - 1, argv + 1, module, curload - module); return SUFFIX (grub_freebsd_load_elf_meta) (relocator, file, kern_end); }
int main(int argc, char *argv[]) { int ret = EXIT_FAILURE; _cleanup_endmntent_ FILE *f = NULL; struct mntent* me; Hashmap *pids = NULL; if (argc > 1) { log_error("This program takes no argument."); return EXIT_FAILURE; } log_set_target(LOG_TARGET_AUTO); log_parse_environment(); log_open(); umask(0022); f = setmntent("/etc/fstab", "r"); if (!f) { if (errno == ENOENT) return EXIT_SUCCESS; log_error("Failed to open /etc/fstab: %m"); return EXIT_FAILURE; } pids = hashmap_new(trivial_hash_func, trivial_compare_func); if (!pids) { log_error("Failed to allocate set"); goto finish; } ret = EXIT_SUCCESS; while ((me = getmntent(f))) { pid_t pid; int k; char *s; /* Remount the root fs, /usr and all API VFS */ if (!mount_point_is_api(me->mnt_dir) && !path_equal(me->mnt_dir, "/") && !path_equal(me->mnt_dir, "/usr")) continue; log_debug("Remounting %s", me->mnt_dir); pid = fork(); if (pid < 0) { log_error("Failed to fork: %m"); ret = EXIT_FAILURE; continue; } if (pid == 0) { const char *arguments[5]; /* Child */ arguments[0] = "/bin/mount"; arguments[1] = me->mnt_dir; arguments[2] = "-o"; arguments[3] = "remount"; arguments[4] = NULL; execv("/bin/mount", (char **) arguments); log_error("Failed to execute /bin/mount: %m"); _exit(EXIT_FAILURE); } /* Parent */ s = strdup(me->mnt_dir); if (!s) { log_oom(); ret = EXIT_FAILURE; continue; } k = hashmap_put(pids, UINT_TO_PTR(pid), s); if (k < 0) { log_error("Failed to add PID to set: %s", strerror(-k)); ret = EXIT_FAILURE; continue; } } while (!hashmap_isempty(pids)) { siginfo_t si = {}; char *s; if (waitid(P_ALL, 0, &si, WEXITED) < 0) { if (errno == EINTR) continue; log_error("waitid() failed: %m"); ret = EXIT_FAILURE; break; } s = hashmap_remove(pids, UINT_TO_PTR(si.si_pid)); if (s) { if (!is_clean_exit(si.si_code, si.si_status, NULL)) { if (si.si_code == CLD_EXITED) log_error("/bin/mount for %s exited with exit status %i.", s, si.si_status); else log_error("/bin/mount for %s terminated by signal %s.", s, signal_to_string(si.si_status)); ret = EXIT_FAILURE; } free(s); } } finish: if (pids) hashmap_free_free(pids); return ret; }