public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* cli()/sti() clarification
@ 2002-07-18  6:27 irfan_hamid
  2002-07-18  6:58 ` george anzinger
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: irfan_hamid @ 2002-07-18  6:27 UTC (permalink / raw)
  To: linux-kernel

Hi, 

I added two system calls, blockintr() and unblockintr() to give cli()/sti() 
control to userland programs (yes I know its not advisable) but I only want 
to do it as a test. My test program looks like this: 

	blockintr();
	/* Some long calculations */
	unblockintr(); 

The problem is that if I press Ctrl+C during the calculation, the program
terminates. So I checked the _syscallN() and __syscall_return() macros to 
see if they explicitly call sti() before returning to userspace, but they 
dont. 

Reading the lkml archives, I found that cli() disables only the interrupts, 
exceptions are allowed, so it makes sense that the SIGINT was delivered, but 
if thats the case, then how come the SIGINT was delivered from the Ctrl+C? 
Doesnt this mean that the SIGINT signal was generated as a result of the 
keyboard interrupt? 

I know I am missing something here, would appreciate if someone could point 
me in the right direction. 

Regards,
Irfan Hamid.

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

* Re: cli()/sti() clarification
  2002-07-18  6:27 cli()/sti() clarification irfan_hamid
@ 2002-07-18  6:58 ` george anzinger
  2002-07-18  9:33 ` Kasper Dupont
  2002-07-18 14:52 ` Marco Colombo
  2 siblings, 0 replies; 5+ messages in thread
From: george anzinger @ 2002-07-18  6:58 UTC (permalink / raw)
  To: irfan_hamid; +Cc: linux-kernel

irfan_hamid@softhome.net wrote:
> 
> Hi,
> 
> I added two system calls, blockintr() and unblockintr() to give cli()/sti()
> control to userland programs (yes I know its not advisable) but I only want
> to do it as a test. My test program looks like this:
> 
>         blockintr();
>         /* Some long calculations */
>         unblockintr();
> 
> The problem is that if I press Ctrl+C during the calculation, the program
> terminates. So I checked the _syscallN() and __syscall_return() macros to
> see if they explicitly call sti() before returning to userspace, but they
> dont.
> 
> Reading the lkml archives, I found that cli() disables only the interrupts,
> exceptions are allowed, so it makes sense that the SIGINT was delivered, but
> if thats the case, then how come the SIGINT was delivered from the Ctrl+C?
> Doesnt this mean that the SIGINT signal was generated as a result of the
> keyboard interrupt?
> 
> I know I am missing something here, would appreciate if someone could point
> me in the right direction.

Return from sys to user space is done by executing a "iret"
instruction.  In addition to picking up the return address
and segment it pick up EFLAGS which will contain the
interrupt flag as it was saved when the system call was
made...
> 
> Regards,
> Irfan Hamid.
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

-- 
George Anzinger   george@mvista.com
High-res-timers: 
http://sourceforge.net/projects/high-res-timers/
Real time sched:  http://sourceforge.net/projects/rtsched/
Preemption patch:
http://www.kernel.org/pub/linux/kernel/people/rml

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

* Re: cli()/sti() clarification
  2002-07-18  6:27 cli()/sti() clarification irfan_hamid
  2002-07-18  6:58 ` george anzinger
@ 2002-07-18  9:33 ` Kasper Dupont
  2002-07-18 14:52 ` Marco Colombo
  2 siblings, 0 replies; 5+ messages in thread
From: Kasper Dupont @ 2002-07-18  9:33 UTC (permalink / raw)
  To: irfan_hamid; +Cc: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1093 bytes --]

irfan_hamid@softhome.net wrote:
> 
> Hi,
> 
> I added two system calls, blockintr() and unblockintr() to give cli()/sti()
> control to userland programs (yes I know its not advisable) but I only want
> to do it as a test. My test program looks like this:
> 
>         blockintr();
>         /* Some long calculations */
>         unblockintr();
> 
> The problem is that if I press Ctrl+C during the calculation, the program
> terminates. So I checked the _syscallN() and __syscall_return() macros to
> see if they explicitly call sti() before returning to userspace, but they
> dont.

The flag register is saved on the stack and restored by the INT 0x80
and IRET instructions. You would want to change the interrupt flag
in that register. Here is an ugly piece of code that is known to
work on some kernel version, I don't remember which.

Another approach would be to use ioperm to get access to the IRQ
controller, and block interrupts there.

-- 
Kasper Dupont -- der bruger for meget tid på usenet.
For sending spam use mailto:razrep@daimi.au.dk
or mailto:mcxumhvenwblvtl@skrammel.yaboo.dk

[-- Attachment #2: cli.c --]
[-- Type: text/plain, Size: 1447 bytes --]

/* This piece of code is ugly and inefficient. */

#include <stdlib.h>
#include <linux/module.h>
#include <asm/current.h>
#include "cli.h"

struct my_module {
  struct module m;
  char name[64];
  unsigned long jmp;
  unsigned long delta;
} my_module;

static int do_cli()
{
	(*(unsigned long*)(((char*)current)+0x1FF4)) &= ~0x200;
	return 0;
}

static int do_sti()
{
        (*(unsigned long*)(((char*)current)+0x1FF4)) |= 0x200;
        return 0;
}

void init_struct(int (*func)(),struct my_module *dst, struct my_module *p)
{
  dst->m.size_of_struct = sizeof(struct module);
  dst->m.next=NULL;
  dst->m.name=p->name;
  dst->m.size=sizeof(my_module);
  dst->m.flags=0;
  dst->m.nsyms=0;
  dst->m.ndeps=0;
  dst->m.syms=NULL;
  dst->m.deps=NULL;
  dst->m.refs=NULL;
  dst->m.init=(void*)&(p->jmp);
  dst->m.cleanup=NULL;
  dst->m.ex_table_start=NULL;
  dst->m.ex_table_end=NULL;
  dst->m.persist_start=NULL;
  dst->m.persist_end=NULL;
  dst->m.can_unload=NULL;
  sprintf(dst->name,"hack_%d_hack",getpid());
  dst->jmp=0xE9909090;
  dst->delta=(unsigned long)func-(unsigned long)(p+1);
}

static void kernel_call(int (*func)())
{
  struct my_module my_module;
  init_struct(func,&my_module,&my_module);
  init_struct(func,&my_module,(void*)create_module(my_module.name,my_module.m.size));
  init_module(my_module.name,&my_module.m);
  delete_module(my_module.name);
}

void cli()
{
  kernel_call(do_cli);
}

void sti()
{
  kernel_call(do_sti);
}

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

* Re: cli()/sti() clarification
  2002-07-18  6:27 cli()/sti() clarification irfan_hamid
  2002-07-18  6:58 ` george anzinger
  2002-07-18  9:33 ` Kasper Dupont
@ 2002-07-18 14:52 ` Marco Colombo
  2 siblings, 0 replies; 5+ messages in thread
From: Marco Colombo @ 2002-07-18 14:52 UTC (permalink / raw)
  To: irfan_hamid; +Cc: linux-kernel

On Thu, 18 Jul 2002 irfan_hamid@softhome.net wrote:

> Hi, 
> 
> I added two system calls, blockintr() and unblockintr() to give cli()/sti() 
> control to userland programs (yes I know its not advisable) but I only want 
> to do it as a test. My test program looks like this: 
> 
> 	blockintr();
> 	/* Some long calculations */
> 	unblockintr(); 

May I ask what are you trying to achieve?

.TM.


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

* Re: cli()/sti() clarification
@ 2002-07-22  7:20 irfan_hamid
  0 siblings, 0 replies; 5+ messages in thread
From: irfan_hamid @ 2002-07-22  7:20 UTC (permalink / raw)
  To: linux-kernel

Thankyou all for explaining the system call internals to me. Feel like an 
idiot now :) 

Marco Colombo: As for what I am trying to achieve, it is simply this. I need 
to do plot extraction from radar raw returns. The scan time for one 
revolution is 2.44 secs. I need to extract plots for each pi/2 radians in 
less than 2.44/4 secs. I have already optimized the extraction algo upto 
SSE2 in assembly and am running the process as realtime, but it just cant 
seem to cut it. So now I am going to try and block interrupts while I do the 
DSP. 

Regards,
Irfan Hamid.

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

end of thread, other threads:[~2002-07-22  7:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-07-18  6:27 cli()/sti() clarification irfan_hamid
2002-07-18  6:58 ` george anzinger
2002-07-18  9:33 ` Kasper Dupont
2002-07-18 14:52 ` Marco Colombo
  -- strict thread matches above, loose matches on Subject: below --
2002-07-22  7:20 irfan_hamid

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