Home | History | Annotate | Download | only in arch-mips
      1 /*
      2  * Copyright 2012, The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *     http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #define _GNU_SOURCE             /* GLibc compatibility to declare pipe2(2) */
     18 #include <portability.h>
     19 #include <unistd.h>
     20 #include <fcntl.h>
     21 
     22 #include <portability.h>
     23 #include <asm/unistd.h>
     24 #include <asm/unistd-portable.h>
     25 
     26 #include <fcntl_portable.h>
     27 #include <asm/unistd-portable.h>
     28 #include <asm/unistd.h>
     29 #include <filefd_portable.h>
     30 
     31 
     32 #define PORTABLE_TAG "pipe_portable"
     33 #include <log_portable.h>
     34 
     35 extern int syscall(int, ...);
     36 
     37 
     38 /* NOTE: LTP defaults to using O_NONBLOCK even if O_NONBLOCK is defined */
     39 
     40 
     41 /*
     42  * Portable to Native event flags mapper.
     43  */
     44 static inline int tdf_flags_pton(int portable_flags)
     45 {
     46     int native_flags = 0;
     47 
     48     ALOGV("%s(portable_flags:0x%x) {", __func__, portable_flags);
     49 
     50     if (portable_flags & O_NONBLOCK_PORTABLE) {
     51         native_flags |= O_NONBLOCK;
     52     }
     53 
     54     if (portable_flags & O_CLOEXEC_PORTABLE) {
     55         native_flags |= O_CLOEXEC;
     56     }
     57 
     58     ALOGV("%s: return(native_flags:%d); }", __func__, native_flags);
     59     return native_flags;
     60 }
     61 
     62 
     63 int WRAP(pipe2)(int pipefd[2], int portable_flags) {
     64     int native_flags;
     65     int rv;
     66 
     67     ALOGV(" ");
     68     ALOGV("%s(pipefd[2]:%p, portable_flags:0x%x) {", __func__,
     69               pipefd,       portable_flags);
     70 
     71     native_flags = tdf_flags_pton(portable_flags);
     72 
     73     rv = REAL(pipe2)(pipefd, native_flags);
     74     if (rv >= 0) {
     75         ALOGV("%s: pipe2() returned pipefd[0]:%d, pipefd[1]:%d", __func__,
     76                                     pipefd[0],    pipefd[1]);
     77 
     78         if (native_flags & O_CLOEXEC) {
     79             filefd_CLOEXEC_enabled(pipefd[0]);
     80             filefd_CLOEXEC_enabled(pipefd[1]);
     81         }
     82     }
     83 
     84     ALOGV("%s: return(rv:%d); }", __func__, rv);
     85     return rv;
     86 }
     87 
     88