






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







Please answer concisely. If you find yourself writing more than a sentence or two, your answer is probably wrong.
one disadvantage of developing and using such a testing strategy when writing new kernel code, relative to doing all testing of the new code directly in the kernel.
and how is it used?
void string copy(char *dest, const char *src);
The string copy() function shall copy the string pointed to by src into an array pointed to by dest.
Explain what is wrong with the following piece of code which is using the string copy() function and how it may affect a program’s run:
void foo() { char to_string[5]; string_copy(to_string, "this is a test."); }
The following x86 assembly code compares the some value field in a structure against the immediate value 16. The offset constants of the structure fields are defined in the data section for your reference. Assume that my list head is the head of the list and is defined.
.data
LOCATION = 0 SOME_VALUE = 2 ON_CHAR = 4 COUNTDOWN = 5 NEXT = 7
.text
movl my_list_head, %edx test_loop: cmpl $0, %edx je test_loop_end cmpl 16, SOME_VALUE(%edx) je found_value movl NEXT(%edx), %edx jmp test_loop
found_value:
test_loop_end:
Please indicate two bugs in this code and a required fix for each:
.long mp1 list head
sort by location: pushl %ebp movl %esp,$ebp pushl %ebx pushl %esi pushl %edi movl 8(%ebp),%eax movl mp1 list head,%edx imull $STRUCT SIZE,%eax pushl %eax call mp1 malloc addl $4,%esp cmpl $0,%eax je MALLOC FAIL movl $0,%ecx CHECK NEXT: cmpl $0,%edx je DONE INSERTING
Insert call to add to sorted array here.
incl %ecx movl NEXT(%edx),%edx jmp CHECK NEXT DONE INSERTING: popl %edi popl %esi popl %ebx leave ret
MALLOC FAIL: pushl %eax call mp1 free addl $4,%esp movl $0,%eax jmp DONE INSERTING
Nick has implemented a new function called mp1 replace onoff that takes in the location, new character, new length, and onoff. This new function must follow the standard C calling conventions.
void mp1 replace onoff(int location, int onoff, long new character, long new length)
mp1 replace onoff uses only the registers %eax, %edi, %edx, and %esi throughout its execution.
Identify the mistakes involving calling conventions and the stack from these code snippets. The issues might be in either the calling code or the function. In the caller code, %eax contains the int for location, %ecx contains a boolean status zero extended word to long, %edi containes the new character zero extended byte to long, and%ebx contains new on length or off length zero extended word to long.
pushl %eax #push location pushl %ecx #push onoff pushl %edi #push new character pushl %ebx #push new length call mp1 replace onof addl $8,%esp popl %ecx popl %eax imull $2, %eax #prep location for mp1 poke ...
mp1 replace onoff: pushl %ebp movl %esp,%ebp pushl %edi movl 12(%ebp),%esi movl 16(%ebp),%eax movl 20(%ebp),%edi movl 24(%ebp),%edx ... #Find and replace the mp1 blink struct node #referenced by location with the corresponding #on char or off char and on length or off length #based on onoff ... movl %edx,%ebx #move in the return value popl %edi leave ret
In some instances, you might want to implement a key based container using a simple linked list. It will be used as a central registry that will allow users to store and retrieve values quickly. Write the retrieval function that looks up a key and returns the corresponding registry value. Follow proper x86 calling conventions.
typedef struct registry node { int key; int value; struct registry node* next; } registry node;
registry node* registry head; #the head of a NULL terminated list
lookup key: