⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 how-autoload-works.txt

📁 cygwin, 著名的在win32下模拟unix操作系统的东东
💻 TXT
字号:
Copyright 2002 Red Hat Inc., Egor DudaHow does function autoloading work?Cygwin has the ability to handle win32 functions which are present onsome platforms and not present on others via autoload mechanism.  It'sessentially a lazy binding of symbols.  It works as following.  For(almost) every function from OS API which cygwin uses, a stub is createdin file autoload.cc.  Each reference to the such function from win32 APIin cygwin dll source code is actually pointing to this stub.When the function, say GetConsoleWindow(), is called for the first time,the control is passed to its stub.  The stub tries to load theappropriate system dll via LoadModule() and get the actual functionaddress via GetProcAddress().  If this operation succeeds, the stub is"patched" to pass control to actual address of GetConsoleWindow() inappropriate system dll, so that next time we won't have to load dll andperform address lookup in it again.  From this point on, the call to thefunction is performed as if the dll/function were linked statically.If LoadModule() or GetProcAddress() fail, (and on nt4 the latter indeedfails because GetConsoleWindow() is not available in kernel32.dll), thenthe application, depending on what kind of stub is created inautoload.cc, will either:1) Exit with fatal error.2) Or return a predefined value indicating an error; and set the windowserror code to 127 (ERROR_PROC_NOT_FOUND).Almost all w32api functions are linked into the cygwin dll in thismanner, dynamically, at runtime.The costs:1) A tiny overhead in the initial call to a function call as each callis performed, indirectly, via a stub.  For the first lookup of a symbolof an unloaded dll, there is also some overhead in loading the dll forthe first time.  The dll is only loaded by the first call to a symbolin the dll.  After the first call to a function, subsequent calls areas fast as a normal, statically loaded function.The benefits:1) Speedup at startup time.  Applications only load those dlls which areactually needed.  For example, if application never uses socketfunctions, winsock dlls are never loaded.2) Greatly simplify wincap system -- we don't need to have a separatecapability for every win32 function which may or may not be present onparticular win32 platform.3) Allows a single cygwin1.dll for all win32 platforms.If you're changing in cygwin1.dll source code and if you use somefunction that was not used there before, you should add a stub so itwill be autoloaded.  To do so, add one of the LoadDllfunc* macros toautoload.cc.  All macros eventually resolve to the following form:LoadDLLfuncEx2 (function name, parameter block length, dll name,                 non-fatality flag , value to return if function not available)Parameter block length is a sum of sizes (in bytes) of parameters which are being passed to the function. If non-fatality flag is set to 0, then failure to load dll and find a function will cause fatal error. If non fatality flag is set to 1, then call to the function will return default value.You can also use shorter versions -- LoadDLLfuncEx and LoadDLLfunc, if thedefaults they provide suit your needs.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -