;
22using namespaceCodeGen;
33assert(!
Type.isNull() &&
"type not provided for type-discriminated schema");
34 returnllvm::ConstantInt::get(
38assert(
Decl.getDecl() &&
39 "declaration not provided for decl-discriminated schema");
40 returnllvm::ConstantInt::get(
IntPtrTy,
46llvm_unreachable(
"bad discrimination kind");
62uint16_t &EntityHash = PtrAuthDiscriminatorHashes[
Declaration];
64 if(EntityHash == 0) {
66EntityHash = llvm::getPointerAuthStableSipHash(Name);
79assert(!Schema.isAddressDiscriminated() &&
80 "function pointers cannot use address-specific discrimination");
82llvm::Constant *Discriminator =
nullptr;
95llvm::Value *Discriminator) {
98 return Builder.CreateCall(Intrinsic, {StorageAddress, Discriminator});
109llvm::Value *Discriminator =
113assert(StorageAddress &&
114 "address not provided for address-discriminated schema");
132 if(PointeeType.
isNull())
144return ::getPointerAuthInfoForPointeeType(*
this,
T);
159 if(PointeeType.isNull())
162return ::getPointerAuthInfoForPointeeType(CGM, PointeeType);
166return ::getPointerAuthInfoForType(*
this,
T);
170 if(
const auto*CI = dyn_cast<llvm::ConstantInt>(
Value))
177assert((Left.isSigned() || Right.isSigned()) &&
178 "shouldn't be called if neither is signed");
179 if(Left.isSigned() != Right.isSigned())
181 returnLeft.getKey() == Right.getKey() &&
182Left.getAuthenticationMode() == Right.getAuthenticationMode();
189 returnDiscriminator ? Discriminator : Builder.getSize(0);
196assert(CurAuth && NewAuth);
218 auto*Intrinsic =
CGM.
getIntrinsic(llvm::Intrinsic::ptrauth_resign);
220Intrinsic, {
Value, CurKey, CurDiscriminator, NewKey, NewDiscriminator});
231 if(!CurAuthInfo && !NewAuthInfo)
234llvm::Value *
Null=
nullptr;
236 if(
auto*PointerValue = dyn_cast<llvm::PointerType>(
Value->
getType())) {
257llvm::BasicBlock *InitBB =
Builder.GetInsertBlock();
258llvm::BasicBlock *ResignBB =
nullptr, *ContBB =
nullptr;
267 Builder.CreateCondBr(IsNonNull, ResignBB, ContBB);
274 else if(!CurAuthInfo)
283Phi->addIncoming(Null, InitBB);
284Phi->addIncoming(
Value, ResignBB);
293llvm::Constant *StorageAddress,
294llvm::ConstantInt *OtherDiscriminator) {
295llvm::Constant *AddressDiscriminator;
296 if(StorageAddress) {
298AddressDiscriminator = StorageAddress;
300AddressDiscriminator = llvm::Constant::getNullValue(
UnqualPtrTy);
303llvm::ConstantInt *IntegerDiscriminator;
304 if(OtherDiscriminator) {
305assert(OtherDiscriminator->getType() ==
Int64Ty);
306IntegerDiscriminator = OtherDiscriminator;
308IntegerDiscriminator = llvm::ConstantInt::get(
Int64Ty, 0);
311 returnllvm::ConstantPtrAuth::get(
Pointer,
312llvm::ConstantInt::get(
Int32Ty, Key),
313IntegerDiscriminator, AddressDiscriminator);
327llvm::Constant *StorageAddress,
GlobalDeclSchemaDecl,
330llvm::ConstantInt *OtherDiscriminator =
347 Pointer, PointerAuth.getKey(),
nullptr,
348cast_or_null<llvm::ConstantInt>(PointerAuth.getDiscriminator()));
355 const auto*FD = cast<FunctionDecl>(GD.
getDecl());
360 if(!FD->hasPrototype())
363Proto->getExtInfo());
375 "function pointers cannot use address-specific discrimination");
377llvm::ConstantInt *Discriminator =
381 false, Discriminator);
388 Pointer, PointerAuth.getKey(),
nullptr,
389cast_or_null<llvm::ConstantInt>(PointerAuth.getDiscriminator()));
398FT, cast<CXXMethodDecl>(FD)->getParent()->getTypeForDecl());
402std::optional<PointerAuthQualifier>
403CodeGenModule::computeVTPointerAuthentication(
const CXXRecordDecl*ThisClass) {
405 if(!DefaultAuthentication)
410 unsignedKey = DefaultAuthentication.getKey();
411 boolAddressDiscriminated = DefaultAuthentication.isAddressDiscriminated();
412 autoDefaultDiscrimination = DefaultAuthentication.getOtherDiscrimination();
413 unsignedTypeBasedDiscriminator =
415 unsignedDiscriminator;
417Discriminator = TypeBasedDiscriminator;
418}
else if(DefaultDiscrimination ==
420Discriminator = DefaultAuthentication.getConstantDiscrimination();
425 if(
autoExplicitAuthentication =
426PrimaryBase->
getAttr<VTablePointerAuthenticationAttr>()) {
427 autoExplicitAddressDiscrimination =
428ExplicitAuthentication->getAddressDiscrimination();
429 autoExplicitDiscriminator =
430ExplicitAuthentication->getExtraDiscrimination();
432 unsignedExplicitKey = ExplicitAuthentication->getKey();
433 if(ExplicitKey == VTablePointerAuthenticationAttr::NoKey)
436 if(ExplicitKey != VTablePointerAuthenticationAttr::DefaultKey) {
437 if(ExplicitKey == VTablePointerAuthenticationAttr::ProcessIndependent)
440assert(ExplicitKey ==
441VTablePointerAuthenticationAttr::ProcessDependent);
446 if(ExplicitAddressDiscrimination !=
447VTablePointerAuthenticationAttr::DefaultAddressDiscrimination)
448AddressDiscriminated =
449ExplicitAddressDiscrimination ==
450VTablePointerAuthenticationAttr::AddressDiscrimination;
452 if(ExplicitDiscriminator ==
453VTablePointerAuthenticationAttr::TypeDiscrimination)
454Discriminator = TypeBasedDiscriminator;
455 else if(ExplicitDiscriminator ==
456VTablePointerAuthenticationAttr::CustomDiscrimination)
457Discriminator = ExplicitAuthentication->getCustomDiscriminationValue();
458 else if(ExplicitDiscriminator ==
459VTablePointerAuthenticationAttr::NoExtraDiscrimination)
468std::optional<PointerAuthQualifier>
470 if(!
Record->getDefinition() || !
Record->isPolymorphic())
473 autoExisting = VTablePtrAuthInfos.find(
Record);
474std::optional<PointerAuthQualifier> Authentication;
475 if(Existing != VTablePtrAuthInfos.end()) {
476Authentication = Existing->getSecond();
478Authentication = computeVTPointerAuthentication(
Record);
479VTablePtrAuthInfos.insert(std::make_pair(
Record, Authentication));
481 returnAuthentication;
484std::optional<CGPointerAuthInfo>
487llvm::Value *StorageAddress) {
492llvm::Value *Discriminator =
nullptr;
493 if(
autoExtraDiscriminator = Authentication->getExtraDiscriminator())
494Discriminator = llvm::ConstantInt::get(
IntPtrTy, ExtraDiscriminator);
496 if(Authentication->isAddressDiscriminated()) {
497assert(StorageAddress &&
498 "address not provided for address-discriminated schema");
503Discriminator = CGF->
Builder.CreatePtrToInt(StorageAddress,
IntPtrTy);
509 false, Discriminator);
522 if(!CurAuthInfo && !NewAuthInfo)
547 if(!CurAuthInfo && !NewAuthInfo)
578assert(
isValid() &&
"pointer isn't valid");
587assert(ElementType &&
"Effective type has to be set");
588assert(!Offset &&
"unexpected non-null offset");
592 if(CurInfo == NewInfo && !
hasOffset())
603llvm::Value *Address::emitRawPointerSlow(
CodeGenFunction&CGF)
const{
static bool isZeroConstant(const llvm::Value *Value)
static llvm::Value * getDiscriminatorOrZero(const CGPointerAuthInfo &Info, CGBuilderTy &Builder)
static bool equalAuthPolicies(const CGPointerAuthInfo &Left, const CGPointerAuthInfo &Right)
static CGPointerAuthInfo getPointerAuthInfoForPointeeType(CodeGenModule &CGM, QualType PointeeType)
Return the natural pointer authentication for values of the given pointee type.
static CGPointerAuthInfo getPointerAuthInfoForType(CodeGenModule &CGM, QualType PointerType)
Return the natural pointer authentication for values of the given pointer type.
llvm::MachO::Record Record
QualType getMemberPointerType(QualType T, const Type *Cls) const
Return the uniqued reference to the type for a member pointer to the specified type in the specified ...
QualType getFunctionNoProtoType(QualType ResultTy, const FunctionType::ExtInfo &Info) const
Return a K&R style C function type like 'int()'.
const CXXRecordDecl * baseForVTableAuthentication(const CXXRecordDecl *ThisClass)
Resolve the root record to be used to derive the vtable pointer authentication policy for the specifi...
uint16_t getPointerAuthVTablePointerDiscriminator(const CXXRecordDecl *RD)
Return the "other" discriminator used for the pointer auth schema used for vtable pointers in instanc...
uint16_t getPointerAuthTypeDiscriminator(QualType T)
Return the "other" type-specific discriminator for the given type.
Represents a C++ struct/union/class.
PointerAuthOptions PointerAuth
Configuration for pointer-signing.
Like RawAddress, an abstract representation of an aligned address, but the pointer contained in this ...
llvm::Value * getBasePointer() const
llvm::Value * emitRawPointer(CodeGenFunction &CGF) const
Return the pointer contained in this class after authenticating it and adding offset to it if necessa...
CharUnits getAlignment() const
llvm::Type * getElementType() const
Return the type of the values stored in this address.
void setPointerAuthInfo(const CGPointerAuthInfo &Info)
KnownNonNull_t isKnownNonNull() const
Whether the pointer is known not to be null.
Address getResignedAddress(const CGPointerAuthInfo &NewInfo, CodeGenFunction &CGF) const
const CGPointerAuthInfo & getPointerAuthInfo() const
llvm::PointerType * getType() const
Return the type of the pointer value.
PointerAuthenticationMode getAuthenticationMode() const
llvm::Value * getDiscriminator() const
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
llvm::Value * EmitPointerAuthAuth(const CGPointerAuthInfo &Info, llvm::Value *Pointer)
Address getAsNaturalAddressOf(Address Addr, QualType PointeeTy)
llvm::Value * emitPointerAuthResignCall(llvm::Value *Pointer, const CGPointerAuthInfo &CurInfo, const CGPointerAuthInfo &NewInfo)
llvm::Value * getAsNaturalPointerTo(Address Addr, QualType PointeeType)
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
llvm::Value * EmitPointerAuthSign(const CGPointerAuthInfo &Info, llvm::Value *Pointer)
llvm::Value * EmitPointerAuthBlendDiscriminator(llvm::Value *StorageAddress, llvm::Value *Discriminator)
Create the discriminator from the storage address and the entity hash.
llvm::Value * emitPointerAuthResign(llvm::Value *Pointer, QualType PointerType, const CGPointerAuthInfo &CurAuthInfo, const CGPointerAuthInfo &NewAuthInfo, bool IsKnownNonNull)
llvm::Value * authPointerToPointerCast(llvm::Value *ResultPtr, QualType SourceType, QualType DestType)
llvm::CallInst * EmitRuntimeCall(llvm::FunctionCallee callee, const Twine &name="")
CGPointerAuthInfo EmitPointerAuthInfo(const PointerAuthSchema &Schema, llvm::Value *StorageAddress, GlobalDecl SchemaDecl, QualType SchemaType)
This class organizes the cross-function state that is used while generating LLVM code.
llvm::Constant * getRawFunctionPointer(GlobalDecl GD, llvm::Type *Ty=nullptr)
Return a function pointer for a reference to the given function.
llvm::Constant * getFunctionPointer(GlobalDecl GD, llvm::Type *Ty=nullptr)
Return the ABI-correct function pointer value for a reference to the given function.
llvm::Constant * getNullPointer(llvm::PointerType *T, QualType QT)
Get target specific null pointer.
CGPointerAuthInfo getMemberFunctionPointerAuthInfo(QualType FT)
llvm::ConstantInt * getPointerAuthOtherDiscriminator(const PointerAuthSchema &Schema, GlobalDecl SchemaDecl, QualType SchemaType)
Given a pointer-authentication schema, return a concrete "other" discriminator for it.
CGPointerAuthInfo getPointerAuthInfoForPointeeType(QualType type)
const llvm::DataLayout & getDataLayout() const
CGPointerAuthInfo getFunctionPointerAuthInfo(QualType T)
Return the abstract pointer authentication schema for a pointer to the given function type.
llvm::Constant * getMemberFunctionPointer(const FunctionDecl *FD, llvm::Type *Ty=nullptr)
std::optional< PointerAuthQualifier > getVTablePointerAuthentication(const CXXRecordDecl *thisClass)
uint16_t getPointerAuthDeclDiscriminator(GlobalDecl GD)
Return the "other" decl-specific discriminator for the given decl.
ASTContext & getContext() const
const CodeGenOptions & getCodeGenOpts() const
StringRef getMangledName(GlobalDecl GD)
llvm::Function * getIntrinsic(unsigned IID, ArrayRef< llvm::Type * > Tys={})
std::optional< CGPointerAuthInfo > getVTablePointerAuthInfo(CodeGenFunction *Context, const CXXRecordDecl *Record, llvm::Value *StorageAddress)
llvm::Constant * getConstantSignedPointer(llvm::Constant *Pointer, const PointerAuthSchema &Schema, llvm::Constant *StorageAddress, GlobalDecl SchemaDecl, QualType SchemaType)
Sign a constant pointer using the given scheme, producing a constant with the same IR type.
bool shouldSignPointer(const PointerAuthSchema &Schema)
Does a given PointerAuthScheme require us to sign a value.
CGPointerAuthInfo getPointerAuthInfoForType(QualType type)
llvm::Value * emitResignedPointer(QualType PointeeTy, CodeGenFunction &CGF) const
llvm::Value * getPointer(CodeGenFunction &CGF) const
llvm::Value * emitRawPointer(CodeGenFunction &CGF) const
Decl - This represents one declaration (or definition), e.g.
Represents a function declaration or definition.
Represents a prototype with parameter type info, e.g.
FunctionType - C99 6.7.5.3 - Function Declarators.
GlobalDecl - represents a global declaration.
const Decl * getDecl() const
A pointer to member type per C++ 8.3.3 - Pointers to members.
static PointerAuthQualifier Create(unsigned Key, bool IsAddressDiscriminated, unsigned ExtraDiscriminator, PointerAuthenticationMode AuthenticationMode, bool IsIsaPointer, bool AuthenticatesNullValues)
Discrimination getOtherDiscrimination() const
bool isAddressDiscriminated() const
@ None
No additional discrimination.
@ Type
Include a hash of the entity's type.
@ Decl
Include a hash of the entity's identity.
@ Constant
Discriminate using a constant value.
bool authenticatesNullValues() const
PointerAuthenticationMode getAuthenticationMode() const
uint16_t getConstantDiscrimination() const
bool isIsaPointer() const
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
A (possibly-)qualified type.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
The base class of the type hierarchy.
bool isBlockPointerType() const
bool isFunctionReferenceType() const
bool isFunctionPointerType() const
bool isSignableType() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isFunctionType() const
const T * getAs() const
Member-template getAs<specific type>'.
uint16_t getPointerAuthDeclDiscriminator(CodeGenModule &CGM, GlobalDecl GD)
Return a declaration discriminator for the given global decl.
uint16_t getPointerAuthTypeDiscriminator(CodeGenModule &CGM, QualType FunctionType)
Return a type discriminator for the given function type.
bool Null(InterpState &S, CodePtr OpPC, uint64_t Value, const Descriptor *Desc)
bool IsNonNull(InterpState &S, CodePtr OpPC)
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T
llvm::IntegerType * Int64Ty
llvm::IntegerType * Int32Ty
llvm::IntegerType * IntPtrTy
llvm::PointerType * UnqualPtrTy
PointerAuthSchema CXXVTablePointers
The ABI for C++ virtual table pointers (the pointer to the table itself) as installed in an actual cl...
PointerAuthSchema FunctionPointers
The ABI for C function pointers.
PointerAuthSchema CXXMemberFunctionPointers
The ABI for C++ member function pointers.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4