Andrew login ID Full Name Recitation Section CS 15 213 Fall 2008 Final Exam Friday December 12 2008 Instructions Make sure that your exam is not missing any sheets then write your full name Andrew login ID and recitation section A H on the front The exam has a maximum score of 106 points This exam is OPEN BOOK You may use any books or notes you like No calculators or other electronic devices are allowed 1 18 2 12 3 10 4 8 5 6 6 7 7 8 8 12 9 8 10 8 11 9 Total 106 Page 1 of 21 Problem 1 18 points For the following questions indicate whether each of the statements following them is true or false 1 The register rax currently has value 0 Which of the following statements are true T F Executing movq rax rcx will cause a segmentation fault T F Executing leaq rax rcx will cause a segmentation fault T F Executing movq rax rcx will cause a segmentation fault T F Executing addq 8 rsp will increase the stack allocation by 8 bytes 2 After a process calls fork which of the following are shared by it and the new child process By shared we mean that an update by one process could affect the behavior of the other T F All file table entries corresponding to files open in the parent before the call to fork T F New file table entries corresponding to files open d by the parent after the fork T F New file table entries corresponding to files open d by the child after the fork T F All of virtual memory T F The stack T F All register contents T F All sockets with connections established before the fork 3 Consider the following global variable declaration char str 80 Which of the following outcomes should be of significant concern if you write a program that calls gets str T F There could be a stack overflow leading to execution of malicious code T F There could be a buffer overflow that modifies other global variables T F There could be a SEGFAULT T F You might get a bad score if you did this for your 15 213 lab Page 2 of 21 4 Consider the following structure definition struct data short things 3 unsigned int doodad char stuff 8 Which of the following holds for an x86 64 machine The size of struct data is 18 The size of struct data is 20 The size of struct data is 24 Network code should use htons for each entry in things that is sent to another computer T F Network code should use htons for data in stuff that is sent to another computer T F T F T F T F 5 When you run two programs on the same Linux machine why do you not have to worry about them using the same physical memory T F T F The programmers knew to avoid using the same addresses and were careful not to do so The virtual addresses used by the running programs are translated to non overlapping physical addresses T F Only one program really runs at a time and the physical memory is saved restored as part of each context switch 6 Suppose we compile and run the following code on a processor where integer multiply has a 10 clock cycle latency and a 2 clock cycle issue time That is although a single product computation requires 10 clock cycles the multiplier can start a new computation every 2 clock cycles int prod for i prod a i 1 0 i n i 2 prod a i 1 Line P Which of the following statements hold for this code T F T F T F T F T F It will properly compute the product for any array a of length n It will have a CPE of 10 It will have a CPE of 2 Changing Line P to be a i a i 1 will change the CPE Changing Line P to be a i a i 1 could change the computed result Page 3 of 21 Problem 2 12 points We are running programs on a machine where values of type int have a 32 bit two s complement representation and values of type long have a 64 bit two s complement representation Right shifts are performed arithmetically Values of type double use the 64 bit IEEE format We generate arbitrary integer values x and y and convert them to values of type long and double as follows Create some arbitrary values int x random int y random Convert to long long lx long x long ly long y Convert to double double dx double x double dy double y For each of the following C expressions you are to indicate whether or not the expression always yields 1 If it can yield 0 give values for the arguments that make the expression evaluate to 0 Hint Note that some properties may hold for dx and dy that do not hold for arbitrary double precision floating point numbers and similarly lx and ly are not arbitrary long s Expression Always 1 Arguments if could yield 0 x x 1 x 2 x x 3 x x 3 x 1 x 2 lx y x ly x y lx ly ly 0 lx ly ly lx dx dy double x y x y dx dy Page 4 of 21 Problem 3 10 points Consider the following x86 64 assembly code On entry edi val rsi K func pushq r12 movl edi r12d pushq rbp movq rsi rbp pushq rbx xorl ebx ebx jmp L8 L4 addl 1 ebx addq 8 rbp cmpl 15213 ebx je L12 L8 cmpq 0 rbp js L4 movl 8 edi call malloc testq rax rax movq rax rcx je L5 testl r12d r12d Move with sign extend movslq ebx rdx je L13 L7 movq rdx rax L5 popq rbx popq rbp movq rcx rax popq r12 ret L13 movq rbp rdx jmp L7 L12 popq rbx xorl ecx ecx popq rbp movq rcx rax popq r12 ret Page 5 of 21 Fill in the blanks of the corresponding C function func int val K int i j for i 0 i 15213 i if j if j return j return NULL Page 6 of 21 Problem 4 8 points The problem requires understanding how C code accessing structures unions and arrays is compiled Assume the x86 64 conventions for data sizes and alignments include def h typedef struct short x A 5 double y float f double d str Unknown constant A typedef union double t str S int array A 5 uni void setVal str p uni u double val p y u t val You do not have a copy of the file def h in which constants A and B are defined but you have the following x86 64 assembly code for the function setVal setVal rdi p rsi u movq 72 rdi rax movq rax rsi ret Based on this code determine the values of …
View Full Document