9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] What's so special about seek() ?
@ 2008-10-20  7:26 Nathaniel W Filardo
  2008-10-20  8:19 ` C H Forsyth
  2008-10-20 21:11 ` Charles Forsyth
  0 siblings, 2 replies; 6+ messages in thread
From: Nathaniel W Filardo @ 2008-10-20  7:26 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 298 bytes --]

/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;

[-- Attachment #2: Type: application/pgp-signature, Size: 204 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [9fans] What's so special about seek() ?
  2008-10-20  7:26 [9fans] What's so special about seek() ? Nathaniel W Filardo
@ 2008-10-20  8:19 ` C H Forsyth
  2008-10-20 20:30   ` Nathaniel W Filardo
  2008-10-20 21:11 ` Charles Forsyth
  1 sibling, 1 reply; 6+ messages in thread
From: C H Forsyth @ 2008-10-20  8:19 UTC (permalink / raw)
  To: 9fans

seek is unusual because it returns a 64-bit value



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [9fans] What's so special about seek() ?
  2008-10-20  8:19 ` C H Forsyth
@ 2008-10-20 20:30   ` Nathaniel W Filardo
  2008-10-20 20:50     ` Steve Simon
  0 siblings, 1 reply; 6+ messages in thread
From: Nathaniel W Filardo @ 2008-10-20 20:30 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 230 bytes --]

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;

[-- Attachment #2: Type: application/pgp-signature, Size: 204 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [9fans] What's so special about seek() ?
  2008-10-20 20:30   ` Nathaniel W Filardo
@ 2008-10-20 20:50     ` Steve Simon
  0 siblings, 0 replies; 6+ messages in thread
From: Steve Simon @ 2008-10-20 20:50 UTC (permalink / raw)
  To: 9fans

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



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [9fans] What's so special about seek() ?
  2008-10-20 21:11 ` Charles Forsyth
@ 2008-10-20 21:03   ` Nathaniel W Filardo
  0 siblings, 0 replies; 6+ messages in thread
From: Nathaniel W Filardo @ 2008-10-20 21:03 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 681 bytes --]

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;

[-- Attachment #2: Type: application/pgp-signature, Size: 204 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [9fans] What's so special about seek() ?
  2008-10-20  7:26 [9fans] What's so special about seek() ? Nathaniel W Filardo
  2008-10-20  8:19 ` C H Forsyth
@ 2008-10-20 21:11 ` Charles Forsyth
  2008-10-20 21:03   ` Nathaniel W Filardo
  1 sibling, 1 reply; 6+ messages in thread
From: Charles Forsyth @ 2008-10-20 21:11 UTC (permalink / raw)
  To: 9fans

>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



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-10-20 21:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-20  7:26 [9fans] What's so special about seek() ? Nathaniel W Filardo
2008-10-20  8:19 ` C H Forsyth
2008-10-20 20:30   ` Nathaniel W Filardo
2008-10-20 20:50     ` Steve Simon
2008-10-20 21:11 ` Charles Forsyth
2008-10-20 21:03   ` Nathaniel W Filardo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).