我试图实现一个自定义软中断处理程序,它与用于实现linux系统调用的默认0x80中断不同。
我已经在0x7F处安装了中断处理程序并发出" int 0x7F"从用户空间成功运行我的处理程序。因为我需要读取一个文件,这是一个奇怪的事情,但无论如何,我需要在处理程序中调用filp_open,这给了我内核日志中的一般保护错误:
[ 3853.779411] general protection fault: 0000 [#12] SMP
[ 3853.779429] Modules linked in: callback_mod(OF) nls_utf8 isofs vesafb(F) vboxsf(OF) snd_intel8x0 snd_ac97_codec ac97_bus snd_pcm snd_seq_midi snd_rawmidi snd_seq_midi_event snd_seq snd_timer snd_seq_device snd microcode vboxvideo(OF) joydev drm rfcomm bnep bluetooth parport_pc psmouse serio_raw ppdev soundcore snd_page_alloc i2c_piix4 mac_hid vboxguest(OF) lp parport hid_generic usbhid hid ahci libahci e1000 [last unloaded: callback_mod]
[ 3853.779449] CPU: 0 PID: 6349 Comm: test Tainted: GF D O 3.11.0-15-generic #25~precise1-Ubuntu
[ 3853.779451] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006
[ 3853.779453] task: db0b4060 ti: dbcca000 task.ti: dbcca000
[ 3853.779454] EIP: 0060:[<c1176bc4>] EFLAGS: 00010082 CPU: 0
[ 3853.779488] EIP is at get_empty_filp+0x14/0x1d0
[ 3853.779489] EAX: ffffff9c EBX: ffffff9c ECX: dbccbf38 EDX: dbccbfc4
[ 3853.779490] ESI: 00000000 EDI: dbccbfc4 EBP: dbccbec8 ESP: dbccbea8
[ 3853.779492] DS: 007b ES: 007b FS: 0000 GS: 00e0 SS: 0068
[ 3853.779496] CR0: 8005003b CR2: b7563f80 CR3: 1bdab000 CR4: 000006f0
[ 3853.779500] Stack:
[ 3853.779501] dbda8b18 dbccbeec c1144c54 dbdbedd0 0000002d ffffff9c dbccbf38 dbccbfc4
[ 3853.779505] dbccbf24 c1182678 c8b3dc40 b7563f80 00000000 dc05c660 00000000 dfbf0000
[ 3853.779508] dbdbedd0 dbccbf28 c1145b5a dbda8b18 dbdbedd0 dbccbfc4 dbccbf18 00000000
[ 3853.779512] Call Trace:
[ 3853.779516] [<c1144c54>] ? handle_pte_fault+0x94/0x2b0
[ 3853.779519] [<c1182678>] path_openat+0x28/0x3f0
[ 3853.779521] [<c1145b5a>] ? handle_mm_fault+0x1fa/0x2d0
[ 3853.779524] [<c11834c5>] do_filp_open+0x35/0x80
[ 3853.779526] [<c1176b3d>] ? ____fput+0xd/0x10
[ 3853.779529] [<c1070d46>] ? task_work_run+0xb6/0xd0
[ 3853.779532] [<c117463b>] file_open_name+0xeb/0x150
[ 3853.779534] [<c11746ce>] filp_open+0x2e/0x30
[ 3853.779537] [<e098703e>] my_intercept+0x2e/0x50 [callback_mod]
[ 3853.779538] Code: ee ff 8b 5d f4 8b 75 f8 8b 7d fc 89 ec 5d c3 90 8d b4 26 00 00 00 00 55 89 e5 57 56 53 83 ec 14 66 66 66 66 90 8b 35 08 a4 9e c1 <64> a1 d0 5f b5 c1 8b b8 00 03 00 00 a1 04 a4 9e c1 89 45 ec 89
[ 3853.779559] EIP: [<c1176bc4>] get_empty_filp+0x14/0x1d0 SS:ESP 0068:dbccbea8
[ 3853.779563] ---[ end trace c6286c432f82c27f ]---
这是我的经纪人:
asmlinkage void isr0x0E( void );
asm(" .text ");
asm(" .type isr0x0E, @function ");
asm("isr0x0E: ");
asm(" call my_intercept ");
asm(" iret ");
这是上面提到的函数:
static void my_intercept(void)
{
char* f = "/tmp/test.txt";
struct file* fs = file_open(f, O_RDWR | O_APPEND | O_CREAT, 0644);
file_close(fs);
}
在上面,file_open和file_close分别调用filp_open和filp_close。
另外,如果我在my_intercept中调用printk,它也会给我一个GPF。
我应该在中断处理程序中使用这些函数吗?我错过了什么吗?