Question: Question-> Given code: #define _XOPEN_SOURCE 600 #include #include #include #define MEM 64000 #include #include #include static ucontext_t ctx; static void conjecture(int len, void* options, int

Question->

Question-> Given code: #define _XOPEN_SOURCE 600 #include #include #include #define MEM 64000

Given code:

#define _XOPEN_SOURCE 600 #include #include #include #define MEM 64000 #include #include #include

static ucontext_t ctx;

static void conjecture(int len, void* options, int sz, void fn(void*)); // Create context and start traversal

void assert(bool b); // Restore context if condition fails

bool is_prime(int x) { for(int i = 2; i

bool is_lt_40(int x) { return x

int nested(int i) { assert(!is_prime(i)); return i * i; }

void app(void* c) { int* i = (int*)c; // printf("Trying %d ", *i); assert(is_lt_40(*i)); int x = nested(*i); printf("%d ", x); }

int main(void) { int mynums[] = {11, 23, 42, 39, 55}; // We have to ensure that conjecture lives in the bottom of the call stack. // If the conjecture frame is popped, we will never be able to rollback to it. conjecture(5, (void*) mynums, sizeof(int), &app); }

We would like to save and restore "contexts". The idea is to store a context (i.e, CPU registers) inside the conjecture method and when an assertion fails, restore the stored context and continue the process. Implement the following functions in the template provided: 1. static void conjecture(int len, void* options, int sz, void fn(void*)); 2. void assert(bool b); About the code: The main function has an array of numbers. Now it checks if the given number is less than 40 and not a prime number and returns the square of that number Example: Input {11,23,49,85,25} Output 625 Instructions: You only have to modify conjecture() and assert() functions and context switching is to be done using make context only Use of loops will result in zero marks

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!