本文整理汇总了C++中USER_ACCESS函数的典型用法代码示例。如果您正苦于以下问题:C++ USER_ACCESS函数的具体用法?C++ USER_ACCESS怎么用?C++ USER_ACCESS使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了USER_ACCESS函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mm_map
int
mm_map(struct mm_struct *mm, uintptr_t addr, size_t len, uint32_t vm_flags,
struct vma_struct **vma_store) {
uintptr_t start = ROUNDDOWN(addr, PGSIZE), end = ROUNDUP(addr + len, PGSIZE);
if (!USER_ACCESS(start, end)) {
return -E_INVAL;
}
assert(mm != NULL);
int ret = -E_INVAL;
struct vma_struct *vma;
if ((vma = find_vma(mm, start)) != NULL && end > vma->vm_start) {
goto out;
}
ret = -E_NO_MEM;
if ((vma = vma_create(start, end, vm_flags)) == NULL) {
goto out;
}
insert_vma_struct(mm, vma);
if (vma_store != NULL) {
*vma_store = vma;
}
ret = 0;
out:
return ret;
}
示例2: user_mem_check
bool
user_mem_check(struct mm_struct *mm, uintptr_t addr, size_t len, bool write) {
if (mm != NULL) {
if (!USER_ACCESS(addr, addr + len)) {
return 0;
}
struct vma_struct *vma;
uintptr_t start = addr, end = addr + len;
while (start < end) {
if ((vma = find_vma(mm, start)) == NULL || start < vma->vm_start) {
return 0;
}
if (!(vma->vm_flags & ((write) ? VM_WRITE : VM_READ))) {
return 0;
}
if (write && (vma->vm_flags & VM_STACK)) {
if (start < vma->vm_start + PGSIZE) { //check stack start & size
return 0;
}
}
start = vma->vm_end;
}
return 1;
}
return KERN_ACCESS(addr, addr + len);
}
示例3: mm_brk
int
mm_brk(struct mm_struct *mm, uintptr_t addr, size_t len) {
uintptr_t start = ROUNDDOWN(addr, PGSIZE), end = ROUNDUP(addr + len, PGSIZE);
if (!USER_ACCESS(start, end)) {
return -E_INVAL;
}
int ret;
if ((ret = mm_unmap(mm, start, end - start)) != 0) {
return ret;
}
uint32_t vm_flags = VM_READ | VM_WRITE;
struct vma_struct *vma = find_vma(mm, start - 1);
if (vma != NULL && vma->vm_end == start && vma->vm_flags == vm_flags) {
vma->vm_end = end;
return 0;
}
if ((vma = vma_create(start, end, vm_flags)) == NULL) {
return -E_NO_MEM;
}
insert_vma_struct(mm, vma);
return 0;
}
示例4: check_mm_swap
static void
check_mm_swap(void) {
size_t nr_free_pages_store = nr_free_pages();
size_t slab_allocated_store = slab_allocated();
int ret, i, j;
for (i = 0; i < max_swap_offset; i ++) {
assert(mem_map[i] == SWAP_UNUSED);
}
extern struct mm_struct *check_mm_struct;
assert(check_mm_struct == NULL);
// step1: check mm_map
struct mm_struct *mm0 = mm_create(), *mm1;
assert(mm0 != NULL && list_empty(&(mm0->mmap_list)));
uintptr_t addr0, addr1;
addr0 = 0;
do {
ret = mm_map(mm0, addr0, PTSIZE, 0, NULL);
assert(ret == (USER_ACCESS(addr0, addr0 + PTSIZE)) ? 0 : -E_INVAL);
addr0 += PTSIZE;
} while (addr0 != 0);
addr0 = 0;
for (i = 0; i < 1024; i ++, addr0 += PTSIZE) {
ret = mm_map(mm0, addr0, PGSIZE, 0, NULL);
assert(ret == -E_INVAL);
}
mm_destroy(mm0);
mm0 = mm_create();
assert(mm0 != NULL && list_empty(&(mm0->mmap_list)));
addr0 = 0, i = 0;
do {
ret = mm_map(mm0, addr0, PTSIZE - PGSIZE, 0, NULL);
assert(ret == (USER_ACCESS(addr0, addr0 + PTSIZE)) ? 0 : -E_INVAL);
if (ret == 0) {
i ++;
}
addr0 += PTSIZE;
} while (addr0 != 0);
addr0 = 0, j = 0;
do {
addr0 += PTSIZE - PGSIZE;
ret = mm_map(mm0, addr0, PGSIZE, 0, NULL);
assert(ret == (USER_ACCESS(addr0, addr0 + PGSIZE)) ? 0 : -E_INVAL);
if (ret == 0) {
j ++;
}
addr0 += PGSIZE;
} while (addr0 != 0);
assert(j + 1 >= i);
mm_destroy(mm0);
assert(nr_free_pages_store == nr_free_pages());
assert(slab_allocated_store == slab_allocated());
cprintf("check_mm_swap: step1, mm_map ok.\n");
// step2: check page fault
mm0 = mm_create();
assert(mm0 != NULL && list_empty(&(mm0->mmap_list)));
// setup page table
struct Page *page = alloc_page();
assert(page != NULL);
pde_t *pgdir = page2kva(page);
memcpy(pgdir, boot_pgdir, PGSIZE);
pgdir[PDX(VPT)] = PADDR(pgdir) | PTE_P | PTE_W;
// prepare for page fault
mm0->pgdir = pgdir;
check_mm_struct = mm0;
lcr3(PADDR(mm0->pgdir));
uint32_t vm_flags = VM_WRITE | VM_READ;
struct vma_struct *vma;
addr0 = 0;
do {
if ((ret = mm_map(mm0, addr0, PTSIZE, vm_flags, &vma)) == 0) {
break;
}
addr0 += PTSIZE;
} while (addr0 != 0);
assert(ret == 0 && addr0 != 0 && mm0->map_count == 1);
//.........这里部分代码省略.........
示例5: mm_unmap
int
mm_unmap(struct mm_struct *mm, uintptr_t addr, size_t len) {
uintptr_t start = ROUNDDOWN(addr, PGSIZE), end = ROUNDUP(addr + len, PGSIZE);
if (!USER_ACCESS(start, end)) {
return -E_INVAL;
}
assert(mm != NULL);
struct vma_struct *vma;
if ((vma = find_vma(mm, start)) == NULL || end <= vma->vm_start) {
return 0;
}
if (vma->vm_start < start && end < vma->vm_end) {
struct vma_struct *nvma;
if ((nvma = vma_create(vma->vm_start, start, vma->vm_flags)) == NULL) {
return -E_NO_MEM;
}
vma_resize(vma, end, vma->vm_end);
insert_vma_struct(mm, nvma);
unmap_range(mm->pgdir, start, end);
return 0;
}
list_entry_t free_list, *le;
list_init(&free_list);
while (vma->vm_start < end) {
le = list_next(&(vma->list_link));
remove_vma_struct(mm, vma);
list_add(&free_list, &(vma->list_link));
if (le == &(mm->mmap_list)) {
break;
}
vma = le2vma(le, list_link);
}
le = list_next(&free_list);
while (le != &free_list) {
vma = le2vma(le, list_link);
le = list_next(le);
uintptr_t un_start, un_end;
if (vma->vm_start < start) {
un_start = start, un_end = vma->vm_end;
vma_resize(vma, vma->vm_start, un_start);
insert_vma_struct(mm, vma);
}
else {
un_start = vma->vm_start, un_end = vma->vm_end;
if (end < un_end) {
un_end = end;
vma_resize(vma, un_end, vma->vm_end);
insert_vma_struct(mm, vma);
}
else {
vma_destroy(vma);
}
}
unmap_range(mm->pgdir, un_start, un_end);
}
return 0;
}
示例6: copy_range
/* ucore use copy-on-write when forking a new process,
* thus copy_range only copy pdt/pte and set their permission to
* READONLY, a write will be handled in pgfault
*/
int
copy_range(pgd_t *to, pgd_t *from, uintptr_t start, uintptr_t end, bool share) {
assert(start % PGSIZE == 0 && end % PGSIZE == 0);
assert(USER_ACCESS(start, end));
do {
pte_t *ptep = get_pte(from, start, 0), *nptep;
if (ptep == NULL) {
if (get_pud(from, start, 0) == NULL) {
start = ROUNDDOWN(start + PUSIZE, PUSIZE);
}
else if (get_pmd(from, start, 0) == NULL) {
start = ROUNDDOWN(start + PMSIZE, PMSIZE);
}
else {
start = ROUNDDOWN(start + PTSIZE, PTSIZE);
}
continue ;
}
if (*ptep != 0) {
if ((nptep = get_pte(to, start, 1)) == NULL) {
return -E_NO_MEM;
}
int ret;
//kprintf("%08x %08x %08x\n", nptep, *nptep, start);
assert(*ptep != 0 && *nptep == 0);
#ifdef ARCH_ARM
//TODO add code to handle swap
if (ptep_present(ptep)){
//no body should be able to write this page
//before a W-pgfault
pte_perm_t perm = PTE_P;
if(ptep_u_read(ptep))
perm |= PTE_U;
if(!share){
//Original page should be set to readonly!
//because Copy-on-write may happen
//after the current proccess modifies its page
ptep_set_perm(ptep, perm);
}else{
if(ptep_u_write(ptep)){
perm |= PTE_W;
}
}
struct Page *page = pte2page(*ptep);
ret = page_insert(to, page, start, perm);
}
#else /* ARCH_ARM */
if (ptep_present(ptep)) {
pte_perm_t perm = ptep_get_perm(ptep, PTE_USER);
struct Page *page = pte2page(*ptep);
if (!share && ptep_s_write(ptep)) {
ptep_unset_s_write(&perm);
pte_perm_t perm_with_swap_stat = ptep_get_perm(ptep, PTE_SWAP);
ptep_set_perm(&perm_with_swap_stat, perm);
page_insert(from, page, start, perm_with_swap_stat);
}
ret = page_insert(to, page, start, perm);
assert(ret == 0);
}
#endif /* ARCH_ARM */
else {
#ifdef CONFIG_NO_SWAP
assert(0);
#endif
swap_entry_t entry;
ptep_copy(&entry, ptep);
swap_duplicate(entry);
ptep_copy(nptep, &entry);
}
}
start += PGSIZE;
} while (start != 0 && start < end);
#ifdef ARCH_ARM
/* we have modified the PTE of the original
* process, so invalidate TLB */
tlb_invalidate_all();
#endif
return 0;
}
示例7: exit_range
void
exit_range(pgd_t *pgdir, uintptr_t start, uintptr_t end) {
assert(start % PGSIZE == 0 && end % PGSIZE == 0);
assert(USER_ACCESS(start, end));
exit_range_pgd(pgdir, start, end);
}