i386 ABI Implementation for x86_64 Kernel
Kedar Soparkar
Short description: The project aims to add the ability to execute 32-bit i386 DragonFly BSD binaries without recompilation on 64-bit x86_64 DragonFly BSD.
i386 ABI Implementation for x86_64 Kernel
Name: Kedar Soparkar
Email: kedarsoparkar@gmail.com
IRC nick: kedar (EFNet)
Timezone: IST (UTC+5:30)
Phone no.: +91-9892690654
Address: BITS Goa, India
Project Description:
The execution of 32-bit binaries in 64-bit environments is an oft-implemented feature, as is seen in several operating systems ranging from FreeBSD (pseudo-emulation) to Debian (ia32libs) to even Windows 7 (WOW64).
What I am aiming for is to modify the kernel so that 32-bit binaries execute without recompilation on 64-bit DragonFly BSD.
This will involve intercepting the operating system calls made by 32-bit applications and generating native 64-bit system calls, converting 32-bit data structures into 64-bit aligned structures etc.
The bulk of the work will involve writing system call wrappers for all the native system calls. Currently, there are 530 system calls, which can be roughly divided into the following classes:
Since, very little is to be done for the OBSOLete, UNIMPLemented & NODEFined syscalls, I've got my work cut out for me:
I intend to create wrappers for the other 347 system calls. However, there is an important distinction. 248 of these system calls accept only non-struct type arguments. I plan to write a Lex-Yacc based parser that will automatically generate the wrappers for these system calls. As for the rest, I plan to manually un-roll & re-roll the structures based on their layout.
As a starter task, I'm initially planning to wrap about 20 system calls which are used by simple binaries. I located these system calls using truss ./a.out >& out on a "hello world" executable & double-checked its type to be ELF32 i386. They occur across different classes, and their numbers are not included in the above estimates for sake of simplicity. These Starter class system calls are:
Since many changes are required to the source at different locations, the DFBSD Linux i386 ABI implementation and the FreeBSD i386 ABI in x86_64 kernel shall serve as non-binding guidelines for this project.
In a nutshell, the goals of this project are:
- To enable execution of 32-bit static & dynamically linked binaries on 64-bit kernel.
- To demonstrate the use of automatic syscall wrapping for non-struct syscalls.
- To create a test suite and test the implementation with it.
Project Timeline:
Pre - Project: (… – May 22)
- Explore the native ABI in the x86_64 system in detail.
- Explore the Linux i386 emulation layer in detail.
- Read the ELF specification to better understand header layout and dynamic linking.
- Read relevant parts of the AMD64 Architecture Programmer's Manual volumes 1 & 2.
Week 1: (May 23 – May 29)
- Explore all possible ways to identify 32-bit executables, choose the most appropriate one & use it in the ELF loader. Possible conditions to check are e_ident[EI_CLASS] == ELFCLASS32 or e_machine == EM_386.
- Identify & set appropriate control bits for 32-bit binaries to execute in 32-bit compatibility sub-mode of the AMD64 long mode while in userland.
Week 2: (May 30 – June 5)
- Identify all source files to be modified for coexistence of 32 & 64 bit ELF loaders. Possible files include src/sys/sys/elf_common.h & src/sys/sys/imgact_elf.h.
Week 3: (June 6 – June 12)
- Map the i386 trap frame to its x86_64 equivalent.
- Modify the platform dependent signal handling code in src/sys/platform/pc64/x86_64/ to conditionally handle 32-bit or 64-bit register frames, using cues from the src/sys/platform/pc32/i386/ implementation.
Week 4: (June 13 – June 19)
- Identify all files necessary to support a pseudo-emulation layer, akin to the Linux i386 ABI.
- Document all modifications undertaken up to this point.
Week 5: (June 20 – June 26)
- Figure out a way to use PT_INTERP to get the path to the dynamic loader using interp_path & emul_path.
- Figure out a way to maintain emulation environment of the current process upon exec calls using trap.c in src/sys/platform/pc64/x86_64/.
Week 6: (June 27 – July 3)
- Create skeletons for syscalls.master & syscalls.conf of the i386 emulation.
- Get the hang of rolling and unrolling structures for the system call wrappers.
- Wrap the Starter class system calls (19 in all).
- Create a list of regular expressions that will recognize all possible lexemes, that are part of system calls, which accept only non-struct data types. Ensure that all typedefs are covered.
Week 7: (July 4 – July 10)
- Prepare a context-free grammar for parsing such system calls and creating the necessary wrapper functions.
- Convert the specifications into a Lex-Yacc based parser.
- Use the parser to create wrappers for the non-struct system calls (248 in all).
Week 8: (July 11 – July 17, Mid-term evaluation)
- Create & test binaries making use of newly-wrapped system calls.
- Document & submit all the code for mid-term evaluation.
- Evaluate any shortcomings & realign schedule if necessary.
Week 9: (July 18 – July 24)
- Explore & decipher the struct data types that form part of the first 2 classes.
- Using this information, wrap all the remaining system calls of the Common & Vendor-specific classes (27 in all).
Week 10: (July 25 – July 31)
- Continue the wrapping process with the BSD, NetBSD & OpenBSD classes of system calls (20 in all).
- Create & test binaries making use of newly-wrapped system calls.
Week 11: (August 1 – August 7)
- Continue the wrapping process with the FreeBSD class of system calls (26 in all).
- Create & test binaries making use of newly-wrapped system calls.
Week 12: (August 8 – August 14)
- Round up the wrapping process with the DragonFly BSD class of system calls (25 in all).
- Create & test binaries making use of newly-wrapped system calls.
Week 13: (August 15 – August 21, Pencils down)
- Integrate all the test binaries used so far into an automated test suite.
- Test the building of a 32-bit world.
- Document all the work done & submit all the code for final submission.
Other Commitments:
I shall be appearing for the Graduate Record Examination (GRE) on May 30, 2011. I shall make up for any time lost, in advance, by starting the project immediately after my college term ends on May 12, 2011. I have no further commitments during the entire GSOC period.
Additional resources needed:
(None)
Links:
All relevant hyperlinks are included inline.
More About Me:
- Current Position: Junior Undergraduate, B.E. Computer Science, BITS Goa
- CGPA: 9.78 (Transcripts available on request)
- Batch Rank: 3
- Adept in C programming (Assignment submissions available on request)
- Knowledge of C++, x86 assembly language
- Professional Assistant for Computer Programming – I (Jan’10–Apr ‘10), Computer Programming – II (Aug’10–Nov’10), Microprocessor Programming & Interfacing (Jan’11– ) at BITS Goa
- Strong believer of watertight documentation & rigorous commenting
