小编inc*_*ent的帖子

VMA和ELF细分之间的关​​系

我需要为可加载的ELF可执行文件段确定VMA.VMA可以打印出来/proc/pid/maps.maps使用可加载段显示的VMA之间的关系对我来说也很清楚.每个部分由一个或多个VMA组成.内核用于从ELF段形成VMA的方法是什么:它还需要考虑权限/标志或其他什么?根据我的理解,带有标志Read, Execute(代码)的段将进入具有相同权限的单独VMA.而具有权限读取,写入(数据)的下一个段应该在另一个VMA中.但这不是第二个可加载段的情况,它通常分为两个或多个VMA:一些与read and write其他VMA分开read only.所以我认为旗帜是VMA生成的唯一罪魁祸首似乎是错误的.我需要帮助来理解段和VMA之间的这种关系.

我想要做的是以编程方式确定ELF的可加载段的VMA,而不将其加载到内存中.所以这方面的任何指针/帮助都是这篇文章的主要目标.

c unix memory elf execution

3
推荐指数
1
解决办法
1037
查看次数

将宏 container_of 与结构成员一起使用

我试图理解一些专有代码,其中使用单个参数调用container_of,该参数是返回结构的成员结构。

struct want{
.
.
struct member_used;
};
member_struct *ptr_member_used;
struct want *ret_struct container_of(ptr_member_used);
Run Code Online (Sandbox Code Playgroud)

我检查了以下链接

http://codinghighway.com/2013/08/10/the-magical-container-of-macro-and-its-use-in-the-linux-kernel/

关于linux中container_of宏的疑问

了解Linux内核中的container_of宏

什么时候使用container_of宏?

但所有这些链接都使用三个参数,但没有一个使用结构成员来检索相应的结构。

我担心的是,container_of 宏如何仅通过传递结构成员来返回相应的结构?

程序在内核 3.13.0 和 gcc 4.8.4 的 64 位 ubuntu 14.0.4 上正确运行

c linux-kernel data-structures

0
推荐指数
1
解决办法
3118
查看次数

C字符串字符串比较总是导致false

我正在尝试在文件中查找字符串。我通过修改的手册页中存在的代码段编写了以下内容getline

#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    FILE * fp;
    char * line = NULL;
    char *fixed_str = "testline4";
    size_t len = 0;
    ssize_t read;

    fp = fopen("test.txt", "r");
    if (fp == NULL)
        exit(EXIT_FAILURE);

    while ((read = getline(&line, &len, fp)) != -1) {
        printf("Retrieved line of length %zu:\n", read);
        printf("%s", line);

        if (strcmp(fixed_str,line)==0)
            printf("the match is found\n");
    }
    //printf("the len of string is %zu\n", strlen(fixed_str));

    fclose(fp);
    if (line)
        free(line);
    exit(EXIT_SUCCESS);
} 
Run Code Online (Sandbox Code Playgroud)

问题是,尽管getline成功且正确地遍历了文件中的所有行,但strcmp的结果始终为false。由于换行符(AM I …

c linux string file

0
推荐指数
1
解决办法
140
查看次数

标签 统计

c ×3

data-structures ×1

elf ×1

execution ×1

file ×1

linux ×1

linux-kernel ×1

memory ×1

string ×1

unix ×1