Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull the latest asan #24

Merged
merged 7 commits into from
Dec 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ jobs:
export ONYX_ARCH=x86_64
./scripts/setup_build.sh
RUN_CLANG_TIDY=0 make -j $(nproc) iso
./scripts/create_disk_image.sh disk-image.img --bootable efi

- name: Upload a Build Artifact(Onyx.iso)
uses: actions/upload-artifact@v2.1.4
Expand All @@ -65,11 +66,11 @@ jobs:
name: vmonyx
path: kernel/vmonyx

- name: Upload a Build Artifact(sysroot)
- name: Upload a Build Artifact(Disk image)
uses: actions/upload-artifact@v2.1.4
with:
name: Sysroot
path: sysroot/
name: Disk-image.img
path: disk-image.img

build-llvm:
# The type of runner that the job will run on
Expand Down Expand Up @@ -113,6 +114,7 @@ jobs:
export ONYX_ARCH=x86_64
./scripts/setup_build.sh
RUN_CLANG_TIDY=0 make -j $(nproc) iso
./scripts/create_disk_image.sh disk-image-llvm.img --bootable efi

- name: Upload a Build Artifact(Onyx.iso)
uses: actions/upload-artifact@v2.1.4
Expand All @@ -126,11 +128,11 @@ jobs:
name: vmonyx-llvm
path: kernel/vmonyx

- name: Upload a Build Artifact(sysroot-llvm)
- name: Upload a Build Artifact(disk-image-llvm)
uses: actions/upload-artifact@v2.1.4
with:
name: Sysroot-llvm
path: sysroot/
name: Disk-image-llvm.img
path: disk-image-llvm.img

# Builds a minimal sysroot, with headers and the libc. Supposed to be used when building a toolchain.
# In this case, we limit ourselves to building a stage 1 GNU toolchain since LLVM is far slower to build,
Expand Down
11 changes: 5 additions & 6 deletions kernel/arch/x86_64/mmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,12 +730,11 @@ bool paging_write_protect(void *addr, struct mm_address_space *mm)

int is_invalid_arch_range(void *address, size_t pages)
{
for(uintptr_t addr = (uintptr_t) address, i = 0; i < pages; ++i, addr += PAGE_SIZE)
{
// Non canonical
if(addr > arch_low_half_max && addr < VM_HIGHER_HALF)
return -1;
}
unsigned long addr = (unsigned long) address;
auto limit = addr + (pages << PAGE_SHIFT);

if (addr <= arch_low_half_max && limit >= VM_HIGHER_HALF)
return -1;
return 0;
}

Expand Down
49 changes: 37 additions & 12 deletions kernel/drivers/ahci/ahci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ irqstatus_t ahci_irq(struct irq_context *ctx, void *cookie)

if(ports & (1U << i))
{
if(!port->port)
{
panic("what? panic at the disco #%u", i);
return IRQ_UNHANDLED;
}

uint32_t port_is = port->port->interrupt_status;
port->port->interrupt_status = port_is;
dev->hba->interrupt_status = (1U << i);
Expand Down Expand Up @@ -901,6 +907,9 @@ void ahci_init_port(struct ahci_port *ahci_port)
struct ahci_device *device = ahci_port->dev;
ahci_hba_memory_regs_t *hba = device->hba;

// ACK old interrupts that might've gotten stuck
uint32_t port_is = port->interrupt_status;
port->interrupt_status = port_is;
/* Enable interrupts */
ahci_enable_interrupts_for_port(port);

Expand Down Expand Up @@ -945,7 +954,7 @@ void ahci_init_port(struct ahci_port *ahci_port)

port->pxcmd = port->pxcmd | AHCI_PORT_CMD_START;

ahci_do_identify(ahci_port);
//ahci_do_identify(ahci_port);
}

int ahci_initialize(struct ahci_device *device)
Expand All @@ -955,9 +964,6 @@ int ahci_initialize(struct ahci_device *device)
/* Firstly, set the AE bit on the GHC register to indicate we're AHCI aware */
hba->ghc = hba->ghc | AHCI_GHC_AHCI_ENABLE;

/* Now, enable interrupts in the HBA */
hba->ghc = hba->ghc | AHCI_GHC_INTERRUPTS_ENABLE;

int nr_ports = AHCI_CAP_NR_PORTS(hba->host_cap);
if(nr_ports == 0) nr_ports = 1;

Expand Down Expand Up @@ -1015,13 +1021,16 @@ int ahci_initialize(struct ahci_device *device)
device->ports[i].port_nr = i;
device->ports[i].port = &hba->ports[i];
device->ports[i].dev = device;
device->ports[i].bdev = dev;

ahci_init_port(&device->ports[i]);

blkdev_init(dev);
}
}

hba->interrupt_status = hba->interrupt_status;
/* Now, enable interrupts in the HBA */
hba->ghc = hba->ghc | AHCI_GHC_INTERRUPTS_ENABLE;

return 0;
}

Expand All @@ -1036,6 +1045,7 @@ int ahci_probe(struct device *dev)
{
int status = 0;
int irq = -1;
int nr_ports;
pci::pci_device *ahci_dev = (pci::pci_device *) dev;

if(ahci_dev->enable_device() < 0)
Expand Down Expand Up @@ -1063,7 +1073,15 @@ int ahci_probe(struct device *dev)
status = -1;
goto ret;
}


/* Initialize AHCI */
if(ahci_initialize(device) < 0)
{
MPRINTF("Failed to initialize the AHCI controller\n");
status = -1;
goto ret;
}

if(ahci_dev->enable_msi(ahci_irq, device))
{
/* If we couldn't enable MSI, use normal I/O APIC pins */
Expand All @@ -1075,12 +1093,19 @@ int ahci_probe(struct device *dev)
assert(install_irq(irq, ahci_irq, (struct device *) ahci_dev,
IRQ_FLAG_REGULAR, device) == 0);
}
/* Initialize AHCI */
if(ahci_initialize(device) < 0)

nr_ports = AHCI_CAP_NR_PORTS(hba->host_cap);
if(nr_ports == 0) nr_ports = 1;

// For every port in the controller, see if we have initialised it. If so, do identify and blkdev_init
for (int i = 0; i < nr_ports; i++)
{
MPRINTF("Failed to initialize the AHCI controller\n");
status = -1;
goto ret;
if (!device->ports[i].bdev)
continue;

ahci_do_identify(&device->ports[i]);

blkdev_init(device->ports[i].bdev);
}

ahci_probe_ports(count_bits<uint32_t>(hba->ports_implemented), hba);
Expand Down
1 change: 1 addition & 0 deletions kernel/drivers/ahci/include/ahci.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ struct ahci_port
struct wait_queue list_wq;
unsigned char identify[512];
uint32_t issued;
blockdev *bdev;
};

struct ahci_device
Expand Down
5 changes: 5 additions & 0 deletions kernel/drivers/ata/ata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,11 @@ int ata_probe(struct device *d)
{
pci::pci_device *device = (pci::pci_device *) d;

// If this is a SATA controller with a valid BAR5 (AHCI HBA BAR), skip this
// and defer to AHCI.
if (device->sub_class() == 6 && device->get_bar(5).has_value())
return -1;

unique_ptr<ide_dev> dev = make_unique<ide_dev>(device);
if(!dev)
return -ENOMEM;
Expand Down
3 changes: 3 additions & 0 deletions kernel/drivers/pci/pci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,9 @@ void __pci_bus_register(struct driver *driver, struct bus *bus)
dev->addr().segment, dev->addr().bus, dev->addr().device, dev->addr().function,
dev->did(), dev->vid());
#endif
// Bound, skip.
if(dev->driver_)
continue;

if((id = pci_driver_supports_device(driver, dev)))
{
Expand Down
2 changes: 1 addition & 1 deletion kernel/include/onyx/x86/include/platform/vm_layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

typedef enum
{
arch_low_half_min = 0x400000,
arch_low_half_min = 0x200000,
arch_brk_base = 0x80000000,
arch_mmap_base = 0x0000550000000000,
arch_low_half_max = 0x00007fffffffffff,
Expand Down
1 change: 0 additions & 1 deletion kernel/kernel/fs/partition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ int partition_setup_disk_gpt(struct blockdev *dev)
goto out;
}

//printk("registered! lba %lu\n", e->first_lba);
nr_parts++;
}

Expand Down
41 changes: 1 addition & 40 deletions kernel/kernel/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,45 +86,6 @@ void *tramp = NULL;
void *phys_fb = NULL;
uintptr_t address = 0;

extern void libc_late_init();

char *kernel_arguments[200];
int kernel_argc = 0;

void kernel_parse_command_line(char *cmd)
{
char *original_string = cmd;
while(*cmd)
{
if(*cmd == '-') /* Found an argument */
{
char *token = strchr(cmd, ' ');
if(!token)
token = original_string + strlen(original_string);
size_t size_token = (size_t)(token - cmd);
char *new_string = (char *) malloc(size_token + 1);
if(!new_string)
{
ERROR("kernel", "failed parsing: out of memory\n");
}

memset(new_string, 0, size_token + 1);
memcpy(new_string, cmd, size_token);

if(kernel_argc == 200)
{
panic("kernel: too many arguments passed to the kernel");
}

kernel_arguments[kernel_argc] = new_string;
kernel_argc++;
cmd += size_token - 1;
}

cmd++;
}
}

void set_initrd_address(void *initrd_address)
{
initrd_addr = initrd_address;
Expand Down Expand Up @@ -332,7 +293,7 @@ void kernel_multitasking(void *arg)
vm_sysfs_init();

/* Pass the root partition to init */
const char *args[] = {(char *) "", NULL};
const char *args[] = {(char *) "", "/dev/sda2", NULL};
const char *envp[] = {"PATH=/bin:/usr/bin:/sbin:", "TERM=linux", "LANG=C", "PWD=/", NULL};

if(find_and_exec_init(args, envp) < 0)
Expand Down
3 changes: 2 additions & 1 deletion kernel/kernel/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,8 @@ void process_exit(unsigned int exit_code)
printk("Panic: %s exited with exit code %u!\n",
current->cmd_line.c_str(), exit_code);
irq_enable();
for(;;);
for(;;)
sched_sleep_ms(10000);
}

process_kill_other_threads();
Expand Down
12 changes: 12 additions & 0 deletions scripts/build_grub_efi_image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh
# Copyright (c) 2021 Pedro Falcato
# This file is part of Onyx, and is released under the terms of the MIT License
# check LICENSE at the root directory for more information
#
# SPDX-License-Identifier: MIT
#

grub-mkimage -p /boot/grub -O "${ONYX_ARCH}-efi" -c scripts/grub/grub-early.cfg \
-o bootx64.efi at_keyboard boot chain configfile fat ext2 multiboot multiboot2 \
linux ls part_gpt reboot serial efi_gop efi_uga echo elf ata ahci gfxterm all_video xzio \
font multiboot
3 changes: 2 additions & 1 deletion scripts/ci/install_ubuntu_deps.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/sh
set -e

sudo apt-get update && sudo apt-get install libmpc-dev libgmp3-dev bison flex libmpfr-dev zstd ninja-build clang lld
sudo apt-get update && sudo apt-get install libmpc-dev libgmp3-dev bison flex libmpfr-dev zstd ninja-build clang lld \
parted mtools
mkdir gn_bin/
cd gn_bin
wget -q https://chrome-infra-packages.appspot.com/dl/gn/gn/linux-amd64/+/latest -O gn.zip
Expand Down
30 changes: 30 additions & 0 deletions scripts/create_adaptive_disk_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/python3
# Copyright (c) 2021 Pedro Falcato
# This file is part of Onyx, and is released under the terms of the MIT License
# check LICENSE at the root directory for more information
#
# SPDX-License-Identifier: MIT
#

import sys
import subprocess

def main():
if len(sys.argv) < 3:
print("create_adaptive_disk_image.py: Bad usage")
exit(1)

# Our argument is whatever du(1) calculated, in 1024-byte units
nr_1024_blocks = int(sys.argv[1])

nr_1024_blocks = nr_1024_blocks * 1024
# Have the final partition image be 20% larger than the total size
# Note that it might be a decent idea to have this be adjustable by the user
# or maybe we get could a better estimate.
nr_1024_blocks = int(nr_1024_blocks * 1.20)

return subprocess.run(["fallocate", "-l", str(nr_1024_blocks), sys.argv[2]]).returncode

if __name__ == "__main__":
main()

Loading