| 1725 | } |
| 1726 | |
| 1727 | JEMALLOC_ALWAYS_INLINE int |
| 1728 | imalloc_body(static_opts_t *sopts, dynamic_opts_t *dopts, tsd_t *tsd) { |
| 1729 | /* Where the actual allocated memory will live. */ |
| 1730 | void *allocation = NULL; |
| 1731 | /* Filled in by compute_size_with_overflow below. */ |
| 1732 | size_t size = 0; |
| 1733 | /* |
| 1734 | * For unaligned allocations, we need only ind. For aligned |
| 1735 | * allocations, or in case of stats or profiling we need usize. |
| 1736 | * |
| 1737 | * These are actually dead stores, in that their values are reset before |
| 1738 | * any branch on their value is taken. Sometimes though, it's |
| 1739 | * convenient to pass them as arguments before this point. To avoid |
| 1740 | * undefined behavior then, we initialize them with dummy stores. |
| 1741 | */ |
| 1742 | szind_t ind = 0; |
| 1743 | size_t usize = 0; |
| 1744 | |
| 1745 | /* Reentrancy is only checked on slow path. */ |
| 1746 | int8_t reentrancy_level; |
| 1747 | |
| 1748 | /* Compute the amount of memory the user wants. */ |
| 1749 | if (unlikely(compute_size_with_overflow(sopts->may_overflow, dopts, |
| 1750 | &size))) { |
| 1751 | goto label_oom; |
| 1752 | } |
| 1753 | |
| 1754 | /* Validate the user input. */ |
| 1755 | if (sopts->bump_empty_alloc) { |
| 1756 | if (unlikely(size == 0)) { |
| 1757 | size = 1; |
| 1758 | } |
| 1759 | } |
| 1760 | |
| 1761 | if (sopts->assert_nonempty_alloc) { |
| 1762 | assert (size != 0); |
| 1763 | } |
| 1764 | |
| 1765 | if (unlikely(dopts->alignment < sopts->min_alignment |
| 1766 | || (dopts->alignment & (dopts->alignment - 1)) != 0)) { |
| 1767 | goto label_invalid_alignment; |
| 1768 | } |
| 1769 | |
| 1770 | /* This is the beginning of the "core" algorithm. */ |
| 1771 | |
| 1772 | if (dopts->alignment == 0) { |
| 1773 | ind = sz_size2index(size); |
| 1774 | if (unlikely(ind >= NSIZES)) { |
| 1775 | goto label_oom; |
| 1776 | } |
| 1777 | if (config_stats || (config_prof && opt_prof)) { |
| 1778 | usize = sz_index2size(ind); |
| 1779 | assert(usize > 0 && usize <= LARGE_MAXCLASS); |
| 1780 | } |
| 1781 | } else { |
| 1782 | usize = sz_sa2u(size, dopts->alignment); |
| 1783 | if (unlikely(usize == 0 || usize > LARGE_MAXCLASS)) { |
| 1784 | goto label_oom; |
no test coverage detected