Skip to content

Commit 96c8d83

Browse files
create CliUint type to match internal embedded cli buffer type, ensuring 32bit vs 64bit etc alignment.
resolves: #2
1 parent 0116c8e commit 96c8d83

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

services/embeddedCliService/include/embeddedCliService.hpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,19 @@ struct EmbeddedCliConfig;
3232
namespace cms {
3333
namespace EmbeddedCLI { //note, all caps CLI needed to avoid conflicts
3434

35+
// used for proper alignment of cli buffer, below
36+
// matches with embedded cli itself
37+
#if UINTPTR_MAX == 0xFFFF
38+
using CliUint = uint16_t;
39+
#elif UINTPTR_MAX == 0xFFFFFFFF
40+
using CliUint = uint32_t;
41+
#elif UINTPTR_MAX == 0xFFFFFFFFFFFFFFFFu
42+
using CliUint = uint64_t;
43+
#else
44+
#error unsupported pointer size
45+
#endif
46+
47+
3548
/**
3649
* The EmbeddedCLI::Service creates a command line interface
3750
* using a provided character device.
@@ -52,7 +65,7 @@ class Service final : public QP::QActive {
5265
* @param customInvitation - a custom string for the CLI prompt.
5366
* Set to nullptr for the internal default prompt
5467
*/
55-
explicit Service(uint64_t* buffer, size_t bufferElementCount, uint16_t maxBindingCount, const char * customInvitation = nullptr);
68+
explicit Service(CliUint* buffer, size_t bufferElementCount, uint16_t maxBindingCount, const char * customInvitation = nullptr);
5669
~Service();
5770

5871
Service(const Service&) = delete;
@@ -67,15 +80,6 @@ class Service final : public QP::QActive {
6780
* to the AO to get the CLI up and running.
6881
*
6982
* @param charDevice - the character device to use
70-
* @param buffer - pointer to a statically allocated buffer using
71-
* uint64. Must be aligned to uint64 boundaries too.
72-
* @param bufferElementCount - the number of uint64 elements
73-
* available at 'buffer'
74-
*
75-
* @note: If 'buffer' is nullptr, will use the embedded-cli's default configuration
76-
* which will allocate memory via malloc.
77-
* @note: Using uint64 to ensure all embedded-cli alignment requirements
78-
* are met, regardless of environment.
7983
*/
8084
void BeginCliAsync(cms::interfaces::CharacterDevice* charDevice);
8185

services/embeddedCliService/src/embeddedCliService.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Q_DEFINE_THIS_MODULE("EmbeddedCliService")
2222
namespace cms {
2323
namespace EmbeddedCLI {
2424

25-
Service::Service(uint64_t* buffer, size_t bufferElementCount, uint16_t maxBindingCount, const char * customInvitation) :
25+
Service::Service(CliUint * buffer, size_t bufferElementCount, uint16_t maxBindingCount, const char * customInvitation) :
2626
QP::QActive(initial),
2727
mCharacterDevice(nullptr),
2828
mEmbeddedCliConfigBacking(),
@@ -39,7 +39,7 @@ Service::Service(uint64_t* buffer, size_t bufferElementCount, uint16_t maxBindin
3939

4040
if (buffer != nullptr) {
4141
mEmbeddedCliConfig->cliBuffer = buffer;
42-
mEmbeddedCliConfig->cliBufferSize = bufferElementCount * sizeof(uint64_t);
42+
mEmbeddedCliConfig->cliBufferSize = bufferElementCount * sizeof(CliUint);
4343
}
4444

4545
if (customInvitation != nullptr) {
@@ -55,7 +55,7 @@ Service::Service(uint64_t* buffer, size_t bufferElementCount, uint16_t maxBindin
5555
// only if we are using that option.
5656
if (buffer != nullptr) {
5757
uint16_t requiredSize = embeddedCliRequiredSize(mEmbeddedCliConfig);
58-
Q_ASSERT(requiredSize <= bufferElementCount * sizeof(uint64_t));
58+
Q_ASSERT(requiredSize <= bufferElementCount * sizeof(CliUint));
5959
}
6060
}
6161

0 commit comments

Comments
 (0)