Linux:是否可以沙箱共享库代码 [英] Linux: Is it possible to sandbox shared library code
本文介绍了Linux:是否可以沙箱共享库代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个需要通过加载共享库来扩展的进程.有没有办法在沙盒环境(外部进程除外)中运行共享库代码,这样如果它出现段错误,它就不会使进程崩溃,并且对它可以分配的内存量有限制,它可以使用的 CPU 周期等
I have a process that needs to be extensible by loading shared libraries. Is there a way to run the shared library code in a sandbox environment (other than an external process) so that if it segfaults it doesn't crash the process and has limitations on how much memory it can allocate, the cpu cycles it can use, etc.
推荐答案
我认为没有一种干净的方法可以做到.你可以试试:
I don't think there is a clean way to do it. You could try:
- 捕获段错误并从中恢复(棘手、特定于架构,但可行)
- 将库的 malloc/calloc 调用替换为可计算分配空间的检测版本 (如何用代码替换默认的 malloc)
- 或者使用 malloc 钩子(http://www.gnu.org/software/libc/manual/html_node/Hooks-for-Malloc.html)
- CPU 周期占整个过程,所以我认为没有任何方法可以获得库的信息.唯一可行的选择 - 手动测量您的代码进行的每个库调用的滴答声.
本质上 - 这会很有趣,但我建议您使用单独的进程方法并使用 RPC、配额、ulimits 等.
In essence - this would be fun to try, but I recommend you go with the separate process approach and use RPC, quotas, ulimits etc.
这篇关于Linux:是否可以沙箱共享库代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文