| 1 |
/*- |
| 2 |
* Copyright (c) 2009 Hans Petter Selasky. All rights reserved. |
| 3 |
* |
| 4 |
* Redistribution and use in source and binary forms, with or without |
| 5 |
* modification, are permitted provided that the following conditions |
| 6 |
* are met: |
| 7 |
* 1. Redistributions of source code must retain the above copyright |
| 8 |
* notice, this list of conditions and the following disclaimer. |
| 9 |
* 2. Redistributions in binary form must reproduce the above copyright |
| 10 |
* notice, this list of conditions and the following disclaimer in the |
| 11 |
* documentation and/or other materials provided with the distribution. |
| 12 |
* |
| 13 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
| 14 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 16 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
| 17 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 18 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 19 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 20 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 21 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 22 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 23 |
* SUCH DAMAGE. |
| 24 |
*/ |
| 25 |
|
| 26 |
/* |
| 27 |
* The following file allows for having the complete V4L stack and |
| 28 |
* hardware drivers in userland. |
| 29 |
*/ |
| 30 |
|
| 31 |
#ifndef _LIBV4LSYSCALL_PRIV_H_ |
| 32 |
#define _LIBV4LSYSCALL_PRIV_H_ |
| 33 |
|
| 34 |
/* Some of these headers are not needed by us, but by linux/videodev2.h, |
| 35 |
which is broken on some systems and doesn't include them itself :( */ |
| 36 |
|
| 37 |
#ifdef linux |
| 38 |
#include <sys/time.h> |
| 39 |
#include <sys/syscall.h> |
| 40 |
#include <linux/types.h> |
| 41 |
#include <linux/ioctl.h> |
| 42 |
/* On 32 bits archs we always use mmap2, on 64 bits archs there is no mmap2 */ |
| 43 |
#ifdef __NR_mmap2 |
| 44 |
#if !defined(SYS_mmap2) |
| 45 |
#define SYS_mmap2 __NR_mmap2 |
| 46 |
#endif |
| 47 |
#define MMAP2_PAGE_SHIFT 12 |
| 48 |
#else |
| 49 |
#define SYS_mmap2 SYS_mmap |
| 50 |
#define MMAP2_PAGE_SHIFT 0 |
| 51 |
#endif |
| 52 |
#endif |
| 53 |
|
| 54 |
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) |
| 55 |
#include <sys/time.h> |
| 56 |
#include <sys/syscall.h> |
| 57 |
#include <sys/types.h> |
| 58 |
#include <sys/ioctl.h> |
| 59 |
#define _IOC_NR(cmd) ((cmd) & 0xFF) |
| 60 |
#define _IOC_TYPE(cmd) IOCGROUP(cmd) |
| 61 |
#define _IOC_SIZE(cmd) IOCPARM_LEN(cmd) |
| 62 |
#define MAP_ANONYMOUS MAP_ANON |
| 63 |
#define MMAP2_PAGE_SHIFT 0 |
| 64 |
#endif |
| 65 |
|
| 66 |
#if defined(__OpenBSD__) |
| 67 |
#include <sys/syscall.h> |
| 68 |
#include <sys/types.h> |
| 69 |
#include <sys/ioctl.h> |
| 70 |
#define _IOC_NR(cmd) ((cmd) & 0xFF) |
| 71 |
#define _IOC_TYPE(cmd) IOCGROUP(cmd) |
| 72 |
#define MMAP2_PAGE_SHIFT 0 |
| 73 |
#endif |
| 74 |
|
| 75 |
#undef SYS_OPEN |
| 76 |
#undef SYS_CLOSE |
| 77 |
#undef SYS_IOCTL |
| 78 |
#undef SYS_READ |
| 79 |
#undef SYS_WRITE |
| 80 |
#undef SYS_MMAP |
| 81 |
#undef SYS_MUNMAP |
| 82 |
|
| 83 |
#ifndef CONFIG_SYS_WRAPPER |
| 84 |
|
| 85 |
#ifdef SYS_openat |
| 86 |
#define SYS_OPEN(file, oflag, mode) \ |
| 87 |
syscall(SYS_openat, AT_FDCWD, (const char *)(file), (int)(oflag), (mode_t)(mode)) |
| 88 |
#else |
| 89 |
#define SYS_OPEN(file, oflag, mode) \ |
| 90 |
syscall(SYS_open, (const char *)(file), (int)(oflag), (mode_t)(mode)) |
| 91 |
#endif |
| 92 |
#define SYS_CLOSE(fd) \ |
| 93 |
syscall(SYS_close, (int)(fd)) |
| 94 |
#define SYS_IOCTL(fd, cmd, arg) \ |
| 95 |
syscall(SYS_ioctl, (int)(fd), (unsigned long)(cmd), (void *)(arg)) |
| 96 |
#define SYS_READ(fd, buf, len) \ |
| 97 |
syscall(SYS_read, (int)(fd), (void *)(buf), (size_t)(len)); |
| 98 |
#define SYS_WRITE(fd, buf, len) \ |
| 99 |
syscall(SYS_write, (int)(fd), (const void *)(buf), (size_t)(len)); |
| 100 |
|
| 101 |
#if defined(__FreeBSD__) |
| 102 |
#define SYS_MMAP(addr, len, prot, flags, fd, off) \ |
| 103 |
__syscall(SYS_mmap, (void *)(addr), (size_t)(len), \ |
| 104 |
(int)(prot), (int)(flags), (int)(fd), (off_t)(off)) |
| 105 |
#elif defined(__FreeBSD_kernel__) |
| 106 |
#define SYS_MMAP(addr, len, prot, flags, fd, off) \ |
| 107 |
syscall(SYS_mmap, (void *)(addr), (size_t)(len), \ |
| 108 |
(int)(prot), (int)(flags), (int)(fd), (off_t)(off)) |
| 109 |
#elif defined(__OpenBSD__) |
| 110 |
register_t __syscall(quad_t, ...); |
| 111 |
#define SYS_MMAP(addr, len, prot, flags, fd, offset) \ |
| 112 |
__syscall((quad_t)SYS_mmap, (void *)(addr), (size_t)(len), \ |
| 113 |
(int)(prot), (int)(flags), (int)(fd), 0, (off_t)(offset)) |
| 114 |
#else |
| 115 |
#define SYS_MMAP(addr, len, prot, flags, fd, off) \ |
| 116 |
syscall(SYS_mmap2, (void *)(addr), (size_t)(len), \ |
| 117 |
(int)(prot), (int)(flags), (int)(fd), (off_t)((off) >> MMAP2_PAGE_SHIFT)) |
| 118 |
#endif |
| 119 |
|
| 120 |
#define SYS_MUNMAP(addr, len) \ |
| 121 |
syscall(SYS_munmap, (void *)(addr), (size_t)(len)) |
| 122 |
|
| 123 |
#else |
| 124 |
|
| 125 |
int v4lx_open_wrapper(const char *, int, int); |
| 126 |
int v4lx_close_wrapper(int); |
| 127 |
int v4lx_ioctl_wrapper(int, unsigned long, void *); |
| 128 |
int v4lx_read_wrapper(int, void *, size_t); |
| 129 |
int v4lx_write_wrapper(int, const void *, size_t); |
| 130 |
void *v4lx_mmap_wrapper(void *, size_t, int, int, int, off_t); |
| 131 |
int v4lx_munmap_wrapper(void *, size_t); |
| 132 |
|
| 133 |
#define SYS_OPEN(...) v4lx_open_wrapper(__VA_ARGS__) |
| 134 |
#define SYS_CLOSE(...) v4lx_close_wrapper(__VA_ARGS__) |
| 135 |
#define SYS_IOCTL(...) v4lx_ioctl_wrapper(__VA_ARGS__) |
| 136 |
#define SYS_READ(...) v4lx_read_wrapper(__VA_ARGS__) |
| 137 |
#define SYS_WRITE(...) v4lx_write_wrapper(__VA_ARGS__) |
| 138 |
#define SYS_MMAP(...) v4lx_mmap_wrapper(__VA_ARGS__) |
| 139 |
#define SYS_MUNMAP(...) v4lx_munmap_wrapper(__VA_ARGS__) |
| 140 |
|
| 141 |
#endif |
| 142 |
|
| 143 |
#endif /* _LIBV4LSYSCALL_PRIV_H_ */ |