void mark_heaps_exec() { /* Grab the page size, to align the heap pointer. */ long int pageSize = sysconf( _SC_PAGESIZE ); if( pageSize == 0 || pageSize == - 1 ) { fprintf( stderr, "*** Failed to obtain page size, guessing 16K.\n" ); perror( "mark_heaps_exec" ); pageSize = 1024 * 16; } /* end pageSize initialization */ /* Align the heap pointer. */ unsigned long int alignedHeapPointer = (unsigned long int) DYNINSTstaticHeap_16M_anyHeap_1; alignedHeapPointer = (alignedHeapPointer) & ~(pageSize - 1); unsigned long int adjustedSize = (unsigned long int) DYNINSTstaticHeap_16M_anyHeap_1 - alignedHeapPointer + sizeOfAnyHeap1; /* Make the heap's page executable. */ int result = mprotect( (void *) alignedHeapPointer, (size_t) adjustedSize, PROT_READ | PROT_WRITE | PROT_EXEC ); if( result != 0 ) { fprintf( stderr, "%s[%d]: Couldn't make DYNINSTstaticHeap_16M_anyHeap_1 executable!\n", __FILE__, __LINE__); perror( "mark_heaps_exec" ); } RTprintf( "*** Marked memory from 0x%lx to 0x%lx executable.\n", alignedHeapPointer, alignedHeapPointer + adjustedSize ); /* Mark _both_ heaps executable. */ alignedHeapPointer = (unsigned long int) DYNINSTstaticHeap_512K_lowmemHeap_1; alignedHeapPointer = (alignedHeapPointer) & ~(pageSize - 1); adjustedSize = (unsigned long int) DYNINSTstaticHeap_512K_lowmemHeap_1 - alignedHeapPointer + sizeOfLowMemHeap1; /* Make the heap's page executable. */ result = mprotect( (void *) alignedHeapPointer, (size_t) adjustedSize, PROT_READ | PROT_WRITE | PROT_EXEC ); if( result != 0 ) { fprintf( stderr, "%s[%d]: Couldn't make DYNINSTstaticHeap_512K_lowmemHeap_1 executable!\n", __FILE__, __LINE__ ); perror( "mark_heaps_exec" ); } RTprintf( "*** Marked memory from 0x%lx to 0x%lx executable.\n", alignedHeapPointer, alignedHeapPointer + adjustedSize ); } /* end mark_heaps_exec() */
int DYNINSTasyncConnect(int mutatorpid) { int sock_fd; struct sockaddr_in sadr; struct in_addr *inadr; struct hostent *hostptr; WORD wsversion = MAKEWORD(2,0); WSADATA wsadata; rtBPatch_asyncEventRecord ev; if (async_socket != -1) { return 0; } RTprintf("%s[%d]: inside DYNINSTasyncConnect\n", __FILE__, __LINE__); if (0 == connect_port) { fprintf(stderr, "%s[%d]: DYNINSTasyncConnect, no port\n", __FILE__, __LINE__); } WSAStartup(wsversion, &wsadata); RTprintf("%s[%d]: inside DYNINSTasyncConnect before gethostbyname\n", __FILE__, __LINE__); hostptr = gethostbyname("localhost"); inadr = (struct in_addr *) ((void*) hostptr->h_addr_list[0]); RTprintf("%s[%d]: inside DYNINSTasyncConnect before memset\n", __FILE__, __LINE__); memset((void*) &sadr, 0, sizeof(sadr)); sadr.sin_family = PF_INET; sadr.sin_port = htons((u_short)connect_port); sadr.sin_addr = *inadr; RTprintf("%s[%d]: DYNINSTasyncConnect before socket\n", __FILE__, __LINE__); sock_fd = socket(PF_INET, SOCK_STREAM, 0); if (sock_fd == INVALID_SOCKET) { fprintf(stderr, "DYNINST: socket failed: %d\n", WSAGetLastError()); } RTprintf("%s[%d]: DYNINSTasyncConnect before connect\n", __FILE__, __LINE__); if (connect(sock_fd, (struct sockaddr *) &sadr, sizeof(sadr)) == SOCKET_ERROR) { fprintf(stderr, "DYNINSTasyncConnect: connect failed: %d\n", WSAGetLastError()); } /* maybe need to do fcntl to set nonblocking writes on this fd */ async_socket = sock_fd; RTprintf("%s[%d]: DYNINSTasyncConnect before write\n", __FILE__, __LINE__); /* after connecting, we need to send along our pid */ ev.type = rtBPatch_newConnectionEvent; ev.pid = _getpid(); if (!DYNINSTwriteEvent((void *) &ev, sizeof(rtBPatch_asyncEventRecord))) { fprintf(stderr, "%s[%d]: DYNINSTwriteEventFailed\n", __FILE__, __LINE__); } /* initialize comms mutex */ //InitializeCriticalSection(&comms_mutex); //fprintf(stderr, "%s[%d]: DYNINSTasyncConnect appears to have succeeded\n", __FILE__, __LINE__); RTprintf("%s[%d]: leaving DYNINSTasyncConnect\n", __FILE__, __LINE__); return 1; /*true*/ }
void DYNINSTos_init(int calledByFork, int calledByAttach) { RTprintf("DYNINSTos_init(%d,%d)\n", calledByFork, calledByAttach); initial_thread_tid = (dyntid_t) GetCurrentThreadId(); }