Why is the orig_eax member included in sys/user.h‘s struct user_regs_struct?
Why is the orig_eax member included in sys/user.h ‘s struct user_regs_struct ?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because it was in
struct pt_regs, which is …. http://tomoyo.sourceforge.jp/cgi-bin/lxr/source/arch/x86/include/asm/user_32.h#L77So, a lot of user-space utilities expect an
orig_eaxfield here, so it is included inuser_regs_structtoo (to be compatible with older debuggers andptracers)Next question is “Why is the
orig_eaxmember included instruct pt_regs?”.It was added in linux 0.95 http://lxr.linux.no/#linux-old+v0.95/include/sys/ptrace.h#L44.
I suggest this was done after some other unix with
pt_regsstruct. Comment in 0.95 saysSo, the place of
orig_eaxis defined by syscall interface. Here it is http://lxr.linux.no/#linux-old+v0.95/kernel/sys_call.sWhy do we need to save old
eaxtwice? Becauseeaxwill be used for the return value of syscall (same file, a bit below):Ptrace needs to be able to read both all registers state before syscall and the return value of syscall; but the return value is written to
%eax. Then originaleax, used before syscall will be lost. To save it, there is aorig_eaxfield.UPDATE: Thanks to R.. and great LXR, I did a full search of
orig_eaxin linux 0.95.It is used not only in ptrace, but also in do_signal when restarting a syscall (if there is a syscall, ended with
ERESTARTSYS)UPDATE2: Linus said something interesting about it:
UPDATE3:
ptracer app (debugger) can changeorig_eaxto change system call number to be called: http://lkml.org/lkml/1999/10/30/82 (in some versions of kernel, is was EIO to change in ptrace an ORIG_EAX)