2013-04-09 14:00:20 +07:00
|
|
|
#pragma once
|
|
|
|
|
2013-04-09 14:16:57 +07:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/syscall.h>
|
|
|
|
|
2013-04-09 14:00:20 +07:00
|
|
|
#ifdef HAVE_LINUX_MODULE_H
|
|
|
|
#include <linux/module.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef MODULE_INIT_IGNORE_MODVERSIONS
|
|
|
|
# define MODULE_INIT_IGNORE_MODVERSIONS 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef MODULE_INIT_IGNORE_VERMAGIC
|
|
|
|
# define MODULE_INIT_IGNORE_VERMAGIC 2
|
|
|
|
#endif
|
2013-04-09 14:16:57 +07:00
|
|
|
|
2023-09-27 22:38:05 +07:00
|
|
|
#ifndef MODULE_INIT_COMPRESSED_FILE
|
|
|
|
# define MODULE_INIT_COMPRESSED_FILE 4
|
|
|
|
#endif
|
|
|
|
|
2013-05-11 10:50:32 +07:00
|
|
|
#ifndef __NR_finit_module
|
|
|
|
# define __NR_finit_module -1
|
|
|
|
#endif
|
|
|
|
|
2013-04-09 14:16:57 +07:00
|
|
|
#ifndef HAVE_FINIT_MODULE
|
2013-05-02 21:47:12 +07:00
|
|
|
#include <errno.h>
|
|
|
|
|
2013-04-09 14:16:57 +07:00
|
|
|
static inline int finit_module(int fd, const char *uargs, int flags)
|
|
|
|
{
|
2013-05-02 21:47:12 +07:00
|
|
|
if (__NR_finit_module == -1) {
|
|
|
|
errno = ENOSYS;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-04-09 14:16:57 +07:00
|
|
|
return syscall(__NR_finit_module, fd, uargs, flags);
|
|
|
|
}
|
|
|
|
#endif
|
2014-04-04 18:19:00 +07:00
|
|
|
|
|
|
|
#if !HAVE_DECL_STRNDUPA
|
2023-12-10 08:35:59 +07:00
|
|
|
#include <string.h>
|
2014-04-07 22:27:11 +07:00
|
|
|
#define strndupa(s, n) \
|
|
|
|
({ \
|
|
|
|
const char *__old = (s); \
|
|
|
|
size_t __len = strnlen(__old, (n)); \
|
|
|
|
char *__new = alloca(__len + 1); \
|
|
|
|
__new[__len] = '\0'; \
|
|
|
|
memcpy(__new, __old, __len); \
|
2014-04-04 18:19:00 +07:00
|
|
|
})
|
|
|
|
#endif
|
2014-09-30 02:18:04 +07:00
|
|
|
|
2023-12-10 08:35:59 +07:00
|
|
|
#if !HAVE_DECL_BASENAME
|
|
|
|
#include <string.h>
|
|
|
|
static inline const char *basename(const char *s)
|
|
|
|
{
|
|
|
|
const char *p = strrchr(s, '/');
|
|
|
|
return p ? p + 1 : s;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-09-30 02:18:04 +07:00
|
|
|
#if !HAVE_DECL_BE32TOH
|
|
|
|
#include <endian.h>
|
|
|
|
#include <byteswap.h>
|
|
|
|
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
|
|
|
#define be32toh(x) bswap_32 (x)
|
|
|
|
#else
|
|
|
|
#define be32toh(x) (x)
|
|
|
|
#endif
|
|
|
|
#endif
|