driver: track number of users on driver

Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
Michael Shaw 2026-08-12 14:44:56 -04:00
commit 8d147a14c4
Signed by: michaelsshaw
GPG key ID: 5A5E0FB20708A9E7
3 changed files with 10 additions and 3 deletions

View file

@ -28,6 +28,8 @@ struct driver {
void (*exit)(void); void (*exit)(void);
void *base; void *base;
size_t size; size_t size;
u32 n_users;
}; };
struct driver *driver_register(const char *name, u32 type, void *init, void *deinit, u32 class); struct driver *driver_register(const char *name, u32 type, void *init, void *deinit, u32 class);

View file

@ -32,6 +32,7 @@ struct driver *driver_register(const char *name, u32 type, void *init, void *dei
driver->exit = NULL; driver->exit = NULL;
driver->base = NULL; driver->base = NULL;
driver->size = 0; driver->size = 0;
driver->n_users = 0;
} }
driver->type = type; driver->type = type;

View file

@ -242,10 +242,13 @@ static int elf_load(const char *name, const char *file, size_t fsize)
void (*exit)(void) = NULL; void (*exit)(void) = NULL;
for (size_t i = 0; i < n_sec; i++) { for (size_t i = 0; i < n_sec; i++) {
if (!secs[i].loadable) continue; if (!secs[i].loadable)
if (!str_prefix(shstrtab + shdr[i].sh_name, ".exitcall")) continue; continue;
if (!str_prefix(shstrtab + shdr[i].sh_name, ".exitcall"))
continue;
void (**fn)(void) = (void (**)(void))(base + secs[i].load_off); void (**fn)(void) = (void (**)(void))(base + secs[i].load_off);
if (fn[0]) exit = fn[0]; if (fn[0])
exit = fn[0];
break; break;
} }
@ -256,6 +259,7 @@ static int elf_load(const char *name, const char *file, size_t fsize)
d->exit = exit; d->exit = exit;
d->base = base; d->base = base;
d->size = total; d->size = total;
d->n_users = 1;
list_insert(&pending_drivers, d); list_insert(&pending_drivers, d);
} }
} }