home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / KERNEL-S / V1.2 / LINUX-1.2 / LINUX-1 / linux / kernel / exec_domain.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-23  |  2.2 KB  |  103 lines

  1. #include <linux/personality.h>
  2. #include <linux/ptrace.h>
  3. #include <linux/sched.h>
  4. #include <linux/mm.h>
  5.  
  6. static asmlinkage void no_lcall7(struct pt_regs * regs);
  7.  
  8.  
  9. static unsigned long ident_map[32] = {
  10.     0,    1,    2,    3,    4,    5,    6,    7,
  11.     8,    9,    10,    11,    12,    13,    14,    15,
  12.     16,    17,    18,    19,    20,    21,    22,    23,
  13.     24,    25,    26,    27,    28,    29,    30,    31
  14. };
  15.  
  16. struct exec_domain default_exec_domain = {
  17.     "Linux",    /* name */
  18.     no_lcall7,    /* lcall7 causes a seg fault. */
  19.     0, 0xff,    /* All personalities. */
  20.     ident_map,    /* Identity map signals. */
  21.     ident_map,    /*  - both ways. */
  22.     NULL,        /* No usage counter. */
  23.     NULL        /* Nothing after this in the list. */
  24. };
  25.  
  26. static struct exec_domain *exec_domains = &default_exec_domain;
  27.  
  28.  
  29. static asmlinkage void no_lcall7(struct pt_regs * regs)
  30. {
  31.     send_sig(SIGSEGV, current, 1);
  32. }
  33.  
  34. struct exec_domain *lookup_exec_domain(unsigned long personality)
  35. {
  36.     unsigned long pers = personality & PER_MASK;
  37.     struct exec_domain *it;
  38.  
  39.     for (it=exec_domains; it; it=it->next)
  40.         if (pers >= it->pers_low
  41.         && pers <= it->pers_high)
  42.             return it;
  43.  
  44.     /* Should never get this far. */
  45.     printk(KERN_ERR "No execution domain for personality 0x%02lx\n", pers);
  46.     return NULL;
  47. }
  48.  
  49. int register_exec_domain(struct exec_domain *it)
  50. {
  51.     struct exec_domain *tmp;
  52.  
  53.     if (!it)
  54.         return -EINVAL;
  55.     if (it->next)
  56.         return -EBUSY;
  57.     for (tmp=exec_domains; tmp; tmp=tmp->next)
  58.         if (tmp == it)
  59.             return -EBUSY;
  60.     it->next = exec_domains;
  61.     exec_domains = it;
  62.     return 0;
  63. }
  64.  
  65. int unregister_exec_domain(struct exec_domain *it)
  66. {
  67.     struct exec_domain ** tmp;
  68.  
  69.     tmp = &exec_domains;
  70.     while (*tmp) {
  71.         if (it == *tmp) {
  72.             *tmp = it->next;
  73.             it->next = NULL;
  74.             return 0;
  75.         }
  76.         tmp = &(*tmp)->next;
  77.     }
  78.     return -EINVAL;
  79. }
  80.  
  81. asmlinkage int sys_personality(unsigned long personality)
  82. {
  83.     struct exec_domain *it;
  84.     unsigned long old_personality;
  85.  
  86.     if (personality == 0xffffffff)
  87.         return current->personality;
  88.  
  89.     it = lookup_exec_domain(personality);
  90.     if (!it)
  91.         return -EINVAL;
  92.  
  93.     old_personality = current->personality;
  94.     if (current->exec_domain && current->exec_domain->use_count)
  95.         (*current->exec_domain->use_count)--;
  96.     current->personality = personality;
  97.     current->exec_domain = it;
  98.     if (current->exec_domain->use_count)
  99.         (*current->exec_domain->use_count)++;
  100.  
  101.     return old_personality;
  102. }
  103.