kernels/linux-2.4.0/drivers/net/wan/sdlamain.c
/*============================================================================
 * Dump adapter memory to user buffer.
 * o verify request structure
 * o copy request structure to kernel data space
 * o verify length/offset
 * o verify user buffer
 * o copy adapter memory image to user buffer
 *
 * Note: when dumping memory, this routine switches curent dual-port memory
 *	 vector, so care must be taken to avoid racing conditions.
 */
Dump adapter memory to user buffer.
o verify request structure
o copy request structure to kernel data space
o verify length/offset
o verify user buffer
o copy adapter memory image to user buffer

when dumping memory, this routine switches curent dual-port memory
vector, so care must be taken to avoid racing conditions.
Dump adapter memory to user buffer . o verify request structure o copy request structure to kernel data space o verify length / offset o verify user buffer o copy adapter memory image to user buffer when dumping memory this routine switches curent dual - port memory vector so care must be taken to avoid racing conditions .
static int ioctl_dump (sdla_t* card, sdla_dump_t* u_dump)
{
	sdla_dump_t dump;
	unsigned winsize;
	unsigned long oldvec;	
	unsigned long flags;
	int err = 0;
	if(copy_from_user((void*)&dump, (void*)u_dump, sizeof(sdla_dump_t)))
		return -EFAULT;
	if ((dump.magic != WANPIPE_MAGIC) ||
	    (dump.offset + dump.length > card->hw.memory))
		return -EINVAL;
	winsize = card->hw.dpmsize;
	save_flags(flags);
        cli();				
	if(card->hw.type != SDLA_S514) {
                oldvec = card->hw.vector;
                while (dump.length) {
                        unsigned pos = dump.offset % winsize;
                        unsigned long vec = dump.offset - pos;
                        unsigned len = (dump.length > (winsize - pos)) ?
                        	(winsize - pos) : dump.length;
                        if (sdla_mapmem(&card->hw, vec) != 0) {
                                err = -EIO;
                                break;
                        }
                        sti();  
                        if(copy_to_user((void *)dump.ptr,
                                (u8 *)card->hw.dpmbase + pos, len)) 
                                return -EFAULT;
                        cli();
                        dump.length     -= len;
                        dump.offset     += len;
                        (char*)dump.ptr += len;
                }
                sdla_mapmem(&card->hw, oldvec);
        }
	else {
                sti();  
               if(copy_to_user((void *)dump.ptr,
	                (u8 *)card->hw.dpmbase + dump.offset, dump.length))
                	return -EFAULT;
               cli();
	}
	restore_flags(flags);		
	return err;
}
static int ioctl_dump ( sdla_t * card , sdla_dump_t * u_dump ) { sdla_dump_t dump ; unsigned winsize ; unsigned long oldvec ; unsigned long flags ; int err = 0 ; if ( copy_from_user ( ( void * ) & dump , ( void * ) u_dump , sizeof ( sdla_dump_t ) ) ) return - EFAULT ; if ( ( dump . magic != WANPIPE_MAGIC ) || ( dump . offset + dump . length > card -> hw . memory ) ) return - EINVAL ; winsize = card -> hw . dpmsize ; save_flags ( flags ) ; cli ( ) ; if ( card -> hw . type != SDLA_S514 ) { oldvec = card -> hw . vector ; while ( dump . length ) { unsigned pos = dump . offset % winsize ; unsigned long vec = dump . offset - pos ; unsigned len = ( dump . length > ( winsize - pos ) ) ? ( winsize - pos ) : dump . length ; if ( sdla_mapmem ( & card -> hw , vec ) != 0 ) { err = - EIO ; break ; } sti ( ) ; if ( copy_to_user ( ( void * ) dump . ptr , ( u8 * ) card -> hw . dpmbase + pos , len ) ) return - EFAULT ; cli ( ) ; dump . length -= len ; dump . offset += len ; ( char * ) dump . ptr += len ; } sdla_mapmem ( & card -> hw , oldvec ) ; } else { sti ( ) ; if ( copy_to_user ( ( void * ) dump . ptr , ( u8 * ) card -> hw . dpmbase + dump . offset , dump . length ) ) return - EFAULT ; cli ( ) ; } restore_flags ( flags ) ; return err ; }
Dump adapter memory to user buffer.
Dump adapter memory to user buffer .
/* DPM window vector */ /* >>> critical section start <<< */ /* current offset */ /* current vector */ /* relocate window */ /* FIXME::: COPY TO KERNEL BUFFER FIRST ?? */ /* Not ideal but tough we have to do this */ /* restore DPM window position */ /* FIXME::: COPY TO KERNEL BUFFER FIRST ?? */ /* Not ideal but tough we have to do this */ /* >>> critical section end <<< */