[dtrace-discuss] values from a struct

James Carlson
2010-09-17T13:47:06Z

On 09/17/10 09:34, goinsane wrote:
> Yes, you''re right, the manpage expresses this, too.
> But how to get the value? copyin returns the address of the scratch buffer.
could this be used as argument of the 2nd copyin of fbt:sockfs:accept:return ?
>
> fbt:sockfs:accept:entry
> {
>     self->sockaddr = arg1;
>     self->socklen  = (int*)copyin(arg2, 4);
>  }

It''s an in-out parameter.  The value at entry is just the _maximum_
size
of the caller''s buffer, and not the _actual_ size of the returned data.

> fbt:sockfs:accept:return
> {
>    self->sockcont = (struct sockaddr_in*)copyin(self->sockaddr,
self->socklen);
> }

I would do this in the entry clause:

	self->sockaddr = arg1;
	self->socklenp = arg2;

and then this in the return clause:

	self->socklen = *(int *)copyin(self->socklenp, 4);
	self->sockcont = (struct sockaddr_in *)copyin(self->sockaddr,
			self->socklen);

(This assumes the application is 32-bit or at least that the system is
little-endian.  Things get more complicated if you have to deal with
64-bit big-endian systems.)

To be really robust, you could have multiple return causes -- one to get
the return length, another to check it and fetch the contents, still
another to look at the sa_family, and so on.

--
James Carlson         42.703N 71.076W         <carlsonj at
workingcode.com>