| 904 | } |
| 905 | |
| 906 | static int |
| 907 | vmem_import(vmem_t *vm, vmem_size_t size, vmem_size_t align, int flags) |
| 908 | { |
| 909 | vmem_addr_t addr; |
| 910 | int error; |
| 911 | |
| 912 | if (vm->vm_importfn == NULL) |
| 913 | return (EINVAL); |
| 914 | |
| 915 | /* |
| 916 | * To make sure we get a span that meets the alignment we double it |
| 917 | * and add the size to the tail. This slightly overestimates. |
| 918 | */ |
| 919 | if (align != vm->vm_quantum_mask + 1) |
| 920 | size = (align * 2) + size; |
| 921 | size = roundup(size, vm->vm_import_quantum); |
| 922 | |
| 923 | if (vm->vm_limit != 0 && vm->vm_limit < vm->vm_size + size) |
| 924 | return (ENOMEM); |
| 925 | |
| 926 | bt_save(vm); |
| 927 | VMEM_UNLOCK(vm); |
| 928 | error = (vm->vm_importfn)(vm->vm_arg, size, flags, &addr); |
| 929 | VMEM_LOCK(vm); |
| 930 | bt_restore(vm); |
| 931 | if (error) |
| 932 | return (ENOMEM); |
| 933 | |
| 934 | vmem_add1(vm, addr, size, BT_TYPE_SPAN); |
| 935 | |
| 936 | return 0; |
| 937 | } |
| 938 | |
| 939 | /* |
| 940 | * vmem_fit: check if a bt can satisfy the given restrictions. |
no test coverage detected