Draft - HAL types update and HAL isolation#4247
Conversation
7bb25b0 to
c4f0b6f
Compare
|
On Fr, 2026-07-17 at 07:08 -0700, Luca Toniolo wrote:
grandixximo left a comment (LinuxCNC/linuxcnc#4247)
Never cease to amaze me...
Are we having a meeting with #4099 as central discussion? We skipped
a few weeks, not sure why @rmu75
Seems about time... or is everyone on summer vacation? Probably
better send to the mailing list...
I had some unexpected troubles with "remote" internet access around
21st of june and it seems I got a bit sidetracked... sorry for that.
Last meeting I have notes for was 2026-06-07 10:00 CEST
According to our cadence, 2026-06-21 would have been late, 2026-07-05
early and the next meeting would be tomorrow "late" at 20:00 CEST.
I'm not sure I can make it this weekend but I will try.
I think luca wants to discuss the hal interface redesign, so maybe
change of plan and meeting at 10:00 would be better? please reply
whoever can make it at what time.
https://greenlight.bbb.uni-rostock.de/b/ste-c4d-brs-3k6
Access code: 869782
(hope this is still active)
best regards
…--
Robert Schöftner ***@***.***>
|
|
Should send to the mailing list, my bad for starting it here 😞 |
| // Make sure we can query pins/params/signals | ||
| retval = hal_lib_init(); | ||
| CHKS(retval < 0, "fetch_hal_param: hal_lib_init(): error=%d", retval); | ||
|
|
There was a problem hiding this comment.
FIXME: init/exit is reference counted
| case HAL_S32: hal_set_si32(u.s, v->s); break; | ||
| case HAL_U32: hal_set_ui32(u.u, v->u); break; | ||
| case HAL_SINT: hal_set_sint(u.s, v->s); break; | ||
| case HAL_UINT: hal_set_uint(u.u, v->u); break; |
There was a problem hiding this comment.
If I understand correctly, these all store through the 8-byte union member in hal.h
AFAIK old-API params keep caller-sized storage hal_bit_t=1B, hal_s32_t=4B. So halcmd setp / hal_set_p on any out-of-tree legacy BIT/S32/U32 param overruns it corrupting adjacent shmem. Won't that already break the old API?
There was a problem hiding this comment.
The HAL allocation has been changed never ever to allocate a chunk less than 8 bytes (and at least 8-byte aligned). So any write is always safe.
Older code may indeed write to the smaller part. That is why the getters also only address the smaller part. The setters will always write to the larger type (even bool). We are assured of always full writes only when the old code is disallowed (removal of hal_data_u and the old hal types). In the transition, we only have compatibility to assure.
And, old style code cannot link to HAL unless recompiled. The HAL memory version has been changed.
There was a problem hiding this comment.
The 8-byte minimum covers standalone allocations, but how does it protect this case?
struct comp_data {
hal_s32_t speed; // hal_param_s32_new(..., &speed) -> 4-byte storage
hal_s32_t accel; // adjacent field, same hal_malloc'd struct
};A recompiled legacy component still exports fields inside one larger struct allocation. When hal_set_si32 writes the sign-extended 64-bit value at &speed, where do the upper 4 bytes (0xFFFFFFFF for -1) land? Does the compiler fixes this? Or will it not compile?
There was a problem hiding this comment.
The case where new code will write an old style param. That is the problem. Need to think a bit more on the scenario.
There was a problem hiding this comment.
As long as the support programs (mostly halcmd and halmodule) are "old style", then there is no problem because they will dereference a hal_data_u construct and write the smaller type.
The new library with hal_set_p() abstracted needs to divert the new setter construct and use hal_data_u dereferencing for parameters until the API break. Then you won't have any problems.
c4f0b6f to
bce8942
Compare
|
@grandixximo the whole |
bce8942 to
2f2ddb5
Compare
2f2ddb5 to
64739e1
Compare
This is the full tree conversion for the HAL types where #4099 would be the first step.
Changes:
State of progress of these changes:
Missing in this tree: