kernel dynamic references
Hi,=0D=0A=0D=0A I'm new to Freebsd and interested in system programming. =
So I'have picked up a task from the project ideas list to start with.=0D=0A=
(part of) the subject is : "This task is to define and implement a gener=
al mechanism for tracking these references and use them in handling modul=
e unload requests."=0D=0A=0D=0ASo, to do that, I'have added an "int dynre=
fs" in struct module (kern_module.c), and functions to increase or decrea=
se this count (module_add/remove_dynrefs(const char * modname) and module=
_updatedynrefs(const char * modname, int action) ) in kern_module.c.=0D=0A=
=0D=0A=0D=0A To avoid unload of a module which has a dynrefs count !=3D 0=
, I have modified module_unload(), so that unload is process only if dy=
nrefs=3D0 or flag=3DLINKER_UNLOAD_FORCE.=0D=0A=0D=0A=0D=0A=0D=0A--- modul=
e.h.orig Wed Jul 4 10:29:53 2007=0D=0A+++ module.h Wed Jul 4 10:21:40 2=
007=0D=0A@@ -147,7 +147,8 @@=0D=0A int module_getid(module_t);=0D=0A modu=
le_t module_getfnext(module_t);=0D=0A void module_setspecific(module_t, m=
odspecific_t *);=0D=0A-=0D=0A+int module_add_dynrefs(const char *);=0D=0A=
+int module_remove_dynrefs(const char *);=0D=0A =0D=0A #ifdef MOD_DEBUG=0D=
=0A extern int mod_debug;=0D=0A=0D=0A--- kern_module.c.orig Wed Jul 4 10=
:33:06 2007=0D=0A+++ kern_module.c Wed Jul 4 10:21:28 2007=0D=0A@@ -52,6=
+52,7 @@=0D=0A TAILQ_ENTRY(module) flink; /* all modules in a file */=0D=
=0A struct linker_file *file; /* file which contains this module */=0D=0A=
int refs; /* reference count */=0D=0A+ int dynrefs; /* dynam=
ic reference count */=0D=0A int id; /* unique id number */=0D=0A cha=
r *name; /* module name */=0D=0A modeventhand_t handler; /* event h=
andler */=0D=0A@@ -65,6 +66,7 @@=0D=0A struct sx modules_sx;=0D=0A static=
int nextid =3D 1;=0D=0A static void module_shutdown(void *, int);=0D=0A+=
static int module_updatedynrefs(const char* , int );=0D=0A =0D=0A static =
int=0D=0A modevent_nop(module_t mod, int what, void *arg)=0D=0A@@ -152,6 =
+154,7 @@=0D=0A }=0D=0A newmod->refs =3D 1;=0D=0A newmod->id =3D nexti=
d++;=0D=0A+ newmod->dynrefs =3D 0;=0D=0A newmod->name =3D (char *)(newmo=
d + 1);=0D=0A strcpy(newmod->name, data->name);=0D=0A newmod->handler =3D=
data->evhand ? data->evhand : modevent_nop;=0D=0A@@ -231,7 +234,9 @@=0D=0A=
module_unload(module_t mod, int flags)=0D=0A {=0D=0A int error;=0D=0A- =
error =3D MOD_EVENT(mod, MOD_QUIESCE);=0D=0A+ MOD_SLOCK;=0D=0A+ (mod->dyn=
refs =3D=3D 0) ? (error =3D MOD_EVENT(mod, MOD_QUIESCE)) : (error =3D EPE=
RM);=0D=0A+ MOD_SUNLOCK;=0D=0A if (error =3D=3D EOPNOTSUPP || error =3D=3D=
EINVAL)=0D=0A error =3D 0;=0D=0A if (flags =3D=3D LINKER_UNLOAD_NORMA=
L && error !=3D 0)=0D=0A@@ -261,6 +266,37 @@=0D=0A =0D=0A MOD_XLOCK_ASSE=
RT;=0D=0A mod->data =3D *datap;=0D=0A+}=0D=0A+=0D=0A+static int=0D=0A+mo=
dule_updatedynrefs(const char* modname, int action)=0D=0A+{=0D=0A+ module=
_t mod;=0D=0A+ =0D=0A+ MOD_XLOCK;=0D=0A+ mod =3D module_lookupbyname(modn=
ame);=0D=0A+=0D=0A+ if(mod =3D=3D 0) {=0D=0A+ MOD_XUNLOCK;=0D=0A+ retur=
n(-1);=0D=0A+ }=0D=0A+=0D=0A+ (action =3D=3D 1) ? mod->dynrefs++ : mod->d=
ynrefs--;=0D=0A+ MOD_XUNLOCK;=0D=0A+ return (0);=0D=0A+}=0D=0A+=0D=0A+int=
=0D=0A+module_add_dynrefs(const char *modname)=0D=0A+{=0D=0A+=0D=0A+ retu=
rn (module_updatedynrefs(modname,1));=0D=0A+}=0D=0A+=0D=0A+int=0D=0A+modu=
le_remove_dynrefs(const char * modname)=0D=0A+{=0D=0A+ return (module_upd=
atedynrefs(modname,0));=0D=0A }=0D=0A =0D=0A /* =0D=0A=0D=0A=0D=0A=0D=0A=0D=
=0A I have compiled and tested. with a 6-2 RELEASE. For the test I'have u=
sed two dummy module, one adding a dynrefs on the other.=0D=0A=0D=0A Any =
comments are welcome.=0D=0A=0D=0A David chosrova =0D=0A=0D=0A=0D=0A=0D=0A=
=0A=0A------------------------ ALICE C'EST ENCORE MIEUX AVEC CANAL+ LE BO=
UQUET ! ---------------=0AD=E9couvrez vite l'offre exclusive ALICEBOX et =
CANAL+ LE BOUQUET, en cliquant ici http://alicebox.fr=0ASoumis =E0 condit=
ions.=0A
_______________________________________________
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"
討論串 (同標題文章)