Skip to content

Commit

Permalink
Implement signature importing (#48)
Browse files Browse the repository at this point in the history
* Bring over the partial implementation of TypeDef importing from the imetadataemit branch and make it a free function that operates on DNMD handles.

* Add SHA1 pal implementation

* Generate public key token from public key

* Finish implementation of TypeDef importing

* Sketch out ImportReferenceToTypeRef

* Port over strong name token improvements from my CoreCLR branch.

* Fix name shadowing

* Implement more of TypeRef importing, with todos and comments for the remaining parts.

* Finish TypeRef importing.

* Implement the remainder of signature importing (TypeSpec and higher level signatures)

* Fix qualified base member access

* Fix PAL errors

* Fix headers and use E_FAIL instead of E_UNEXPECTED (which isn't available in DNCP)

* Fix typo caught by static analysis

* Initialize variable to avoid a maybe-uninitialized warning that isn't accurate

* Apply suggestions from code review

Co-authored-by: Aaron Robinson <[email protected]>

* Comment about initialization

* Implement importing TypeRef to self as TypeDef

* Correctly handle implicit ExportedType rows for types in the source Assembly referenced by a nil ResolutionScope in the source module.

* Refactor adding AssemblyRef rows to always add to both the module and assembly (as the CoreCLR does)

* Use non-deprecated oneshot SHA API on OpenSSL and use API with the same shape from CommonCrypto

* Implement PR feedback

* make md_added_row_t constructor explicit and add back removed comment

---------

Co-authored-by: Aaron Robinson <[email protected]>
  • Loading branch information
jkoritzinsky and AaronRobinsonMSFT authored Jan 10, 2024
1 parent 92849ce commit e727af4
Show file tree
Hide file tree
Showing 9 changed files with 2,205 additions and 13 deletions.
37 changes: 37 additions & 0 deletions src/inc/dnmd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,41 @@ struct mdhandle_deleter_t final
// C++ lifetime wrapper for mdhandle_t type
using mdhandle_ptr = std::unique_ptr<mdhandle_t, mdhandle_deleter_t>;

struct md_added_row_t final
{
private:
mdcursor_t new_row;
public:
md_added_row_t() = default;
explicit md_added_row_t(mdcursor_t row) : new_row{ row } {}
md_added_row_t(md_added_row_t const& other) = delete;
md_added_row_t(md_added_row_t&& other)
{
*this = std::move(other);
}

md_added_row_t& operator=(md_added_row_t const& other) = delete;
md_added_row_t& operator=(md_added_row_t&& other)
{
new_row = other.new_row;
other.new_row = {}; // Clear the other's row so we don't double-commit.
return *this;
}

~md_added_row_t()
{
md_commit_row_add(new_row);
}

operator mdcursor_t()
{
return new_row;
}

mdcursor_t* operator&()
{
return &new_row;
}
};

#endif // _SRC_INC_DNMD_HPP_
30 changes: 30 additions & 0 deletions src/inc/internal/span.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,31 @@ class span
throw std::out_of_range{ "Out of bounds access" };
return _ptr[idx];
}

operator span<T const>() const
{
return { _ptr, _size };
}

T* begin() noexcept
{
return _ptr;
}

T const* cbegin() const noexcept
{
return _ptr;
}

T* end() noexcept
{
return _ptr + _size;
}

T const* cend() const noexcept
{
return _ptr + _size;
}
};

template<typename T, typename Deleter>
Expand Down Expand Up @@ -89,6 +114,11 @@ class owning_span final : public span<T>
this->_ptr = {};
return tmp;
}

operator owning_span<T const, Deleter>() const
{
return { this->_ptr, this->_size };
}
};

struct free_deleter final
Expand Down
21 changes: 21 additions & 0 deletions src/interfaces/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set(SOURCES
./hcorenum.cpp
./pal.cpp
./signatures.cpp
./importhelpers.cpp
)

set(HEADERS
Expand All @@ -17,6 +18,7 @@ set(HEADERS
./pal.hpp
./dnmdowner.hpp
./signatures.hpp
./importhelpers.hpp
)

if(NOT MSVC)
Expand Down Expand Up @@ -80,6 +82,25 @@ if (NOT WIN32)
target_link_libraries(dnmd_interfaces PRIVATE ${ICU_TARGET_NAME})
endif()

if (WIN32)
target_link_libraries(dnmd_interfaces_static PUBLIC bcrypt)
target_link_libraries(dnmd_interfaces PRIVATE bcrypt)
elseif(UNIX)
include(FindOpenSSL)
target_link_libraries(dnmd_interfaces_static PUBLIC OpenSSL::Crypto)
target_link_libraries(dnmd_interfaces PRIVATE OpenSSL::Crypto)
elseif(APPLE)
find_library(SECURITY_LIBRARY Security REQUIRED)
target_link_libraries(dnmd_interfaces_static PUBLIC ${SECURITY_LIBRARY})
target_link_libraries(dnmd_interfaces PRIVATE ${SECURITY_LIBRARY})

include(CheckIncludeFile)
check_include_file("CommonCrypto/CommonDigest.h" HAVE_COMMON_DIGEST_H)
if (NOT HAVE_COMMON_DIGEST_H)
message(FATAL_ERROR "CommonCrypto/CommonDigest.h not found")
endif()
endif()

set_target_properties(dnmd_interfaces PROPERTIES
PUBLIC_HEADER ../inc/dnmd_interfaces.hpp
INTERPROCEDURAL_OPTIMIZATION $<$<NOT:$<CONFIG:DEBUG>>:TRUE>)
Expand Down
Loading

0 comments on commit e727af4

Please sign in to comment.