[Git][ghc/ghc][master] 2 commits: rts/adjustor: Clean up code style of Nativei386 adjustor
Marge Bot (@marge-bot)
gitlab at gitlab.haskell.org
Mon Nov 18 09:07:52 UTC 2024
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
325fcb5d by Ben Gamari at 2024-11-18T04:06:45-05:00
rts/adjustor: Clean up code style of Nativei386 adjustor
- - - - -
39bb6e58 by Ben Gamari at 2024-11-18T04:06:45-05:00
rts/adjustor: Fix stack overrun error in Nativei386 adjustor
We were reserving the wrong kind of adjustor context (the generic
`AdjustorContext` used by other adjustor implementations, rather than
the i386-specific `CCallContext`) to return the adjustor context while
freeing, resulting in #25485.
Fixes #25485.
- - - - -
2 changed files:
- rts/adjustor/Nativei386.c
- rts/adjustor/Nativei386Asm.S
Changes:
=====================================
rts/adjustor/Nativei386.c
=====================================
@@ -60,38 +60,37 @@ void initAdjustors(void) {
void*
createAdjustor(StgStablePtr hptr, StgFunPtr wptr,
- char *typeString STG_UNUSED
- )
+ char *typeString STG_UNUSED)
{
- // The adjustor puts the following things on the stack:
- // 1.) %ebp link
- // 2.) padding and (a copy of) the arguments
- // 3.) a dummy argument
- // 4.) hptr
- // 5.) return address (for returning to the adjustor)
- // All these have to add up to a multiple of 16.
-
- int sz = totalArgumentSize(typeString);
- // first, include everything in frame_size
- StgInt frame_size = sz * 4 + 16;
- // align to 16 bytes
- frame_size = (frame_size + 15) & ~15;
- // only count 2.) and 3.) as part of frame_size
- frame_size -= 12;
-
- struct CCallContext context = {
- .hptr = hptr,
- .wptr = wptr,
- .frame_size = frame_size,
- .argument_size = sz,
- };
- return alloc_adjustor(ccall_pool, &context);
+ // The adjustor puts the following things on the stack:
+ // 1. %ebp link
+ // 2. padding and (a copy of) the arguments
+ // 3. a dummy argument
+ // 4. hptr
+ // 5. return address (for returning to the adjustor)
+ // All these have to add up to a multiple of 16.
+
+ int sz = totalArgumentSize(typeString);
+ // first, include everything in frame_size
+ StgInt frame_size = sz * 4 + 16;
+ // align to 16 bytes
+ frame_size = (frame_size + 15) & ~15;
+ // only count 2.) and 3.) as part of frame_size
+ frame_size -= 12;
+
+ struct CCallContext context = {
+ .hptr = hptr,
+ .wptr = wptr,
+ .frame_size = frame_size,
+ .argument_size = sz,
+ };
+ return alloc_adjustor(ccall_pool, &context);
}
void
freeHaskellFunctionPtr(void* ptr)
{
- struct AdjustorContext context;
+ struct CCallContext context;
free_adjustor(ptr, &context);
freeStablePtr(context.hptr);
}
=====================================
rts/adjustor/Nativei386Asm.S
=====================================
@@ -26,28 +26,28 @@ DECLARE_CSYM(ccall_adjustor)
// Record a frame pointer. Paired with the `leave` below.
pushl %ebp
movl %esp, %ebp
-
+
subl FRAME_SIZE_OFF(%eax), %esp
// Save %esi and %edi as we need to clobber them to perform the shuffle
pushl %esi
pushl %edi
-
+
// Shuffle the stack down...
leal 8(%ebp), %esi
leal 12(%esp), %edi
movl ARGUMENT_WORDS_OFF(%eax), %ecx
rep
movsl
-
+
// Restore %edi and %esi
popl %edi
popl %esi
-
+
// Perform the call
pushl HPTR_OFF(%eax)
call *WPTR_OFF(%eax)
-
+
leave
ret
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/d9326a48acb5340dc1d67052bdfd8abfb35f5b54...39bb6e583d64738db51441a556d499aa93a4fc4a
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/d9326a48acb5340dc1d67052bdfd8abfb35f5b54...39bb6e583d64738db51441a556d499aa93a4fc4a
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20241118/fb917ade/attachment-0001.html>
More information about the ghc-commits
mailing list