Skip to content

Commit 1ece9ce

Browse files
xdoardoresistor
authored andcommitted
[CHERIoT] Add LoadGlobal permission encoding to cheriot_mmio and cheriot_shared_object attributes
1 parent 2486434 commit 1ece9ce

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
@@ -3048,16 +3048,16 @@ def CHERILibCall : DeclOrTypeAttr {
30483048
let Subjects = SubjectList<[Function], ErrorDiag>;
30493049
}
30503050

3051-
def CHERIOTMMIODevice : DeclOrTypeAttr {
3051+
def CHERIoTMMIODevice : DeclOrTypeAttr {
30523052
let Spellings = [GNU<"cheriot_mmio">];
3053-
let Documentation = [CHERIOTMMIODeviceDocs];
3053+
let Documentation = [CHERIoTMMIODeviceDocs];
30543054
let Args = [StringArgument<"DeviceName">, StringArgument<"EncodedPermissions", 1>];
30553055
let Subjects = SubjectList<[GlobalVar], ErrorDiag>;
30563056
}
30573057

3058-
def CHERIOTSharedObject : DeclOrTypeAttr {
3058+
def CHERIoTSharedObject : DeclOrTypeAttr {
30593059
let Spellings = [GNU<"cheriot_shared_object">];
3060-
let Documentation = [CHERIOTSharedObjectDocs];
3060+
let Documentation = [CHERIoTSharedObjectDocs];
30613061
let Args = [StringArgument<"ObjectName">, StringArgument<"EncodedPermissions", 1>];
30623062
let Subjects = SubjectList<[GlobalVar], ErrorDiag>;
30633063
}

clang/include/clang/Basic/AttrDocs.td

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,7 +1522,7 @@ Further reading for other annotations:
15221522
}];
15231523
}
15241524

1525-
def CHERIOTMMIODeviceDocs : Documentation {
1525+
def CHERIoTMMIODeviceDocs : Documentation {
15261526
let Category = DocCatVariable;
15271527
let Content = [{
15281528
Indicates that the global it refers to must be treated as a cross-compartment
@@ -1535,7 +1535,7 @@ qualifiers.
15351535
of the MMIO-bound device. An example of this is ``"uart"``. The
15361536
``"<permissions_encoding>"`` indicates the permissions of the capability
15371537
resulting from the import. The permissions encoding is a string of variable
1538-
length. The symbols allowed in the string are ``R``, ``W``, ``c`` and ``m``,
1538+
length. The symbols allowed in the string are ``R``, ``W``, ``c``, ``m`` and ``g``,
15391539
whose meaning is explained in the table below.
15401540

15411541

@@ -1545,18 +1545,19 @@ whose meaning is explained in the table below.
15451545
"``R``","Load (Read)", "May be used to read.",""
15461546
"``W``","Store (Write)", "May be used to write.",""
15471547
"``c``","Load / Store Capability", "May be used to load or store capabilities as well as non-capability data.","``R`` or ``W``"
1548-
"``m``","Load Mutable", "May be used to load capabilities with write permission.","``R``"
1548+
"``m``","Load Mutable", "May be used to load capabilities with write permission.","``R`` and ``c``"
1549+
"``g``","Load Global", " May be used to load capabilities with the global permission.","``R`` and ``c``"
15491550

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

1554-
**Warning**: The ``<permissions_encoding>`` parameter is optional, and if no encoding is given ``"RWcm"`` is assumed.
1555+
**Warning**: The ``<permissions_encoding>`` parameter is optional, and if no encoding is given ``"RWcmg"`` is assumed.
15551556
}];
15561557
}
15571558

15581559

1559-
def CHERIOTSharedObjectDocs : Documentation {
1560+
def CHERIoTSharedObjectDocs : Documentation {
15601561
let Category = DocCatVariable;
15611562
let Content = [{
15621563
Indicates that the global it refers to must be treated as a cross-compartment
@@ -1570,7 +1571,7 @@ cross-compartment shared object. The target global must have the `extern` and
15701571
of the shared object. The ``"<permissions_encoding>"`` indicates the permissions
15711572
of the capability resulting from the import. The permissions encoding is a
15721573
string of variable length. The symbols allowed in the string are ``R``, ``W``,
1573-
``c`` and ``m``, whose meaning is explained in the table below.
1574+
``c``, ``m`` and ``g``, whose meaning is explained in the table below.
15741575

15751576

15761577
.. csv-table:: Supported Syntaxes
@@ -1579,13 +1580,14 @@ string of variable length. The symbols allowed in the string are ``R``, ``W``,
15791580
"``R``","Load (Read)", "May be used to read.",""
15801581
"``W``","Store (Write)", "May be used to write.",""
15811582
"``c``","Load / Store Capability", "May be used to load or store capabilities as well as non-capability data.","``R`` or ``W``"
1582-
"``m``","Load Mutable", "May be used to load capabilities with write permission.","``R``"
1583+
"``m``","Load Mutable", "May be used to load capabilities with write permission.","``R`` and ``c``"
1584+
"``g``","Load Global", " May be used to load capabilities with the global permission.","``R`` and ``c``"
15831585

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

1588-
**Warning**: The ``<permissions_encoding>`` parameter is optional, and if no encoding is given ``"RWcm"`` is assumed.
1590+
**Warning**: The ``<permissions_encoding>`` parameter is optional, and if no encoding is given ``"RWcmg"`` is assumed.
15891591
}];
15901592
}
15911593

clang/lib/AST/TypePrinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2149,10 +2149,10 @@ void TypePrinter::printAttributedAfter(const AttributedType *T,
21492149
case attr::CHERILibCall:
21502150
OS << "cheri_libcall";
21512151
break;
2152-
case attr::CHERIOTMMIODevice:
2152+
case attr::CHERIoTMMIODevice:
21532153
OS << "cheriot_mmio";
21542154
break;
2155-
case attr::CHERIOTSharedObject:
2155+
case attr::CHERIoTSharedObject:
21562156
OS << "cheriot_shared_object";
21572157
break;
21582158
case attr::CHERIoTSealedType:

clang/lib/CodeGen/Targets/RISCV.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -875,17 +875,17 @@ class RISCVTargetCodeGenInfo : public CommonCheriTargetCodeGenInfo {
875875
// `cheriot_cap_import` attribute in the generated LLVM IR, so that the
876876
// back-end can generate the proper import entries and correctly
877877
// translate references to this global.
878-
if (VD->hasAttr<CHERIOTMMIODeviceAttr>()) {
879-
auto *Attr = D->getAttr<CHERIOTMMIODeviceAttr>();
878+
if (VD->hasAttr<CHERIoTMMIODeviceAttr>()) {
879+
auto *Attr = D->getAttr<CHERIoTMMIODeviceAttr>();
880880
llvm::CHERIoTGlobalCapabilityImportAttr CapImportAttr(
881881
llvm::CHERIoTGlobalCapabilityImportAttr::MMIO,
882882
Attr->getDeviceName(), Attr->getEncodedPermissions());
883883
GVar->addAttribute(CapImportAttr.getAttrName(), CapImportAttr.str());
884884
}
885885

886886
// Same for the `cheriot_shared_object(...)` attribute.
887-
if (VD->hasAttr<CHERIOTSharedObjectAttr>()) {
888-
auto *Attr = D->getAttr<CHERIOTSharedObjectAttr>();
887+
if (VD->hasAttr<CHERIoTSharedObjectAttr>()) {
888+
auto *Attr = D->getAttr<CHERIoTSharedObjectAttr>();
889889
llvm::CHERIoTGlobalCapabilityImportAttr CapImportAttr(
890890
llvm::CHERIoTGlobalCapabilityImportAttr::SharedObject,
891891
Attr->getObjectName(), Attr->getEncodedPermissions());

clang/lib/Sema/SemaDecl.cpp

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

13736-
if (auto *Attr = RealDecl->getAttr<CHERIOTSharedObjectAttr>())
13736+
if (auto *Attr = RealDecl->getAttr<CHERIoTSharedObjectAttr>())
1373713737
AttrName = Attr->getAttrName();
1373813738
else {
13739-
AttrName = RealDecl->getAttr<CHERIOTMMIODeviceAttr>()->getAttrName();
13739+
AttrName = RealDecl->getAttr<CHERIoTMMIODeviceAttr>()->getAttrName();
1374013740
}
1374113741

1374213742
Diag(RealDecl->getLocation(),

clang/lib/Sema/SemaDeclAttr.cpp

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

2208-
static void handleCHERIOTMMIODevice(Sema &S, Decl *D, const ParsedAttr &Attr,
2208+
static void handleCHERIoTMMIODevice(Sema &S, Decl *D, const ParsedAttr &Attr,
22092209
Sema::DeclAttributeLocation DAL) {
22102210
auto *VD = dyn_cast<VarDecl>(D);
22112211
if (!VD || !VD->hasGlobalStorage())
@@ -2265,11 +2265,11 @@ static void handleCHERIOTMMIODevice(Sema &S, Decl *D, const ParsedAttr &Attr,
22652265
FailedSemanticCheckCallback))
22662266
return;
22672267

2268-
return D->addAttr(::new (S.Context) CHERIOTMMIODeviceAttr(
2268+
return D->addAttr(::new (S.Context) CHERIoTMMIODeviceAttr(
22692269
S.Context, Attr, DeviceName, OwnedPermissions));
22702270
}
22712271

2272-
static void handleCHERIOTSharedObject(Sema &S, Decl *D, const ParsedAttr &Attr,
2272+
static void handleCHERIoTSharedObject(Sema &S, Decl *D, const ParsedAttr &Attr,
22732273
Sema::DeclAttributeLocation DAL) {
22742274
auto *VD = dyn_cast<VarDecl>(D);
22752275
if (!VD || !VD->hasGlobalStorage())
@@ -2325,7 +2325,7 @@ static void handleCHERIOTSharedObject(Sema &S, Decl *D, const ParsedAttr &Attr,
23252325
FailedSemanticCheckCallback))
23262326
return;
23272327

2328-
D->addAttr(::new (S.Context) CHERIOTSharedObjectAttr(
2328+
D->addAttr(::new (S.Context) CHERIoTSharedObjectAttr(
23292329
S.Context, Attr, ObjectName, OwnedPermissions));
23302330
}
23312331

@@ -7967,11 +7967,11 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const ParsedAttr &AL,
79677967
case ParsedAttr::AT_CHERICompartmentName:
79687968
handleCHERICompartmentName(S, D, AL, DAL);
79697969
break;
7970-
case ParsedAttr::AT_CHERIOTMMIODevice:
7971-
handleCHERIOTMMIODevice(S, D, AL, DAL);
7970+
case ParsedAttr::AT_CHERIoTMMIODevice:
7971+
handleCHERIoTMMIODevice(S, D, AL, DAL);
79727972
break;
7973-
case ParsedAttr::AT_CHERIOTSharedObject:
7974-
handleCHERIOTSharedObject(S, D, AL, DAL);
7973+
case ParsedAttr::AT_CHERIoTSharedObject:
7974+
handleCHERIoTSharedObject(S, D, AL, DAL);
79757975
break;
79767976
case ParsedAttr::AT_CHERIoTSealedType:
79777977
handleCHERIoTSealedType(S, D, AL, DAL);

0 commit comments

Comments
 (0)