Re: system call syscall

sct@dcs.ed.ac.uk
Thu, 14 Mar 96 00:06 GMT


Hi,

[Linus, there's a patch below, so bear with me...]

On Tue, 12 Mar 1996 14:00:36 PST, Marty Leisner
<leisner@sdsp.mc.xerox.com> said:

> Is there a reason some sys call numbers have embbed __ (double) quotes or
> (single) _ quotes?

In general, the ones with a single underscore have the same calling
convention as the intended user-mode-visible function, whereas the
double-underscore functions have to undergo some argument mangling
first.

For example, the intended application interface for sysctl() is

int sysctl(int *name, int nlen, void *oldval, size_t *oldlenp,
void *newval, size_t newlen);

However, the i386 architecture allows only a limited number of
registers to be passed through a syscall gate, so the kernel function
sys_sysctl() is actually defined as

extern asmlinkage int sys_sysctl(struct __sysctl_args *args)

The libc sets up an auxilliary function, _sysctl(), which interfaces
directly to sys_sysctl(). libc then exports a different sysctl()
function which marshalls the arguments into the form expected by
_sysctl().

For most kernel functions, this marshalling step is not required, so
there is no need to differentiate between the kernel-mode and
user-mode functions, and the extra _function form is unnecessary. In
this case, the kernel function is defined with the single _ in
unistd.h.

> Also, it seems there's a number of routines that are public
> they aren't used by anyone else (i.e. the do_xxxx, where xxxx is string, etc).

My initial implementation of sysctl was intended as a skeleton onto
which other facilities could easily be added. Some of the do_xxxx
functions are intended as hooks to manage some common forms of
sysctl() operation, and may be used by modules which register their
own private sysctl tables.

> Quickly inspecting the code, can do_sysctl do anything
> useful (seems like it also returns an error).

Nope, it does work --- in line 181, we have

if (error != ENOTDIR)
return error;

which will return any error OR SUCCESS CODE back to the caller. Only
if the sysctl parsing returns the specific error ENOTDIR will we loop
back and try the next sysctl table.

There is in fact a problem here --- this line should, of course, read

if (error != -ENOTDIR)
return error;

since all error codes are represented internally as negative ints.
This will prevent the parser from scanning module-loaded sysctl
tables as it stands, but won't affect normal sysctl(2) calls to the
main sysctl name table.

Cheers,
Stephen.

--
Stephen Tweedie <sct@dcs.ed.ac.uk>
Department of Computer Science, Edinburgh University, Scotland.