| 504 | // ===================== |
| 505 | |
| 506 | Error CodeHolder::new_section(Out<Section*> section_out, const char* name, size_t name_size, SectionFlags flags, uint32_t alignment, int32_t order) noexcept { |
| 507 | *section_out = nullptr; |
| 508 | |
| 509 | if (ASMJIT_UNLIKELY(!Support::is_zero_or_power_of_2(alignment))) { |
| 510 | return make_error(Error::kInvalidArgument); |
| 511 | } |
| 512 | |
| 513 | if (name_size == SIZE_MAX) { |
| 514 | name_size = strlen(name); |
| 515 | } |
| 516 | |
| 517 | if (ASMJIT_UNLIKELY(name_size > Globals::kMaxSectionNameSize)) { |
| 518 | return make_error(Error::kInvalidSectionName); |
| 519 | } |
| 520 | |
| 521 | uint32_t section_id = _sections._size; |
| 522 | if (ASMJIT_UNLIKELY(section_id == Globals::kInvalidId)) { |
| 523 | return make_error(Error::kTooManySections); |
| 524 | } |
| 525 | |
| 526 | ASMJIT_PROPAGATE(_sections.reserve_additional(_arena)); |
| 527 | ASMJIT_PROPAGATE(_sections_by_order.reserve_additional(_arena)); |
| 528 | |
| 529 | Section* section = _arena.alloc_oneshot<Section>(); |
| 530 | if (ASMJIT_UNLIKELY(!section)) { |
| 531 | return make_error(Error::kOutOfMemory); |
| 532 | } |
| 533 | |
| 534 | if (alignment == 0u) { |
| 535 | alignment = 1u; |
| 536 | } |
| 537 | |
| 538 | Section_init_data(section, section_id, flags, alignment, order); |
| 539 | Section_init_buffer(section); |
| 540 | memcpy(section->_name.str, name, name_size); |
| 541 | |
| 542 | Section** insert_position = std::lower_bound(_sections_by_order.begin(), _sections_by_order.end(), section, [](const Section* a, const Section* b) { |
| 543 | return std::make_tuple(a->order(), a->section_id()) < std::make_tuple(b->order(), b->section_id()); |
| 544 | }); |
| 545 | |
| 546 | _sections.append_unchecked(section); |
| 547 | _sections_by_order.insert_unchecked((size_t)(insert_position - _sections_by_order.data()), section); |
| 548 | |
| 549 | *section_out = section; |
| 550 | return Error::kOk; |
| 551 | } |
| 552 | |
| 553 | Section* CodeHolder::section_by_name(const char* name, size_t name_size) const noexcept { |
| 554 | if (name_size == SIZE_MAX) { |