小编pje*_*y58的帖子

什么时候 ELF .text 段不是 ELF .text 段?

我无法找到适当的文档来解决我在内核和用户空间中生成一致的 HMAC 的问题。根据Linux Kernel Development中的 Robert Love 的说法,内存描述符mm->start_codemm->end_code应该包含该.text段。在 ELF 文档中明确定义了在静态可执行文件中查找.text段,并且很容易理解。因此,给出以下两个代码片段,人们期望获得匹配的 HMAC:

核心:

__mm = get_task_mm(__task);

__retcode = ntru_crypto_hmac_init(__crypto_context);
if(__retcode != NTRU_CRYPTO_HMAC_OK)
    return 1;

__retcode = ntru_crypto_hmac_update(__crypto_context, (const uint8_t*)__mm->start_code, 
                                    __mm->end_code - __mm->start_code);
if(__retcode != NTRU_CRYPTO_HMAC_OK)
   return 1;

__retcode = ntru_crypto_hmac_final(__crypto_context, __hmac);
if(__retcode != NTRU_CRYPTO_HMAC_OK)
    return 1;

return 0;
Run Code Online (Sandbox Code Playgroud)

用户区:

for (j = 0; j < file_hdr32.e_shnum; j++)
{
   if (!strcmp(".text", strIndex + section_hdr32[j]->sh_name))
   {
       retcode = ntru_crypto_hmac_init(__crypto_context());
       if(retcode != NTRU_CRYPTO_HMAC_OK)
       { …
Run Code Online (Sandbox Code Playgroud)

elf hmac linux-kernel

4
推荐指数
1
解决办法
2113
查看次数

内核模式clock_gettime()

我正在尝试在内核中使用POSIX时钟函数,但编译器不断给我错误:错误:函数'clock_gettime'的隐式声明

long __timer_end(struct timespec start_time)
{
    struct timespec end_time;
    clock_gettime(CLOCK_REALTIME_COARSE, &end_time);
    return(end_time.tv_nsec - start_time.tv_nsec);

}

struct timespec __timer_start(void)
{
    struct timespec start_time;
    clock_gettime(CLOCK_REALTIME_COARSE, &start_time);
    return start_time;
}
Run Code Online (Sandbox Code Playgroud)

函数定义<linux/posix_clock.h>为的结构的一部分,posix_clock_operations并且有一对函数posix_clock_register()posix_clock_unregister()。这些评论使人们相信这些功能将构成该posix_clock_operations结构。我已经在init和exit函数中实现了它们,希望它们的存在会神奇地使for的声明clock_gettime()出现,但事实并非如此。

有谁知道我需要做些什么才能使这一功能起作用?我真的需要定义我自己的所有函数posix clock_operations吗?

提前致谢,

皮特

linux posix kernel timer

2
推荐指数
1
解决办法
7519
查看次数

标签 统计

elf ×1

hmac ×1

kernel ×1

linux ×1

linux-kernel ×1

posix ×1

timer ×1