[9fans] What's so special about seek() ? - Plan9

This is a discussion on [9fans] What's so special about seek() ? - Plan9 ; /sys/src/libc/9syscall/mkfile has a rather odd looking special case for the seek system call... it looks like if seek fails (returns -1) that the first two arguments (fd and offset) are overwritten with -1. What's going on here? The manual page ...

+ Reply to Thread
Results 1 to 6 of 6

Thread: [9fans] What's so special about seek() ?

  1. [9fans] What's so special about seek() ?

    /sys/src/libc/9syscall/mkfile has a rather odd looking special case for the
    seek system call... it looks like if seek fails (returns -1) that the first
    two arguments (fd and offset) are overwritten with -1. What's going on
    here? The manual page doesn't hint at anything...

    Thanks.
    --nwf;

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.9 (GNU/Linux)

    iEYEARECAAYFAkj8MrUACgkQTeQabvr9Tc/bpQCfRK9x72hIRZNhKLmCED6bRyZ8
    MDoAniB1gmzMcdzEhFzj0gW4eIzNmxHw
    =bO2W
    -----END PGP SIGNATURE-----


  2. Re: [9fans] What's so special about seek() ?

    seek is unusual because it returns a 64-bit value


  3. Re: [9fans] What's so special about seek() ?

    On Mon, Oct 20, 2008 at 09:19:50AM +0100, C H Forsyth wrote:
    > seek is unusual because it returns a 64-bit value


    Forgive my ignorance, but I don't see how the code in question relates to
    returning a 64-bit value?

    --nwf;

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.9 (GNU/Linux)

    iEYEARECAAYFAkj86loACgkQTeQabvr9Tc/W6ACcDBGVs3TkhuymG/UxFFNu/Ec/
    QEsAnRwukm4KLO7d31298DXpQzLfdiyd
    =DT6e
    -----END PGP SIGNATURE-----


  4. Re: [9fans] What's so special about seek() ?

    The seek system call is here

    /sys/src/9/port/sysfile.c:855

    The arg variable here is a pointer to the users stack making
    the system call. most return values are 32 bit and are passed
    back through syscall()

    /sys/src/9/pc/trap.c:660

    but seek is different, it overwrites 64 bits starting at the first arg
    on the stack of the users seek call.

    I am pretty sure I have this right, I am sure somone
    will be correct me if I am wrong.

    -Steve


  5. Re: [9fans] What's so special about seek() ?

    On Mon, Oct 20, 2008 at 10:11:22PM +0100, Charles Forsyth wrote:
    > >Forgive my ignorance, but I don't see how the code in question relates to
    > >returning a 64-bit value?

    > MOVL a+0(FP),CX
    > MOVL AX,0(CX)
    > MOVL AX,4(CX)
    >
    > that's how a 64-bit value is returned on 32-bit machines:
    > similar to returning a structure, the caller passes a
    > hidden first argument referring to the 64-bit return location.
    > in this case, since -1 is already in AX, storing that in both 32-bit
    > parts of the 64-bit value produces -1LL


    Oh interesting. Thanks for the clarification. I had thought 64 bit returns
    were done in %eax and %edx. Sorry for the noise.
    --nwf;

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.9 (GNU/Linux)

    iEYEARECAAYFAkj88iAACgkQTeQabvr9Tc90DACbBp1JR1Petk sLRpM60avm+o0I
    OygAn1HMsWDSz3d/MXmVR0wHQDGH1aVH
    =TO/M
    -----END PGP SIGNATURE-----


  6. Re: [9fans] What's so special about seek() ?

    >Forgive my ignorance, but I don't see how the code in question relates to
    >returning a 64-bit value?

    MOVL a+0(FP),CX
    MOVL AX,0(CX)
    MOVL AX,4(CX)

    that's how a 64-bit value is returned on 32-bit machines:
    similar to returning a structure, the caller passes a
    hidden first argument referring to the 64-bit return location.
    in this case, since -1 is already in AX, storing that in both 32-bit
    parts of the 64-bit value produces -1LL


+ Reply to Thread