[lkml]   [1997]   [Jul]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
SubjectRe: Let me start over - "FPU & ptrace function"

On Fri, 18 Jul 1997, Stephen Polkowski wrote:

> Hi all,
> First hack attempt:
> Insert this code starting at line 394 in ptrace.c

You don't want to do it like that (the patchs, the not code ;). You want
to use the program diff, it will produce patches for you, like so:

- ------8<------Cut Here------8<------
- --- linux/arch/i386/kernel/ptrace.c.orig Fri Jul 18 19:16:25 1997
+++ linux/arch/i386/kernel/ptrace.c Fri Jul 18 19:20:44 1997
@@ -392,6 +392,22 @@
child->p_pptr = current;
+ if (hard_math) { /* for now skip fpu if using 387 emulator */
+ addr &= -4; /* align */
+ if (addr == &dummy->u_fpvalid) {
+ tmp = 1;
+ }
+ if (addr >= (long) &dummy->i387.cwd &&
+ addr <= (long) &dummy->i387.st_space[19]) {
+ __asm__("fnop"); /* forced dump of fpu state */
+ addr -= (long) &dummy->i387.cwd;
+ addr += (long) &child->tss.i387.hard.cwd;
+ tmp = *((long*) addr);
+ }
+ }
send_sig(SIGSTOP, child, 1);
ret = 0;
goto out;
- ------8<------Cut Here------8<------
To produce this patch I did this:
cp linux/arch/i386/kernel/ptrace.c linux/arch/i386/kernel/ptrace.c.orig
pico linux/arch/i386/kernel/ptrace.c
diff -u linux/arch/i386/kernel/ptrace.c.orig linux/arch/i386/kernel/ptrace.c >fpu.ptrace.diff
The -u produces a unified context diff (you can use --unified if you
wish). diff does work on directory trees too, and if you make many
changes this would be a more reasonable option. You can use the
- --recursive option on a pair of source trees (Linus produces patches like
this), like this (I have a Symlink linux -> linux-2.1.45):

cp -rd linux-2.1.45 linux-2.1.45.saved
<edit linux-2.1.45 tree>
diff -u --recursive linux linux-2.1.45.saved
This sould produce the same patch as before (touch wood ;). If you create
new files you have to also use the --new-file option.

To apply a patch all you need do is "patch -p0 <some.patch", "cat
some.patch |patch -p0", or "cat some.patch.gz |gzip -dc |patch -p0". The
- -p0 means don't strip anything from the path in the patch, -p1 would mean
strip the first bit of the path (ie for "/usr/src/linux/..." you would get
"usr/src/linux/..."; "linux/drivers/..." would be "drivers/...") and so
on. You can add -E which means remove emptied files.

> I haven't had a chance to compile this yet. Perhaps
> I'll get to it during my lunch break. I have three questions about
> this code. First, will the "hard_math" link (I hope so).

Should do, can't see why not.

> Second,
> is there a way in the kernel to tell if the child has used the
> fpu or not.

In the kernel it should be child->user_math, (child is just like current,
except that it's the child's task struct ;) you can find it's whole
structure in linux/include/linux/sched.h, and there is lots).

> For now, I'm just assuming its always used, and I return
> u_fpvalid as being true.

If it's not used, you proberbly want to return the initalised state rather
than the real state, if the child wasn't the last process that used the
fpu, then the fpu state won't be that of the child (processes that havent
used the fpu wont change it's state).

> Lastly, is there a better way to force a
> fpu dump other than executing a fpu instruction in the current process.
> I'm only adding code to read the state. I could
> add code to write to the fpu state, but I don't want to risk putting a
> security hole into the kernel. Thanks for your comments.
> Regards,
> Steve

PS most of this info gleaned with the use of grep ;)
- --
PGP Pub key ID: 1024/30AF2D69
On-line, adj.: FP: FC 4E 41 9E 64 C3 AB 28 A3 5A 57 F8 CC D9 A7 B8
The idea that a human being should always be accessible to a computer.

Version: 2.6.3i
Charset: noconv
Comment: Probably (spelt

 \ /
  Last update: 2005-03-22 13:39    [W:0.050 / U:11.560 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site