Skip to content

Commit 0e31f10

Browse files
committed
[CHERIoT] Add LoadGlobal permission encoding to cheriot_mmio and cheriot_shared_object attributes
1 parent 3e342ea commit 0e31f10

File tree

11 files changed

+436
-313
lines changed

11 files changed

+436
-313
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2892,16 +2892,16 @@ def CHERILibCall : DeclOrTypeAttr {
28922892
let Subjects = SubjectList<[Function], ErrorDiag>;
28932893
}
28942894

2895-
def CHERIOTMMIODevice : DeclOrTypeAttr {
2895+
def CHERIoTMMIODevice : DeclOrTypeAttr {
28962896
let Spellings = [GNU<"cheriot_mmio">];
2897-
let Documentation = [CHERIOTMMIODeviceDocs];
2897+
let Documentation = [CHERIoTMMIODeviceDocs];
28982898
let Args = [StringArgument<"DeviceName">, StringArgument<"EncodedPermissions", 1>];
28992899
let Subjects = SubjectList<[GlobalVar], ErrorDiag>;
29002900
}
29012901

2902-
def CHERIOTSharedObject : DeclOrTypeAttr {
2902+
def CHERIoTSharedObject : DeclOrTypeAttr {
29032903
let Spellings = [GNU<"cheriot_shared_object">];
2904-
let Documentation = [CHERIOTSharedObjectDocs];
2904+
let Documentation = [CHERIoTSharedObjectDocs];
29052905
let Args = [StringArgument<"ObjectName">, StringArgument<"EncodedPermissions", 1>];
29062906
let Subjects = SubjectList<[GlobalVar], ErrorDiag>;
29072907
}

clang/include/clang/Basic/AttrDocs.td

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,7 +1473,7 @@ Further reading for other annotations:
14731473
}];
14741474
}
14751475

1476-
def CHERIOTMMIODeviceDocs : Documentation {
1476+
def CHERIoTMMIODeviceDocs : Documentation {
14771477
let Category = DocCatVariable;
14781478
let Content = [{
14791479
Indicates that the global it refers to must be treated as a cross-compartment
@@ -1486,7 +1486,7 @@ qualifiers.
14861486
of the MMIO-bound device. An example of this is ``"uart"``. The
14871487
``"<permissions_encoding>"`` indicates the permissions of the capability
14881488
resulting from the import. The permissions encoding is a string of variable
1489-
length. The symbols allowed in the string are ``R``, ``W``, ``c`` and ``m``,
1489+
length. The symbols allowed in the string are ``R``, ``W``, ``c``, ``m`` and ``g``,
14901490
whose meaning is explained in the table below.
14911491

14921492

@@ -1496,18 +1496,19 @@ whose meaning is explained in the table below.
14961496
"``R``","Load (Read)", "May be used to read.",""
14971497
"``W``","Store (Write)", "May be used to write.",""
14981498
"``c``","Load / Store Capability", "May be used to load or store capabilities as well as non-capability data.","``R`` or ``W``"
1499-
"``m``","Load Mutable", "May be used to load capabilities with write permission.","``R``"
1499+
"``m``","Load Mutable", "May be used to load capabilities with write permission.","``R`` and ``c``"
1500+
"``g``","Load Global", " May be used to load capabilities with the global permission.","``R`` and ``c``"
15001501

15011502
Examples of valid encodings are: ``"RWcm"`` (all permissions), ``"R"`` (read
15021503
only), etc. Note that the order in which symbols appear is not relevant: for
15031504
example, `"RWcm"` and `"mcWR"` are both valid and entail the same permissions.
15041505

1505-
**Warning**: The ``<permissions_encoding>`` parameter is optional, and if no encoding is given ``"RWcm"`` is assumed.
1506+
**Warning**: The ``<permissions_encoding>`` parameter is optional, and if no encoding is given ``"RWcmg"`` is assumed.
15061507
}];
15071508
}
15081509

15091510

1510-
def CHERIOTSharedObjectDocs : Documentation {
1511+
def CHERIoTSharedObjectDocs : Documentation {
15111512
let Category = DocCatVariable;
15121513
let Content = [{
15131514
Indicates that the global it refers to must be treated as a cross-compartment
@@ -1521,7 +1522,7 @@ cross-compartment shared object. The target global must have the `extern` and
15211522
of the shared object. The ``"<permissions_encoding>"`` indicates the permissions
15221523
of the capability resulting from the import. The permissions encoding is a
15231524
string of variable length. The symbols allowed in the string are ``R``, ``W``,
1524-
``c`` and ``m``, whose meaning is explained in the table below.
1525+
``c``, ``m`` and ``g``, whose meaning is explained in the table below.
15251526

15261527

15271528
.. csv-table:: Supported Syntaxes
@@ -1530,13 +1531,14 @@ string of variable length. The symbols allowed in the string are ``R``, ``W``,
15301531
"``R``","Load (Read)", "May be used to read.",""
15311532
"``W``","Store (Write)", "May be used to write.",""
15321533
"``c``","Load / Store Capability", "May be used to load or store capabilities as well as non-capability data.","``R`` or ``W``"
1533-
"``m``","Load Mutable", "May be used to load capabilities with write permission.","``R``"
1534+
"``m``","Load Mutable", "May be used to load capabilities with write permission.","``R`` and ``c``"
1535+
"``g``","Load Global", " May be used to load capabilities with the global permission.","``R`` and ``c``"
15341536

15351537
Examples of valid encodings are: ``"RWcm"`` (all permissions), ``"R"`` (read
15361538
only), etc. Note that the order in which symbols appear is not relevant: for
15371539
example, `"RWcm"` and `"mcWR"` are both valid and entail the same permissions.
15381540

1539-
**Warning**: The ``<permissions_encoding>`` parameter is optional, and if no encoding is given ``"RWcm"`` is assumed.
1541+
**Warning**: The ``<permissions_encoding>`` parameter is optional, and if no encoding is given ``"RWcmg"`` is assumed.
15401542
}];
15411543
}
15421544

clang/lib/AST/TypePrinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2106,10 +2106,10 @@ void TypePrinter::printAttributedAfter(const AttributedType *T,
21062106
case attr::CHERILibCall:
21072107
OS << "cheri_libcall";
21082108
break;
2109-
case attr::CHERIOTMMIODevice:
2109+
case attr::CHERIoTMMIODevice:
21102110
OS << "cheriot_mmio";
21112111
break;
2112-
case attr::CHERIOTSharedObject:
2112+
case attr::CHERIoTSharedObject:
21132113
OS << "cheriot_shared_object";
21142114
break;
21152115
case attr::CHERIoTSealedType:

clang/lib/CodeGen/Targets/RISCV.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -667,17 +667,17 @@ class RISCVTargetCodeGenInfo : public CommonCheriTargetCodeGenInfo {
667667
// `cheriot_cap_import` attribute in the generated LLVM IR, so that the
668668
// back-end can generate the proper import entries and correctly
669669
// translate references to this global.
670-
if (VD->hasAttr<CHERIOTMMIODeviceAttr>()) {
671-
auto *Attr = D->getAttr<CHERIOTMMIODeviceAttr>();
670+
if (VD->hasAttr<CHERIoTMMIODeviceAttr>()) {
671+
auto *Attr = D->getAttr<CHERIoTMMIODeviceAttr>();
672672
llvm::CHERIoTGlobalCapabilityImportAttr CapImportAttr(
673673
llvm::CHERIoTGlobalCapabilityImportAttr::MMIO,
674674
Attr->getDeviceName(), Attr->getEncodedPermissions());
675675
GVar->addAttribute(CapImportAttr.getAttrName(), CapImportAttr.str());
676676
}
677677

678678
// Same for the `cheriot_shared_object(...)` attribute.
679-
if (VD->hasAttr<CHERIOTSharedObjectAttr>()) {
680-
auto *Attr = D->getAttr<CHERIOTSharedObjectAttr>();
679+
if (VD->hasAttr<CHERIoTSharedObjectAttr>()) {
680+
auto *Attr = D->getAttr<CHERIoTSharedObjectAttr>();
681681
llvm::CHERIoTGlobalCapabilityImportAttr CapImportAttr(
682682
llvm::CHERIoTGlobalCapabilityImportAttr::SharedObject,
683683
Attr->getObjectName(), Attr->getEncodedPermissions());

clang/lib/Sema/SemaDecl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13504,14 +13504,14 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) {
1350413504
// CHERIoT-specific check: if the decl has the `cheriot_mmio` or
1350513505
// `cheriot_shared_object` attributes and also has an explicit definition, an
1350613506
// error must be generated.
13507-
if (RealDecl->hasAttr<CHERIOTSharedObjectAttr>() ||
13508-
RealDecl->hasAttr<CHERIOTMMIODeviceAttr>()) {
13507+
if (RealDecl->hasAttr<CHERIoTSharedObjectAttr>() ||
13508+
RealDecl->hasAttr<CHERIoTMMIODeviceAttr>()) {
1350913509
const IdentifierInfo *AttrName;
1351013510

13511-
if (auto *Attr = RealDecl->getAttr<CHERIOTSharedObjectAttr>())
13511+
if (auto *Attr = RealDecl->getAttr<CHERIoTSharedObjectAttr>())
1351213512
AttrName = Attr->getAttrName();
1351313513
else {
13514-
AttrName = RealDecl->getAttr<CHERIOTMMIODeviceAttr>()->getAttrName();
13514+
AttrName = RealDecl->getAttr<CHERIoTMMIODeviceAttr>()->getAttrName();
1351513515
}
1351613516

1351713517
Diag(RealDecl->getLocation(),

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2106,7 +2106,7 @@ static void handleCHERIMethodSuffix(Sema &S, Decl *D, const ParsedAttr &Attr) {
21062106
D->addAttr(::new (S.Context) CHERIMethodSuffixAttr(S.Context, Attr, Str));
21072107
}
21082108

2109-
static void handleCHERIOTMMIODevice(Sema &S, Decl *D, const ParsedAttr &Attr,
2109+
static void handleCHERIoTMMIODevice(Sema &S, Decl *D, const ParsedAttr &Attr,
21102110
Sema::DeclAttributeLocation DAL) {
21112111
auto *VD = dyn_cast<VarDecl>(D);
21122112
if (!VD || !VD->hasGlobalStorage())
@@ -2166,11 +2166,11 @@ static void handleCHERIOTMMIODevice(Sema &S, Decl *D, const ParsedAttr &Attr,
21662166
FailedSemanticCheckCallback))
21672167
return;
21682168

2169-
return D->addAttr(::new (S.Context) CHERIOTMMIODeviceAttr(
2169+
return D->addAttr(::new (S.Context) CHERIoTMMIODeviceAttr(
21702170
S.Context, Attr, DeviceName, OwnedPermissions));
21712171
}
21722172

2173-
static void handleCHERIOTSharedObject(Sema &S, Decl *D, const ParsedAttr &Attr,
2173+
static void handleCHERIoTSharedObject(Sema &S, Decl *D, const ParsedAttr &Attr,
21742174
Sema::DeclAttributeLocation DAL) {
21752175
auto *VD = dyn_cast<VarDecl>(D);
21762176
if (!VD || !VD->hasGlobalStorage())
@@ -2226,7 +2226,7 @@ static void handleCHERIOTSharedObject(Sema &S, Decl *D, const ParsedAttr &Attr,
22262226
FailedSemanticCheckCallback))
22272227
return;
22282228

2229-
D->addAttr(::new (S.Context) CHERIOTSharedObjectAttr(
2229+
D->addAttr(::new (S.Context) CHERIoTSharedObjectAttr(
22302230
S.Context, Attr, ObjectName, OwnedPermissions));
22312231
}
22322232

@@ -7501,11 +7501,11 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const ParsedAttr &AL,
75017501
case ParsedAttr::AT_CHERICompartmentName:
75027502
handleCHERICompartmentName(S, D, AL, DAL);
75037503
break;
7504-
case ParsedAttr::AT_CHERIOTMMIODevice:
7505-
handleCHERIOTMMIODevice(S, D, AL, DAL);
7504+
case ParsedAttr::AT_CHERIoTMMIODevice:
7505+
handleCHERIoTMMIODevice(S, D, AL, DAL);
75067506
break;
7507-
case ParsedAttr::AT_CHERIOTSharedObject:
7508-
handleCHERIOTSharedObject(S, D, AL, DAL);
7507+
case ParsedAttr::AT_CHERIoTSharedObject:
7508+
handleCHERIoTSharedObject(S, D, AL, DAL);
75097509
break;
75107510
case ParsedAttr::AT_CHERIoTSealedType:
75117511
handleCHERIoTSealedType(S, D, AL, DAL);

0 commit comments

Comments
 (0)