是2.4.18版本,中文是我自己的注释,这个函数的功能到底是什么。。。
谁能告诉我,如果能稍微注释一下(语句的作用)那就更好了
445/*
446 * Please read Documentation/cachetlb.txt before using this function,
447 * accessing foreign memory spaces can cause cache coherency problems.
448 *
449 * Accessing a VM_IO area is even more dangerous, therefore the function
450 * fails if pages is != NULL and a VM_IO area is found.
451 */
452int get_user_pages(struct task_struct *tsk, struct mm_struct *mm, unsigned long start,
453 int len, int write, int force, struct page **pages, struct vm_area_struct **vmas)
454{
455 int i;
456 unsigned int flags;
457
458 /*
459 * Require read or write permissions.
460 * If 'force' is set, we only require the "MAY" flags.
461 */
462 flags = write ? (VM_WRITE | VM_MAYWRITE) : (VM_READ | VM_MAYREAD);
463 flags &= force ? (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
464 i = 0;
465
466 do {
467 struct vm_area_struct * vma;
468
469 vma = find_extend_vma(mm, start);
470
471 if ( !vma || (pages && vma->vm_flags & VM_IO) || !(flags & vma->vm_flags) )
472 return i ? : -EFAULT;
473
474 spin_lock(&mm->page_table_lock);
475 do {
476 struct page *map;
477 while (!(map = follow_page(mm, start, write))) {
478 spin_unlock(&mm->page_table_lock);
479 switch (handle_mm_fault(mm, vma, start, write)) {
480 case 1:
481 tsk->min_flt++;
482 break;
483 case 2:
484 tsk->maj_flt++;
485 break;
486 case 0:
487 if (i) return i;
488 return -EFAULT;
489 default:
490 if (i) return i;
491 return -ENOMEM;
492 }
493 spin_lock(&mm->page_table_lock);
494 }
495 if (pages) {
496 pages[i] = get_page_map(map);
497 /* FIXME: call the correct function,
498 * depending on the type of the found page
499 */
500 if (!pages[i])
501 goto bad_page;
//调用page_cache_get(),分配一张新的物理页面
502 page_cache_get(pages[i]);
503 }
504 if (vmas)
505 vmas[i] = vma;
506 i++;
507 start += PAGE_SIZE;
508 len--;
509 } while(len && start < vma->vm_end);
510 spin_unlock(&mm->page_table_lock);
511 } while(len);
512out:
513 return i;
514
515 /*
516 * We found an invalid page in the VMA. Release all we have
517 * so far and fail.
518 */
519bad_page:
520 spin_unlock(&mm->page_table_lock);
521 while (i--)
522 page_cache_release(pages[i]); //递减page结构中的使用计数
523 i = -EFAULT;
524 goto out;
525}