# gen_calls.c

Go to the documentation of this file.

    00001 /*****************************************************************************************
    00002  Copyright (c) 2002-2004 The UbixOS Project
    00003  All rights reserved.
    00004
    00005  Redistribution and use in source and binary forms, with or without modification, are
    00006  permitted provided that the following conditions are met:
    00007
    00008  Redistributions of source code must retain the above copyright notice, this list of
    00009  conditions, the following disclaimer and the list of authors.  Redistributions in binary
    00010  form must reproduce the above copyright notice, this list of conditions, the following
    00011  disclaimer and the list of authors in the documentation and/or other materials provided
    00012  with the distribution. Neither the name of the UbixOS Project nor the names of its
    00013  contributors may be used to endorse or promote products derived from this software
    00014  without specific prior written permission.
    00015
    00016  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
    00017  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    00018  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
    00019  THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    00020  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
    00021  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    00022  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
    00023  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    00024  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    00025
    00026  $Id: gen__calls_8c-source.html 88 2016-01-12 00:11:29Z reddawg $
    00027
    00028 *****************************************************************************************/
    00029
    00030 #include <ubixos/types.h>
    00031 #include <sys/thread.h>
    00032 #include <sys/gen_calls.h>
    00033 #include <sys/kern_descrip.h>
    00034 #include <ubixos/sched.h>
    00035 #include <lib/kprintf.h>
    00036 #include <lib/kmalloc.h>
    00037 #include <string.h>
    00038 #include <assert.h>
    00039
    00040 /* return the process id */
    00041 int getpid(struct thread *td, struct getpid_args *uap) {
    00042   #ifdef DEBUG
    00043   kprintf("[%s:%i]",__FILE__,__LINE__);
    00044   #endif
    00045   td->td_retval[0] = _current->id;
    00046   return (0);
    00047   }
    00048
    00049 /* return the process user id */
    00050 int getuid(struct thread *td, struct getuid_args *uap) {
    00051   #ifdef DEBUG
    00052   kprintf("[%s:%i]",__FILE__,__LINE__);
    00053   #endif
    00054   td->td_retval[0] = _current->uid;
    00055   return (0);
    00056   }
    00057
    00058 /* return the process group id */
    00059 int getgid(struct thread *td, struct getgid_args *uap) {
    00060   #ifdef DEBUG
    00061   kprintf("[%s:%i]",__FILE__,__LINE__);
    00062   #endif
    00063   td->td_retval[0] = _current->gid;
    00064   return (0);
    00065   }
    00066
    00067 int  sys_write(struct thread *td, struct write_args *uap) {
    00068   char *buffer = 0x0;
    00069   char *in     = 0x0;
    00070
    00071   #ifdef DEBUG
    00072   kprintf("[%s:%i]",__FILE__,__LINE__);
    00073   #endif
    00074 kprintf("sw[%i]",uap->fd);
    00075
    00076   if (uap->fd == 2) {
    00077     kprintf("stderr: %s",uap->buf);
    00078     }
    00079
    00080   if (uap->fd == 1) {
    00081     in = (char *)uap->buf;
    00082     buffer = kmalloc(1024);
    00083     memcpy(buffer,uap->buf,uap->nbyte);
    00084     kprintf("%s",buffer);
    00085     kfree(buffer);
    00086     td->td_retval[0] = uap->nbyte;
    00087     }
    00088   else {
    00089     kprintf("[%i]",uap->nbyte);
    00090     buffer = kmalloc(uap->nbyte);
    00091     memcpy(buffer,uap->buf,uap->nbyte);
    00092     //kprint(buffer);
    00093     kfree(buffer);
    00094     kprintf("(%i) %s",uap->fd,uap->buf);
    00095     td->td_retval[0] = uap->nbyte;
    00096     }
    00097   return(0x0);
    00098   }
    00099
    00100 int issetugid(register struct thread *td, struct issetugid_args *uap) {
    00101   #ifdef DEBUG
    00102   kprintf("[%s:%i]",__FILE__,__LINE__);
    00103   #endif
    00104   td->td_retval[0] = 0;
    00105   return (0);
    00106   }
    00107
    00108 int readlink(struct thread *td,struct readlink_args *uap) {
    00109   #ifdef DEBUG
    00110   kprintf("[%s:%i]",__FILE__,__LINE__);
    00111   #endif
    00112   kprintf("readlink: [%s:%i]\n",uap->path,uap->count);
    00113   td->td_retval[0] = -1;
    00114   td->td_retval[1] = 0x0;
    00115   return(0x0);
    00116   }
    00117
    00118 int gettimeofday_new(struct thread *td, struct gettimeofday_args *uap) {
    00119   #ifdef DEBUG
    00120   kprintf("[%s:%i]",__FILE__,__LINE__);
    00121   #endif
    00122   return(0x0);
    00123   }
    00124
    00125 int read(struct thread *td,struct read_args *uap) {
    00126   int          error = 0x0;
    00127   size_t       count = 0x0;
    00128   struct file *fd    = 0x0;
    00129
    00130   #ifdef DEBUG
    00131   kprintf("[%s:%i]",__FILE__,__LINE__);
    00132   #endif
    00133
    00134   error = getfd(td,&fd,uap->fd);
    00135
    00136   if (error)
    00137     return(error);
    00138
    00139   count = fread(uap->buf,uap->nbyte,0x1,fd->fd);
    00140   kprintf("count: %i\n",count);
    00141   td->td_retval[0] = count;
    00142
    00143   return(error);
    00144   }
    00145
    00149 int setitimer(struct thread *td, struct setitimer_args *uap) {
    00150   int error = 0x0;
    00151
    00152   return(error);
    00153   }
    00154
    00155 /***
    00156  END
    00157  ***/