News for hackers. Stuff that matters.
Re:Vale's First Prototype for Immutable Region Borrowing by conaclos on Wednesday July 12, 2023 @08:27AM (#36693549)
If I am not wrong, there is a generation number embedded in the reference (smart pointer?). This allows to check if the generation of the reference and the generation of the referee match.
Re:Vale's First Prototype for Immutable Region Borrowing by marhee on Wednesday July 12, 2023 @08:41AM (#36693694)
Yes, there is a generation number in the reference. It is checked against the generation number of the allocation that is stored in the allocation:

  void __check(GenerationalReference genRef) {
    uint64_t currentGeneration = *(uint64_t*)((char*)genRef.alloc - 8);
    assert(genRef.rememberedGeneration == currentGeneration);
  }
So indeed you it allows you to check for a match, as long as the alloc pointer is valid. The alloc pointer is invalid after a free, because it maybe be in a region no longer accessible to the program (it was returned to the os by free's implementation) or it was given out as part of an other allocation, in which case it can hold arbitrary data.