diff -rc2P linux-2.4.19/include/asm-i386/resource.h linux-CTX/include/asm-i386/resource.h *** linux-2.4.19/include/asm-i386/resource.h Fri Sep 22 17:21:19 2000 --- linux-CTX/include/asm-i386/resource.h Sun Sep 22 17:00:42 2002 *************** *** 17,22 **** #define RLIMIT_AS 9 /* address space limit */ #define RLIMIT_LOCKS 10 /* maximum file locks held */ ! #define RLIM_NLIMITS 11 /* --- 17,23 ---- #define RLIMIT_AS 9 /* address space limit */ #define RLIMIT_LOCKS 10 /* maximum file locks held */ + #define RLIMIT_CTX_AS 11 /* per ctx address space limit */ ! #define RLIM_NLIMITS 12 /* *************** *** 41,44 **** --- 42,46 ---- { RLIM_INFINITY, RLIM_INFINITY }, \ { RLIM_INFINITY, RLIM_INFINITY }, \ + { RLIM_INFINITY, RLIM_INFINITY }, \ } diff -rc2P linux-2.4.19/include/linux/sched.h linux-CTX/include/linux/sched.h *** linux-2.4.19/include/linux/sched.h Mon Sep 23 01:41:34 2002 --- linux-CTX/include/linux/sched.h Sun Sep 22 17:04:27 2002 *************** *** 298,301 **** --- 298,302 ---- /* context */ #define S_CTX_INFO_HIDEINFO 32 /* Hide some information in /proc */ + #define S_CTX_INFO_RLIMIT_AS 64 /* Limit address space per ctx */ #define NB_IPV4ROOT 16 diff -rc2P linux-2.4.19/mm/mmap.c linux-CTX/mm/mmap.c *** linux-2.4.19/mm/mmap.c Fri Aug 2 20:39:46 2002 --- linux-CTX/mm/mmap.c Mon Sep 23 01:45:16 2002 *************** *** 493,496 **** --- 493,519 ---- return -ENOMEM; + /* Check against ctx address space limit. */ + if (current->s_info != NULL && (current->s_info->flags & S_CTX_INFO_RLIMIT_AS)!=0){ + struct task_struct *p; + unsigned long total_vm = 0; + + p = current; + + read_lock(&tasklist_lock); + for_each_task(p) + { + if (p->s_context == current->s_context) { + if (p->mm == NULL) { continue; } + total_vm += p->mm->total_vm; + } + } + read_unlock(&tasklist_lock); + + if ((total_vm << PAGE_SHIFT) + len + > current->rlim[RLIMIT_CTX_AS].rlim_cur) + return -ENOMEM; + } + + /* Private writable mapping? Check memory availability.. */ if ((vm_flags & (VM_SHARED | VM_WRITE)) == VM_WRITE && *************** *** 1058,1061 **** --- 1081,1108 ---- } + + /* Check against ctx address space limit. */ + if (current->s_info != NULL && (current->s_info->flags & S_CTX_INFO_RLIMIT_AS)!=0){ + struct task_struct *p; + unsigned long total_vm = 0; + + p = current; + + read_lock(&tasklist_lock); + for_each_task(p) + { + if (p->s_context == current->s_context) { + if (p->mm == NULL) { continue; } + total_vm += p->mm->total_vm; + } + } + read_unlock(&tasklist_lock); + + if ((total_vm << PAGE_SHIFT) + len + > current->rlim[RLIMIT_CTX_AS].rlim_cur) + return -ENOMEM; + } + + /* Check against address space limits *after* clearing old maps... */ if ((mm->total_vm << PAGE_SHIFT) + len diff -rc2P linux-2.4.19/mm/mremap.c linux-CTX/mm/mremap.c *** linux-2.4.19/mm/mremap.c Thu Sep 20 23:31:26 2001 --- linux-CTX/mm/mremap.c Mon Sep 23 01:45:22 2002 *************** *** 286,289 **** --- 286,310 ---- > current->rlim[RLIMIT_AS].rlim_cur) goto out; + /* Check against ctx address space limit. */ + if (current->s_info != NULL && (current->s_info->flags & S_CTX_INFO_RLIMIT_AS)!=0){ + struct task_struct *p; + unsigned long total_vm = 0; + + p = current; + + read_lock(&tasklist_lock); + for_each_task(p) + { + if (p->s_context == current->s_context) { + if (p->mm == NULL) { continue; } + total_vm += p->mm->total_vm; + } + } + read_unlock(&tasklist_lock); + + if ((total_vm << PAGE_SHIFT) + (new_len - old_len) + > current->rlim[RLIMIT_CTX_AS].rlim_cur) + goto out; + } /* Private writable mapping? Check memory availability.. */ if ((vma->vm_flags & (VM_SHARED | VM_WRITE)) == VM_WRITE &&