static unsigned int protocol_child(struct service_backend *backend, struct service_state *state, unsigned int id, char *path, unsigned int length) { struct system_node *node = (struct system_node *)backend->map(state, id, sizeof (struct system_node)); struct list_item *current; struct system_node *n = node; spinlock_acquire(&node->children.spinlock); for (current = node->children.head; current; current = current->next) { struct system_node *n2 = current->data; unsigned int length0 = ascii_length(n2->name); if (n2->type == SYSTEM_NODETYPE_MULTIGROUP) { unsigned int colon = memory_findbyte(path, length, ':'); unsigned int val; if (length0 != colon) continue; if (!memory_match(n2->name, path, colon)) continue; val = ascii_rvalue(path + colon + 1, length - colon - 1, 10); if (val != n2->index) continue; } else { if (length0 != length) continue; if (!memory_match(n2->name, path, length)) continue; } n = n2; break; } spinlock_release(&node->children.spinlock); return (unsigned int)n; }
static unsigned int child(struct service_backend *backend, struct service_state *state, struct cpio_header *header, unsigned int id, char *path, unsigned int length) { struct cpio_header *eheader; unsigned int current = 0; do { char *name; eheader = mapheader(backend, state, current); if (!eheader) break; if (eheader->namesize != header->namesize + length + 1) continue; name = mapname(backend, state, eheader, current); if (!name) break; if (memory_match(name + header->namesize, path, length)) return current; } while ((current = cpio_next(eheader, current))); return id; }
static unsigned int findvalue(unsigned int id, struct elf_header *header, struct elf_sectionheader *symbolheader, char *strings, unsigned int count, char *symbolname) { unsigned int i; for (i = 0; i < symbolheader->size / symbolheader->esize; i++) { struct elf_symbol symbol; if (!file_seekreadall(id, &symbol, symbolheader->esize, symbolheader->offset + i * symbolheader->esize)) return 0; if (strings[symbol.name + count] != '\0' || !memory_match(symbolname, &strings[symbol.name], count)) continue; if (header->type == ELF_TYPE_RELOCATABLE) { struct elf_sectionheader referenceheader; if (!readsectionheader(id, header, symbol.shindex, &referenceheader)) return 0; return referenceheader.address + referenceheader.offset + symbol.value; } return symbol.value; } return 0; }
static unsigned int protocol_match(struct service_backend *backend, struct service_state *state) { struct system_header *header = (struct system_header *)backend->map(state, 0, sizeof (struct system_header)); return (header) ? memory_match(header->id, "FUDGE_SYSTEM", 12) : 0; }
unsigned int elf_validate(struct elf_header *header) { unsigned char id[] = {ELF_IDENTITY_MAGIC0, ELF_IDENTITY_MAGIC1, ELF_IDENTITY_MAGIC2, ELF_IDENTITY_MAGIC3}; return memory_match(header->identify, id, 4); }
static unsigned int protocol_child(struct service_backend *backend, struct service_state *state, char *path, unsigned int length) { struct cpio_header header; struct cpio_header eheader; unsigned char name[1024]; unsigned int id = 0; if (!length) return 1; if (!readheader(backend, &header, state->id)) return 0; if (!readname(backend, &header, state->id, name, 1024)) return 0; if (path[length - 1] == '/') length--; do { unsigned char cname[1024]; if (id == state->id) break; if (!readheader(backend, &eheader, id)) break; if (eheader.namesize - header.namesize != length + 1) continue; if (!readname(backend, &eheader, id, cname, 1024)) break; if (memory_match(cname + header.namesize, path, length)) { state->id = id; return 1; } } while ((id = cpio_next(&eheader, id))); return 0; }