Lucas De Marchi | 1407064 | 2013-04-09 04:00:20 -0300 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Lucas De Marchi | 55112d1 | 2013-04-09 04:16:57 -0300 | [diff] [blame] | 3 | #include <unistd.h> |
| 4 | #include <sys/syscall.h> |
| 5 | |
Lucas De Marchi | 1407064 | 2013-04-09 04:00:20 -0300 | [diff] [blame] | 6 | #ifdef HAVE_LINUX_MODULE_H |
| 7 | #include <linux/module.h> |
| 8 | #endif |
| 9 | |
| 10 | #ifndef MODULE_INIT_IGNORE_MODVERSIONS |
| 11 | # define MODULE_INIT_IGNORE_MODVERSIONS 1 |
| 12 | #endif |
| 13 | |
| 14 | #ifndef MODULE_INIT_IGNORE_VERMAGIC |
| 15 | # define MODULE_INIT_IGNORE_VERMAGIC 2 |
| 16 | #endif |
Lucas De Marchi | 55112d1 | 2013-04-09 04:16:57 -0300 | [diff] [blame] | 17 | |
Lucas De Marchi | 03f7dfb | 2013-05-11 00:50:32 -0300 | [diff] [blame] | 18 | #ifndef __NR_finit_module |
| 19 | # define __NR_finit_module -1 |
| 20 | #endif |
| 21 | |
Lucas De Marchi | 55112d1 | 2013-04-09 04:16:57 -0300 | [diff] [blame] | 22 | #ifndef HAVE_FINIT_MODULE |
Jan Luebbe | 5eac795 | 2013-05-02 16:47:12 +0200 | [diff] [blame] | 23 | #include <errno.h> |
| 24 | |
Lucas De Marchi | 55112d1 | 2013-04-09 04:16:57 -0300 | [diff] [blame] | 25 | static inline int finit_module(int fd, const char *uargs, int flags) |
| 26 | { |
Jan Luebbe | 5eac795 | 2013-05-02 16:47:12 +0200 | [diff] [blame] | 27 | if (__NR_finit_module == -1) { |
| 28 | errno = ENOSYS; |
| 29 | return -1; |
| 30 | } |
| 31 | |
Lucas De Marchi | 55112d1 | 2013-04-09 04:16:57 -0300 | [diff] [blame] | 32 | return syscall(__NR_finit_module, fd, uargs, flags); |
| 33 | } |
| 34 | #endif |
Lucas De Marchi | 04c0956 | 2014-04-04 08:19:00 -0300 | [diff] [blame] | 35 | |
Sean Callanan | a322503 | 2019-11-05 12:48:55 -0800 | [diff] [blame] | 36 | #if (!HAVE_DECL_STRNDUPA && !defined(__APPLE__)) |
Lucas De Marchi | f5cdd57 | 2014-04-07 12:27:11 -0300 | [diff] [blame] | 37 | #define strndupa(s, n) \ |
| 38 | ({ \ |
| 39 | const char *__old = (s); \ |
| 40 | size_t __len = strnlen(__old, (n)); \ |
| 41 | char *__new = alloca(__len + 1); \ |
| 42 | __new[__len] = '\0'; \ |
| 43 | memcpy(__new, __old, __len); \ |
Lucas De Marchi | 04c0956 | 2014-04-04 08:19:00 -0300 | [diff] [blame] | 44 | }) |
| 45 | #endif |
Randy MacLeod | 9b34db1 | 2014-09-29 21:18:04 +0200 | [diff] [blame] | 46 | |
| 47 | #if !HAVE_DECL_BE32TOH |
| 48 | #include <endian.h> |
| 49 | #include <byteswap.h> |
| 50 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 51 | #define be32toh(x) bswap_32 (x) |
| 52 | #else |
| 53 | #define be32toh(x) (x) |
| 54 | #endif |
| 55 | #endif |