随笔 - 42  文章 - 3  trackbacks - 0
<2012年7月>
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

常用链接

留言簿(2)

随笔档案

文章档案

网页收藏

搜索

  •  

最新评论

阅读排行榜

评论排行榜

 
在编写共享库时,为保证ABI(app binary interface)兼容:
  1 尽量使用C语言 2不要在接口类使用虚函数和模板; 3 不要改变成员函数的访问权限; 4 不要使用STL 5 不要依赖使用虚拟析构函数,最好自己实现,显式调用;
6 不要在DLL里面申请内存,DLL外释放,DLL和APP可能不在同一个内存堆;

可重入(reentrant)函数可以由多于一个任务并发使用,而不必担心数据错误。相反, 不可重入(non-reentrant)函数不能由超过一个任务所共享,除非能确保函数的互斥(或者使用信号量,或者在代码的关键部分禁用中断)。可重入函数可以在任意时刻被中断,稍后再继续运行,不会丢失数据。可重入函数要么使用本地变量,要么在使用全局变量时保护自己的数据。
Reentrant Function:A function whose effect, when called by two or more threads,is guaranteed to be as if the threads each executed thefunction one after another in an undefined order, even ifthe actual execution is interleaved.
Thread-Safe Function:A function that may be safely invoked concurrently by multiple threads.

函数可重入的必要条件:
1 不使用任何(局部)静态变量或者全局的非常量;
2 不返回任何局部静态或者全局非常量指针;
3 仅依赖调用方的参数;
4 不依赖任何单个资源的锁;
5 不调用任何不可重入的函数;

In classical OS, stack grows downwards. After each push operatation, the value of ebp becomes small, and vice versa.

esp is the top of the stack.

ebp is usually set to esp at the start of the function. Local variables are accessed by subtracting a constant offset from ebp. All x86 calling conventions define ebp as being preserved across function calls. ebp itself actually points to the previous frame's base pointer, which enables stack walking in a debugger and viewing other frames local variables to work.

Most function prologs look something like:
push ebp      ; Preserve current frame pointer
mov ebp, esp  ; Create new frame pointer pointing to current stack top
sub esp, 20   ; allocate 20 bytes worth of locals on stack. 

Then later in the function you may have code like (presuming both local variables are 4 bytes)
mov [ebp-4], eax    ; Store eax in first local
mov ebx, [ebp - 8]  ; Load ebx from second local

objdump is a program for displaying various information about object files. For instance, it can be used as a disassembler to view executable in assembly form. It is part of the GNU Binutils for fine-grained control over executable and other binary data.

For example, to completely disassemble a binary:
objdump -Dslx file


posted on 2012-07-17 22:20 鹰击长空 阅读(289) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理