From: Kasper Dupont <kasperd@daimi.au.dk>
To: irfan_hamid@softhome.net
Cc: linux-kernel@vger.kernel.org
Subject: Re: cli()/sti() clarification
Date: Thu, 18 Jul 2002 11:33:23 +0200 [thread overview]
Message-ID: <3D368B63.E2CFB52@daimi.au.dk> (raw)
In-Reply-To: courier.3D365FDC.0000712F@softhome.net
[-- 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);
}
next prev parent reply other threads:[~2002-07-18 9:30 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-07-18 6:27 cli()/sti() clarification irfan_hamid
2002-07-18 6:58 ` george anzinger
2002-07-18 9:33 ` Kasper Dupont [this message]
2002-07-18 14:52 ` Marco Colombo
-- strict thread matches above, loose matches on Subject: below --
2002-07-22 7:20 irfan_hamid
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3D368B63.E2CFB52@daimi.au.dk \
--to=kasperd@daimi.au.dk \
--cc=irfan_hamid@softhome.net \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox