Print this page
OS-4930 lxbrand ptrace should be more mindful of segregs
Reviewed by: Joshua M. Clulow <jmc@joyent.com>
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
OS-3561 lxbrand emulation library should execute on alternate stack
OS-3558 lxbrand add support for full in-kernel syscall handling
OS-3545 lx_syscall_regs should not walk stack
OS-3868 many LTP testcases now hang
OS-3901 lxbrand lx_recvmsg fails to translate control messages when 64-bit
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Patrick Mooney <patrick.mooney@joyent.com>
Reviewed by: Bryan Cantrill <bryan@joyent.com>
OS-2834 ship lx brand

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/intel/ia32/os/archdep.c
          +++ new/usr/src/uts/intel/ia32/os/archdep.c
↓ open down ↓ 17 lines elided ↑ open up ↑
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
  23   23   */
  24   24  
  25   25  /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
  26   26  /*        All Rights Reserved   */
  27   27  /*
  28      - * Copyright (c) 2012, Joyent, Inc.  All rights reserved.
       28 + * Copyright 2015 Joyent, Inc.
  29   29   * Copyright 2012 Nexenta Systems, Inc.  All rights reserved.
  30   30   */
  31   31  
  32   32  #include <sys/param.h>
  33   33  #include <sys/types.h>
  34   34  #include <sys/vmparam.h>
  35   35  #include <sys/systm.h>
  36   36  #include <sys/signal.h>
  37   37  #include <sys/stack.h>
  38   38  #include <sys/regset.h>
↓ open down ↓ 529 lines elided ↑ open up ↑
 568  568          dmc->gregs[REG_RSP] = (greg_t)(uint32_t)smc->gregs[UESP];
 569  569          dmc->gregs[REG_SS] = (greg_t)(uint32_t)smc->gregs[SS];
 570  570  
 571  571          /*
 572  572           * A valid fpregs is only copied in if uc.uc_flags has UC_FPU set
 573  573           * otherwise there is no guarantee that anything in fpregs is valid.
 574  574           */
 575  575          if (src->uc_flags & UC_FPU)
 576  576                  fpregset_32ton(&src->uc_mcontext.fpregs,
 577  577                      &dst->uc_mcontext.fpregs);
      578 +
      579 +        /*
      580 +         * Copy the brand-private data:
      581 +         */
      582 +        dst->uc_brand_data[0] = (void *)(uintptr_t)src->uc_brand_data[0];
      583 +        dst->uc_brand_data[1] = (void *)(uintptr_t)src->uc_brand_data[1];
      584 +        dst->uc_brand_data[2] = (void *)(uintptr_t)src->uc_brand_data[2];
 578  585  }
 579  586  
 580  587  #endif  /* _SYSCALL32_IMPL */
 581  588  
 582  589  /*
 583  590   * Return the user-level PC.
 584  591   * If in a system call, return the address of the syscall trap.
 585  592   */
 586  593  greg_t
 587  594  getuserpc()
↓ open down ↓ 34 lines elided ↑ open up ↑
 622  629   */
 623  630  
 624  631  #if defined(IS_CS) || defined(IS_NOT_CS)
 625  632  #error  "IS_CS and IS_NOT_CS already defined"
 626  633  #endif
 627  634  
 628  635  #define IS_CS           1
 629  636  #define IS_NOT_CS       0
 630  637  
 631  638  /*ARGSUSED*/
 632      -static greg_t
      639 +greg_t
 633  640  fix_segreg(greg_t sr, int iscs, model_t datamodel)
 634  641  {
      642 +        kthread_t *t = curthread;
      643 +
 635  644          switch (sr &= 0xffff) {
 636  645  
 637  646          case 0:
 638  647                  if (iscs == IS_CS)
 639  648                          return (0 | SEL_UPL);
 640  649                  else
 641  650                          return (0);
 642  651  
 643  652  #if defined(__amd64)
 644  653          /*
↓ open down ↓ 15 lines elided ↑ open up ↑
 660  669          /*FALLTHROUGH*/
 661  670          case UDS_SEL:
 662  671          case LWPFS_SEL:
 663  672          case LWPGS_SEL:
 664  673          case SEL_UPL:
 665  674                  return (sr);
 666  675          default:
 667  676                  break;
 668  677          }
 669  678  
      679 +        /*
      680 +         * Allow this process's brand to do any necessary segment register
      681 +         * manipulation.
      682 +         */
      683 +        if (PROC_IS_BRANDED(t->t_procp) && BRMOP(t->t_procp)->b_fixsegreg) {
      684 +                greg_t bsr = BRMOP(t->t_procp)->b_fixsegreg(sr, datamodel);
      685 +
      686 +                if (bsr == 0 && iscs == IS_CS)
      687 +                        return (0 | SEL_UPL);
      688 +                else
      689 +                        return (bsr);
      690 +        }
      691 +
 670  692          /*
 671  693           * Force it into the LDT in ring 3 for 32-bit processes, which by
 672  694           * default do not have an LDT, so that any attempt to use an invalid
 673  695           * selector will reference the (non-existant) LDT, and cause a #gp
 674  696           * fault for the process.
 675  697           *
 676  698           * 64-bit processes get the null gdt selector since they
 677  699           * are not allowed to have a private LDT.
 678  700           */
 679  701  #if defined(__amd64)
↓ open down ↓ 866 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX