genericopenlibs/openenvcore/backend/src/syscall/handleipc.cpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 #include "sysif.h"
       
    23 #include "ipcclient.h"
       
    24 #include "sysreent.h"
       
    25 #include "sysusrinclude.h"
       
    26 
       
    27 
       
    28 extern "C" {
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // Funcation name: mkfifo
       
    32 // Description: Provides a FIFO special file (a named pipe).
       
    33 // Returns: 0     : On success
       
    34 //          -1    : On error
       
    35 // In case of error, errno value set to 
       
    36 //          EACCES: One  of  the  directories in pathname did not allow search 
       
    37 //                  (exe-cute) permission.
       
    38 //          EEXIST: pathname already exists.
       
    39 //          ENAMETOOLONG: Either the total length of pathname is greater 
       
    40 //                        than PATH_MAX, or an individual  file  name  component  
       
    41 //                        has a length greater than NAME_MAX.  In the GNU system, 
       
    42 //                        there is no imposed limit on over-all  file name length,
       
    43 //                        but some file systems may place limits on the length of a component.
       
    44 //          ENOENT: A directory component in pathname does not exist or  is  a  dan-gling
       
    45 //                  symbolic link.
       
    46 //          ENOSPC: The directory or filesystem has no room for the new file.
       
    47 //          ENOTDIR: A  component  used as a directory in pathname is not, in fact, a
       
    48 //                   directory.
       
    49 //          EROFS:  pathname refers to a read-only filesystem.
       
    50 // To be removed
       
    51 //          EFAULT: Pathname is not valid.
       
    52 //          EMFILE: Too many file descriptors are in use by the process.
       
    53 //          ENFILE: System limit on the total number of open files has been 
       
    54 //                  reached.
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 
       
    58 EXPORT_C int _mkfifo_r(int *aErrno, const wchar_t *_widename, mode_t mode)
       
    59     {
       
    60 	return Backend()->mkfifo(_widename, mode, *aErrno);
       
    61     }
       
    62 
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // Funcation name: pipe
       
    66 // Description: It provides mechanism to flow data in one direction.
       
    67 // Returns: 0     : On success
       
    68 //          -1    : On error
       
    69 // In case of error, errno value set to 
       
    70 //          EFAULT: filedes is not valid.
       
    71 //          EMFILE: Too many file descriptors are in use by the process.
       
    72 //          ENFILE: System limit on the total number of open files has been 
       
    73 //                  reached.
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 
       
    77 EXPORT_C int _pipe_r(int *aErrno, int fildes[2])
       
    78     {
       
    79     return Backend()->pipe(fildes, *aErrno);
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // Funcation name: semget
       
    84 // Description: Get semaphore identifier using the IPC key generated by ftok.
       
    85 // Returns: None zero number (semaphore identifier): On success
       
    86 //          -1              : On error.
       
    87 // In case of error, errno value set to 
       
    88 //          EACCES - Semaphore exists but access denied.
       
    89 //          EEXIST - A semaphore identifier exists for the argument key but 
       
    90 //                   ((semflg&IPC_CREAT)&&(semflg&IPC_EXCL)) is non-zero.
       
    91 //          EINVAL - The value of nsems is either less than or equal to 0 or 
       
    92 //                   greater than the system-imposed limit, or a semaphore 
       
    93 //                   identifier exists for the argument key, but the number of 
       
    94 //                   semaphores in the set associated with it is less than nsems 
       
    95 //                   and nsems is not equal to 0.
       
    96 //          ENOENT - A semaphore identifier does not exist for the argument key 
       
    97 //                   and (semflg&IPC_CREAT) is equal to 0.
       
    98 //          ENOSPC - A semaphore identifier is to be created but the system-imposed 
       
    99 //                   limit on the maximum number of allowed semaphores system-wide 
       
   100 //                   would be exceeded.
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 
       
   104 
       
   105 EXPORT_C int _semget_r(int *aErrno, key_t akey, int nsems, int asemflgs)
       
   106     {
       
   107 	return Backend()->iIpcS.semget(akey, nsems, asemflgs, *aErrno); 
       
   108     }
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // Funcation name: semop
       
   112 // Description: Perform atomically a user-defined array of semaphore operations 
       
   113 //              on the set of semaphores associated with the semaphore identifier 
       
   114 //              specified by the argument semid.
       
   115 // Returns: 0  : On success
       
   116 //          -1 : On error.
       
   117 // In case of error, errno value set to 
       
   118 //          E2BIG - The value of nsops is greater than the system-imposed maximum.
       
   119 //          EACCES - Operation permission is denied to the calling process, see IPC.
       
   120 //          EAGAIN - The operation would result in suspension of the calling process 
       
   121 //                   but (sem_flg&IPC_NOWAIT) is non-zero.
       
   122 //          EFBIG - The value of sem_num is less than 0 or greater than or equal to 
       
   123 //                   the number of semaphores in the set associated with semid.
       
   124 //          EIDRM - The semaphore identifier semid is removed from the system.
       
   125 //          EINTR - The semop() function was interrupted by a signal.
       
   126 //          EINVAL - The value of semid is not a valid semaphore identifier, or the 
       
   127 //                   number of individual semaphores for which the calling process 
       
   128 //                   requests a SEM_UNDO would exceed the system-imposed limit.
       
   129 //          ENOSPC - The limit on the number of individual processes requesting a 
       
   130 //                   SEM_UNDO would be exceeded.
       
   131 //          ERANGE - An operation would cause a semval to overflow the system-imposed 
       
   132 //                   limit, or an operation would cause a semadj value to overflow the 
       
   133 //                   system-imposed limit
       
   134 // -----------------------------------------------------------------------------
       
   135 //
       
   136 EXPORT_C int _semop_r(int *aErrno, int semid, struct sembuf *sops, unsigned nsops)
       
   137     {
       
   138 	return Backend()->iIpcS.semop(semid, sops, nsops, *aErrno);	
       
   139     }
       
   140 
       
   141 // -----------------------------------------------------------------------------
       
   142 // Funcation name: semctl
       
   143 // Description: Provides a variety of semaphore control operations as specified by cmd.
       
   144 // Returns: 
       
   145 //          If successful, the value returned by semctl() depends on cmd as follows:
       
   146 //                 GETVAL - Value of semval. 
       
   147 //                 GETPID - Value of sempid. 
       
   148 //                 GETNCNT - Value of semncnt. 
       
   149 //                 GETZCNT - Value of semzcnt. 
       
   150 //                 All others, it returns 0. 
       
   151 //          -1 : On error.
       
   152 // In case of error, errno value set to 
       
   153 //          EACCES - Operation permission is denied to the calling process.
       
   154 //          EINVAL - The value of semid is not a valid semaphore identifier, 
       
   155 //                   or the value of semnum is less than 0 or greater than or 
       
   156 //                   equal to sem_nsems, or the value of cmd is not a valid command.
       
   157 //          EPERM - The argument cmd is equal to IPC_RMID or IPC_SET and the 
       
   158 //                   effective user ID of the calling process is not equal to 
       
   159 //                   that of a process with appropriate privileges and it is not 
       
   160 //                   equal to the value of sem_perm.cuid or sem_perm.uid in the 
       
   161 //                   data structure associated with semid.
       
   162 //          ERANGE - The argument cmd is equal to SETVAL or SETALL and the value 
       
   163 //                   to which semval is to be set is greater than the system-imposed maximum
       
   164 // -----------------------------------------------------------------------------
       
   165 //
       
   166 EXPORT_C int _semctl_r(int *aErrno, int semid, int semnum, int cmd, ...)
       
   167     {
       
   168     
       
   169 	va_list ap;
       
   170 	union semun semun;
       
   171 	union semun *semun_ptr;
       
   172 
       
   173 	
       
   174 	if (cmd == IPC_SET || cmd == IPC_STAT || cmd == GETALL
       
   175 	    || cmd == SETVAL || cmd == SETALL) 
       
   176 	    {
       
   177 		va_start(ap, cmd);
       
   178 		semun = va_arg(ap, union semun);
       
   179 		semun_ptr = &semun;
       
   180 		va_end(ap);
       
   181 	    } 
       
   182 	else 
       
   183 	    {
       
   184 		semun_ptr = NULL;
       
   185 	    }
       
   186 
       
   187 	return Backend()->iIpcS.semctl(semid, semnum, cmd, semun_ptr, *aErrno);
       
   188     }
       
   189 
       
   190 // -----------------------------------------------------------------------------
       
   191 // Funcation name: shmget
       
   192 // Description: Get shared memory identifier using the IPC key generated by ftok.
       
   193 // Returns: None zero number (shared memory identifier): On success
       
   194 //          -1              : On error.
       
   195 // In case of error, errno value set to 
       
   196 //          EACCES - Operation permission is denied to the calling process, see IPC.
       
   197 //          EINVAL - The value of semid is not a valid semaphore identifier, or the 
       
   198 //                   value of semnum is less than 0 or greater than or equal to 
       
   199 //                   sem_nsems, or the value of cmd is not a valid command.
       
   200 //          EPERM -  The argument cmd is equal to IPC_RMID or IPC_SET and the effective 
       
   201 //                   user ID of the calling process is not equal to that of a process 
       
   202 //                   with appropriate privileges and it is not equal to the value of 
       
   203 //                   sem_perm.cuid or sem_perm.uid in the data structure associated 
       
   204 //                   with semid.
       
   205 //          ERANGE - The argument cmd is equal to SETVAL or SETALL and the value to 
       
   206 //                   which semval is to be set is greater than the system-imposed 
       
   207 //                   maximum.
       
   208 // -----------------------------------------------------------------------------
       
   209 //
       
   210 
       
   211 EXPORT_C int _shmget_r(int *aErrno, key_t key, int size, int shmflg)
       
   212     {
       
   213     return Backend()->iIpcS.shmget(key, size, shmflg, *aErrno);
       
   214     }
       
   215 
       
   216 // -----------------------------------------------------------------------------
       
   217 // Funcation name: shmat
       
   218 // Description: Attaches the shared memory segment associated with the shared 
       
   219 //              memory identifier specified by shmid to the address space of 
       
   220 //              the calling process.
       
   221 // Returns: Segment's start address: On success
       
   222 //          -1   : On error.
       
   223 // In case of error, errno value set to 
       
   224 //          EACCES - Operation permission is denied to the calling process.
       
   225 //          EINVAL - The value of shmid is not a valid shared memory identifier; 
       
   226 //                   the shmaddr is not a null pointer and the value of 
       
   227 //                   (shmaddr-((ptrdiff_t)shmaddr%SHMLBA)) is an illegal 
       
   228 //                   address for attaching shared memory; or the shmaddr is not 
       
   229 //                   a null pointer, (shmflg&SHM_RND) is 0 and the value of 
       
   230 //                   shmaddr is an illegal address for attaching shared memory. 
       
   231 //          EMFILE - The number of shared memory segments attached to the calling 
       
   232 //                   process would exceed the system-imposed limit.
       
   233 //          ENOMEM - The available data space is not large enough to accommodate 
       
   234 //                   the shared memory segment.
       
   235 // -----------------------------------------------------------------------------
       
   236 //
       
   237 EXPORT_C void* _shmat_r(int *aErrno, int shmid, const void *shmaddr, int shmflg)
       
   238     {
       
   239     return Backend()->iIpcS.shmat(shmid, shmaddr, shmflg, *aErrno);
       
   240     }
       
   241 
       
   242 // -----------------------------------------------------------------------------
       
   243 // Funcation name: shmdt
       
   244 // Description: Detaches the shared memory segment located at the address 
       
   245 //              specified by shmaddr from the address space of the calling process.
       
   246 // Returns: 0    : On success.
       
   247 //          -1   : On error.
       
   248 // In case of error, errno value set to 
       
   249 //          EINVAL - The value of shmaddr is not the data segment start 
       
   250 //                   address of a shared memory segment.
       
   251 // -----------------------------------------------------------------------------
       
   252 //
       
   253 EXPORT_C int _shmdt_r(int *aErrno, const void *shmaddr)
       
   254     {
       
   255     return Backend()->iIpcS.shmdt(shmaddr, *aErrno);
       
   256     }
       
   257 
       
   258 // -----------------------------------------------------------------------------
       
   259 // Funcation name: shmctl
       
   260 // Description: Provides a variety of shared memory control operations as 
       
   261 //              specified by cmd.
       
   262 // Returns: 0  : On success
       
   263 //          -1 : On error.
       
   264 // In case of error, errno value set to 
       
   265 //          EACCES - The argument cmd is equal to IPC_STAT and the calling 
       
   266 //                   process does not have read permission.
       
   267 //          EINVAL- The value of shmid is not a valid shared memory 
       
   268 //                   identifier, or the value of cmd is not a valid command. 
       
   269 //          EPERM - The argument cmd is equal to IPC_RMID or IPC_SET and the 
       
   270 //                  effective user ID of the calling process is not equal to 
       
   271 //                  that of a process with appropriate privileges and it is 
       
   272 //                  not equal to the value of shm_perm.cuid or shm_perm.uid 
       
   273 //                  in the data structure associated with shmid. 
       
   274 //          EOVERFLO - The cmd argument is IPC_STAT and the gid or uid value 
       
   275 //                     is too large to be stored in the structure pointed to 
       
   276 //                     by the buf argument
       
   277 // -----------------------------------------------------------------------------
       
   278 //
       
   279 EXPORT_C int _shmctl_r(int *aErrno, int shmid, int cmd, struct shmid_ds *buf)
       
   280     {
       
   281     return Backend()->iIpcS.shmctl(shmid, cmd, buf, *aErrno);
       
   282     }
       
   283 
       
   284 
       
   285 //the message queue functions
       
   286 EXPORT_C int _msgget_r(key_t aKey, int aMsgFlag, int *aErrno)
       
   287 	{
       
   288 	return Backend()->iIpcS.msgget(aKey, aMsgFlag, *aErrno);
       
   289 	}
       
   290 
       
   291 EXPORT_C int _msgsnd_r(int msqid, const void *msgp, size_t msgsz, int msgflg, int *aErrno)
       
   292     {
       
   293     return Backend()->iIpcS.msgsnd(msqid, msgp, msgsz, msgflg, *aErrno);
       
   294     }
       
   295     
       
   296 EXPORT_C int _msgrcv_r(int msqid, void* msgp, size_t msgsz, long msgtyp, int msgflg, int *aErrno)
       
   297     {
       
   298     return Backend()->iIpcS.msgrcv(msqid, msgp, msgsz, msgtyp, msgflg, *aErrno);
       
   299     }
       
   300     
       
   301 EXPORT_C int _msgctl_r(int msqid, int cmd, struct msqid_ds *buf, int *aErrno)
       
   302     {
       
   303     return Backend()->iIpcS.msgctl(msqid, cmd, buf, *aErrno);
       
   304     }
       
   305 
       
   306 } //end extern "C"