blob: 4c0d136e4ca5cdf73f5b1541dcf40b71ada896c2 [file] [log] [blame]
Lucas De Marchi14070642013-04-09 04:00:20 -03001#pragma once
2
Lucas De Marchi55112d12013-04-09 04:16:57 -03003#include <unistd.h>
4#include <sys/syscall.h>
5
Lucas De Marchi14070642013-04-09 04:00:20 -03006#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 Marchi55112d12013-04-09 04:16:57 -030017
Lucas De Marchi03f7dfb2013-05-11 00:50:32 -030018#ifndef __NR_finit_module
19# define __NR_finit_module -1
20#endif
21
Lucas De Marchi55112d12013-04-09 04:16:57 -030022#ifndef HAVE_FINIT_MODULE
Jan Luebbe5eac7952013-05-02 16:47:12 +020023#include <errno.h>
24
Lucas De Marchi55112d12013-04-09 04:16:57 -030025static inline int finit_module(int fd, const char *uargs, int flags)
26{
Jan Luebbe5eac7952013-05-02 16:47:12 +020027 if (__NR_finit_module == -1) {
28 errno = ENOSYS;
29 return -1;
30 }
31
Lucas De Marchi55112d12013-04-09 04:16:57 -030032 return syscall(__NR_finit_module, fd, uargs, flags);
33}
34#endif
Lucas De Marchi04c09562014-04-04 08:19:00 -030035
36#if !HAVE_DECL_STRNDUPA
Lucas De Marchif5cdd572014-04-07 12:27:11 -030037#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 Marchi04c09562014-04-04 08:19:00 -030044 })
45#endif
Randy MacLeod9b34db12014-09-29 21:18:04 +020046
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