OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
Sip.c
Go to the documentation of this file.
1
8#include <Uefi.h>
10#include <Guid/AppleVariable.h>
12#include <Library/UefiRuntimeServicesTableLib.h>
13
14EFI_STATUS
16 OUT UINT32 *CsrActiveConfig,
17 OUT UINT32 *Attributes OPTIONAL
18 )
19{
20 EFI_STATUS Status;
21 UINTN DataSize;
22
23 ASSERT (CsrActiveConfig != NULL);
24
25 DataSize = sizeof (*CsrActiveConfig);
26
27 Status = gRT->GetVariable (
28 L"csr-active-config",
30 Attributes,
31 &DataSize,
32 CsrActiveConfig
33 );
34
35 return Status;
36}
37
38EFI_STATUS
40 IN UINT32 *CsrActiveConfig,
41 IN UINT32 Attributes
42 )
43{
44 EFI_STATUS Status;
45
46 Status = gRT->SetVariable (
47 L"csr-active-config",
49 Attributes,
50 CsrActiveConfig == NULL ? 0 : sizeof (*CsrActiveConfig),
51 CsrActiveConfig
52 );
53
54 return Status;
55}
56
57BOOLEAN
59 IN EFI_STATUS GetStatus,
60 IN UINT32 CsrActiveConfig
61 )
62{
63 ASSERT (GetStatus == EFI_NOT_FOUND || !EFI_ERROR (GetStatus));
64
65 //
66 // CSR_ALLOW_APPLE_INTERNAL with no other bits set reports as SIP enabled
67 // (and is used as the enable value in some Apl setups)
68 //
69 return GetStatus == EFI_NOT_FOUND || (CsrActiveConfig & ~CSR_ALLOW_APPLE_INTERNAL) == 0;
70}
71
72EFI_STATUS
74 IN UINT32 CsrActiveConfig
75 )
76{
77 EFI_STATUS Status;
78 UINT32 Attributes;
79 UINT32 CsrConfig;
80
81 //
82 // Use existing attributes where present (e.g. keep changes made while WriteFlash = false as volatile only)
83 //
84 Status = OcGetSip (&CsrConfig, &Attributes);
85
86 if ((Status != EFI_NOT_FOUND) && EFI_ERROR (Status)) {
87 DEBUG ((DEBUG_ERROR, "OCVAR: Error getting SIP status - %r\n", Status));
88 } else {
89 if (Status == EFI_NOT_FOUND) {
90 Attributes = CSR_APPLE_SIP_NVRAM_NV_ATTR;
91 } else {
92 Attributes &= CSR_APPLE_SIP_NVRAM_NV_ATTR;
93 }
94
95 if (OcIsSipEnabled (Status, CsrConfig)) {
96 CsrConfig = CsrActiveConfig;
97 Status = OcSetSip (&CsrConfig, Attributes);
98 if (EFI_ERROR (Status)) {
99 DEBUG ((DEBUG_ERROR, "OCVAR: Error disabling SIP - r\n", Status));
100 }
101 } else {
102 CsrConfig = 0;
103 Status = OcSetSip (&CsrConfig, Attributes);
104 if (EFI_ERROR (Status)) {
105 DEBUG ((DEBUG_ERROR, "OCVAR: Error enabling SIP - r\n", Status));
106 }
107 }
108 }
109
110 return Status;
111}
#define CSR_APPLE_SIP_NVRAM_NV_ATTR
EFI_GUID gAppleBootVariableGuid
EFI_STATUS OcGetSip(OUT UINT32 *CsrActiveConfig, OUT UINT32 *Attributes OPTIONAL)
Definition Sip.c:15
BOOLEAN OcIsSipEnabled(IN EFI_STATUS GetStatus, IN UINT32 CsrActiveConfig)
Definition Sip.c:58
EFI_STATUS OcToggleSip(IN UINT32 CsrActiveConfig)
Definition Sip.c:73
EFI_STATUS OcSetSip(IN UINT32 *CsrActiveConfig, IN UINT32 Attributes)
Definition Sip.c:39
EFI_RUNTIME_SERVICES * gRT
#define ASSERT(x)
Definition coder.h:55