2002-02-04 10:04:52

by Vlodavsky, Zvi

[permalink] [raw]
Subject: Using "query_module"


Please personally CC me with responses on this posting:

I would like to use the "query_module" system call with the QM_SYMBOLS flag
in an application, but I am not sure of what the appropriate way of doing it
is, and whether it is safe.

I have the man-page for query_module on the system on which I am compiling,
but I can't find the function prototype in <linux/module.h>. So, I just
wrote the prototype in my code. Is this the way this should be done?

Other than that, the man page states that struct module_symbol looks like
this:
struct module_symbol
{
unsigned long value;
unsigned long name;
};

But in module.h it is defined as:
struct module_symbol
{
unsigned long value;
const char *name;
};

>From my understanding, the second definition is the way the kernel uses this
struct, and the first definition is the way the user should interpret the
result of query_module with the QM_SYMBOLS flag. Am I right? (Shouldn't
there be 2 different structures for this?)

Most importantly, I would like to understand whether it is safe to use this
system call. If I compile my application on a machine in which this function
is implemented (in libc), is the system call guaranteed to work on kernels
2.2 and up? Do I need to do a preliminary check such as "if
(query_module(NULL, 0, NULL, 0, NULL))" for the existence of the system
call, or would it simply fail if I use it regularly?

Thanks for your help,
Zvi.

---------------
Zvi Vlodavsky
Software Engineer
Network Communications Group, Intel Corp.
[email protected]

Disclaimer: In this e-mail, I do not speak on behalf of Intel corp.


2002-02-04 10:20:45

by Keith Owens

[permalink] [raw]
Subject: Re: Using "query_module"

On Mon, 4 Feb 2002 12:04:19 +0200 ,
"Vlodavsky, Zvi" <[email protected]> wrote:
>Please personally CC me with responses on this posting:
>I would like to use the "query_module" system call with the QM_SYMBOLS flag
>in an application, but I am not sure of what the appropriate way of doing it
>is, and whether it is safe.

query_module(NULL, 0, NULL, 0, NULL) returns 0 if the kernel supports
query_module, -ENOSYS if it does not.

If the kernel supports query_module,
query_module(NULL, -1, NULL, 0, NULL)
returns -ENOSYS if the kernel has been compiled without modules,
-EINVAL if the kernel was compiled with module support.

Grab the modutils source and see utils/modstat.c::new_get_kernel_info,
it uses all the query_module facilities.