| 1784 | } |
| 1785 | |
| 1786 | JEMALLOC_ALWAYS_INLINE int |
| 1787 | imalloc_body(static_opts_t *sopts, dynamic_opts_t *dopts, tsd_t *tsd) { |
| 1788 | /* Where the actual allocated memory will live. */ |
| 1789 | void *allocation = NULL; |
| 1790 | /* Filled in by compute_size_with_overflow below. */ |
| 1791 | size_t size = 0; |
| 1792 | /* |
| 1793 | * For unaligned allocations, we need only ind. For aligned |
| 1794 | * allocations, or in case of stats or profiling we need usize. |
| 1795 | * |
| 1796 | * These are actually dead stores, in that their values are reset before |
| 1797 | * any branch on their value is taken. Sometimes though, it's |
| 1798 | * convenient to pass them as arguments before this point. To avoid |
| 1799 | * undefined behavior then, we initialize them with dummy stores. |
| 1800 | */ |
| 1801 | szind_t ind = 0; |
| 1802 | size_t usize = 0; |
| 1803 | |
| 1804 | /* Reentrancy is only checked on slow path. */ |
| 1805 | int8_t reentrancy_level; |
| 1806 | |
| 1807 | /* Compute the amount of memory the user wants. */ |
| 1808 | if (unlikely(compute_size_with_overflow(sopts->may_overflow, dopts, |
| 1809 | &size))) { |
| 1810 | goto label_oom; |
| 1811 | } |
| 1812 | |
| 1813 | /* Validate the user input. */ |
| 1814 | if (sopts->bump_empty_alloc) { |
| 1815 | if (unlikely(size == 0)) { |
| 1816 | size = 1; |
| 1817 | } |
| 1818 | } |
| 1819 | |
| 1820 | if (sopts->assert_nonempty_alloc) { |
| 1821 | assert (size != 0); |
| 1822 | } |
| 1823 | |
| 1824 | if (unlikely(dopts->alignment < sopts->min_alignment |
| 1825 | || (dopts->alignment & (dopts->alignment - 1)) != 0)) { |
| 1826 | goto label_invalid_alignment; |
| 1827 | } |
| 1828 | |
| 1829 | /* This is the beginning of the "core" algorithm. */ |
| 1830 | |
| 1831 | if (dopts->alignment == 0) { |
| 1832 | ind = sz_size2index(size); |
| 1833 | if (unlikely(ind >= NSIZES)) { |
| 1834 | goto label_oom; |
| 1835 | } |
| 1836 | if (config_stats || (config_prof && opt_prof)) { |
| 1837 | usize = sz_index2size(ind); |
| 1838 | assert(usize > 0 && usize <= LARGE_MAXCLASS); |
| 1839 | } |
| 1840 | } else { |
| 1841 | usize = sz_sa2u(size, dopts->alignment); |
| 1842 | if (unlikely(usize == 0 || usize > LARGE_MAXCLASS)) { |
| 1843 | goto label_oom; |
no test coverage detected