linux - [C] 内核中的双向链表在上层应用是否会有问题?(list.h)
天蓬老师
天蓬老师 2017-04-17 11:14:49
0
2
650

我将内核中的双向链表的list.h文件放到上层使用(目前在Ubuntu系统上暂时未出现问题),是否会隐含着一些问题???

由于list.h里面使用到了内核的一些头文件不能包括在上层应用中,我将一些宏直接移植到了list.h里面,其它代码没有任何的变动。移植的宏如下:

#define prefetch(x) __builtin_prefetch(x)

#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)

#define container_of(ptr, type, member) ({            \
    const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
    (type *)( (char *)__mptr - offsetof(type,member) );})

有的文章在上层应用中使用list.h文件时,采用“在编译中使用‘-D KERNEL’开关‘欺骗’编译器”的方法是否妥当?(这与我单独将list.h文件提取到上层应用没有本质的区别)

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(2)
刘奇

There will be no problem. This is a GNU/c compiler extension, but be careful when using it. You cannot add the same node, otherwise a loop will be formed. In addition, the red-black tree of the kernel can also be used. The implementation of the structure is very detailed. Judging from my current use, I have not added any compilation options for this file. I only need to extract the list.h file and add the above macros

大家讲道理

There will be no problem, this is purely using the characteristics of the C language and has nothing to do with the kernel

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template