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->
Given code:
#define _XOPEN_SOURCE 600 #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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started