Ignore:
Timestamp:
Jun 18, 2017, 10:06:41 PM (5 years ago)
Author:
alain
Message:

Introduce syscalls.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/syscalls/sys_signal.c

    r1 r23  
    11/*
    2  * sys_sem.c: interface to access signal service
     2 * sys_signal.c - associate a specific signal handler to a given signal.
    33 *
    4  * Copyright (c) 2008,2009,2010,2011,2012 Ghassan Almaless
    5  * Copyright (c) 2011,2012,2013,2014,2015 UPMC Sorbonne Universites
     4 * Authors   Ghassan Almaless (2008,2009,2010,2011,2012)
     5 *           Alain Greiner (2016,2017)
     6 *
     7 * Copyright (c) UPMC Sorbonne Universites
    68 *
    79 * This file is part of ALMOS-kernel.
     
    2123 */
    2224
    23 #include <types.h>
     25#include <hal_types.h>
    2426#include <errno.h>
    2527#include <thread.h>
    26 #include <task.h>
    27 #include <pid.h>
     28#include <printk.h>
    2829#include <signal.h>
    2930
     31//////////////////////////////////
     32int sys_signal( uint32_t   sig_id,
     33                void     * handler )
     34
     35        thread_t  * this = CURRENT_THREAD;
    3036
    31 int sys_signal(uint_t sig, sa_handler_t *handler)
    32 
    33         register struct thread_s *this;
    34         int retval;
    35 
    36         this = current_thread;
    37 
    38         if((sig == 0) || (sig >= SIG_NR) || (sig == SIGKILL) || (sig == SIGSTOP))
     37        if((sig_id == 0) || (sig_id >= SIG_NR) || (sig_id == SIGKILL) || (sig_id == SIGSTOP))
    3938        {
    40                 this->info.errno = EINVAL;
    41                 return SIG_ERROR;
     39        printk("\n[ERROR] in %s : illega signal index = %d\n", __FUNCTION__ , sig_id );
     40                this->errno = EINVAL;
     41                return -1;
    4242        }
    4343
    44         retval = (int) this->task->sig_mgr.sigactions[sig];
    45         this->task->sig_mgr.sigactions[sig] = handler;
     44        // register handler in signal manager for the calling process
     45        this->process->sig_mgr.sigactions[sig_id] = handler;
    4646
    47         sig_dmsg(1, "%s: handler @%x has been registred for signal %d\n",
    48                __FUNCTION__,
    49                handler,
    50                sig);
     47        signal_dmsg("\n[INFO] %s : handler @%x has been registred for signal %d\n",
     48                    __FUNCTION__ , handler , sig_id );
    5149
    52         return retval;
    53 }
    54 
    55 
    56 int sys_sigreturn_setup(void *sigreturn_func)
    57 {
    58         struct thread_s *this;
    59 
    60         this = current_thread;
    61         this->info.attr.sigreturn_func = sigreturn_func;
    62         cpu_context_set_sigreturn(&this->pws, sigreturn_func);
    6350        return 0;
    6451}
    6552
    66 
    67 int sys_kill(pid_t pid, uint_t sig)
    68 {
    69         cid_t   location;
    70         error_t err;
    71 
    72         if((sig == 0) || (sig >= SIG_NR))
    73         {
    74                 err = EINVAL;
    75         }
    76         else
    77         {
    78                 if ( PID_GET_CLUSTER(pid) == current_cid )
    79                         location = current_cid;
    80                 else
    81                         location = task_whereis(pid);
    82 
    83                 err = signal_rise(pid, location, sig);
    84 
    85                 /* No error, return 0 */
    86                 if (!err)
    87                         return 0;
    88         }
    89 
    90         /* Error. Set errno and return */
    91         current_thread->info.errno = err;
    92         return -1;
    93 }
Note: See TracChangeset for help on using the changeset viewer.