/* This routine allocates a new "struct lguest_device_desc" from descriptor table page just above the Guest's normal memory. It returns a pointer to that descriptor.  */
static struct lguest_device_desc* new_dev_desc(u16 type)
/* This routine allocates a new "struct lguest_device_desc" from descriptor table page just above the Guest's normal memory. It returns a pointer to that descriptor.  */
static struct lguest_device_desc* new_dev_desc(u16 type)
{
	struct lguest_device_desc d = { .type = type };
	void *p;
	if (devices.lastdev)
		p = device_config(devices.lastdev)
			+ devices.lastdev->desc->config_len;
	else
		p = devices.descpage;
	if (p + sizeof(d) > (void *)devices.descpage + getpagesize())
		errx(1, "Too many devices");
	return memcpy(p, &d, sizeof(d));
}