Settings: Mark termination enables as an unaligned ptr

Unfortunately, the termination enables are not always at an aligned
boundary, and MSVC needs to taint the ptr type with __unaligned
in that case.
pull/35/head
Paul Hollinsky 2021-05-05 03:38:58 -04:00
parent 1bb114004e
commit 295ba490aa
10 changed files with 24 additions and 13 deletions

View File

@ -2,6 +2,7 @@
#define __IDEVICESETTINGS_H_ #define __IDEVICESETTINGS_H_
#include <stdint.h> #include <stdint.h>
#include "icsneo/platform/unaligned.h"
#pragma pack(push, 2) #pragma pack(push, 2)
@ -736,14 +737,14 @@ protected:
IDeviceSettings(warn_t createInoperableSettings, std::shared_ptr<Communication> com) IDeviceSettings(warn_t createInoperableSettings, std::shared_ptr<Communication> com)
: disabled(true), readonly(true), report(com->report), structSize(0) { (void)createInoperableSettings; } : disabled(true), readonly(true), report(com->report), structSize(0) { (void)createInoperableSettings; }
virtual const uint64_t* getTerminationEnables() const { return nullptr; } virtual ICSNEO_UNALIGNED(const uint64_t*) getTerminationEnables() const { return nullptr; }
virtual uint64_t* getMutableTerminationEnables() { virtual ICSNEO_UNALIGNED(uint64_t*) getMutableTerminationEnables() {
if(disabled || readonly) if(disabled || readonly)
return nullptr; return nullptr;
const uint8_t* offset = (const uint8_t*)getTerminationEnables(); const auto offset = reinterpret_cast<ICSNEO_UNALIGNED(const uint8_t*)>(getTerminationEnables());
if(offset == nullptr) if(offset == nullptr)
return nullptr; return nullptr;
return reinterpret_cast<uint64_t*>((void*)(settings.data() + (offset - settingsInDeviceRAM.data()))); return reinterpret_cast<ICSNEO_UNALIGNED(uint64_t*)>((void*)(settings.data() + (offset - settingsInDeviceRAM.data())));
} }
}; };

View File

@ -210,7 +210,7 @@ public:
} }
protected: protected:
const uint64_t* getTerminationEnables() const override { ICSNEO_UNALIGNED(const uint64_t*) getTerminationEnables() const override {
auto cfg = getStructurePointer<neovifire2_settings_t>(); auto cfg = getStructurePointer<neovifire2_settings_t>();
if(cfg == nullptr) if(cfg == nullptr)
return nullptr; return nullptr;

View File

@ -171,7 +171,7 @@ public:
} }
protected: protected:
const uint64_t* getTerminationEnables() const override { ICSNEO_UNALIGNED(const uint64_t*) getTerminationEnables() const override {
auto cfg = getStructurePointer<radgigalog_settings_t>(); auto cfg = getStructurePointer<radgigalog_settings_t>();
if(cfg == nullptr) if(cfg == nullptr)
return nullptr; return nullptr;

View File

@ -150,7 +150,7 @@ public:
} }
protected: protected:
const uint64_t* getTerminationEnables() const override { ICSNEO_UNALIGNED(const uint64_t*) getTerminationEnables() const override {
auto cfg = getStructurePointer<radgigastar_settings_t>(); auto cfg = getStructurePointer<radgigastar_settings_t>();
if(cfg == nullptr) if(cfg == nullptr)
return nullptr; return nullptr;

View File

@ -46,7 +46,7 @@ public:
} }
protected: protected:
const uint64_t* getTerminationEnables() const override { ICSNEO_UNALIGNED(const uint64_t*) getTerminationEnables() const override {
auto cfg = getStructurePointer<valuecan4_4_2el_settings_t>(); auto cfg = getStructurePointer<valuecan4_4_2el_settings_t>();
if(cfg == nullptr) if(cfg == nullptr)
return nullptr; return nullptr;

View File

@ -45,7 +45,7 @@ public:
} }
protected: protected:
const uint64_t* getTerminationEnables() const override { ICSNEO_UNALIGNED(const uint64_t*) getTerminationEnables() const override {
auto cfg = getStructurePointer<valuecan4_1_2_settings_t>(); auto cfg = getStructurePointer<valuecan4_1_2_settings_t>();
if(cfg == nullptr) if(cfg == nullptr)
return nullptr; return nullptr;

View File

@ -60,7 +60,7 @@ public:
} }
protected: protected:
const uint64_t* getTerminationEnables() const override { ICSNEO_UNALIGNED(const uint64_t*) getTerminationEnables() const override {
auto cfg = getStructurePointer<valuecan4_4_2el_settings_t>(); auto cfg = getStructurePointer<valuecan4_4_2el_settings_t>();
if(cfg == nullptr) if(cfg == nullptr)
return nullptr; return nullptr;

View File

@ -46,7 +46,7 @@ public:
} }
protected: protected:
const uint64_t* getTerminationEnables() const override { ICSNEO_UNALIGNED(const uint64_t*) getTerminationEnables() const override {
auto cfg = getStructurePointer<valuecan4_industrial_settings_t>(); auto cfg = getStructurePointer<valuecan4_industrial_settings_t>();
if(cfg == nullptr) if(cfg == nullptr)
return nullptr; return nullptr;

View File

@ -114,7 +114,7 @@ public:
} }
protected: protected:
const uint64_t* getTerminationEnables() const override { ICSNEO_UNALIGNED(const uint64_t*) getTerminationEnables() const override {
// Check the structure pointer even though we're not using it so // Check the structure pointer even though we're not using it so
// all of the other checks that go along with it are performed // all of the other checks that go along with it are performed
if(getStructurePointer<vividcan_settings_t>() == nullptr) if(getStructurePointer<vividcan_settings_t>() == nullptr)
@ -122,7 +122,7 @@ protected:
return &activeTerminationEnables; return &activeTerminationEnables;
} }
uint64_t* getMutableTerminationEnables() override { ICSNEO_UNALIGNED(uint64_t*) getMutableTerminationEnables() override {
if(getMutableStructurePointer<vividcan_settings_t>() == nullptr) if(getMutableStructurePointer<vividcan_settings_t>() == nullptr)
return nullptr; return nullptr;
return &queuedTerminationEnables; return &queuedTerminationEnables;

View File

@ -0,0 +1,10 @@
#ifndef __UNALIGNED_H_
#define __UNALIGNED_H_
#if defined(MSVC)
#define ICSNEO_UNALIGNED(x) __unaligned x
#else
#define ICSNEO_UNALIGNED(x) x
#endif
#endif