csystem-callsminix

MINIX 2 - syscall to kernel


I want to make 2 syscalls to kernel (getlot and setlot). They have to read and set some value in struct proc, which is in kernel. What is the problem? What is missing?

In /usr/include/minix/callnr.h I increased NCALLS and add 2 define

 #define NCALLS       80    /* number of system calls allowed */

 #define SETLOT       78
 #define GETLOT       79

In usr/src/mm/main.c

PUBLIC void do_setlot()
{
    message msg;
    msg = mm_in;
   _taskcall(SYSTASK, SYS_SETLOT), &msg);
}

PUBLIC void do_getlot()
{
    message msg;
    msg = mm_in;
   _taskcall(SYSTASK, SYS_GETLOT, &msg);
}

In /usr/src/mm/proto.h I added two prototypes

_PROTOTYPE( void do_setlot, (void));
_PROTOTYPE( void do_getlot, (void));

In /usr/src/mm/table.c I added to the end of _PROTOTYPE (int (*call_vec[NCALLS]), (void) )

do_setlot,
do_getlot,

In /usr/src/fs/table.c I added to the end of_PROTOTYPE (int (*call_vec[]), (void) )

no_sys,
no_sys,

In /usr/include/minix/com.h I created 2 SYS_xxx define

#   define SYS_SETLOT    22
#   define SYS_GETLOT    23

In /usr/src/kernel/system.c I wrote

FORWARD _PROTOTYPE( int do_procsetlot, (message *m_ptr) );
FORWARD _PROTOTYPE( int do_procgetlot, (message *m_ptr) );

Then added SYS_xxx to switch in PUBLIC void sys_task()

case SYS_SETLOT:    r = do_procsetlot(&m);  break;
case SYS_GETLOT:    r = do_procgetlot(&m);  break; 

And at the bottom I wrote 2 definions

PRIVATE int do_procsetlot(m_ptr)
register message *m_ptr;
{
  pid_t prid;
  int i;
  int tickets;
  prid = m_ptr->m1_i1;
  tickets = m_ptr->m1_i2;

  if(tickets > LOT_MAX)
    return EINVAL;
  if(tickets < LOT_MIN)
    return EINVAL;
  for(i = 0 ; i <NR_PROCS; i++)
  {
     if(proc[i].p_pid == prid)
     {
       proc[i].tickets_number = tickets;
       return 0;
     }
  {
  return EINVAL;
 }


PRIVATE int do_procgetlot(m_ptr)
register message *m_ptr;
{
  int i;
  pid_t prid;
  prid = m_ptr->m1_i1;

  for(i = 0 ; i< NR_PROCS; i++)
  {
    if(proc[i].p_pid == prid)
        return proc[i].tickets_number;
  }
 return EINVAL;
}

Finally after make hdboot I got error:

exec cc -c -I/usr/include main.c
exec cc -c -I/usr/include proc.c
exec cc -c -I/usr/include system.c
"system.c", line 1260: static not expected
make in /usr/src/kernel: Exit code 1

Line 1260 is

PRIVATE int do_procgetlot(m_ptr)

Solution

  • I know this message is years old, but...

    You have a syntax error at the bottom of do_procsetlot:

      {
      return EINVAL;
     }
    

    ...should be:

      }
      return EINVAL;
     }
    

    I hope you figured it out yourself some time in 2014!

    BTW, the Minix 2 compiler totally supports ANSI C, so you shouldn't need all the K&Risms.