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 #include <portability.h> 18 #include <unistd.h> 19 #include <fcntl.h> 20 21 #include <asm/unistd-portable.h> 22 #include <asm/unistd.h> 23 24 #include <fcntl_portable.h> 25 #include <sys/eventfd.h> 26 #include <eventfd_portable.h> 27 #include <filefd_portable.h> 28 29 #define PORTABLE_TAG "eventfd_portable" 30 #include <log_portable.h> 31 32 33 /* NOTE: LTP defaults to using O_NONBLOCK even if EFD_NONBLOCK is defined */ 34 35 36 /* 37 * Portable to Native event flags mapper. 38 */ 39 static inline int efd_flags_pton(int portable_flags) 40 { 41 int native_flags = 0; 42 43 ALOGV("%s(portable_flags:0x%x) {", __func__, portable_flags); 44 45 if (portable_flags & EFD_NONBLOCK_PORTABLE) { 46 native_flags |= EFD_NONBLOCK; 47 portable_flags &= ~EFD_NONBLOCK_PORTABLE; 48 } 49 50 if (portable_flags & EFD_CLOEXEC_PORTABLE) { 51 native_flags |= EFD_CLOEXEC; 52 portable_flags &= EFD_CLOEXEC_PORTABLE; 53 } 54 55 if (portable_flags & EFD_SEMAPHORE_PORTABLE) { 56 native_flags |= EFD_SEMAPHORE; 57 portable_flags &= EFD_SEMAPHORE_PORTABLE; 58 } 59 60 if (portable_flags != 0) { 61 ALOGW("%s: portable_flags:0x%x != 0; Unsupported Flags being used!", 62 __func__, portable_flags); 63 } 64 ALOGV("%s: return(native_flags:%d); }", __func__, native_flags); 65 return native_flags; 66 } 67 68 69 /* 70 * In the original eventfd() the portable_flags were unused up to 71 * linux 2.6.26 and had to be zero. Android simply uses the 72 * new eventfd2 system call number, so it likely best to just use 73 * the Android eventfd() for both eventfd and eventfd2 system calls. 74 */ 75 int WRAP(eventfd)(unsigned int initval, int portable_flags) { 76 int rv; 77 int native_flags; 78 79 ALOGV(" "); 80 ALOGV("%s(initval:%u, portable_flags:%d) {", __func__, 81 initval, portable_flags); 82 83 native_flags = efd_flags_pton(portable_flags); 84 85 rv = REAL(eventfd)(initval, native_flags); 86 if (rv >= 0) { 87 if (native_flags & EFD_CLOEXEC) { 88 filefd_CLOEXEC_enabled(rv); 89 } 90 filefd_opened(rv, EVENT_FD_TYPE); 91 } 92 93 ALOGV("%s: return(rv:%d); }", __func__, rv); 94 return rv; 95 } 96 97