xdr variable length arrays

xdr variable length arrays

Post by Craig Malon » Fri, 04 Jul 2003 05:44:33



Does anyone know how to peek at the length of a variable length xdr
array before I deserialize it so that I can allocate properly?

Thanks in advance,
Craig

 
 
 

xdr variable length arrays

Post by Mada » Fri, 04 Jul 2003 19:05:48


 Not 100% sure but what I think is that you are looking after the key word
 "Opaque". Using this you can handle char* rather than char[n] (example only).

Quote:> Does anyone know how to peek at the length of a variable length xdr
> array before I deserialize it so that I can allocate properly?
> Thanks in advance,
> Craig

 Hope This helps.

--
Madan Mohan
------------ And now a word from our sponsor ------------------
Want to have instant messaging, and chat rooms, and discussion
groups for your local users or business, you need dbabble!
--  See http://netwinsite.com/sponsor/sponsor_dbabble.htm  ----

 
 
 

xdr variable length arrays

Post by Mada » Fri, 04 Jul 2003 19:08:15




>  Not 100% sure but what I think is that you are looking after the key word
>  "Opaque". Using this you can handle char* rather than char[n] (example only).

  Have a look at

  man -s 3nsl xdr_opaque

  for more accurate help.

Quote:>> Does anyone know how to peek at the length of a variable length xdr
>> array before I deserialize it so that I can allocate properly?
>> Thanks in advance,
>> Craig
>  Hope This helps.
> --

--
Madan Mohan
 
 
 

1. variable length array on stack

I was surprised to notice a variable length array on stack
in the 2.4.7 (== 2.4.6-ac5) drivers/media/video/meye.c:

static void *ptable_alloc(int npages, u32 *pt_addr) {
        int i = 0;
        void *vmem;
        u32 ptable[npages+1];
        ....

I had no idea you could do that!  gcc extension?  Sincere thanks
for teaching me that.  But maybe the construction is inappropriate
in the kernel?  In practice npages here is always 1024, which means
a deeper stack than we'd like to risk.  Wouldn't the (untested)
patch below be better?  Am I missing something when I substitute
kvirt_to_bus(adr) for virt_to_bus(__va(kvirt_to_pa(adr)))?

Hugh

--- linux-2.4.7/drivers/media/video/meye.c      Wed Jul  4 22:41:33 2001

 /* return a page table pointing to N pages of locked memory */
 static void *ptable_alloc(int npages, u32 *pt_addr) {
-       int i = 0;
+       int i;
        void *vmem;
-       u32 ptable[npages+1];
-       signed long size;
+       u32 *ptable;
        unsigned long adr;

-       size = (npages + 1) * PAGE_SIZE;
-       vmem = rvmalloc(size);
+       vmem = rvmalloc((npages + 1) * PAGE_SIZE);
        if (!vmem)
                return NULL;

-       memset(ptable, 0, sizeof(ptable));
-        adr = (unsigned long)vmem;
-       while (size > 0) {
-               ptable[i++] = virt_to_bus(__va(kvirt_to_pa(adr)));
+       adr = (unsigned long)vmem;
+       ptable = (u32 *)(vmem + npages * PAGE_SIZE);
+       for (i = 0; i < npages; i++) {
+               ptable[i] = (u32) kvirt_to_bus(adr);
                adr += PAGE_SIZE;
-               size -= PAGE_SIZE;
        }

-       memcpy(vmem + npages * PAGE_SIZE, ptable, PAGE_SIZE);
-       *pt_addr = ptable[npages];
-
+       *pt_addr = (u32) kvirt_to_bus(adr);
        return vmem;
 }

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

2. entstat -d en0 question

3. Setting variables in a variable array of null variables

4. SLIP and modem help wanted.

5. XDR question: How to receive data over sockets using XDR?

6. DCE

7. How should I find out array length in ksh

8. Terminal for Linux: anyone have this problem?

9. Compile error : variable length argument processing

10. Variable length recs: Mainframe -> Unix - Help!!!

11. Q: any way to expand variable length in csh beyond 1024?

12. variable length subnet mask

13. Reading tapes in variable block length mode with UnixWare