Commit 2311b8562c866cdfdbb133365753cc91a6206f4d
1 parent
16a0f764
Exists in
master
and in
1 other branch
Adjusting delayed loading on windows ipc client module.
Showing
7 changed files
with
276 additions
and
90 deletions
Show diff stats
client/Makefile.in
| ... | ... | @@ -39,6 +39,9 @@ MAIN_SOURCES= \ |
| 39 | 39 | $(wildcard src/session/remote/*.cc) \ |
| 40 | 40 | $(wildcard src/session/remote/@OSNAME@/*.cc) |
| 41 | 41 | |
| 42 | +DYNAMIC_SOURCES= \ | |
| 43 | + $(wildcard src/core/@OSNAME@/dynamic/*.cc) | |
| 44 | + | |
| 42 | 45 | TEST_SOURCES= \ |
| 43 | 46 | $(wildcard src/testprogram/*.cc) |
| 44 | 47 | |
| ... | ... | @@ -191,7 +194,8 @@ Release: \ |
| 191 | 194 | $(BINRLS)/lib$(MODULE_NAME).static.a |
| 192 | 195 | |
| 193 | 196 | $(BINRLS)/lib$(MODULE_NAME)@LIBEXT@: \ |
| 194 | - $(foreach SRC, $(basename $(MAIN_SOURCES)), $(OBJRLS)/$(SRC).o) | |
| 197 | + $(foreach SRC, $(basename $(MAIN_SOURCES)), $(OBJRLS)/$(SRC).o) \ | |
| 198 | + $(foreach SRC, $(basename $(DYNAMIC_SOURCES)), $(OBJRLS)/$(SRC).o) | |
| 195 | 199 | |
| 196 | 200 | @$(MKDIR) $(@D) |
| 197 | 201 | @echo $< ... |
| ... | ... | @@ -308,7 +312,8 @@ $(BINDBG)/$(MODULE_NAME)-client@EXEEXT@: \ |
| 308 | 312 | |
| 309 | 313 | |
| 310 | 314 | $(BINDBG)/lib$(MODULE_NAME)@LIBEXT@: \ |
| 311 | - $(foreach SRC, $(basename $(MAIN_SOURCES)), $(OBJDBG)/$(SRC).o) | |
| 315 | + $(foreach SRC, $(basename $(MAIN_SOURCES)), $(OBJDBG)/$(SRC).o) \ | |
| 316 | + $(foreach SRC, $(basename $(DYNAMIC_SOURCES)), $(OBJDBG)/$(SRC).o) | |
| 312 | 317 | |
| 313 | 318 | @$(MKDIR) $(@D) |
| 314 | 319 | @echo $< ... | ... | ... |
client/ipcclient.cbp
| ... | ... | @@ -49,6 +49,7 @@ |
| 49 | 49 | <Unit filename="src/core/linux/request.cc" /> |
| 50 | 50 | <Unit filename="src/core/session.cc" /> |
| 51 | 51 | <Unit filename="src/core/windows/attribute.cc" /> |
| 52 | + <Unit filename="src/core/windows/dynamic/init.cc" /> | |
| 52 | 53 | <Unit filename="src/core/windows/pop.cc" /> |
| 53 | 54 | <Unit filename="src/core/windows/push.cc" /> |
| 54 | 55 | <Unit filename="src/core/windows/request.cc" /> | ... | ... |
| ... | ... | @@ -0,0 +1,74 @@ |
| 1 | +/* | |
| 2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | + * | |
| 6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | + * | |
| 8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | + * Free Software Foundation. | |
| 11 | + * | |
| 12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | + * obter mais detalhes. | |
| 16 | + * | |
| 17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | + * | |
| 21 | + * Este programa está nomeado como - e possui - linhas de código. | |
| 22 | + * | |
| 23 | + * Contatos: | |
| 24 | + * | |
| 25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | + * | |
| 28 | + */ | |
| 29 | + | |
| 30 | +/** | |
| 31 | + * @file src/os/linux/attribute.cc | |
| 32 | + * | |
| 33 | + * @brief Implements methods for static attribute management. | |
| 34 | + * | |
| 35 | + * @author perry.werneck@gmail.com | |
| 36 | + * | |
| 37 | + */ | |
| 38 | + | |
| 39 | + #include <lib3270/ipc.h> | |
| 40 | + #include <lib3270/toggle.h> | |
| 41 | + #include <lib3270/properties.h> | |
| 42 | + | |
| 43 | +/*---[ Implement ]----------------------------------------------------------------------------------*/ | |
| 44 | + | |
| 45 | + std::vector<const LIB3270_PROPERTY *> TN3270::getAttributes() noexcept { | |
| 46 | + | |
| 47 | + std::vector<const LIB3270_PROPERTY *> attributes; | |
| 48 | + | |
| 49 | + for(auto prop = lib3270_get_int_properties_list(); prop->name; prop++) { | |
| 50 | + attributes.push_back((const LIB3270_PROPERTY *) prop); | |
| 51 | + } | |
| 52 | + | |
| 53 | + for(auto prop = lib3270_get_unsigned_properties_list(); prop->name; prop++) { | |
| 54 | + attributes.push_back((const LIB3270_PROPERTY *) prop); | |
| 55 | + } | |
| 56 | + | |
| 57 | + for(auto prop = lib3270_get_string_properties_list(); prop->name; prop++) { | |
| 58 | + attributes.push_back((const LIB3270_PROPERTY *) prop); | |
| 59 | + } | |
| 60 | + | |
| 61 | + for(auto prop = lib3270_get_toggle_list(); prop->name; prop++) { | |
| 62 | + attributes.push_back((const LIB3270_PROPERTY *) prop); | |
| 63 | + } | |
| 64 | + | |
| 65 | + for(auto prop = lib3270_get_boolean_properties_list(); prop->name; prop++) { | |
| 66 | + attributes.push_back((const LIB3270_PROPERTY *) prop); | |
| 67 | + } | |
| 68 | + | |
| 69 | + return attributes; | |
| 70 | + | |
| 71 | + } | |
| 72 | + | |
| 73 | + | |
| 74 | + | ... | ... |
| ... | ... | @@ -0,0 +1,194 @@ |
| 1 | +/* | |
| 2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | + * | |
| 6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | + * | |
| 8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | + * Free Software Foundation. | |
| 11 | + * | |
| 12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | + * obter mais detalhes. | |
| 16 | + * | |
| 17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | + * | |
| 21 | + * Este programa está nomeado como - e possui - linhas de código. | |
| 22 | + * | |
| 23 | + * Contatos: | |
| 24 | + * | |
| 25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | + * | |
| 28 | + */ | |
| 29 | + | |
| 30 | +/** | |
| 31 | + * @file | |
| 32 | + * | |
| 33 | + * @brief Win32 delayed loading support methods. | |
| 34 | + * | |
| 35 | + * @author perry.werneck@gmail.com | |
| 36 | + * | |
| 37 | + */ | |
| 38 | + | |
| 39 | + #include <config.h> | |
| 40 | + #include <ipc-client-internals.h> | |
| 41 | + #include <fcntl.h> | |
| 42 | + | |
| 43 | + extern "C" { | |
| 44 | + | |
| 45 | + extern __declspec (dllexport) PfnDliHook __pfnDliNotifyHook2; | |
| 46 | + extern __declspec (dllexport) PfnDliHook __pfnDliFailureHook2; | |
| 47 | + | |
| 48 | + FARPROC WINAPI IPC3270_DelayLoadHook(unsigned reason, DelayLoadInfo * info); | |
| 49 | + | |
| 50 | + } | |
| 51 | + | |
| 52 | + using std::string; | |
| 53 | + | |
| 54 | +/*---[ Implement ]----------------------------------------------------------------------------------*/ | |
| 55 | + | |
| 56 | + // https://docs.microsoft.com/en-us/cpp/build/reference/loading-all-imports-for-a-delay-loaded-dll?view=vs-2019 | |
| 57 | + | |
| 58 | + PfnDliHook __pfnDliNotifyHook2 = IPC3270_DelayLoadHook; | |
| 59 | + PfnDliHook __pfnDliFailureHook2 = IPC3270_DelayLoadHook; | |
| 60 | + | |
| 61 | + static HANDLE hModule = 0; | |
| 62 | + static HANDLE hEventLog = 0; | |
| 63 | + | |
| 64 | + BOOL WINAPI DllMain(HANDLE hInstance, DWORD dwcallpurpose, LPVOID lpvResvd) { | |
| 65 | + switch(dwcallpurpose) { | |
| 66 | + case DLL_PROCESS_ATTACH: | |
| 67 | + hModule = hInstance; | |
| 68 | + hEventLog = RegisterEventSource(NULL, LIB3270_STRINGIZE_VALUE_OF(PRODUCT_NAME)); | |
| 69 | + break; | |
| 70 | + | |
| 71 | + case DLL_PROCESS_DETACH: | |
| 72 | + hModule = 0; | |
| 73 | + DeregisterEventSource(hEventLog); | |
| 74 | + hEventLog = 0; | |
| 75 | + break; | |
| 76 | + | |
| 77 | + } | |
| 78 | + | |
| 79 | + return TRUE; | |
| 80 | + } | |
| 81 | + | |
| 82 | + static void eventlog(const char *msg) { | |
| 83 | + | |
| 84 | + std::string username = TN3270::getUserName(); | |
| 85 | + | |
| 86 | + const char *outMsg[] = { | |
| 87 | + username.c_str(), | |
| 88 | + PACKAGE_NAME, | |
| 89 | + msg | |
| 90 | + }; | |
| 91 | + | |
| 92 | + debug("username"," ",msg); | |
| 93 | + | |
| 94 | + ReportEvent( | |
| 95 | + hEventLog, | |
| 96 | + EVENTLOG_ERROR_TYPE, | |
| 97 | + 1, | |
| 98 | + 0, | |
| 99 | + NULL, | |
| 100 | + 3, | |
| 101 | + 0, | |
| 102 | + outMsg, | |
| 103 | + NULL | |
| 104 | + ); | |
| 105 | + | |
| 106 | + } | |
| 107 | + | |
| 108 | + static void dummyProc() { | |
| 109 | + debug(__FUNCTION__," was called"); | |
| 110 | + throw std::runtime_error("Operation not supported"); | |
| 111 | + } | |
| 112 | + | |
| 113 | + FARPROC WINAPI IPC3270_DelayLoadHook(unsigned reason, DelayLoadInfo * info) { | |
| 114 | + | |
| 115 | + static string savedpath; | |
| 116 | + | |
| 117 | + // https://docs.microsoft.com/en-us/cpp/build/reference/structure-and-constant-definitions?view=vs-2019 | |
| 118 | + | |
| 119 | + debug(__FUNCTION__," ",(const char *) info->szDll); | |
| 120 | + | |
| 121 | + switch (reason) { | |
| 122 | + case dliNoteStartProcessing: | |
| 123 | + debug(__FUNCTION__,"::dliNoteStartProcessing") | |
| 124 | + { | |
| 125 | + string installLocation = TN3270::getInstallLocation(); | |
| 126 | + | |
| 127 | + if(!installLocation.empty()) { | |
| 128 | + | |
| 129 | + char curdir[4096]; | |
| 130 | + memset(curdir,0,sizeof(curdir)); | |
| 131 | + | |
| 132 | + if(GetCurrentDirectory(sizeof(curdir)-1,curdir)) { | |
| 133 | + savedpath = curdir; | |
| 134 | + debug("Saved path: \"",savedpath,"\""); | |
| 135 | + } else { | |
| 136 | + savedpath.clear(); | |
| 137 | + } | |
| 138 | + | |
| 139 | + SetCurrentDirectory(installLocation.c_str()); | |
| 140 | + | |
| 141 | + debug("Current path changed to \"",installLocation,"\""); | |
| 142 | + } | |
| 143 | + } | |
| 144 | + break; | |
| 145 | + | |
| 146 | + case dliNoteEndProcessing: | |
| 147 | + debug(__FUNCTION__,"::dliNoteEndProcessing") | |
| 148 | + | |
| 149 | + if(!savedpath.empty()) { | |
| 150 | + debug("Restoring current path to \"",savedpath,"\""); | |
| 151 | + SetCurrentDirectory(savedpath.c_str()); | |
| 152 | + savedpath.clear(); | |
| 153 | + | |
| 154 | + } | |
| 155 | + | |
| 156 | + break; | |
| 157 | + | |
| 158 | + case dliNotePreLoadLibrary: | |
| 159 | + debug(__FUNCTION__,"::dliNotePreLoadLibrary"); | |
| 160 | + break; | |
| 161 | + | |
| 162 | + case dliNotePreGetProcAddress: | |
| 163 | + debug(__FUNCTION__,"::dliNotePreGetProcAddress") | |
| 164 | + break; | |
| 165 | + | |
| 166 | + case dliFailLoadLib: | |
| 167 | + debug(__FUNCTION__,"::dliFailLoadLib") | |
| 168 | + { | |
| 169 | + string msg = "Can't load "; | |
| 170 | + msg += (const char *) info->szDll; | |
| 171 | + eventlog(msg.c_str()); | |
| 172 | + } | |
| 173 | + return (FARPROC) hModule; | |
| 174 | + | |
| 175 | + case dliFailGetProc: | |
| 176 | + debug(__FUNCTION__,"::dliFailGetProc"); | |
| 177 | + { | |
| 178 | + string msg = "Can't find method on "; | |
| 179 | + msg += (const char *) info->szDll; | |
| 180 | + eventlog(msg.c_str()); | |
| 181 | + } | |
| 182 | + return (FARPROC) dummyProc; | |
| 183 | + | |
| 184 | + default: | |
| 185 | + debug(__FUNCTION__,"::default") | |
| 186 | + | |
| 187 | + } | |
| 188 | + | |
| 189 | + // Returning NULL causes the delay load machinery to perform default | |
| 190 | + // processing for this notification. | |
| 191 | + return NULL; | |
| 192 | + | |
| 193 | + } | |
| 194 | + | ... | ... |
client/src/core/windows/tools.cc
| ... | ... | @@ -45,79 +45,6 @@ |
| 45 | 45 | |
| 46 | 46 | /*---[ Implement ]----------------------------------------------------------------------------------*/ |
| 47 | 47 | |
| 48 | - // https://docs.microsoft.com/en-us/cpp/build/reference/loading-all-imports-for-a-delay-loaded-dll?view=vs-2019 | |
| 49 | - | |
| 50 | - PfnDliHook __pfnDliNotifyHook2 = IPC3270_DelayLoadHook; | |
| 51 | - PfnDliHook __pfnDliFailureHook2 = IPC3270_DelayLoadHook; | |
| 52 | - | |
| 53 | - FARPROC WINAPI IPC3270_DelayLoadHook(unsigned reason, DelayLoadInfo * info) { | |
| 54 | - | |
| 55 | - // https://docs.microsoft.com/en-us/cpp/build/reference/structure-and-constant-definitions?view=vs-2019 | |
| 56 | - | |
| 57 | - debug(__FUNCTION__," ",(const char *) info->szDll); | |
| 58 | - | |
| 59 | - switch (reason) { | |
| 60 | - case dliNoteStartProcessing: | |
| 61 | - debug(__FUNCTION__,"::dliNoteStartProcessing") | |
| 62 | - /* | |
| 63 | - { | |
| 64 | - string installLocation = TN3270::getInstallLocation(); | |
| 65 | - if(!installLocation.empty()) { | |
| 66 | - SetCurrentDirectory(installLocation.c_str()); | |
| 67 | - } | |
| 68 | - } | |
| 69 | - */ | |
| 70 | - break; | |
| 71 | - | |
| 72 | - case dliNoteEndProcessing: | |
| 73 | - debug(__FUNCTION__,"::dliNoteEndProcessing") | |
| 74 | - break; | |
| 75 | - | |
| 76 | - case dliNotePreLoadLibrary: | |
| 77 | - debug(__FUNCTION__,"::dliNotePreLoadLibrary"); | |
| 78 | - | |
| 79 | - /* | |
| 80 | - { | |
| 81 | - // http://otb.manusoft.com/2013/01/using-delayload-to-specify-dependent-dll-path.htm | |
| 82 | - | |
| 83 | - string myPath = TN3270::getInstallLocation(); | |
| 84 | - | |
| 85 | - myPath += "\\"; | |
| 86 | - myPath += (const char *) info->szDll; | |
| 87 | - | |
| 88 | - debug("Checking ",myPath,"=",access(myPath.c_str(), R_OK)); | |
| 89 | - | |
| 90 | - if(access(myPath.c_str(), R_OK) == 0) { | |
| 91 | - return (FARPROC) LoadLibrary(myPath.c_str()); | |
| 92 | - } | |
| 93 | - | |
| 94 | - } | |
| 95 | - */ | |
| 96 | - break; | |
| 97 | - | |
| 98 | - case dliNotePreGetProcAddress: | |
| 99 | - debug(__FUNCTION__,"::dliNotePreGetProcAddress") | |
| 100 | - break; | |
| 101 | - | |
| 102 | - case dliFailLoadLib: | |
| 103 | - debug(__FUNCTION__,"::dliFailLoadLib") | |
| 104 | - break; | |
| 105 | - | |
| 106 | - case dliFailGetProc: | |
| 107 | - debug(__FUNCTION__,"::dliFailGetProc") | |
| 108 | - break; | |
| 109 | - | |
| 110 | - default: | |
| 111 | - debug(__FUNCTION__,"::default") | |
| 112 | - | |
| 113 | - } | |
| 114 | - | |
| 115 | - // Returning NULL causes the delay load machinery to perform default | |
| 116 | - // processing for this notification. | |
| 117 | - return NULL; | |
| 118 | - | |
| 119 | - } | |
| 120 | - | |
| 121 | 48 | namespace TN3270 { |
| 122 | 49 | |
| 123 | 50 | std::string getUserName() { | ... | ... |
client/src/include/lib3270/ipc.h
| ... | ... | @@ -65,19 +65,6 @@ |
| 65 | 65 | |
| 66 | 66 | #include <string> |
| 67 | 67 | |
| 68 | -#ifdef _WIN32 | |
| 69 | - | |
| 70 | - extern "C" { | |
| 71 | - | |
| 72 | - extern __declspec (dllexport) PfnDliHook __pfnDliNotifyHook2; | |
| 73 | - extern __declspec (dllexport) PfnDliHook __pfnDliFailureHook2; | |
| 74 | - | |
| 75 | - FARPROC WINAPI IPC3270_DelayLoadHook(unsigned reason, DelayLoadInfo * info); | |
| 76 | - | |
| 77 | - } | |
| 78 | - | |
| 79 | -#endif // _WIN32 | |
| 80 | - | |
| 81 | 68 | namespace TN3270 { |
| 82 | 69 | |
| 83 | 70 | class Host; | ... | ... |