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.h> 22 #include <asm/unistd-portable.h> 23 24 #include <fcntl_portable.h> 25 #include <timerfd_portable.h> 26 27 #include <filefd_portable.h> 28 29 30 #define PORTABLE_TAG "timerfd_portable" 31 #include <log_portable.h> 32 33 extern int syscall(int, ...); 34 35 36 /* NOTE: LTP defaults to using O_NONBLOCK even if TFD_NONBLOCK is defined */ 37 38 39 /* 40 * Portable to Native event flags mapper. 41 */ 42 static inline int tdf_flags_pton(int portable_flags) 43 { 44 int native_flags = 0; 45 46 ALOGV("%s(portable_flags:0x%x) {", __func__, portable_flags); 47 48 if (portable_flags & TFD_NONBLOCK_PORTABLE) { 49 native_flags |= TFD_NONBLOCK; 50 } 51 52 if (portable_flags & TFD_CLOEXEC_PORTABLE) { 53 native_flags |= TFD_CLOEXEC; 54 } 55 56 ALOGV("%s: return(native_flags:%d); }", __func__, native_flags); 57 return native_flags; 58 } 59 60 61 int WRAP(timerfd_create)(int clockid, int portable_flags) { 62 int rv; 63 int native_flags; 64 65 ALOGV(" "); 66 ALOGV("%s(clockid:%d, portable_flags:%d) {", __func__, 67 clockid, portable_flags); 68 69 native_flags = tdf_flags_pton(portable_flags); 70 71 rv = REAL(syscall)(__NR_timerfd_create, clockid, native_flags); 72 if (rv >= 0) { 73 if (native_flags & TFD_CLOEXEC) { 74 filefd_CLOEXEC_enabled(rv); 75 } 76 filefd_opened(rv, TIMER_FD_TYPE); 77 } 78 79 ALOGV("%s: return(rv:%d); }", __func__, rv); 80 return rv; 81 } 82 83