SharedLibrary_VMS.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //
  2. // SharedLibrary_VMS.cpp
  3. //
  4. // $Id: //poco/1.4/Foundation/src/SharedLibrary_VMS.cpp#2 $
  5. //
  6. // Library: Foundation
  7. // Package: SharedLibrary
  8. // Module: SharedLibrary
  9. //
  10. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #include "Poco/SharedLibrary_VMS.h"
  16. #include "Poco/Path.h"
  17. #include <lib$routines.h>
  18. #include <libdef.h>
  19. #include <descrip.h>
  20. #include <chfdef.h>
  21. #include <libfisdef.h>
  22. namespace Poco {
  23. FastMutex SharedLibraryImpl::_mutex;
  24. SharedLibraryImpl::SharedLibraryImpl()
  25. {
  26. }
  27. SharedLibraryImpl::~SharedLibraryImpl()
  28. {
  29. }
  30. void SharedLibraryImpl::loadImpl(const std::string& path, int /*flags*/)
  31. {
  32. FastMutex::ScopedLock lock(_mutex);
  33. if (!_path.empty()) throw LibraryAlreadyLoadedException(path);
  34. _path = path;
  35. }
  36. void SharedLibraryImpl::unloadImpl()
  37. {
  38. _path.clear();
  39. }
  40. bool SharedLibraryImpl::isLoadedImpl() const
  41. {
  42. return !_path.empty();
  43. }
  44. void* SharedLibraryImpl::findSymbolImpl(const std::string& name)
  45. {
  46. FastMutex::ScopedLock lock(_mutex);
  47. if (_path.empty()) return NULL;
  48. Path p(_path);
  49. std::string filename = p.getBaseName();
  50. std::string ext = p.getExtension();
  51. std::string imageSpec = p.makeParent().toString();
  52. if (!imageSpec.empty() && !ext.empty())
  53. {
  54. imageSpec.append(".");
  55. imageSpec.append(ext);
  56. }
  57. int value = 0;
  58. long flags = LIB$M_FIS_MIXEDCASE;
  59. POCO_DESCRIPTOR_STRING(filenameDsc, filename);
  60. POCO_DESCRIPTOR_STRING(symbolDsc, name);
  61. POCO_DESCRIPTOR_STRING(imageSpecDsc, imageSpec);
  62. try
  63. {
  64. // lib$find_image_symbol only accepts 32-bit pointers
  65. #pragma pointer_size save
  66. #pragma pointer_size 32
  67. lib$find_image_symbol(&filenameDsc, &symbolDsc, &value, imageSpec.empty() ? 0 : &imageSpecDsc, flags);
  68. #pragma pointer_size restore
  69. }
  70. catch (struct chf$signal_array& sigarr)
  71. {
  72. unsigned sig = sigarr.chf$is_sig_name;
  73. unsigned act = LIB$_ACTIMAGE;
  74. if (lib$match_cond(&sig, &act))
  75. throw LibraryLoadException(_path);
  76. }
  77. return (void*) value;
  78. }
  79. const std::string& SharedLibraryImpl::getPathImpl() const
  80. {
  81. return _path;
  82. }
  83. std::string SharedLibraryImpl::suffixImpl()
  84. {
  85. #if defined(_DEBUG)
  86. return "d.exe";
  87. #else
  88. return ".exe";
  89. #endif
  90. }
  91. } // namespace Poco