2022/2/6 下午10:13 COMP 3430 - Operating Systems file:///C:/Users/12042/Desktop/assignment.html 1/11 COMP 3430 - Operating Systems Assignment 1 Franklin Bristow and Robert Guderian Winter 2022 Description Question 1: ELF What to print ELF Header Program Headers Section Headers Running Checking your output 32-bit binaries Evaluation Question 2: Herding Processes and Threads Process herder Thread herder Notes Evaluation Submitting your assignment General Advice Description In assignment 1, we are looking for you to be able to demonstrate a few different things: Reading and interpreting binary files (ELF). Managing processes and communication with signals. Managing threads and communication through shared memory. Assignment 1 is due on Friday, February 18th, 2022 at 4:30pm CDT. 2022/2/6 下午10:13 COMP 3430 - Operating Systems file:///C:/Users/12042/Desktop/assignment.html 2/11 Submissions that violate any of the following will not be evaluated (i.e., you will receive a score of 0 for the assignment): All solutions must be written in C. No other languages are accepted. All solutions must include a working Makefile. Forget how to make a Makefile? Never knew how to make a Makefile? Thankfully, you can go to https://makefiletutorial.com and find some very easy to use basic examples. Your Makefile should contain a clean rule. When is run in your directory, all the temporary files, including the executable should be removed (e.g., rm -f my_prog). All solutions must be compiled by issuing the command make in the directory containing the Makefile. No other build commands are acceptable, even if documented in the README.md. All solutions must include a Markdown-formatted README.md file that minimally describes how to run your submission. Forget how to make a README.md? Never knew how to make README.md? Thankfully, you can go to https://readme.so/ and build a nice, Markdown-formatted README.md with a nice preview and some handy buttons to help you build it. All solutions must run to successful completion. Premature termination for any reason (no obvious output, Segmentation Fault, Bus Error, etc.) is considered to be a solution implementation that does not run. For programs that are expected to terminate on their own (without your intervention), programs should complete in a reasonable amount of time (e.g., < 30 seconds). All solutions must compile. Code that does not compile will not be evaluated. Programs must produce no errors when compiled with the flags Note that -Werror prevents your code from being compiled when warnings are present. make clean -Wall -Wpedantic -Wextra -Werror 2022/2/6 下午10:13 COMP 3430 - Operating Systems file:///C:/Users/12042/Desktop/assignment.html 3/11 If these flags are not in your Makefile, your submission will be treated as though it does not compile. Your code must compile and run on a machine on aviary.cs.umanitoba.ca. No late submissions will be accepted. The assignment deadline is enforced electronically. Submissions will not be accepted by e-mail. Reminder: All submitted code will be evaluated using an automated similarity testing tool, alongside commonly available online solutions for problems. Question 1: ELF Some ELFs don’t make toys, Public Domain One of the first things than an operating system does when launching a new process is to read the program into memory. Some operating systems (including Linux) use ELF formatted binaries to represent compiled programs. Using one of the two strategies for reading binary files described in the supplementary video (and in lab 1), write a program that reads an ELF formatted file and writes out some information about the program. Your program should work for both 32-bit and 64-bit ELF files. What to print 2022/2/6 下午10:13 COMP 3430 - Operating Systems file:///C:/Users/12042/Desktop/assignment.html 4/11 ELF Header From the ELF header, your program should print out: 1. Whether the program is 32-bit or 64-bit. 2. The endianness of the file. 3. The target operating system ABI. 4. The object file type. 5. The instruction set architecture. 6. The address of the entry point from where the process starts executing. 7. The address of the program header table in the file. 8. The size of an entry and the number of entries in the program header table. 9. The size of an entry and the number of entries in the section header table. 10. The entry in the section headers that is the string table. ELF header sample output ELF header: * 64-bit * little endian * compiled for 0x00 (operating system) * has type 0x02 * compiled for 0x3e (isa) * entry point address 0x00000000004010c0 * program header table starts at 0x0000000000000040 * there are 11 program headers, each is 56 bytes * there are 33 section headers, each is 64 bytes * the section header string table is 32 Note: This is sample output to show you the expected format. This doesn’t necessarily show the actual outputs you will get (outputs will change based on the file you’re reading). Program Headers For each program header, your program should print out: 1. The segment type. 2. The virtual address of the segment in memory. 3. The size in the file image of the program header. 4. The first (up to) 32 bytes of actual segment data, formatted as hexadecimal bytes. Your output should be 16 bytes wide, and 16-bit byte pairs (i.e., 2 × 8 bits) should be printed as little-endian to match the output of hexdump. 2022/2/6 下午10:13 COMP 3430 - Operating Systems file:///C:/Users/12042/Desktop/assignment.html 5/11 Program header sample output Program header #0: * segment type 0x00000006 * virtual address of segment 0x0000000000400040 * size in file 616 bytes * first up to 32 bytes starting at 0x0000000000000040: 06 00 00 00 04 00 00 00 40 00 00 00 00 00 00 00 40 00 40 00 00 00 00 00 40 00 40 00 00 00 00 00 Note: This is sample output to show you the expected format. This doesn’t necessarily show the actual outputs you will get (outputs will change based on the file you’re reading). Section Headers For each section header, your program should print out: 1. The name of the section. The ELF header specifies which section header is the string table section header (this is the last field in the ELF header). You can find the names for sections in the file at the offset specified by the section header that is the string table section. 2. The section header type. 3. The virtual address of the section in memory. 4. The size in the file image of the section header. 5. The first (up to) 32 bytes of actual section data, formatted as hexadecimal bytes. Your output should be 16 bytes wide, and 16-bit byte pairs (i.e., 2 × 8 bits) should be printed as little-endian to match the output of hexdump. Section header sample output Section header #23 * section name .data * type 0x01 * virtual address of section 0x0000000000400040 * size in file 617 bytes * first up to 32 bytes starting at 0x0000000000000040: 06 00 00 00 04 00 00 00 40 00 00 00 00 00 00 00 40 00 40 00 00 00 00 00 40 00 40 00 00 00 00 00 Note: This is sample output to show you the expected format. This doesn’t necessarily show the actual outputs you will get (outputs will change based on the file you’re reading). 2022/2/6 下午10:13 COMP 3430 - Operating Systems file:///C:/Users/12042/Desktop/assignment.html 6/11 Running Your program should accept the name of the ELF file it should read as its first (and only) argument. Your program should be able to read itself. Here are some examples of what you might want to check out: Checking your output Use the readelf command to help you check your output. The readelf command will let you print out different parts of the file (different headers) by passing different flags. To learn more about which flags print out which section, take a look at man readelf. To check that you’re printing the correct bytes for the different sections, you can use a tool like hexdump along with the -s option. To learn more about how to use hexdump, take a look at man hexdump. 32-bit binaries You are able to compile 32-bit binaries using gcc and clang by passing the -m32 option: Evaluation 5 points are awarded for code quality and design. “High quality” is defined as code that follows the standards and best practices that you can find in the “Standards and Best Practices” folder at the root of the Assignments section on UM Learn: Level Description