How do I find my buffers once I have lost them?

Barry Shein bzs at world.std.com
Thu Nov 8 13:58:42 AEST 1990


>When the kernel gets the interrupt how can it find the user buffer again
>(assuming it has been locked into memory) to do the next transfer? The
>buffer may no longer be mapped into the kernel's virtual address space
>since at the time of the interrupt some other user process may be running.
>How can the kernel even find the original user process (to, say, send a
>SIGIO to it)? Does it have to search the process table looking for it?
>It can't search physical RAM looking for the buffer since the buffer may
>be segmented into many chunks of RAM.

Well, one way to handle this is to just use a temp buffer to DMA
between and use copyin() and/or copyout() to move the data, but it
sounds like you're trying very hard to avoid that, ok.

Depending on how much info you really have to keep around you could
certainly declare a structure specific to the device with the items
you want to know latter, use rmalloc() or similar to create one for
each transfer and have the buffer struct point at it when you start.
Being as the buf struct is handed back to you at interrupt time you
could just snoop in there for the info you saved previously. So
the obvious thing would be:

	struct mydevinfo {
	  pid_t user_pid;
	  caddr_t user_buffer;
	};

and then when you set up the transfer something like:

	struct mydevinfo *myp;

	myp = (struct mydevinfo *)rmalloc(sizeof(struct mydevinfo));
	myp->user_pid = pid;
	myp->user_buffer = buffer;
	bp->b_un.b_addr = (caddr_t)myp;

and in the interrupt handler:

	struct mydevinfo *myp;

	myp = (struct mydevinfo *)bp->b_un.b_addr;

and so on.

sort of disgusting but it would do the job.

Maybe I'm missing something here...

gee, an internals question...imagine...I just had to *try* to answer,
but I'd suggest you wait until people pick apart my suggestion before
taking the advice.
-- 
        -Barry Shein

Software Tool & Die    | {xylogics,uunet}!world!bzs | bzs at world.std.com
Purveyors to the Trade | Voice: 617-739-0202        | Login: 617-739-WRLD



More information about the Comp.unix.internals mailing list