Good day,

I got some plan9 binaries to work on Linux (8c, 8l, cat, sed, cal and a few more were tested), but all others are failing at exactly the same instruction:

plock+0x31 MOVL 0x30(CX), CX

(which is called whenever malloc is used). For some context:

acid: asm(plock+0x20)
plock+0x20      JEQ             plock+0x27(SB)
plock+0x22      CALL    abort(SB)
plock+0x27      MOVL    pv+0xc(SP), AX
plock+0x2b      MOVL    _tos(SB), CX
plock+0x31      MOVL    0x30(CX), CX
plock+0x32      DECL    CX
plock+0x33      XORB    CL, 0xc4830448(CX)
plock+0x39      ADCB    AL,BL

The line of interest is plock+0x2b: (_tos(SB), CX); which is supposed to store a value at CX. However, when the binary is run in Linux, CX becomes 0 after that instruction, so plock+0x31 becomes (MOVL 0x30, CX) resulting in a segfault as 0x30 is an invalid address in the process address space (it starts only at 0x1000).

acid: asm(_tos)
_tos            ADDB    AL, 0x0(AX)

I defined a TEXT section for _tos, in the 'Hello Assembly' program discussed earlier, and used _tos after printing Hello on the screen. acid tells me CX becomes 0 after that instruction, which is exactly what happens on Linux too:

DATA    string<>+0(SB)/8, $"Plan9\n\z\z"
GLOBL   string<>+0(SB), $8

TEXT    _main+0(SB), 1, $0
MOVL    $string<>+0(SB), 4(SP)
MOVL    $8, AX
MOVL    _tos(SB), CX
MOVL    0x30(CX), CX
INT             $64

TEXT    _tos+0(SB), 1, $0
ADDB    AL, 0x0(AX)

8.out: 1831: suicide: sys: trap: fault read addr=0x30 pc=0x00001033

What is _tos supposed to do, and why does it set CX to different values for some plan9 binaries, but not in a standalone assembled program and on linux (in both cases, CX is set to 0)?

Thanks in advance for your help!

Regards,
Anant


Reply via email to