Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6069659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:50:46+00:00 2026-05-23T09:50:46+00:00

Why is the orig_eax member included in sys/user.h ‘s struct user_regs_struct ?

  • 0

Why is the orig_eax member included in sys/user.h‘s struct user_regs_struct?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:50:46+00:00Added an answer on May 23, 2026 at 9:50 am

    Because it was in struct pt_regs, which is …. http://tomoyo.sourceforge.jp/cgi-bin/lxr/source/arch/x86/include/asm/user_32.h#L77

     73  * is still the layout used by user mode (the new
     74  * pt_regs doesn't have all registers as the kernel
     75  * doesn't use the extra segment registers)
    

    So, a lot of user-space utilities expect an orig_eax field here, so it is included in user_regs_struct too (to be compatible with older debuggers and ptracers)

    Next question is “Why is the orig_eax member included in struct 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_regs struct. Comment in 0.95 says

      29 * this struct defines the way the registers are stored on the 
      30 * stack during a system call.
    

    So, the place of orig_eax is defined by syscall interface. Here it is http://lxr.linux.no/#linux-old+v0.95/kernel/sys_call.s

      17 * Stack layout in 'ret_from_system_call':
      18 *      ptrace needs to have all regs on the stack.
      19 *      if the order here is changed, it needs to be 
      20 *      updated in fork.c:copy_process, signal.c:do_signal,
      21 *      ptrace.c ptrace.h
      22 *
      23 *       0(%esp) - %ebx
     ...
      29 *      18(%esp) - %eax
     ...
      34 *      2C(%esp) - orig_eax
    

    Why do we need to save old eax twice? Because eax will be used for the return value of syscall (same file, a bit below):

      96_system_call:
      97        cld
      98        pushl %eax              # save orig_eax
      99        push %gs
    ...
     102        push %ds
     103        pushl %eax              # save eax.  The return value will be put here.
     104        pushl %ebp
    ...
     117        call _sys_call_table(,%eax,4)
    

    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 original eax, used before syscall will be lost. To save it, there is a orig_eax field.

    UPDATE: Thanks to R.. and great LXR, I did a full search of orig_eax in 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)

     158                        *(&eax) = orig_eax;
    

    UPDATE2: Linus said something interesting about it:

    It’s important that ORIG_EAX be set to some value that is not a
    valid system call number, so that the system call restart logic (see the
    signal handling code) doesn’t trigger.

    UPDATE3: ptracer app (debugger) can change orig_eax to 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)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a program which I can run like this: py2py.py < orig.py >
I was studying the Kernel Architecture and its programming to get the idea about
I'm trying to compare data from two sources. ORIG Kick-Ass: Music From The Motion
If I have an object of type MyBull and a List<MyBull> orig : //
I have a code like <a href='javascript:showImage()'><img src='/public/visit_images/img1.jpg' width=100 height=100></img></a> <div class='orig_image' style=position:absolute; width:200px;
Does anyone know of a way to get the free disk space of a
I have created a helper that requires some parameters and should upload a file,
I've got a problem making alpha PNGs with PHP GD. I don't have imageMagik
I have the following method I came across in a code review. Inside the
I'm trying to check the value of extracted data against a csv I already

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.