kernel: add ubsan bindings, fix some UB reported by it

This commit is contained in:
Matheus
2024-12-31 11:20:27 -03:00
parent 4ee5fa42ae
commit 6245a3d19f
11 changed files with 348 additions and 90 deletions
+8 -6
View File
@@ -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;