| 59 | } |
| 60 | |
| 61 | void TempVectorStack::alloc(uint32_t num_bytes, uint8_t** data, int* id) { |
| 62 | int64_t estimated_alloc_size = EstimatedAllocationSize(num_bytes); |
| 63 | int64_t new_top = top_ + estimated_alloc_size; |
| 64 | // Stack overflow check (see GH-39582). |
| 65 | // XXX cannot return a regular Status because most consumers do not either. |
| 66 | ARROW_CHECK_LE(new_top, buffer_size_) |
| 67 | << "TempVectorStack::alloc overflow: allocating " << estimated_alloc_size |
| 68 | << " on top of " << top_ << " in stack of size " << buffer_size_; |
| 69 | #ifdef ADDRESS_SANITIZER |
| 70 | ASAN_UNPOISON_MEMORY_REGION(buffer_->mutable_data() + top_, estimated_alloc_size); |
| 71 | #endif |
| 72 | *data = buffer_->mutable_data() + top_ + /*one guard*/ sizeof(uint64_t); |
| 73 | #ifndef NDEBUG |
| 74 | // We set 8 bytes before the beginning of the allocated range and |
| 75 | // 8 bytes after the end to check for stack overflow (which would |
| 76 | // result in those known bytes being corrupted). |
| 77 | reinterpret_cast<uint64_t*>(buffer_->mutable_data() + top_)[0] = kGuard1; |
| 78 | reinterpret_cast<uint64_t*>(buffer_->mutable_data() + new_top)[-1] = kGuard2; |
| 79 | #endif |
| 80 | *id = num_vectors_++; |
| 81 | top_ = new_top; |
| 82 | } |
| 83 | |
| 84 | void TempVectorStack::release(int id, uint32_t num_bytes) { |
| 85 | ARROW_DCHECK(num_vectors_ == id + 1); |
no test coverage detected