MCPcopy Create free account
hub / github.com/F-Stack/f-stack / vmmdev_mmap_single

Function vmmdev_mmap_single

freebsd/amd64/vmm/vmm_dev.c:883–945  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

881}
882
883static int
884vmmdev_mmap_single(struct cdev *cdev, vm_ooffset_t *offset, vm_size_t mapsize,
885 struct vm_object **objp, int nprot)
886{
887 struct vmmdev_softc *sc;
888 vm_paddr_t gpa;
889 size_t len;
890 vm_ooffset_t segoff, first, last;
891 int error, found, segid;
892 uint16_t lastcpu;
893 bool sysmem;
894
895 error = vmm_priv_check(curthread->td_ucred);
896 if (error)
897 return (error);
898
899 first = *offset;
900 last = first + mapsize;
901 if ((nprot & PROT_EXEC) || first < 0 || first >= last)
902 return (EINVAL);
903
904 sc = vmmdev_lookup2(cdev);
905 if (sc == NULL) {
906 /* virtual machine is in the process of being created */
907 return (EINVAL);
908 }
909
910 /*
911 * Get a read lock on the guest memory map by freezing any vcpu.
912 */
913 lastcpu = vm_get_maxcpus(sc->vm) - 1;
914 error = vcpu_lock_one(sc, lastcpu);
915 if (error)
916 return (error);
917
918 gpa = 0;
919 found = 0;
920 while (!found) {
921 error = vm_mmap_getnext(sc->vm, &gpa, &segid, &segoff, &len,
922 NULL, NULL);
923 if (error)
924 break;
925
926 if (first >= gpa && last <= gpa + len)
927 found = 1;
928 else
929 gpa += len;
930 }
931
932 if (found) {
933 error = vm_get_memseg(sc->vm, segid, &len, &sysmem, objp);
934 KASSERT(error == 0 && *objp != NULL,
935 ("%s: invalid memory segment %d", __func__, segid));
936 if (sysmem) {
937 vm_object_reference(*objp);
938 *offset = segoff + (first - gpa);
939 } else {
940 error = EINVAL;

Callers

nothing calls this directly

Calls 7

vmmdev_lookup2Function · 0.85
vm_get_maxcpusFunction · 0.85
vcpu_lock_oneFunction · 0.85
vm_mmap_getnextFunction · 0.85
vm_get_memsegFunction · 0.85
vm_object_referenceFunction · 0.85
vcpu_unlock_oneFunction · 0.85

Tested by

no test coverage detected