3Fermer5
FarewellLe 26/04/2013 à 19:42
Bon, je crois avoir une solution qui tient en 4 octets. Pas compilé, pas testé, mais le linker est complexe, donc tu pourrais déjà me dire si c'est pas complètement déconnant.

Le patch (attention, j'ai ouvert l'original je sais pas comment, Kate l'a modifié sans prévenir, donc le patch n'est pas applicable tel quel (il me sort un fichier de 600 lignes pour les quelques modifs que j'ai faites :/). Mais au moins, tu localises les modifs avec ça) :
 kernel::LibsExec:
	movem.l	d0-d7/a0-a6,-(a7)			;
 	GET_DATA_PTR					; Get Preos Data Ptr
-	moveq	#0,d7					; Set Error
 	pea	(12).w					; Create a list (Next, RealReturnAddr, LibPtr)
@@ -1189,17 +1189,18 @@
 	move.l	a0,(a7)					; Ok ?
 	beq.s	\AllocError
 	move.l	a0,a3					; Ptr to node
	move.l	(LibsExecList-Ref)(a6),(a3)+		; Save Next node in List
 	move.l	(4*16)(a7),(a3)+			; Save Real Return Address
 	move.l	a3,(LibsExecList-Ref)(a6)		; Update list head
 	move.l	(4*17)(a7),a2				; Get Library name
 	move.b	(4*18+2)(a7),d3				; Minimum Library version
 	bsr	kernel::FindLib				; Find the library
+	clr.l	4*17(sp)				; Set error
 	move.l	a0,(a3)					; Save the lib & Check for success
 	beq.s	\FreeNode
 	move.l	a0,a5					; Relocation of the library.
 	bsr	kernel::relocation			; If it failed the library is free!
 	tst.w	d0					;
 	bne.s	\FreeNode
 	move.l	a5,(a3)					; Update Library Code section
 	move.l	a5,a0
@@ -1216,30 +1217,33 @@
 	rts						; Jump to the function and return \next

 \next	subq.l	#8,a7					; Fix stack ptr.
+	st.b	(sp)					; Set success
 	movem.l	d0-d7/a0-a7,-(a7)			; Pop a7 to increase Stack Frame
	GET_DATA_PTR					; Get a6
 	subq.l	#4,a7					; Create Stack Frame
 \UnrelocLib:
 	move.l	(LibsExecList-Ref)(a6),a3
 	move.l	(a3),a5					; Read Lib Ptr
	bsr	kernel::unrelocation			; Unreloc & delete.
 \FreeNode:
 	move.l	(LibsExecList-Ref)(a6),a3		; Kernel::relocation may destroy all registers if an error occured ! (execpt a6 & a5)
 	move.l	-(a3),(4*16)(a7)			; Set Return Address
 	move.l	-(a3),(LibsExecList-Ref)(a6)		; Set new head
 	move.l	a3,(a7)
 	ROM_THROW HeapFreePtr				; Free Node
-	moveq	#1,d7					; Set no error
-\AllocError
+\AllocError2:
 	addq.l	#4,a7					; Fix stack
-	move.l	d7,(4*16)(a7)				; Set error
 \end:	movem.l	(a7)+,d0-d7/a0-a6
 	rts

+\AllocError:
+	clr.l	4*17(sp)					; Set error
+	bra.s	\AllocError2

Ce qui donne :; It calls the function without modifying the registers, and it pops its argument ; during the call (LIB_DESCRIPTOR, function, and version). ; kernel::LibsExec(char name[], WORD function, BYTE version, ...) kernel::LibsExec: movem.l d0-d7/a0-a6,-(a7) ; GET_DATA_PTR ; Get Preos Data Ptr moveq #0,d7 ; Set Error pea (12).w ; Create a list (Next, RealReturnAddr, LibPtr) ROM_THROW HeapAllocPtr ; Alloc Node move.l a0,(a7) ; Ok ? beq.s \AllocError move.l a0,a3 ; Ptr to node move.l (LibsExecList-Ref)(a6),(a3)+ ; Save Next node in List move.l (4*16)(a7),(a3)+ ; Save Real Return Address move.l a3,(LibsExecList-Ref)(a6) ; Update list head move.l (4*17)(a7),a2 ; Get Library name move.b (4*18+2)(a7),d3 ; Minimum Library version bsr kernel::FindLib ; Find the library clr.l 4*17(sp) ; Set error move.l a0,(a3) ; Save the lib & Check for success beq.s \FreeNode move.l a0,a5 ; Relocation of the library. bsr kernel::relocation ; If it failed the library is free! tst.w d0 ; bne.s \FreeNode move.l a5,(a3) ; Update Library Code section move.l a5,a0 move.w (4*18)(a7),d0 ; Function # bsr.s kernel::LibsPtr ; Get the ptr to the required func move.l a0,d0 beq.s \UnrelocLib move.l a0,(4*17)(a7) ; New return address lea \next(pc),a0 move.l a0,(4*18)(a7) ; After it return here addq.l #4,a7 ; Pop Stack Frame movem.l (a7)+,d0-d7/a0-a6 addq.l #4,a7 ; Pop First Return Address rts ; Jump to the function and return \next \next subq.l #8,a7 ; Fix stack ptr. st.b (sp) ; Set success movem.l d0-d7/a0-a7,-(a7) ; Pop a7 to increase Stack Frame GET_DATA_PTR ; Get a6 subq.l #4,a7 ; Create Stack Frame \UnrelocLib: move.l (LibsExecList-Ref)(a6),a3 move.l (a3),a5 ; Read Lib Ptr bsr kernel::unrelocation ; Unreloc & delete. \FreeNode: move.l (LibsExecList-Ref)(a6),a3 ; Kernel::relocation may destroy all registers if an error occured ! (execpt a6 & a5) move.l -(a3),(4*16)(a7) ; Set Return Address move.l -(a3),(LibsExecList-Ref)(a6) ; Set new head move.l a3,(a7) ROM_THROW HeapFreePtr ; Free Node moveq #1,d7 ; Set no error \AllocError2: addq.l #4,a7 ; Fix stack \end: movem.l (a7)+,d0-d7/a0-a6 rts \AllocError: clr.l 4*17(sp) ; Set error bra.s \AllocError2