【问题标题】:how to make loadable kernel module on solaris? no linux如何在 solaris 上制作可加载的内核模块?没有Linux
【发布时间】:2018-11-16 21:50:49
【问题描述】:

1。如何在 solaris 11 上创建可加载内核模块?

  • 简单的可加载内核模块(hello world)。
  • 我搜索了,但只展示了如何创建 Linux 内核模块。
  • 在 linux 中,头文件 linux/kernel.h,但在 solaris 上不包含头文件

2。如何在 solaris 11 上编译可加载内核模块?

  • gcc -D_KERNEL -m64 -c cpluscplus.cpp
  • 如上编译合适吗?
  • 64位,x86

【问题讨论】:

  • "我搜索了,但只展示了如何创建 Linux 内核模块。" - 刚刚尝试在谷歌上搜索“构建 solaris 内核模块”,第一个参考文献之一是 docs.oracle.com/cd/E19253-01/817-5789/fgouv/index.html
  • 有一点需要注意,因为它没有很好的记录:如果您不提供driver.conf 文件,您的内核模块将不会附加并且错误消息不会很有用。详情请见man driver.conf

标签: unix module kernel solaris kernel-module


【解决方案1】:

这是我能想到的最小的 hello world 内核模块:

#include <sys/modctl.h>
#include <sys/cmn_err.h>

/*
 * Module linkage information for the kernel.
 */
static struct modlmisc modlmisc = {
        &mod_miscops, "test module"
};

static struct modlinkage modlinkage = {
        MODREV_1, (void *)&modlmisc, NULL
};


int
_init(void)
{
        return (mod_install(&modlinkage));
}

int
_fini(void)
{
        return (mod_remove(&modlinkage));
}

int
_info(struct modinfo *modinfop)
{
        cmn_err(CE_NOTE, "hello kernel");
        return (mod_info(&modlinkage, modinfop));
}

使用 Oracle Developer Studio 12.6 和 Solaris 链接器将其编译为 64 位二进制文​​件,如下所示:

cc -D_KERNEL -I include -m64 -c foomod.c
ld -64 -z type=kmod -znodefs -o foomod foomod.o

对于 GCC,您可能需要一组不同的选项。

然后加载它:

modload ./foomod

这将抱怨签名验证。除非您在启用验证启动的情况下运行系统,否则这是无害的。

检查模块是否已加载:

# modinfo -i foomod
ID  LOADADDR         SIZE   INFO REV NAMEDESC
312 fffffffff7a8ddc0 268    --   1   foomod (test module)
# dmesg | tail -1
Mar 16 12:22:57 ST091 foomod: [ID 548715 kern.notice] NOTICE: hello kernel

这适用于在 x86 机器上运行的 Solaris 11.4 SRU 33(实际上是 VirtualBox 实例)。

【讨论】:

    猜你喜欢
    • 2021-10-31
    • 2019-10-31
    • 1970-01-01
    • 2016-10-12
    • 1970-01-01
    • 2023-03-20
    • 2015-07-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多