带 pthread 的电子围栏

发布于 2024-09-11 23:18:44 字数 872 浏览 5 评论 0原文

我正在开发一个多线程(基于 pthread)项目。该项目使用我正在编写的库。

为了检查它,我将它与 -lefence 链接起来,它给了我 SIGSEGV。在花了很多时间找出问题所在之后,我最终决定在库上搜索错误,即使它的功能非常简单。

作为测试,我尝试编译与 -lefence 链接的测试单元,并得到了 SIGSEGV。该测试不会干扰动态分配的内存,但在不同测试单元中成功的代码除外。

我还注意到 -pthread 标志将内存分配设置为包装。 gcc -dumpspecs | gcc -dumpspecs | gcc -dumpspecs | grep pthread 产生以下结果:

%{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT}
%{pthread:-lpthread}    %{shared:-lc}    %{!shared:%{mieee-fp:-lieee} %{profile:-lc_p}%{!profile:-lc}}
 %{static: %{fmudflap|fmudflapth:  --wrap=malloc --wrap=free --wrap=calloc --wrap=realloc --wrap=mmap --wrap=munmap --wrap=alloca} %{fmudflapth: --wrap=pthread_create}} %{fmudflap|fmudflapth: --wrap=main}

libefence 是否不支持多线程?

编辑: 基本上我假设电围栏库取代了常规 libc 的 malloc/free 调用。事实上,它们用线程安全罩包裹起来是没有用的,因为它们再次用不可重入的东西包裹起来。

I'm working on a multithreaded (pthread based) project. The project uses a library that I'm writing.

In order to check it I linked it with -lefence and it gave me SIGSEGV. After a lot of time spent in figuring out what's wrong, I finally decided to search the error on the library, even if it's functionality is extremely simple.

As test, I've tried to compile the test-unit linking with -lefence and I got SIGSEGV. The test is not messing with dynamically allocated memory, with the exception of code which, in different test units, succeded.

I noticed also that the -pthread flag sets the memory allocation as wrapped. gcc -dumpspecs | grep pthread produces the following:

%{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT}
%{pthread:-lpthread}    %{shared:-lc}    %{!shared:%{mieee-fp:-lieee} %{profile:-lc_p}%{!profile:-lc}}
 %{static: %{fmudflap|fmudflapth:  --wrap=malloc --wrap=free --wrap=calloc --wrap=realloc --wrap=mmap --wrap=munmap --wrap=alloca} %{fmudflapth: --wrap=pthread_create}} %{fmudflap|fmudflapth: --wrap=main}

Can it be the case that libefence is not supporting multithreading?

Edit: Basically I'm supposing that the electric fence library replaces the malloc/free calls of the regular libc. The fact that they have been wrapped with a thread-safe hood is useless, since they've wrapped again with non-reentrant stuff.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

雨落星ぅ辰 2024-09-18 23:18:44

检查这两个 - phthread 肯定有问题( https://bugzilla. redhat.com/show_bug.cgi?id=54368 ),但最近有人声称已修复( http://www.mail-archive.com/[电子邮件受保护]/ msg280548.html )还请注意提到了另一个延迟补丁。

Check put these two - it definitely did have a problem with phthread ( https://bugzilla.redhat.com/show_bug.cgi?id=54368 ) but recently someone claimed a fix ( http://www.mail-archive.com/[email protected]/msg280548.html ) Notice also the mention of another, delayed patch.

风渺 2024-09-18 23:18:44

你尝试过valgrind吗?

Have you tried valgrind?

鲸落 2024-09-18 23:18:44

为了检查它,我将它与 -lefence 链接起来,它给了我 SIGSEGV。在花了很多时间找出问题所在之后,我最终决定在库上搜索错误,即使它的功能非常简单。

我只知道电围栏的概念,但你应该能够立即注意到你的缓冲区溢出发生在哪里:

gcc ... -g ;
gdb a.out ;
run 
**Program received signal SIGSEGV, Segmentation fault.
address in function () from file.c**

那就是你的溢出!

In order to check it I linked it with -lefence and it gave me SIGSEGV. After a lot of time spent in figuring out what's wrong, I finally decided to search the error on the library, even if it's functionality is extremely simple.

I only know the concept of Electric fence, but you should be able to notice immediately where your buffer overflow occurs:

gcc ... -g ;
gdb a.out ;
run 
**Program received signal SIGSEGV, Segmentation fault.
address in function () from file.c**

and there is your overflow!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文