summaryrefslogtreecommitdiff
path: root/src/sys
diff options
context:
space:
mode:
Diffstat (limited to 'src/sys')
-rw-r--r--src/sys/include/np/symbol.h16
-rw-r--r--src/sys/np/core/np_symbol.c62
2 files changed, 67 insertions, 11 deletions
diff --git a/src/sys/include/np/symbol.h b/src/sys/include/np/symbol.h
index 9882a46..daa3002 100644
--- a/src/sys/include/np/symbol.h
+++ b/src/sys/include/np/symbol.h
@@ -43,11 +43,13 @@
*
* @name: Name of the symbol
* @addr: Data the symbol holds
+ * @id: Symbol ID
* @link: Queue link
*/
struct symbol {
char *name;
void *addr;
+ size_t id;
TAILQ_ENTRY(symbol) link;
};
@@ -104,4 +106,18 @@ struct symbol *symbol_alloc(struct symlist *slp, char *name, void *addr);
* value on failure.
*/
int symbol_lookup(struct symlist *slp, char *name, struct symbol **res_p);
+
+/*
+ * Lookup a specific symbol from a symbol
+ * table using its ID
+ *
+ * @slp: Symbol list pointer
+ * @name: Symbol name
+ * @res_p: Result pointer is written here
+ *
+ * Returns zero on success, otherwise a less than zero
+ * value on failure.
+ */
+int symbol_lookup_id(struct symlist *slp, size_t id, struct symbol **res_p);
+
#endif /* !_NP_SYMBOL_H_ */
diff --git a/src/sys/np/core/np_symbol.c b/src/sys/np/core/np_symbol.c
index 7c9349a..db9109c 100644
--- a/src/sys/np/core/np_symbol.c
+++ b/src/sys/np/core/np_symbol.c
@@ -91,25 +91,55 @@ symbol_lookup(struct symlist *slp, char *name, struct symbol **res_p)
if (strcmp(sym->name, name) == 0) {
symbol_cache(slp, sym);
- break;
+ *res_p = sym;
+ return 0;
+ }
+ }
+
+ return -1;
+}
+
+int
+symbol_lookup_id(struct symlist *slp, size_t id, struct symbol **res_p)
+{
+ struct symbol *sym = NULL;
+
+ if (slp == NULL || res_p == NULL) {
+ return -EINVAL;
+ }
+
+ /* Is it in the cache? */
+ for (uint16_t i = 0; i < slp->cache_i; ++i) {
+ sym = slp->cache[i];
+ if (sym->id == id) {
+ *res_p = sym;
+ return 0;
}
}
- *res_p = sym;
- return (sym == NULL) ? -1 : 0;
+ /* Go through each entry to find it */
+ TAILQ_FOREACH(sym, &slp->symq, link) {
+ if (sym == NULL)
+ continue;
+
+ if (sym->id == id) {
+ symbol_cache(slp, sym);
+ *res_p = sym;
+ return 0;
+ }
+ }
+
+ return -1;
}
struct symbol *
symbol_alloc(struct symlist *slp, char *name, void *addr)
{
- struct symbol *sym;
+ char namebuf[64];
+ struct symbol *sym = NULL;
struct np_work *work;
- if (slp == NULL || name == NULL) {
- return NULL;
- }
-
- if (addr == NULL) {
+ if (slp == NULL || addr == NULL) {
return NULL;
}
@@ -125,9 +155,19 @@ symbol_alloc(struct symlist *slp, char *name, void *addr)
return NULL;
}
- /* Initialize the symbol */
- sym->name = ptrbox_strdup(name, work->work_mem);
sym->addr = addr;
+ sym->id = slp->nsym;
+
+ /*
+ * If there is no name to use, we'll make one up for
+ * ourselves.
+ */
+ if (name == NULL) {
+ sym->name = ptrbox_strdup(name, work->work_mem);
+ } else {
+ snprintf(namebuf, sizeof(namebuf), "__internal.%d", sym->id);
+ sym->name = ptrbox_strdup(namebuf, work->work_mem);
+ }
TAILQ_INSERT_TAIL(&slp->symq, sym, link);
++slp->nsym;