Never copy a buffer from the interrupt handler context to the user space. Copy the required data and schedule it accordingly. Iqbal On Tue, 2003-08-05 at 06:45, kjw75799@etri.re.kr wrote: > Let me have time to ask some questions about Linux. > > we can access user buffer within interrupt handler (kernel mode) if we > tocuch segment selectors. > Like these: > mm_segment_t fs; > fs = get_fs(); > set_fs(get_dsc()); > call user space function . > ..... > set_fs(fs); > > My question is: > Can we execute(call) a function of user space within the interrupt > handler? > > reference site http://www.cs.unm.edu/~jotto/linux/linux.html > > Something similar happens with segment selectors when an interrupt > takes place. But in this case there is no assurance that the handler > is executing in the context of the interested process. Suppose though > that by some bit of magic the interrupt handler knows the process's > pid and a buffer address. Then in the case that the handler needs to > write data to the buffer we could do something like the following: > > struct task_struct* pid2task(int); > void in_thehandler(); > > int pid; > char* user_buf; > char ch; > > unsigned long pgdir; > struct task_struct *temp; > > void in_thehandler() > { > temp = current_set[0]; > current_set[0] = pid2task(pid); > if (!current_set[0]) { > printk("error: couldn't find process.\n"); > } > else { > > /* make CR3 point to this guy's page directory */ > pgdir = current_set[0]->tss.cr3; > __asm__ __volatile__("movl %0,%%cr3": :"r" (pgdir)); > > memcpy_tofs(user_buf, &ch, 1); > } > current_set[0] = temp; > > /* restore CR3 to point to the original page directory */ > pgdir = current_set[0]->tss.cr3; > __asm__ __volatile__("movl %0,%%cr3": :"r" (pgdir)); > } > > struct task_struct* pid2task(int pid) > { > /* see the section on Virtual to Physical address translation */ > } > > Here, we do a bit of a context switch by finding out the task > structure associated with the pid (by calling pid2task()and then > loading the page directory pointer for that task into the CR3 register > (the latter is the hardware's entry point to a given process's paging > structures). Then we can use the _fs functions. When we are done we > restore the saved context. The code for updating CR3 was lifted from > the SET_PAGE_DIR macro in include/asm. > > Thank you in advance > > > > > > -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/