Questions about kernel system calls and organization

Questions about kernel system calls and organization

Post by Mat » Wed, 04 Sep 2002 07:00:58



I'm a new kernel hacker; I have some questions about the Linux
kernel's organization - where certain system calls are and why they
are located where they are. A bunch of stuff has probably been asked
and answered before, so if someone knows of a website that answers
some or all of the below questions, I'd be very grateful for it's
address.

1. What type of calls are in kernel/sys.c? Are these calls primarily
for the root user, or suid root apps?

2. Why are there so many calls in kernel/sys.c? Some calls
({get,set}priority, umask, and some of the {get,set}*id calls) don't
even look like they belong there. Can these functions be
mentally/logically grouped together in some way?

3. What do all the signal calls (kernel/signal.c) do? (It's a bit hard
for me to tell from just looking at the source.) Also, I know that
sigprocmask() allows manipulation of a process' blocked signal set,
but is there a correspoinding function to get the process' blocked
signal set?

4. There are lots of calls in kernel/schedule.c; it looks like some of
them duplicate the functionality of other ones. Is this true (and if
so, why?), or are these calls all unrelated? (I admit this is an
ambiguous question... sorry :-{ )

5. Why are there so many calls for creating new files? (in fs/namei.c
and in fs/open.c: creat, open, mknod, link, symlink, mkdir)? These
calls also appear to duplicate each other's functionality (to some
degree). Is this true (and if so, why?), or are these calls all
unrelated?


 
 
 

Questions about kernel system calls and organization

Post by Mat » Sat, 07 Sep 2002 07:51:04


Heh, looks like no one noticed my post on 2 Sept. Here it is again,
hope someone reads it this time...

I'm a new kernel hacker; I have some questions about the Linux
kernel's organization - where certain system calls are and why they
are located where they are. A bunch of stuff has probably been asked
and answered before, so if someone knows of a website that answers
some or all of the below questions, I'd be very grateful for it's
address.

1. What type of calls are in kernel/sys.c? Are these calls primarily
for the root user, or suid root apps?

2. Why are there so many calls in kernel/sys.c? Some calls
({get,set}priority, umask, and some of the {get,set}*id calls) don't
even look like they belong there. Can these functions be
mentally/logically grouped together in some way?

3. What do all the signal calls (kernel/signal.c) do? (It's a bit hard
for me to tell from just looking at the source.) Also, I know that
sigprocmask() allows manipulation of a process' blocked signal set,
but is there a correspoinding function to get the process' blocked
signal set?

4. There are lots of calls in kernel/schedule.c; it looks like some of
them duplicate the functionality of other ones. Is this true (and if
so, why?), or are these calls all unrelated? (I admit this is an
ambiguous question... sorry :-{ )

5. Why are there so many calls for creating new files? (in fs/namei.c
and in fs/open.c: creat, open, mknod, link, symlink, mkdir)? These
calls also appear to duplicate each other's functionality (to some
degree). Is this true (and if so, why?), or are these calls all
unrelated?



 
 
 

Questions about kernel system calls and organization

Post by Tim Robert » Mon, 09 Sep 2002 12:39:31



>Heh, looks like no one noticed my post on 2 Sept. Here it is again,
>hope someone reads it this time...

Three days is not a lot of time for a response on Usenet newsgroup...

Quote:>I'm a new kernel hacker; I have some questions about the Linux
>kernel's organization - where certain system calls are and why they
>are located where they are.

It is important to remember that Linux was designed to be a Unix
work-alike.  The vast majority of the system calls were inherited from Unix
and/or Posix, not designed from scratch.

It is not clear to me whether you have done any user-mode Linux/Unix
development.  Have you written any non-trivial Linux programs?  If not, I
strongly suggest you do so before digging in to the kernel.  Many of the
concepts become clearer once you see how they are applied in user-mode
code.

Quote:>1. What type of calls are in kernel/sys.c? Are these calls primarily
>for the root user, or suid root apps?

It's a mix.  Each call checks for root if necessary.  Sys.c contains things
that are, generically "process control": user and group ID management,
priority management, etc.  Reboot is there because there was no obvious
place to put them.

Quote:>2. Why are there so many calls in kernel/sys.c? Some calls
>({get,set}priority, umask, and some of the {get,set}*id calls) don't
>even look like they belong there. Can these functions be
>mentally/logically grouped together in some way?

They are all involved in process management in some sense.  Where else
would you put them?

Quote:>3. What do all the signal calls (kernel/signal.c) do? (It's a bit hard
>for me to tell from just looking at the source.)

You might check the "signal" man pages to get an overview of the signal
mechanism.

Quote:>Also, I know that
>sigprocmask() allows manipulation of a process' blocked signal set,
>but is there a correspoinding function to get the process' blocked
>signal set?

sigprocmask() performs both functions: it sets a new mask, and returns the
old mask.

Quote:>5. Why are there so many calls for creating new files? (in fs/namei.c
>and in fs/open.c: creat, open, mknod, link, symlink, mkdir)? These
>calls also appear to duplicate each other's functionality (to some
>degree). Is this true (and if so, why?), or are these calls all
>unrelated?

The short answer is "history": Linux has all these syscalls because Unix
had all these syscalls.

Theoretically, you could have wrapped all of these functions into one, but
they really do different things.  Creat creates normal files.  Mknod
creates devices.  Link creates hard links.  Symlink creates symbolic links.
Mkdir creates directory entries.  In terms of implementation, these are
similar concepts, in that a directory is just a special kind of file, but
at a user level, they are quite different.

When Brian Kernighan was asked if there was anything he would change if he
could go back to the beginning of Unix, his answer was: 'If I had it all to
do over again, I'd spell creat with an "e".'cc
--

  Providenza & Boekelheide, Inc.

 
 
 

1. Kernel Extension(system call) loaded but could not call it !!!!

Hi ,
can anybody tell me why I am unable to call my own system call.

/* This is the kernel extension I wrote */

testcall_entry(int cmd, struct uio *uio)
{

   if (cmd == CFG_INIT) {
      if (pincode(testcall_entry) != 0) { /* pin the kernel ext into
memory */
         return(ENOMEM);                  /* report error  */
         }
      }
   else {
      unpincode(testcall_entry);
   }
   return(0);

/* These are the steps I followed to compile the extension */
cc -c -O -qlist -qsource testcall.c
ld -e testcall_entry -T512 -H512 -bI:./testcall.exp -bI:./kernex.exp
testcall.o -o testcall

/* this is a test system call */
int testcall()
{
        return 10;

Yes I did load the kernel extension and it was loaded successfully and
gave me kmid also.

/* This is a sample file to test system call */
main ()

{
        int val = 0;

        printf ("value before testcall %d\n",val);
        val = testcall ();
        printf ("value after testcall %d\n",val);

/* This is what I use to compile this program */
cc -bI:./kernex.exp -bI:./testcall.exp sample.c

/* This is the error it gives  when I run the a.out file */
exec(): 0509-036 Cannot load program a.out because of the following
errors:
        0509-023 Symbol testcall in a.out is not defined.
        0509-026 System error: Cannot run a file that does not have a
valid format.

Nilesh

2. Hp 895 cxi

3. Vienna, AT - Head, Systems and Database Administration Unit, UN System Organization

4. IPX over PPP

5. How I could add a new system call to linux or modify a system calls

6. books?

7. How to use open system call in a new system call

8. getting burner to work in 7.2

9. "Interrupted system call" at "low level" - system calls

10. A question about Kernel system call mechanism

11. System Administration Group Organization

12. JOB: Vienna, AT - Computer Operations Officer, UN System Organization

13. Schemes for File System Organization under Unix