mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-30 14:08:21 +00:00
kernel: add ubsan bindings, fix some UB reported by it
This commit is contained in:
+8
-6
@@ -12,6 +12,11 @@ uint16_t pci_read16(int bus, int device, int function, uint32_t offset) {
|
||||
return (pci_archread32(bus, device, function, offset) >> ((offset & 0b11) * 8)) & 0xffff;
|
||||
}
|
||||
|
||||
uint32_t pci_read32(int bus, int device, int function, uint32_t offset) {
|
||||
return pci_archread32(bus, device, function, offset);
|
||||
}
|
||||
|
||||
|
||||
void pci_write8(int bus, int device, int function, uint32_t offset, uint8_t v) {
|
||||
uint32_t old = pci_archread32(bus, device, function, offset);
|
||||
int bitoffset = 8 * (offset & 0b11);
|
||||
@@ -23,19 +28,16 @@ void pci_write8(int bus, int device, int function, uint32_t offset, uint8_t v) {
|
||||
void pci_write16(int bus, int device, int function, uint32_t offset, uint16_t v) {
|
||||
uint32_t old = pci_archread32(bus, device, function, offset);
|
||||
int bitoffset = 8 * (offset & 0b11);
|
||||
old &= ~(0xffff << bitoffset);
|
||||
old |= v << bitoffset;
|
||||
old &= ~(0xfffflu << bitoffset);
|
||||
old |= (uint32_t)v << bitoffset;
|
||||
pci_archwrite32(bus, device, function, offset, old);
|
||||
}
|
||||
|
||||
uint32_t pci_read32(int bus, int device, int function, uint32_t offset) {
|
||||
return pci_archread32(bus, device, function, offset);
|
||||
}
|
||||
|
||||
void pci_write32(int bus, int device, int function, uint32_t offset, uint32_t value) {
|
||||
pci_archwrite32(bus, device, function, offset, value);
|
||||
}
|
||||
|
||||
|
||||
int pci_getcapoffset(pcienum_t *e, int cap, int n) {
|
||||
if ((PCI_READ16(e, PCI_CONFIG_STATUS) & PCI_STATUS_HASCAP) == 0)
|
||||
return 0;
|
||||
|
||||
@@ -30,7 +30,7 @@ static int maxseek(int minor, size_t *max) {
|
||||
|
||||
static long current = 0xdeadbeefbadc0ffe;
|
||||
|
||||
static uint8_t getrand8() {
|
||||
__attribute__((no_sanitize("undefined"))) static uint8_t getrand8() {
|
||||
current += timekeeper_timefromboot().ns * timekeeper_timefromboot().s - timekeeper_time().ns * timekeeper_time().s + timekeeper_time().s;
|
||||
return current & 0xff;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user