Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
* Under what conditions do xdr_long work?
@ 1994-03-11 18:01 Martin Sjolin
  1994-03-13 17:37 ` John T. Kohl
  1994-03-14 19:55 ` Eric Werme USSG
  0 siblings, 2 replies; 3+ messages in thread
From: Martin Sjolin @ 1994-03-11 18:01 UTC (permalink / raw)


I have almost finished porting finished porting LINCKS, an object-centered 
multi-user database system, to a OSF1/Alpha. I have everything up and
running after a one day work. But, I have problems understanding under
what conditions xdr_long works!  We use callrpc/registerrpc for 
communication between the different processes in the database server.

On HP-UX, Sun, Linux, Ultrix, SGI, etc sizeof(long) == sizeof(int).
Of course, I changed the existing xdr_long to use xdr_int instead. 
Everything works, but then I would like to use long integer and started 
to play with the xdr_long routines ...

Now, why is that:

1). using xdrmem_create/xdrstdio_create to create a xdr stream
    and then using xdr_long to encode a long (64bits) integer
    worked(!), but

2). then I tried to use xdr_long within our xdr routines called
    by callrpc/registerrpc (using UDP/IP as transport medium),
    and of course the callrpc fails!

3). In the man page for xdr_long it says using xdr_long for
    long 'C' integers ...

Now, I very well aware that xdr_long should *not* work for 64-bits
long, but why this behaviour? Does xdr_long perform a test on what 
kind of xdr stream is used? And is this documented somewhere?

A somewhat confused

Martin.
PS. For more information about LINCKS, mail me or to lincks@ida.liu.se

-- 
Martin Sj\"olin     | e-mail: marsj@ida.liu.se  | phone : +46 13 28 24 10
Department of Computer and Information Science  | fax   : +46 13 28 26 66
University of Link\"oping, S-581 83 Link\"oping, SWEDEN                   



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

* Re: Under what conditions do xdr_long work?
  1994-03-11 18:01 Under what conditions do xdr_long work? Martin Sjolin
@ 1994-03-13 17:37 ` John T. Kohl
  1994-03-14 19:55 ` Eric Werme USSG
  1 sibling, 0 replies; 3+ messages in thread
From: John T. Kohl @ 1994-03-13 17:37 UTC (permalink / raw)


I recently did the bulk of the work in porting my company's product to
DEC OSF/1 on Alpha AXP.  This was our first 64-bit architecture.
Here's what I determined about the behaviour of the XDR routines on DEC
OSF/1 V1.3:

(a) xdr_{u_,}long in user space takes a pointer to a long.  It encodes/decodes
from/to that long.

If it's encoding, it range-checks the value.
	* If xdr_long, the top 33 bits must be all zeros or ones.  (if
	this is not the case, the value will lose precision when stuffed
	into a 32-bit XDR encoding).
	* If xdr_u_long, the top 32 bits must be clear.
        * practical import:
	  (i) do not xdr_long or xdr_u_long pointers. They won't fit.
	  (ii) don't xdr_long or xdr_u_long uninitialized or otherwise
	  garbage long/u_long values (e.g. random numbers).  They
	  probably won't fit.
	  (iii) You will get an XDR failure if the range check fails, so
	  it's fairly simple to find the offending out-of-range item.

If it's decoding, it zero-fills (u_long) or sign-extends (long) the top
32 bits.

(b) xdr_{u_,}long in the kernel take pointers to int (in V1.3, at
least).  If you have longs in kernel RPC code, you'll need to roll your
own xdr_*long routines to do the range-checking and zero/sign extending.
--
John Kohl <jtk@atria.com> or <jtkohl@mit.edu>
working for but not representing:	Atria Software
---------
Oh, just enjoy yourself!


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

* Re: Under what conditions do xdr_long work?
  1994-03-11 18:01 Under what conditions do xdr_long work? Martin Sjolin
  1994-03-13 17:37 ` John T. Kohl
@ 1994-03-14 19:55 ` Eric Werme USSG
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Werme USSG @ 1994-03-14 19:55 UTC (permalink / raw)


marsj@ida.liu.se (Martin Sjolin) writes:

>I have problems understanding under
>what conditions xdr_long works!

>On HP-UX, Sun, Linux, Ultrix, SGI, etc sizeof(long) == sizeof(int).
>Of course, I changed the existing xdr_long to use xdr_int instead. 
>Everything works, but then I would like to use long integer and started 
>to play with the xdr_long routines ...

A lot of the xdr routines are confusingly named, so you probably should be
confused.  The XDR support in V1.2 and I think in V1.3 is also a little
confused, but things are better in V2.0, which is now shipping.

xdr_long() encodes longs in the XDR stream.  Unfortunately, the stream
only allocates 32 bits to the data.  Therefore, there are new routines
for 64 bit data.

The man pages now explain the difficulty.  Here are some that don't quite
match V2.0, but are close enough.

  xdr_long(xdrs, lp)
  XDR *xdrs;
  long *lp;

       A filter primitive that translates between C long integers and their
       external representations.  This routine returns one if it succeeds,
       zero otherwise.

       Note that the argument lp must be the C language type long. The amount
       of data encoded to the XDR stream is only 4 bytes (not the full 8
       bytes of data represented by the C long type). This is because in the
       context of XDR streams a long type is considered to be 4 bytes. When
       data is encoded from the XDR stream, 4 bytes will be received from the
       XDR stream; the xdr_long interface then then sign extends the high
       order 4 bytes of the C long type.

       Prior to serializing the data on the ENCODE side the xdr_long performs
       a validity check to insure that the value represents a valid 32-bit
       signed number.  This involves determining that the signed value is no
       less than the most negative 32-bit signed quantity (which is the hexa-
       decimal value 0x80000000) and no greater than the most positive 32-bit
       signed quantity (which is the hexadecimal value 0x7fffffff).  If the
       value pointed to by the argument lp is not within this range the
       xdr_long interface returns an error.

       To translate the full 8 bytes of a C long, use the xdr_hyper inter-
       face.

       See the following section that explains the differences between
       xdr_long and xdr_hyper.

  xdr_longlong_t(xdrs, hp)
  XDR *xdrs;
  longlong_t *hp;

       A filter primitive that translates between C long integers and their
       external representations. (The typedef longlong_t is defined as long
       in the file <rpc/types.h>, which is included from the file
       <rpc/xdr.h>.) This routine will translate all 8 bytes of data to the
       XDR stream. Note that this differentiates this routine from xdr_long
       in that they both take a pointer to a long as an argument, while
       xdr_long only translates 4 bytes of data to the XDR stream. This rou-
       tine returns one if it succeeds, zero otherwise.

       The xdr_longlong_t routine is functionally equivalent to the xdr_hyper
       routine.

       See the following section that explains the differences between
       xdr_long and xdr_hyper.
  Differences Between xdr_long and xdr_hyper Routines

  On DEC OSF/1 platforms, the C programming language and the XDR routines
  apply different conventions to the definitions of the long data type.

  On DEC OSF/1 platforms, the C programming language applies the following
  conventions for int and long data types:

  __________________________
  Data Type   bits   bytes
  __________________________
  int         32     4 bytes

  long        64     8 bytes
  __________________________

  The XDR routines apply the following conventions:

  __________________________
  Data Type   bits   bytes
  __________________________
  int         32     4 bytes

  long        32     4 bytes

  hyper       64     8 bytes
  __________________________
  8 bytes

  The xdr_long() and xdr_u_long() interfaces serialize 4 bytes of data. The
  xdr_hyper() and xdr_u_hyper() serialize 8 bytes of data.

  On DEC OSF/1 systems, the second argument to both xdr_long and xdr_hyper
  must be either a pointer or of the C language type long (8 bytes).  When
  xdr_hyper is called with a parameter that points to a long all 8-bytes are
  serialized.  In contrast, when xdr_long is called with a parameter that
  points to a long only the low order 4-bytes are serialized.

  When calling xdr_long on the DECODE operation, the upper 4-bytes of the
  long are sign extended in accordance with the high order bit of the lower
  4-byte quantity. This is necessary to maintain the XDR convention of
  xdr_long serializing 4-bytes.

  If you want all 8-bytes to be serialized, use the xdr_hyper interface.

  The xdr_longlong_t and the xdr_u_longlong_t perform the same function as
  the xdr_hyper and the xdr_u_hyper interfaces respectively.

>Now, why is that:

>1). using xdrmem_create/xdrstdio_create to create a xdr stream
>    and then using xdr_long to encode a long (64bits) integer
>    worked(!), but

If your long was beteween -2^32 and 2^32-1 it should have (though I
think V1.3 would accept any value).

>2). then I tried to use xdr_long within our xdr routines called
>    by callrpc/registerrpc (using UDP/IP as transport medium),
>    and of course the callrpc fails!

I think it should have worked.

I hope the above will explain the behaviour you see.

BTW, xdr_hyper() was first, but I think xdr_longlong_t() is supplanting
xdr_hyper().  I use xdr_longlong_t().
-- 
Eric (Ric) Werme		| werme@zk3.dec.com
Digital Equipment Corp.		| This space intentionally left blank.


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

end of thread, other threads:[~1994-03-14 19:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1994-03-11 18:01 Under what conditions do xdr_long work? Martin Sjolin
1994-03-13 17:37 ` John T. Kohl
1994-03-14 19:55 ` Eric Werme USSG

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox