From dbce178a0e6997a799ba38247059dcb8213f4572 Mon Sep 17 00:00:00 2001 From: m00nbsd <42475391+m00nbsd@users.noreply.github.com> Date: Sat, 13 Jun 2020 12:10:16 +0200 Subject: sys/netbsd: support multiple vHCI buses (#1822) --- pkg/csource/generated.go | 47 +++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-) (limited to 'pkg/csource') diff --git a/pkg/csource/generated.go b/pkg/csource/generated.go index 0d4219de6..fe69f9237 100644 --- a/pkg/csource/generated.go +++ b/pkg/csource/generated.go @@ -1342,7 +1342,11 @@ static bool lookup_control_response(const struct vusb_descriptors* descs, const static int vhci_open(void) { - return open("/dev/vhci", O_RDWR); + char path[1024]; + + snprintf(path, sizeof(path), "/dev/vhci%llu", procid); + + return open(path, O_RDWR); } static int vhci_setport(int fd, u_int port) @@ -1397,31 +1401,22 @@ static volatile long syz_usb_connect_impl(uint64 speed, uint64 dev_len, lookup_connect_out_response_t lookup_connect_response_out) { struct usb_device_index* index; - int portnum, fd, rv; + int fd, rv; bool done; - portnum = procid + 1; - debug("syz_usb_connect: dev: %p\n", dev); if (!dev) { debug("syz_usb_connect: dev is null\n"); return -1; } - if (portnum != 1) { - /* For now, we support only one proc. */ - debug("syz_usb_connect: not proc1 %d\n", (int)procid); - return -1; - } debug("syz_usb_connect: device data:\n"); debug_dump_data(dev, dev_len); fd = vhci_open(); if (fd < 0) { - debug("syz_usb_connect: vhci_open failed with %d\n", fd); - return -1; + fail("syz_usb_connect: vhci_open failed with %d", errno); } - debug("syz_usb_connect: vhci_open success\n"); index = add_usb_index(fd, dev, dev_len); if (!index) { @@ -1434,12 +1429,10 @@ static volatile long syz_usb_connect_impl(uint64 speed, uint64 dev_len, NONFAILING(analyze_usb_device(index)); #endif - rv = vhci_setport(fd, portnum); + rv = vhci_setport(fd, 1); if (rv != 0) { - debug("syz_usb_connect: vhci_setport failed with %d\n", rv); - goto err; + fail("syz_usb_connect: vhci_setport failed with %d", errno); } - debug("syz_usb_connect: vhci_setport success\n"); rv = vhci_usb_attach(fd); if (rv != 0) { @@ -1563,10 +1556,28 @@ static volatile long syz_usb_disconnect(volatile long a0) #endif #if SYZ_EXECUTOR || SYZ_USB +#include static void setup_usb(void) { - if (chmod("/dev/vhci", 0666)) - fail("failed to chmod /dev/vhci"); + struct dirent* ent; + char path[1024]; + DIR* dir; + + dir = opendir("/dev"); + if (dir == NULL) + fail("failed to open /dev"); + + while ((ent = readdir(dir)) != NULL) { + if (ent->d_type != DT_CHR) + continue; + if (strncmp(ent->d_name, "vhci", 4)) + continue; + snprintf(path, sizeof(path), "/dev/%s", ent->d_name); + if (chmod(path, 0666)) + fail("failed to chmod %s", path); + } + + closedir(dir); } #endif -- cgit mrf-deployment