From d0a9eb8e0788a413ea4ced45392c5802a7a40277 Mon Sep 17 00:00:00 2001 From: yosoyubik Date: Fri, 31 Oct 2025 13:15:44 +0100 Subject: [PATCH] u3: fix alignment in u3a_pile_prep --- pkg/noun/allocate.c | 12 +++++++----- pkg/noun/allocate.h | 2 +- pkg/noun/jets/b/reel.c | 2 +- pkg/noun/jets/e/json_de.c | 2 +- pkg/noun/jets/e/parse.c | 5 ++--- pkg/noun/manage.c | 7 ++++--- pkg/noun/retrieve.c | 6 +++--- pkg/noun/serial.c | 6 +++--- 8 files changed, 22 insertions(+), 20 deletions(-) diff --git a/pkg/noun/allocate.c b/pkg/noun/allocate.c index 4da3414204..ac6d5f34a1 100644 --- a/pkg/noun/allocate.c +++ b/pkg/noun/allocate.c @@ -252,11 +252,13 @@ u3a_wealloc(void* lag_v, c3_w len_w) /* u3a_pile_prep(): initialize stack control. */ void -u3a_pile_prep(u3a_pile* pil_u, c3_w len_w) +u3a_pile_prep(u3a_pile* pil_u, c3_w len_w, c3_w lin_w) { + c3_w pad_w = -(uintptr_t)len_w & (lin_w - 1); + // frame size, in words // - c3_w wor_w = (len_w + 3) >> 2; + c3_w wor_w = (len_w + 3 + pad_w) >> 2; c3_o nor_o = u3a_is_north(u3R); pil_u->mov_ws = (c3y == nor_o) ? -wor_w : wor_w; @@ -691,7 +693,7 @@ _ca_take_north(u3_noun veb) u3_noun pro; _ca_take* fam_u; u3a_pile pil_u; - u3a_pile_prep(&pil_u, sizeof(*fam_u)); + u3a_pile_prep(&pil_u, sizeof(*fam_u), _Alignof(*fam_u)); // commence taking // @@ -731,7 +733,7 @@ _ca_take_south(u3_noun veb) u3_noun pro; _ca_take* fam_u; u3a_pile pil_u; - u3a_pile_prep(&pil_u, sizeof(*fam_u)); + u3a_pile_prep(&pil_u, sizeof(*fam_u), _Alignof(*fam_u)); // commence taking // @@ -1966,7 +1968,7 @@ u3a_walk_fore(u3_noun a, // initialize stack control; push argument // - u3a_pile_prep(&pil_u, sizeof(u3_noun)); + u3a_pile_prep(&pil_u, sizeof(u3_noun), _Alignof(u3_noun)); top = u3a_push(&pil_u); *top = a; diff --git a/pkg/noun/allocate.h b/pkg/noun/allocate.h index 418db1a7ba..7c9d8ff68a 100644 --- a/pkg/noun/allocate.h +++ b/pkg/noun/allocate.h @@ -608,7 +608,7 @@ u3a_post_info(u3_post); /* u3a_pile_prep(): initialize stack control. */ void - u3a_pile_prep(u3a_pile* pil_u, c3_w len_w); + u3a_pile_prep(u3a_pile* pil_u, c3_w len_w, c3_w lin_w); /* C-style aligned allocation - *not* compatible with above. */ diff --git a/pkg/noun/jets/b/reel.c b/pkg/noun/jets/b/reel.c index fe84f5a1dc..5c8421579d 100644 --- a/pkg/noun/jets/b/reel.c +++ b/pkg/noun/jets/b/reel.c @@ -17,7 +17,7 @@ u3_noun* top; u3_noun i, t = a; - u3a_pile_prep(&pil_u, sizeof(u3_noun)); + u3a_pile_prep(&pil_u, sizeof(u3_noun), _Alignof(u3_noun)); // push list onto road stack // diff --git a/pkg/noun/jets/e/json_de.c b/pkg/noun/jets/e/json_de.c index 92c5280a8b..c30728ad32 100644 --- a/pkg/noun/jets/e/json_de.c +++ b/pkg/noun/jets/e/json_de.c @@ -111,7 +111,7 @@ _parse(u3_atom txt) } json_open_buffer(sam_u, byt_y, len_w); json_set_allocator(sam_u, &loc_u); - u3a_pile_prep(pil_u, sizeof(u3qedj_coll)); + u3a_pile_prep(pil_u, sizeof(u3qedj_coll), _Alignof(u3qedj_coll)); // // core logic diff --git a/pkg/noun/jets/e/parse.c b/pkg/noun/jets/e/parse.c index 4ae8ab0c96..ac1a222572 100644 --- a/pkg/noun/jets/e/parse.c +++ b/pkg/noun/jets/e/parse.c @@ -473,7 +473,7 @@ u3nc(u3k(p_tub), u3k(pquq_vex)), u3k(puq_vex)); - + u3k(p_vex); u3k(quq_vex); wag = u3n_slam_on(u3k(hez), gud); @@ -975,7 +975,7 @@ _stir_pair* par_u; u3_noun p_wag, puq_wag, quq_wag; - u3a_pile_prep(&pil_u, sizeof(*par_u)); + u3a_pile_prep(&pil_u, sizeof(*par_u), _Alignof(*par_u)); // push incremental, successful [fel] parse results onto road stack // @@ -1049,4 +1049,3 @@ #undef _p #undef _q - \ No newline at end of file diff --git a/pkg/noun/manage.c b/pkg/noun/manage.c index 9a73ea3ce4..014a451aa9 100644 --- a/pkg/noun/manage.c +++ b/pkg/noun/manage.c @@ -184,7 +184,7 @@ _cm_signal_handle(c3_l sig_l) static void #ifndef U3_OS_windows _cm_signal_handle_over(int emergency, stackoverflow_context_t scp) -#else +#else _cm_signal_handle_over(int x) #endif { @@ -1032,7 +1032,8 @@ u3m_leap(c3_w pad_w) { u3a_pile pil_u; c3_p ptr_p; - u3a_pile_prep(&pil_u, sizeof(u3a_road) + 15); // XX refactor to wiseof + // u3a_pile_prep(&pil_u, sizeof(u3a_road) + 15); // XX refactor to wiseof + u3a_pile_prep(&pil_u, sizeof(u3a_road), _Alignof(u3a_road)); ptr_p = (c3_p)u3a_push(&pil_u); // XX add push_once, push_once_aligned @@ -1138,7 +1139,7 @@ u3m_leap(c3_w pad_w) if ( NULL != stk_u ) { rod_u->off_w = stk_u->off_w; rod_u->fow_w = stk_u->fow_w; - } + } /* Set up the new road. */ diff --git a/pkg/noun/retrieve.c b/pkg/noun/retrieve.c index 3d2e182c47..8da1a71a13 100644 --- a/pkg/noun/retrieve.c +++ b/pkg/noun/retrieve.c @@ -514,7 +514,7 @@ _cr_sing(u3_noun a, u3_noun b) // initialize stack control, push arguments onto the stack (none-frame) // - u3a_pile_prep(&pil_u, sizeof(eqframe)); + u3a_pile_prep(&pil_u, sizeof(eqframe), _Alignof(eqframe)); fam_u = _cr_sing_push(&pil_u, a, b); // loop while arguments are on the stack @@ -1803,7 +1803,7 @@ u3r_mug(u3_noun veb) // u3_assert( u3_none != veb ); - u3a_pile_prep(&pil_u, sizeof(*fam_u)); + u3a_pile_prep(&pil_u, sizeof(*fam_u), _Alignof(*fam_u)); // commence mugging // @@ -1887,7 +1887,7 @@ u3r_safe(u3_noun fol, u3_weak* out) case 0: *out = u3_none; return __(1 == t_fol); - + case 1: *out = t_fol; return c3y; diff --git a/pkg/noun/serial.c b/pkg/noun/serial.c index 5dd6f595a5..2c498a6cc6 100644 --- a/pkg/noun/serial.c +++ b/pkg/noun/serial.c @@ -433,7 +433,7 @@ u3s_cue(u3_atom a) // initialize stack control // - u3a_pile_prep(&pil_u, sizeof(*fam_u)); + u3a_pile_prep(&pil_u, sizeof(*fam_u), _Alignof(*fam_u)); // commence cueing at bit-position 0 // @@ -589,7 +589,7 @@ _cs_cue_xeno(u3_cue_xeno* sil_u, // initialize stack control // - u3a_pile_prep(&pil_u, sizeof(*fam_u)); + u3a_pile_prep(&pil_u, sizeof(*fam_u), _Alignof(*fam_u)); // init bitstream-reader // @@ -824,7 +824,7 @@ u3s_cue_bytes(c3_d len_d, const c3_y* byt_y) // initialize stack control // - u3a_pile_prep(&pil_u, sizeof(*fam_u)); + u3a_pile_prep(&pil_u, sizeof(*fam_u), _Alignof(*fam_u)); // initialize a hash table for dereferencing backrefs //