// Takes a handle (as returned from dlopen()) and returns the absolute path to the image loaded JL_DLLEXPORT const char *jl_pathname_for_handle(void *handle) { if (!handle) return NULL; #ifdef __APPLE__ // Iterate through all images currently in memory for (int32_t i = _dyld_image_count() - 1; i >= 0 ; i--) { // dlopen() each image, check handle const char *image_name = _dyld_get_image_name(i); void *probe_lib = jl_load_dynamic_library(image_name, JL_RTLD_DEFAULT); jl_dlclose(probe_lib); // If the handle is the same as what was passed in (modulo mode bits), return this image name if (((intptr_t)handle & (-4)) == ((intptr_t)probe_lib & (-4))) return image_name; } #elif defined(_OS_WINDOWS_) wchar_t *pth16 = (wchar_t*)malloc(32768); // max long path length DWORD n16 = GetModuleFileNameW((HMODULE)handle,pth16,32768); if (n16 <= 0) { free(pth16); return NULL; } pth16[n16] = L'\0'; DWORD n8 = WideCharToMultiByte(CP_UTF8, 0, pth16, -1, NULL, 0, NULL, NULL); if (n8 == 0) { free(pth16); return NULL; } char *filepath = (char*)malloc(++n8); if (!WideCharToMultiByte(CP_UTF8, 0, pth16, -1, filepath, n8, NULL, NULL)) { free(pth16); free(filepath); return NULL; } free(pth16); return filepath; #else // Linux, FreeBSD, ... struct link_map *map; dlinfo(handle, RTLD_DI_LINKMAP, &map); #ifdef JL_MSAN_ENABLED __msan_unpoison(&map,sizeof(struct link_map*)); if (map) { __msan_unpoison(map, sizeof(struct link_map)); __msan_unpoison_string(map->l_name); } #endif if (map) return map->l_name; #endif return NULL; }
void WaitObjectContainer::Clear() { #ifdef USE_WINDOWS_STYLE_SOCKETS m_handles.clear(); #else m_maxFd = 0; FD_ZERO(&m_readfds); FD_ZERO(&m_writefds); # ifdef CRYPTOPP_MSAN __msan_unpoison(&m_readfds, sizeof(m_readfds)); __msan_unpoison(&m_writefds, sizeof(m_writefds)); # endif #endif m_noWait = false; m_firstEventTime = 0; }
NO_SANITIZE_ADDRESS void ThreadState::visitStack(Visitor* visitor) { if (m_stackState == NoHeapPointersOnStack) return; Address* start = reinterpret_cast<Address*>(m_startOfStack); // If there is a safepoint scope marker we should stop the stack // scanning there to not touch active parts of the stack. Anything // interesting beyond that point is in the safepoint stack copy. // If there is no scope marker the thread is blocked and we should // scan all the way to the recorded end stack pointer. Address* end = reinterpret_cast<Address*>(m_endOfStack); Address* safePointScopeMarker = reinterpret_cast<Address*>(m_safePointScopeMarker); Address* current = safePointScopeMarker ? safePointScopeMarker : end; // Ensure that current is aligned by address size otherwise the loop below // will read past start address. current = reinterpret_cast<Address*>(reinterpret_cast<intptr_t>(current) & ~(sizeof(Address) - 1)); for (; current < start; ++current) { Address ptr = *current; #if defined(MEMORY_SANITIZER) // |ptr| may be uninitialized by design. Mark it as initialized to keep // MSan from complaining. // Note: it may be tempting to get rid of |ptr| and simply use |current| // here, but that would be incorrect. We intentionally use a local // variable because we don't want to unpoison the original stack. __msan_unpoison(&ptr, sizeof(ptr)); #endif Heap::checkAndMarkPointer(visitor, ptr); visitAsanFakeStackForPointer(visitor, ptr); } for (Address ptr : m_safePointStackCopy) { #if defined(MEMORY_SANITIZER) // See the comment above. __msan_unpoison(&ptr, sizeof(ptr)); #endif Heap::checkAndMarkPointer(visitor, ptr); visitAsanFakeStackForPointer(visitor, ptr); } }
int uv__pipe2(int pipefd[2], int flags) { #if defined(__NR_pipe2) int result; result = syscall(__NR_pipe2, pipefd, flags); #if MSAN_ACTIVE if (!result) __msan_unpoison(pipefd, sizeof(int[2])); #endif return result; #else return errno = ENOSYS, -1; #endif }
int uv__epoll_wait(int epfd, struct uv__epoll_event* events, int nevents, int timeout) { #if defined(__NR_epoll_wait) int result; result = syscall(__NR_epoll_wait, epfd, events, nevents, timeout); #if MSAN_ACTIVE if (result > 0) __msan_unpoison(events, sizeof(events[0]) * result); #endif return result; #else return errno = ENOSYS, -1; #endif }
bool Socket::ReceiveReady(const timeval *timeout) { fd_set fds; FD_ZERO(&fds); FD_SET(m_s, &fds); #ifdef CRYPTOPP_MSAN __msan_unpoison(&fds, sizeof(fds)); #endif int ready; if (timeout == NULL) ready = select((int)m_s+1, &fds, NULL, NULL, NULL); else { timeval timeoutCopy = *timeout; // select() modified timeout on Linux ready = select((int)m_s+1, &fds, NULL, NULL, &timeoutCopy); } CheckAndHandleError_int("select", ready); return ready > 0; }
/* fill_with_entropy writes |len| bytes of entropy into |out|. It returns one * on success and zero on error. */ static char fill_with_entropy(uint8_t *out, size_t len) { while (len > 0) { ssize_t r; if (urandom_fd == kHaveGetrandom) { #if defined(USE_SYS_getrandom) do { r = syscall(SYS_getrandom, out, len, 0 /* no flags */); } while (r == -1 && errno == EINTR); #if defined(__has_feature) #if __has_feature(memory_sanitizer) if (r > 0) { /* MSAN doesn't recognise |syscall| and thus doesn't notice that we * have initialised the output buffer. */ __msan_unpoison(out, r); } #endif /* memory_sanitizer */ #endif /*__has_feature */ #else /* USE_SYS_getrandom */ abort(); #endif } else { do { r = read(urandom_fd, out, len); } while (r == -1 && errno == EINTR); } if (r <= 0) { return 0; } out += r; len -= r; } return 1; }