Fixed unaligned memory read in DMI

This commit is contained in:
SChernykh 2022-05-19 20:56:19 +02:00
parent c877ba8145
commit 285719cde4
3 changed files with 6 additions and 6 deletions

View file

@ -30,7 +30,7 @@ namespace xmrig {
template<typename T>
inline T readUnaligned(const T* ptr)
{
static_assert(std::is_integral<T>::value, "Integer type required");
static_assert(std::is_trivially_copyable<T>::value, "T must be trivially copyable");
T result;
memcpy(&result, ptr, sizeof(T));
@ -41,7 +41,7 @@ inline T readUnaligned(const T* ptr)
template<typename T>
inline void writeUnaligned(T* ptr, T data)
{
static_assert(std::is_integral<T>::value, "Integer type required");
static_assert(std::is_trivially_copyable<T>::value, "T must be trivially copyable");
memcpy(ptr, &data, sizeof(T));
}

View file

@ -28,13 +28,12 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
void randomx_set_huge_pages_jit(bool)
{
}
void randomx_set_optimized_dataset_init(int)
{
}

View file

@ -24,6 +24,7 @@
#include <cstddef>
#include <cstdint>
#include "base/tools/Alignment.h"
namespace xmrig {
@ -45,10 +46,10 @@ struct u64 {
template<typename T>
inline T dmi_get(const uint8_t *data) { return *reinterpret_cast<const T *>(data); }
inline T dmi_get(const uint8_t *data) { return readUnaligned(reinterpret_cast<const T *>(data)); }
template<typename T>
inline T dmi_get(const dmi_header *h, size_t offset) { return *reinterpret_cast<const T *>(h->data + offset); }
inline T dmi_get(const dmi_header *h, size_t offset) { return readUnaligned(reinterpret_cast<const T *>(h->data + offset)); }
const char *dmi_string(dmi_header *dm, size_t offset);