Search Results

Search found 8 results on 1 pages for 'user353573'.

Page 1/1 | 1 

  • how to clear stack after stack overflow signal occur

    - by user353573
    In pthread, After reaching yellow zone in stack, signal handler stop the recursive function by making it return however, we can only continue to use extra area in yellow zone, how to clear the rubbish before the yellow zone in the thread stack ? (Copied from "answers"): #include <pthread.h> #include <stdio.h> #include <stdlib.h> #include <signal.h> #include <setjmp.h> #include <sys/mman.h> #include <unistd.h> #include <assert.h> #include <sys/resource.h> #define ALT_STACK_SIZE (64*1024) #define YELLOW_ZONE_PAGES (1) typedef struct { size_t stack_size; char* stack_pointer; char* red_zone_boundary; char* yellow_zone_boundary; sigjmp_buf return_point; size_t red_zone_size; } ThreadInfo; static pthread_key_t thread_info_key; static struct sigaction newAct, oldAct; bool gofromyellow = false; int call_times = 0; static void main_routine(){ // make it overflow if(gofromyellow == true) { printf("return from yellow zone, called %d times\n", call_times); return; } else { call_times = call_times + 1; main_routine(); gofromyellow = true; } } // red zone management static void stackoverflow_routine(){ fprintf(stderr, "stack overflow error.\n"); fflush(stderr); } // yellow zone management static void yellow_zone_hook(){ fprintf(stderr, "exceed yellow zone.\n"); fflush(stderr); } static int get_stack_info(void** stackaddr, size_t* stacksize){ int ret = -1; pthread_attr_t attr; pthread_attr_init(&attr); if(pthread_getattr_np(pthread_self(), &attr) == 0){ ret = pthread_attr_getstack(&attr, stackaddr, stacksize); } pthread_attr_destroy(&attr); return ret; } static int is_in_stack(const ThreadInfo* tinfo, char* pointer){ return (tinfo->stack_pointer <= pointer) && (pointer < tinfo->stack_pointer + tinfo->stack_size); } static int is_in_red_zone(const ThreadInfo* tinfo, char* pointer){ if(tinfo->red_zone_boundary){ return (tinfo->stack_pointer <= pointer) && (pointer < tinfo->red_zone_boundary); } } static int is_in_yellow_zone(const ThreadInfo* tinfo, char* pointer){ if(tinfo->yellow_zone_boundary){ return (tinfo->red_zone_boundary <= pointer) && (pointer < tinfo->yellow_zone_boundary); } } static void set_yellow_zone(ThreadInfo* tinfo){ int pagesize = sysconf(_SC_PAGE_SIZE); assert(pagesize > 0); tinfo->yellow_zone_boundary = tinfo->red_zone_boundary + pagesize * YELLOW_ZONE_PAGES; mprotect(tinfo->red_zone_boundary, pagesize * YELLOW_ZONE_PAGES, PROT_NONE); } static void reset_yellow_zone(ThreadInfo* tinfo){ size_t pagesize = tinfo->yellow_zone_boundary - tinfo->red_zone_boundary; if(mmap(tinfo->red_zone_boundary, pagesize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0) == 0){ perror("mmap failed"), exit(1); } mprotect(tinfo->red_zone_boundary, pagesize, PROT_READ | PROT_WRITE); tinfo->yellow_zone_boundary = 0; } static void signal_handler(int sig, siginfo_t* sig_info, void* sig_data){ if(sig == SIGSEGV){ ThreadInfo* tinfo = (ThreadInfo*) pthread_getspecific(thread_info_key); char* fault_address = (char*) sig_info->si_addr; if(is_in_stack(tinfo, fault_address)){ if(is_in_red_zone(tinfo, fault_address)){ siglongjmp(tinfo->return_point, 1); }else if(is_in_yellow_zone(tinfo, fault_address)){ reset_yellow_zone(tinfo); yellow_zone_hook(); gofromyellow = true; return; } else { //inside stack not related overflow SEGV happen } } } } static void register_application_info(){ pthread_key_create(&thread_info_key, NULL); sigemptyset(&newAct.sa_mask); sigaddset(&newAct.sa_mask, SIGSEGV); newAct.sa_sigaction = signal_handler; newAct.sa_flags = SA_SIGINFO | SA_RESTART | SA_ONSTACK; sigaction(SIGSEGV, &newAct, &oldAct); } static void register_thread_info(ThreadInfo* tinfo){ stack_t ss; pthread_setspecific(thread_info_key, tinfo); get_stack_info((void**)&tinfo->stack_pointer, &tinfo->stack_size); printf("stack size %d mb\n", tinfo->stack_size/1024/1024 ); tinfo->red_zone_boundary = tinfo->stack_pointer + tinfo->red_zone_size; set_yellow_zone(tinfo); ss.ss_sp = (char*)malloc(ALT_STACK_SIZE); ss.ss_size = ALT_STACK_SIZE; ss.ss_flags = 0; sigaltstack(&ss, NULL); } static void* thread_routine(void* p){ ThreadInfo* tinfo = (ThreadInfo*)p; register_thread_info(tinfo); if(sigsetjmp(tinfo->return_point, 1) == 0){ main_routine(); } else { stackoverflow_routine(); } free(tinfo); printf("after tinfo, end thread\n"); return 0; } int main(int argc, char** argv){ register_application_info(); if( argc == 2 ){ int stacksize = atoi(argv[1]); pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 1024 * 1024 * stacksize); { pthread_t pid0; ThreadInfo* tinfo = (ThreadInfo*)calloc(1, sizeof(ThreadInfo)); pthread_attr_getguardsize(&attr, &tinfo->red_zone_size); pthread_create(&pid0, &attr, thread_routine, tinfo); pthread_join(pid0, NULL); } } else { printf("Usage: %s stacksize(mb)\n", argv[0]); } return 0; } C language in linux, ubuntu

    Read the article

  • error: ‘struct mcontext_t’ has no member named ‘eip’

    - by user353573
    original is struct sigcontext *sc; after changing to struct mcontext_t, error occur. How to fix it? error: ‘struct mcontext_t’ has no member named ‘eip’ #include <stdio.h> #include <signal.h> #include <asm/ucontext.h> static unsigned long target; void handler(int signum, siginfo_t *siginfo, void *uc0){ struct ucontext *uc; mcontext_t *sc; uc = (struct ucontext *)uc0; sc = &uc->uc_mcontext; sc->eip = target; }

    Read the article

  • how to make changes to database in WPF?

    - by user353573
    Drag access database into designer xsd, toolkit:datagrid get datacontext from resources correctly show the table content through this binding. Press button in the button column, can show each row correctly. delete row and add row also work in datagrid however, when i press button column to add a new row or delete a row, there is no change in the underlying database, how to commit the changes from datagrid to database in WPF if not using ADO.net ? The following code is what i try do not work private void datagrid2_delete(object sender, RoutedEventArgs e) { Button showButton = (Button)sender; //person p = (person)showButton.DataContext; DataRowView ds = (DataRowView)showButton.DataContext; //DataSet1.customertableRow p = (DataSet1.customertableRow)ds; //ds.BeginEdit(); //ds.Delete(); //ds.EndEdit(); /* DataSourceProvider provider = (DataSourceProvider)this.FindResource("Family"); WpfApplication1.DataSet1.customertableDataTable table = (WpfApplication1.DataSet1.customertableDataTable)provider.Data; table.AddcustomertableRow("hello3", 5, System.DateTime.Today); table.AcceptChanges(); }

    Read the article

  • how to assign value to EIP with C language in ubuntu

    - by user353573
    where is wrong? how to assign value to eip to change the location of running in program? Please help !!!! error: cannot convert ‘mcontext_t*’ to ‘sigcontext*’ in assignment struct ucontext { unsigned long uc_flags; struct ucontext *uc_link; stack_t uc_stack; struct sigcontext uc_mcontext; sigset_t uc_sigmask; /* mask last for extensibility */ }; #include <stdio.h> #include <signal.h> #include <asm/ucontext.h> void handler(int signum, siginfo_t *siginfo, void *uc0){ struct ucontext *uc; struct sigcontext *sc; uc = (struct ucontext *)uc0; sc = &uc->uc_mcontext; sc->eip = target; //uc->uc_mcontext.gregs[REG_EIP] } int main (int argc, char** argv){ struct sigaction act; act.sa_sigaction = handler; act.sa_flags = SA_SIGINFO; sigaction(SIGTRAP, &act, NULL); asm("movl $skipped, %0" : : "m" (target)); asm("int3"); // cause SIGTRAP printf("to be skipped.\n"); asm("skipped:"); printf("Done.\n"); }

    Read the article

  • cannot convert ‘mcontext_t*’ to ‘sigcontext*’ in assignment

    - by user353573
    i have checked asm/ucontext.h it should be sigcontext, but why pop up the error message cannot convert ‘mcontext_t*’ to ‘sigcontext*’ in assignment #include <stdio.h> #include <signal.h> #include <asm/ucontext.h> static unsigned long target; void handler(int signum, siginfo_t *siginfo, void *uc0){ struct ucontext *uc; struct sigcontext *sc; uc = (struct ucontext *)uc0; sc = &uc->uc_mcontext; sc->eip = target; } struct ucontext { unsigned long uc_flags; struct ucontext *uc_link; stack_t uc_stack; struct sigcontext uc_mcontext; sigset_t uc_sigmask; /* mask last for extensibility */ };

    Read the article

  • Break the limit of threading, segmentation fault

    - by user353573
    use pthread_create to create limited number of threads running concurrently Successfully compile and run However, after adding function pointer array to run the function, Segmentation fault Where is wrong? workserver number: 0 Segmentation fault void* workserver(void arg) { int status; while(true) { printf("workserver number: %d\n", (int)arg); ( job_queue[(int)arg])(); sleep(3); status = pthread_mutex_lock(&data.mutex); if(status != 0) printf("%d lock mutex", status); data.value = 1; status = pthread_cond_signal(&data.cond); if(status != 0) printf("%d signal condition", status); status = pthread_mutex_unlock(&data.mutex); if(status != 0) printf("%d unlock mutex", status); } }

    Read the article

1