From 04c0ac14a49e0969333008a9522b64046d58fbdc Mon Sep 17 00:00:00 2001 From: Todd Poynor Date: Wed, 8 May 2013 20:21:00 -0700 Subject: [PATCH] libc: add timerfd calls Change-Id: Id63b907266d5b87c7422a51d393a1430551ca33d --- libc/SYSCALLS.TXT | 3 ++ libc/arch-arm/syscalls.mk | 3 ++ libc/arch-arm/syscalls/timerfd_create.S | 15 ++++++++ libc/arch-arm/syscalls/timerfd_gettime.S | 15 ++++++++ libc/arch-arm/syscalls/timerfd_settime.S | 15 ++++++++ libc/arch-mips/syscalls.mk | 3 ++ libc/arch-mips/syscalls/timerfd_create.S | 22 +++++++++++ libc/arch-mips/syscalls/timerfd_gettime.S | 22 +++++++++++ libc/arch-mips/syscalls/timerfd_settime.S | 22 +++++++++++ libc/arch-x86/syscalls.mk | 3 ++ libc/arch-x86/syscalls/timerfd_create.S | 24 ++++++++++++ libc/arch-x86/syscalls/timerfd_gettime.S | 24 ++++++++++++ libc/arch-x86/syscalls/timerfd_settime.S | 30 +++++++++++++++ libc/include/sys/timerfd.h | 45 +++++++++++++++++++++++ libc/kernel/common/linux/timerfd.h | 31 ++++++++++++++++ 15 files changed, 277 insertions(+) create mode 100644 libc/arch-arm/syscalls/timerfd_create.S create mode 100644 libc/arch-arm/syscalls/timerfd_gettime.S create mode 100644 libc/arch-arm/syscalls/timerfd_settime.S create mode 100644 libc/arch-mips/syscalls/timerfd_create.S create mode 100644 libc/arch-mips/syscalls/timerfd_gettime.S create mode 100644 libc/arch-mips/syscalls/timerfd_settime.S create mode 100644 libc/arch-x86/syscalls/timerfd_create.S create mode 100644 libc/arch-x86/syscalls/timerfd_gettime.S create mode 100644 libc/arch-x86/syscalls/timerfd_settime.S create mode 100644 libc/include/sys/timerfd.h create mode 100644 libc/kernel/common/linux/timerfd.h diff --git a/libc/SYSCALLS.TXT b/libc/SYSCALLS.TXT index 96cc9e6a9..ac04e51e4 100644 --- a/libc/SYSCALLS.TXT +++ b/libc/SYSCALLS.TXT @@ -221,6 +221,9 @@ int __timer_getoverrun:timer_getoverrun(timer_t) int __timer_delete:timer_delete(timer_t) 1 int utimes(const char*, const struct timeval tvp[2]) 1 int utimensat(int, const char *, const struct timespec times[2], int) 1 +int timerfd_create(clockid_t, int) 1 +int timerfd_settime(int, int, const struct itimerspec *, struct itimerspec *) 1 +int timerfd_gettime(int, struct itimerspec *) 1 # signals int sigaction(int, const struct sigaction *, struct sigaction *) 1 diff --git a/libc/arch-arm/syscalls.mk b/libc/arch-arm/syscalls.mk index 9eb51369e..3c8f20490 100644 --- a/libc/arch-arm/syscalls.mk +++ b/libc/arch-arm/syscalls.mk @@ -144,6 +144,9 @@ syscall_src += arch-arm/syscalls/__timer_getoverrun.S syscall_src += arch-arm/syscalls/__timer_delete.S syscall_src += arch-arm/syscalls/utimes.S syscall_src += arch-arm/syscalls/utimensat.S +syscall_src += arch-arm/syscalls/timerfd_create.S +syscall_src += arch-arm/syscalls/timerfd_settime.S +syscall_src += arch-arm/syscalls/timerfd_gettime.S syscall_src += arch-arm/syscalls/sigaction.S syscall_src += arch-arm/syscalls/sigprocmask.S syscall_src += arch-arm/syscalls/__sigsuspend.S diff --git a/libc/arch-arm/syscalls/timerfd_create.S b/libc/arch-arm/syscalls/timerfd_create.S new file mode 100644 index 000000000..7e3f16f02 --- /dev/null +++ b/libc/arch-arm/syscalls/timerfd_create.S @@ -0,0 +1,15 @@ +/* autogenerated by gensyscalls.py */ +#include +#include +#include + +ENTRY(timerfd_create) + mov ip, r7 + ldr r7, =__NR_timerfd_create + swi #0 + mov r7, ip + cmn r0, #(MAX_ERRNO + 1) + bxls lr + neg r0, r0 + b __set_errno +END(timerfd_create) diff --git a/libc/arch-arm/syscalls/timerfd_gettime.S b/libc/arch-arm/syscalls/timerfd_gettime.S new file mode 100644 index 000000000..2c3e2cf78 --- /dev/null +++ b/libc/arch-arm/syscalls/timerfd_gettime.S @@ -0,0 +1,15 @@ +/* autogenerated by gensyscalls.py */ +#include +#include +#include + +ENTRY(timerfd_gettime) + mov ip, r7 + ldr r7, =__NR_timerfd_gettime + swi #0 + mov r7, ip + cmn r0, #(MAX_ERRNO + 1) + bxls lr + neg r0, r0 + b __set_errno +END(timerfd_gettime) diff --git a/libc/arch-arm/syscalls/timerfd_settime.S b/libc/arch-arm/syscalls/timerfd_settime.S new file mode 100644 index 000000000..f7f0cf0e0 --- /dev/null +++ b/libc/arch-arm/syscalls/timerfd_settime.S @@ -0,0 +1,15 @@ +/* autogenerated by gensyscalls.py */ +#include +#include +#include + +ENTRY(timerfd_settime) + mov ip, r7 + ldr r7, =__NR_timerfd_settime + swi #0 + mov r7, ip + cmn r0, #(MAX_ERRNO + 1) + bxls lr + neg r0, r0 + b __set_errno +END(timerfd_settime) diff --git a/libc/arch-mips/syscalls.mk b/libc/arch-mips/syscalls.mk index 0b8eccd28..d3096bc78 100644 --- a/libc/arch-mips/syscalls.mk +++ b/libc/arch-mips/syscalls.mk @@ -147,6 +147,9 @@ syscall_src += arch-mips/syscalls/__timer_getoverrun.S syscall_src += arch-mips/syscalls/__timer_delete.S syscall_src += arch-mips/syscalls/utimes.S syscall_src += arch-mips/syscalls/utimensat.S +syscall_src += arch-mips/syscalls/timerfd_create.S +syscall_src += arch-mips/syscalls/timerfd_settime.S +syscall_src += arch-mips/syscalls/timerfd_gettime.S syscall_src += arch-mips/syscalls/sigaction.S syscall_src += arch-mips/syscalls/sigprocmask.S syscall_src += arch-mips/syscalls/__sigsuspend.S diff --git a/libc/arch-mips/syscalls/timerfd_create.S b/libc/arch-mips/syscalls/timerfd_create.S new file mode 100644 index 000000000..b5ac003cf --- /dev/null +++ b/libc/arch-mips/syscalls/timerfd_create.S @@ -0,0 +1,22 @@ +/* autogenerated by gensyscalls.py */ +#include + .text + .globl timerfd_create + .align 4 + .ent timerfd_create + +timerfd_create: + .set noreorder + .cpload $t9 + li $v0, __NR_timerfd_create + syscall + bnez $a3, 1f + move $a0, $v0 + j $ra + nop +1: + la $t9,__set_errno + j $t9 + nop + .set reorder + .end timerfd_create diff --git a/libc/arch-mips/syscalls/timerfd_gettime.S b/libc/arch-mips/syscalls/timerfd_gettime.S new file mode 100644 index 000000000..b1c21fff9 --- /dev/null +++ b/libc/arch-mips/syscalls/timerfd_gettime.S @@ -0,0 +1,22 @@ +/* autogenerated by gensyscalls.py */ +#include + .text + .globl timerfd_gettime + .align 4 + .ent timerfd_gettime + +timerfd_gettime: + .set noreorder + .cpload $t9 + li $v0, __NR_timerfd_gettime + syscall + bnez $a3, 1f + move $a0, $v0 + j $ra + nop +1: + la $t9,__set_errno + j $t9 + nop + .set reorder + .end timerfd_gettime diff --git a/libc/arch-mips/syscalls/timerfd_settime.S b/libc/arch-mips/syscalls/timerfd_settime.S new file mode 100644 index 000000000..f68819d69 --- /dev/null +++ b/libc/arch-mips/syscalls/timerfd_settime.S @@ -0,0 +1,22 @@ +/* autogenerated by gensyscalls.py */ +#include + .text + .globl timerfd_settime + .align 4 + .ent timerfd_settime + +timerfd_settime: + .set noreorder + .cpload $t9 + li $v0, __NR_timerfd_settime + syscall + bnez $a3, 1f + move $a0, $v0 + j $ra + nop +1: + la $t9,__set_errno + j $t9 + nop + .set reorder + .end timerfd_settime diff --git a/libc/arch-x86/syscalls.mk b/libc/arch-x86/syscalls.mk index b4ad564ed..31eb93008 100644 --- a/libc/arch-x86/syscalls.mk +++ b/libc/arch-x86/syscalls.mk @@ -148,6 +148,9 @@ syscall_src += arch-x86/syscalls/__timer_getoverrun.S syscall_src += arch-x86/syscalls/__timer_delete.S syscall_src += arch-x86/syscalls/utimes.S syscall_src += arch-x86/syscalls/utimensat.S +syscall_src += arch-x86/syscalls/timerfd_create.S +syscall_src += arch-x86/syscalls/timerfd_settime.S +syscall_src += arch-x86/syscalls/timerfd_gettime.S syscall_src += arch-x86/syscalls/sigaction.S syscall_src += arch-x86/syscalls/sigprocmask.S syscall_src += arch-x86/syscalls/__sigsuspend.S diff --git a/libc/arch-x86/syscalls/timerfd_create.S b/libc/arch-x86/syscalls/timerfd_create.S new file mode 100644 index 000000000..801f8a7f7 --- /dev/null +++ b/libc/arch-x86/syscalls/timerfd_create.S @@ -0,0 +1,24 @@ +/* autogenerated by gensyscalls.py */ +#include +#include +#include + +ENTRY(timerfd_create) + pushl %ebx + pushl %ecx + mov 12(%esp), %ebx + mov 16(%esp), %ecx + movl $__NR_timerfd_create, %eax + int $0x80 + cmpl $-MAX_ERRNO, %eax + jb 1f + negl %eax + pushl %eax + call __set_errno + addl $4, %esp + orl $-1, %eax +1: + popl %ecx + popl %ebx + ret +END(timerfd_create) diff --git a/libc/arch-x86/syscalls/timerfd_gettime.S b/libc/arch-x86/syscalls/timerfd_gettime.S new file mode 100644 index 000000000..fde17beaf --- /dev/null +++ b/libc/arch-x86/syscalls/timerfd_gettime.S @@ -0,0 +1,24 @@ +/* autogenerated by gensyscalls.py */ +#include +#include +#include + +ENTRY(timerfd_gettime) + pushl %ebx + pushl %ecx + mov 12(%esp), %ebx + mov 16(%esp), %ecx + movl $__NR_timerfd_gettime, %eax + int $0x80 + cmpl $-MAX_ERRNO, %eax + jb 1f + negl %eax + pushl %eax + call __set_errno + addl $4, %esp + orl $-1, %eax +1: + popl %ecx + popl %ebx + ret +END(timerfd_gettime) diff --git a/libc/arch-x86/syscalls/timerfd_settime.S b/libc/arch-x86/syscalls/timerfd_settime.S new file mode 100644 index 000000000..5a5f3e4e2 --- /dev/null +++ b/libc/arch-x86/syscalls/timerfd_settime.S @@ -0,0 +1,30 @@ +/* autogenerated by gensyscalls.py */ +#include +#include +#include + +ENTRY(timerfd_settime) + pushl %ebx + pushl %ecx + pushl %edx + pushl %esi + mov 20(%esp), %ebx + mov 24(%esp), %ecx + mov 28(%esp), %edx + mov 32(%esp), %esi + movl $__NR_timerfd_settime, %eax + int $0x80 + cmpl $-MAX_ERRNO, %eax + jb 1f + negl %eax + pushl %eax + call __set_errno + addl $4, %esp + orl $-1, %eax +1: + popl %esi + popl %edx + popl %ecx + popl %ebx + ret +END(timerfd_settime) diff --git a/libc/include/sys/timerfd.h b/libc/include/sys/timerfd.h new file mode 100644 index 000000000..0651f1ca6 --- /dev/null +++ b/libc/include/sys/timerfd.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _SYS_TIMERFD_H_ +#define _SYS_TIMERFD_H_ + +#include +#include +#include + +__BEGIN_DECLS + +extern int timerfd_create(clockid_t, int); +extern int timerfd_settime(int, int, const struct itimerspec*, + struct itimerspec*); +extern int timerfd_gettime(int, struct itimerspec*); + +__END_DECLS + +#endif /* _SYS_TIMERFD_H */ diff --git a/libc/kernel/common/linux/timerfd.h b/libc/kernel/common/linux/timerfd.h new file mode 100644 index 000000000..0165ebbb3 --- /dev/null +++ b/libc/kernel/common/linux/timerfd.h @@ -0,0 +1,31 @@ +/**************************************************************************** + **************************************************************************** + *** + *** This header was automatically generated from a Linux kernel header + *** of the same name, to make information necessary for userspace to + *** call into the kernel available to libc. It contains only constants, + *** structures, and macros generated from the original header, and thus, + *** contains no copyrightable information. + *** + *** To edit the content of this header, modify the corresponding + *** source file (e.g. under external/kernel-headers/original/) then + *** run bionic/libc/kernel/tools/update_all.py + *** + *** Any manual change here will be lost the next time this script will + *** be run. You've been warned! + *** + **************************************************************************** + ****************************************************************************/ +#ifndef _LINUX_TIMERFD_H +#define _LINUX_TIMERFD_H +#include +#define TFD_TIMER_ABSTIME (1 << 0) +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +#define TFD_TIMER_CANCEL_ON_SET (1 << 1) +#define TFD_CLOEXEC O_CLOEXEC +#define TFD_NONBLOCK O_NONBLOCK +#define TFD_SHARED_FCNTL_FLAGS (TFD_CLOEXEC | TFD_NONBLOCK) +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +#define TFD_CREATE_FLAGS TFD_SHARED_FCNTL_FLAGS +#define TFD_SETTIME_FLAGS (TFD_TIMER_ABSTIME | TFD_TIMER_CANCEL_ON_SET) +#endif