Lines Matching +full:ecx +full:- +full:2000

1 //===-- sanitizer_linux.cpp -----------------------------------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 // run-time libraries and implements linux-specific functions from
12 //===----------------------------------------------------------------------===//
132 // Are we using 32-bit or 64-bit Linux syscalls?
134 // but it still needs to use 64-bit syscalls.
192 // Seccomp-BPF-sandboxed processes rely on SIGSYS to handle trapped syscalls.
239 // --------------- sanitizer_libc.h
248 // mmap2 specifies file offset in 4096-byte units.
319 out->st_dev = in->st_dev;
320 out->st_ino = in->st_ino;
321 out->st_mode = in->st_mode;
322 out->st_nlink = in->st_nlink;
323 out->st_uid = in->st_uid;
324 out->st_gid = in->st_gid;
325 out->st_rdev = in->st_rdev;
326 out->st_size = in->st_size;
327 out->st_blksize = in->st_blksize;
328 out->st_blocks = in->st_blocks;
329 out->st_atime = in->st_atime;
330 out->st_mtime = in->st_mtime;
331 out->st_ctime = in->st_ctime;
338 out->st_dev = makedev(in->stx_dev_major, in->stx_dev_minor);
339 out->st_ino = in->stx_ino;
340 out->st_mode = in->stx_mode;
341 out->st_nlink = in->stx_nlink;
342 out->st_uid = in->stx_uid;
343 out->st_gid = in->stx_gid;
344 out->st_rdev = makedev(in->stx_rdev_major, in->stx_rdev_minor);
345 out->st_size = in->stx_size;
346 out->st_blksize = in->stx_blksize;
347 out->st_blocks = in->stx_blocks;
348 out->st_atime = in->stx_atime.tv_sec;
349 out->st_atim.tv_nsec = in->stx_atime.tv_nsec;
350 out->st_mtime = in->stx_mtime.tv_sec;
351 out->st_mtim.tv_nsec = in->stx_mtime.tv_nsec;
352 out->st_ctime = in->stx_ctime.tv_sec;
353 out->st_ctim.tv_nsec = in->stx_ctime.tv_nsec;
382 out->st_dev = in->st_dev;
383 out->st_ino = in->st_ino;
384 out->st_mode = in->st_mode;
385 out->st_nlink = in->st_nlink;
386 out->st_uid = in->st_uid;
387 out->st_gid = in->st_gid;
388 out->st_rdev = in->st_rdev;
389 out->st_size = in->st_size;
390 out->st_blksize = in->st_blksize;
391 out->st_blocks = in->st_blocks;
394 out->st_atim.tv_sec = in->st_atime;
395 out->st_atim.tv_nsec = in->st_atime_nsec;
396 out->st_mtim.tv_sec = in->st_mtime;
397 out->st_mtim.tv_nsec = in->st_mtime_nsec;
398 out->st_ctim.tv_sec = in->st_ctime;
399 out->st_ctim.tv_nsec = in->st_ctime_nsec;
401 out->st_atime = in->st_atime;
402 out->st_atimensec = in->st_atime_nsec;
403 out->st_mtime = in->st_mtime;
404 out->st_mtimensec = in->st_mtime_nsec;
405 out->st_ctime = in->st_ctime;
406 out->st_atimensec = in->st_ctime_nsec;
519 return -1;
589 // ----------------- sanitizer_common.h
628 // TgKill is expected to return -1 on error, not an errno.
629 return errno != 0 ? -1 : 0;
682 const char *endp = (char *)internal_memchr(p, '\0', len - (p - environ));
719 CHECK_LE(count, arr_size - 1); // FIXME: make this more flexible.
734 if (internal_sysctlbyname("kern.ps_strings", &pss, &sz, NULL, 0) == -1) {
738 *argv = pss->ps_argvstr;
739 *envp = pss->ps_envstr;
741 *argv = __ps_strings->ps_argvstr;
742 *envp = __ps_strings->ps_envstr;
750 // Do not special-case ARM and infer argc from argv everywhere.
757 static const int kMaxArgv = 2000, kMaxEnvp = 2000;
783 sched_yield(); /* No userspace futex-like synchronization */
793 /* No userspace futex-like synchronization */
801 // ----------------- sanitizer_linux.h
804 // 32-bit syscall here.
925 if (real_sysctlnametomib(sname, oid, &len) == -1)
926 return (-1);
943 k_act.handler = u_act->handler;
944 k_act.sigaction = u_act->sigaction;
945 internal_memcpy(&k_act.sa_mask, &u_act->sa_mask,
948 k_act.sa_flags = u_act->sa_flags | SA_RESTORER;
956 // oldact->sa_restorer upon a call to sigaction(xxx, NULL, oldact).
958 k_act.sa_restorer = u_act->sa_restorer;
968 u_oldact->handler = k_oldact.handler;
969 u_oldact->sigaction = k_oldact.sigaction;
970 internal_memcpy(&u_oldact->sa_mask, &k_oldact.sa_mask,
972 u_oldact->sa_flags = k_oldact.sa_flags;
974 u_oldact->sa_restorer = k_oldact.sa_restorer;
1003 signum -= 1;
1007 const uptr idx = signum / (sizeof(k_set->sig[0]) * 8);
1008 const uptr bit = signum % (sizeof(k_set->sig[0]) * 8);
1009 k_set->sig[idx] &= ~((uptr)1 << bit);
1013 signum -= 1;
1017 const uptr idx = signum / (sizeof(k_set->sig[0]) * 8);
1018 const uptr bit = signum % (sizeof(k_set->sig[0]) * 8);
1019 return k_set->sig[idx] & ((uptr)1 << bit);
1055 threads->clear();
1073 begin += entry->d_reclen;
1074 if (entry->d_ino == 1) {
1080 if (entry->d_ino && *entry->d_name >= '0' && *entry->d_name <= '9')
1081 threads->push_back(internal_atoll(entry->d_name));
1084 // Now we are going to detect short-read or early EOF. In such cases Linux
1089 // The first one was a short-read by definition.
1091 } else if (read > buffer_.size() - 1024) {
1096 } else if (!threads->empty() && !IsAlive(threads->back())) {
1146 // if we are running on 64-bit kernel.
1166 return 0x7f7ffffff000ULL; // (0x00007f8000000000 - PAGE_SIZE)
1170 // On PowerPC64 we have two different address space layouts: 44- and 46-bit.
1173 // Note that with 'ulimit -s unlimited' the stack is moved away from the top
1176 // Similarly, aarch64 has multiple address space layouts: 39, 42 and 47-bit.
1177 // loongarch64 also has multiple address space layouts: default is 47-bit.
1178 // RISC-V 64 also has multiple address space layouts: 39, 48 and 57-bit.
1179 return (1ULL << (MostSignificantSetBitIndex(GET_CURRENT_FRAME()) + 1)) - 1;
1181 return (1ULL << 40) - 1; // 0x000000ffffffffffUL;
1183 return (1ULL << 53) - 1; // 0x001fffffffffffffUL;
1187 return (1ULL << 47) - 1; // 0x00007fffffffffffUL;
1191 return (1ULL << 31) - 1; // 0x7fffffff;
1193 return (1ULL << 32) - 1; // 0xffffffff;
1201 if (!common_flags()->full_address_space)
1202 addr -= GetKernelAreaSize();
1237 const int Mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
1239 const int Mib[4] = {CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME};
1282 // Match full names of the form /path/to/base_name{-,.}*
1287 while (name > full_name && *name != '/') name--;
1293 return (name[base_name_length] == '-' || name[base_name_length] == '.');
1304 char *base = (char *)map->l_addr;
1306 char *phdrs = base + ehdr->e_phoff;
1307 char *phdrs_end = phdrs + ehdr->e_phnum * ehdr->e_phentsize;
1311 // objects have a non-zero base.
1312 uptr preferred_base = (uptr)-1;
1313 for (char *iter = phdrs; iter != phdrs_end; iter += ehdr->e_phentsize) {
1315 if (phdr->p_type == PT_LOAD && preferred_base > (uptr)phdr->p_vaddr)
1316 preferred_base = (uptr)phdr->p_vaddr;
1320 sptr delta = (uptr)base - preferred_base;
1322 for (char *iter = phdrs; iter != phdrs_end; iter += ehdr->e_phentsize) {
1324 if (phdr->p_type == PT_LOAD) {
1325 uptr seg_start = phdr->p_vaddr + delta;
1326 uptr seg_end = seg_start + phdr->p_memsz;
1331 cb((void *)seg_start, seg_end - seg_start);
1349 return -EINVAL;
1351 child_stack = (char *)child_stack - 2 * sizeof(unsigned long long);
1401 return -EINVAL;
1403 child_stack = (char *)child_stack - 2 * sizeof(unsigned long long);
1424 * if we are using 32-bit abi.
1471 return -EINVAL;
1513 return -EINVAL;
1515 child_stack = (char *)child_stack - 2 * sizeof(unsigned long long);
1552 : "i"(-EINVAL), "r"(__fn), "r"(__stack), "r"(__flags), "r"(__arg),
1561 return -EINVAL;
1629 return -EINVAL;
1662 "bne- cr1, 1f\n\t"
1666 "stdu 29, -8(1)\n\t"
1667 "stdu 1, -%12(1)\n\t"
1692 : "0"(-1), "i"(EINVAL), "i"(__NR_clone), "i"(__NR_exit), "r"(__fn),
1703 return -EINVAL;
1705 child_stack = (char *)child_stack - 7 * sizeof(unsigned int);
1713 * %ecx = child_stack,
1720 "movl (%%ecx), %%ebx\n"
1726 "movl %%ebx, (%%ecx)\n"
1747 "addl $_GLOBAL_OFFSET_TABLE_+[.-here], %%ebx\n"
1765 return -EINVAL;
1766 child_stack = (char *)child_stack - 2 * sizeof(unsigned int);
1843 if (info->dlpi_name && info->dlpi_name[0] == 'l' &&
1844 info->dlpi_name[1] == 'i' && info->dlpi_name[2] == 'b') {
1870 return ANDROID_POST_LOLLIPOP; // post-L
1893 return common_flags()->handle_abort;
1895 return common_flags()->handle_sigill;
1897 return common_flags()->handle_sigtrap;
1899 return common_flags()->handle_sigfpe;
1901 return common_flags()->handle_segv;
1903 return common_flags()->handle_sigbus;
1910 if (result == kHandleSignalYes && !common_flags()->allow_user_segv_handler)
1945 u8 *aux = reinterpret_cast<u8 *>(ucontext->uc_mcontext.__reserved);
1948 if (ctx->size == 0)
1950 if (ctx->magic == kEsrMagic) {
1951 *esr = ((__sanitizer_esr_context *)ctx)->esr;
1954 aux += ctx->size;
1970 uptr err = ucontext->uc_mcontext.mc_err;
1972 uptr err = ucontext->uc_mcontext.__gregs[_REG_ERR];
1975 uptr err = ucontext->uc_mcontext.gregs[Err];
1977 uptr err = ucontext->uc_mcontext.gregs[REG_ERR];
1985 exception_source = (uint32_t *)ucontext->uc_mcontext.pc;
2031 uptr fsr = ucontext->uc_mcontext.error_code;
2052 u32 flags = ucontext->uc_mcontext.__flags;
2062 uptr pc = ucontext->uc_mcontext.gregs[REG_PC];
2067 uptr pc = scontext->sigc_regs.tpc;
2069 uptr pc = scontext->si_regs.pc;
2076 unsigned long pc = ucontext->uc_mcontext.mc_gpregs.gp_sepc;
2078 unsigned long pc = ucontext->uc_mcontext.__gregs[REG_PC];
2087 unsigned rd = faulty_instruction & 0xF80; // bits 7-11, inclusive
2124 unsigned funct3 = (faulty_instruction >> 12) & 0x7; // bits 12-14, inclusive
2153 case 0b0000111: // floating-point loads
2163 case 0b0100111: // floating-point stores
2186 return si->si_signo == SIGSEGV && si->si_code != 128;
2232 return "ecx";
2257 RegName, ctx->uc_mcontext.gregs[RegNum]);
2259 Printf("%s = 0x%08x ", RegName, ctx->uc_mcontext.gregs[RegNum]);
2313 Printf("rax = 0x%016lx ", ucontext->uc_mcontext.mc_rax);
2314 Printf("rbx = 0x%016lx ", ucontext->uc_mcontext.mc_rbx);
2315 Printf("rcx = 0x%016lx ", ucontext->uc_mcontext.mc_rcx);
2316 Printf("rdx = 0x%016lx ", ucontext->uc_mcontext.mc_rdx);
2318 Printf("rdi = 0x%016lx ", ucontext->uc_mcontext.mc_rdi);
2319 Printf("rsi = 0x%016lx ", ucontext->uc_mcontext.mc_rsi);
2320 Printf("rbp = 0x%016lx ", ucontext->uc_mcontext.mc_rbp);
2321 Printf("rsp = 0x%016lx ", ucontext->uc_mcontext.mc_rsp);
2323 Printf(" r8 = 0x%016lx ", ucontext->uc_mcontext.mc_r8);
2324 Printf(" r9 = 0x%016lx ", ucontext->uc_mcontext.mc_r9);
2325 Printf("r10 = 0x%016lx ", ucontext->uc_mcontext.mc_r10);
2326 Printf("r11 = 0x%016lx ", ucontext->uc_mcontext.mc_r11);
2328 Printf("r12 = 0x%016lx ", ucontext->uc_mcontext.mc_r12);
2329 Printf("r13 = 0x%016lx ", ucontext->uc_mcontext.mc_r13);
2330 Printf("r14 = 0x%016lx ", ucontext->uc_mcontext.mc_r14);
2331 Printf("r15 = 0x%016lx ", ucontext->uc_mcontext.mc_r15);
2335 Printf("eax = 0x%08x ", ucontext->uc_mcontext.mc_eax);
2336 Printf("ebx = 0x%08x ", ucontext->uc_mcontext.mc_ebx);
2337 Printf("ecx = 0x%08x ", ucontext->uc_mcontext.mc_ecx);
2338 Printf("edx = 0x%08x ", ucontext->uc_mcontext.mc_edx);
2340 Printf("edi = 0x%08x ", ucontext->uc_mcontext.mc_edi);
2341 Printf("esi = 0x%08x ", ucontext->uc_mcontext.mc_esi);
2342 Printf("ebp = 0x%08x ", ucontext->uc_mcontext.mc_ebp);
2343 Printf("esp = 0x%08x ", ucontext->uc_mcontext.mc_esp);
2361 *pc = ucontext->uc_mcontext.arm_pc;
2362 *bp = ucontext->uc_mcontext.arm_fp;
2363 *sp = ucontext->uc_mcontext.arm_sp;
2367 *pc = ucontext->uc_mcontext.mc_gpregs.gp_elr;
2368 *bp = ucontext->uc_mcontext.mc_gpregs.gp_x[29];
2369 *sp = ucontext->uc_mcontext.mc_gpregs.gp_sp;
2372 *pc = ucontext->uc_mcontext.pc;
2373 *bp = ucontext->uc_mcontext.regs[29];
2374 *sp = ucontext->uc_mcontext.sp;
2378 *pc = ucontext->uc_mcontext.sc_iaoq[0];
2380 *bp = ucontext->uc_mcontext.sc_gr[3];
2381 *sp = ucontext->uc_mcontext.sc_gr[30];
2385 *pc = ucontext->uc_mcontext.mc_rip;
2386 *bp = ucontext->uc_mcontext.mc_rbp;
2387 *sp = ucontext->uc_mcontext.mc_rsp;
2390 *pc = ucontext->uc_mcontext.gregs[REG_RIP];
2391 *bp = ucontext->uc_mcontext.gregs[REG_RBP];
2392 *sp = ucontext->uc_mcontext.gregs[REG_RSP];
2397 *pc = ucontext->uc_mcontext.mc_eip;
2398 *bp = ucontext->uc_mcontext.mc_ebp;
2399 *sp = ucontext->uc_mcontext.mc_esp;
2415 *pc = ucontext->uc_mcontext.gregs[REG_EIP];
2416 *bp = ucontext->uc_mcontext.gregs[REG_EBP];
2417 *sp = ucontext->uc_mcontext.gregs[REG_UESP];
2422 *pc = ucontext->uc_mcontext.mc_srr0;
2423 *sp = ucontext->uc_mcontext.mc_frame[1];
2424 *bp = ucontext->uc_mcontext.mc_frame[31];
2427 *pc = ucontext->uc_mcontext.regs->nip;
2428 *sp = ucontext->uc_mcontext.regs->gpr[PT_R1];
2429 // The powerpc{,64}-linux ABIs do not specify r31 as the frame
2431 *bp = ucontext->uc_mcontext.regs->gpr[PT_R31];
2441 *pc = ucontext->uc_mcontext.gregs[REG_PC];
2442 *sp = ucontext->uc_mcontext.gregs[REG_O6] + STACK_BIAS;
2447 *pc = scontext->sigc_regs.tpc;
2448 *sp = scontext->sigc_regs.u_regs[14] + STACK_BIAS;
2450 *pc = scontext->si_regs.pc;
2451 *sp = scontext->si_regs.u_regs[14];
2457 *pc = ucontext->uc_mcontext.pc;
2458 *bp = ucontext->uc_mcontext.gregs[30];
2459 *sp = ucontext->uc_mcontext.gregs[29];
2463 *pc = ucontext->uc_mcontext.psw.addr;
2465 *pc = ucontext->uc_mcontext.psw.addr & 0x7fffffff;
2467 *bp = ucontext->uc_mcontext.gregs[11];
2468 *sp = ucontext->uc_mcontext.gregs[15];
2472 *pc = ucontext->uc_mcontext.mc_gpregs.gp_sepc;
2473 *bp = ucontext->uc_mcontext.mc_gpregs.gp_s[0];
2474 *sp = ucontext->uc_mcontext.mc_gpregs.gp_sp;
2476 *pc = ucontext->uc_mcontext.__gregs[REG_PC];
2477 *bp = ucontext->uc_mcontext.__gregs[REG_S0];
2478 *sp = ucontext->uc_mcontext.__gregs[REG_SP];
2482 *pc = ucontext->uc_mcontext.pc;
2483 *bp = ucontext->uc_mcontext.r30;
2484 *sp = ucontext->uc_mcontext.r29;
2487 *pc = ucontext->uc_mcontext.__pc;
2488 *bp = ucontext->uc_mcontext.__gregs[22];
2489 *sp = ucontext->uc_mcontext.__gregs[3];
2511 if (UNLIKELY(internal_sysctl(mib, 3, &paxflags, &len, NULL, 0) == -1)) {
2526 if (UNLIKELY(r == -1)) {
2536 "ASLR will be disabled and the program re-executed.\n");
2538 CHECK_NE(internal_procctl(P_PID, 0, PROC_ASLR_CTL, &aslr_ctl), -1);
2544 if (old_personality != -1 && (old_personality & ADDR_NO_RANDOMIZE) == 0) {
2549 "ASLR will be disabled and the program re-executed.\n");
2550 CHECK_NE(personality(old_personality | ADDR_NO_RANDOMIZE), -1);
2568 if (UNLIKELY(internal_sysctl(mib, 3, &paxflags, &len, NULL, 0) == -1)) {