int main(int argc, char** argv, char** envp) { /* Declare ourself as a real time task */ struct sched_param param; param.sched_priority=MY_PRIORITY; CHECK_NOT_M1(sched_setscheduler(0, SCHED_FIFO, ¶m)); /* Lock memory */ CHECK_NOT_M1(mlockall(MCL_CURRENT|MCL_FUTURE)); /* Pre-fault our stack - this is useless because of mlock(2) */ pthread_stack_prefault(); /* get the current time */ struct timespec t; CHECK_NOT_M1(clock_gettime(CLOCK_MONOTONIC, &t)); /* start after one second */ timespec_add_nanos(&t, interval); while(true) { /* wait untill next shot */ CHECK_NOT_M1(clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &t, NULL)); /* do the stuff * ... * calculate next shot */ timespec_add_nanos(&t, interval); } return EXIT_SUCCESS; }
int main(int argc, char** argv, char** envp) { const char *str1="this is the content of str1"; const char *str2="this is the content of str2"; const char *str3="this is the content of str3"; proc_print_mmap_self_only(); printf("str1 is %p (%s)\n", str1, str1); printf("str2 is %p (%s)\n", str2, str2); printf("str3 is %p (%s)\n", str3, str3); // this does NOT generate a compile error! printf("doing assignment of one const char* to another\n"); str1=str3; printf("str1 is %p (%s)\n", str1, str1); printf("str2 is %p (%s)\n", str2, str2); printf("str3 is %p (%s)\n", str3, str3); // next line will cause the following compiled time error: // --- char_pointer.c:15: error: assignment of read-only location ‘*(str1 + 2u)’ // str1[2]='y'; // --> This means const strings cannot be changed directly // We should get a segmentation fault for trying the following... // The casting is neccessary to avoid a compilation error. printf("trying to change the value of the const char* buffer...\n"); if(signal_segfault_protect()) { char *p=(char *)str1; sprintf(p, "new content ovriding old"); } // So lets relax the constraints of the mmu char *p=(char *)str1; CHECK_NOT_M1(mprotect(page_adr((void*)p), getpagesize(), PROT_READ|PROT_WRITE|PROT_EXEC)); proc_print_mmap_self_only(); sprintf(p, "new content ovriding old"); printf("str1 is %p (%s)\n", str1, str1); printf("str2 is %p (%s)\n", str2, str2); printf("str3 is %p (%s)\n", str3, str3); return EXIT_SUCCESS; }