Print this page
OS-3825 lxbrand rsyslogd abort on centos6
OS-4047 lxbrand vsyscall while SIGSEGV? on next trap we're handler-free!
Reviewed by: Bryan Cantrill <bryan@joyent.com>
        
*** 30,40 ****
  /*      Copyright (c) 1987, 1988 Microsoft Corporation          */
  /*              All Rights Reserved                             */
  /*                                                              */
  
  /*
!  * Copyright 2012 Joyent, Inc. All rights reserved.
   */
  
  #include <sys/types.h>
  #include <sys/sysmacros.h>
  #include <sys/param.h>
--- 30,40 ----
  /*      Copyright (c) 1987, 1988 Microsoft Corporation          */
  /*              All Rights Reserved                             */
  /*                                                              */
  
  /*
!  * Copyright 2015 Joyent, Inc.
   */
  
  #include <sys/types.h>
  #include <sys/sysmacros.h>
  #include <sys/param.h>
*** 99,108 ****
--- 99,109 ----
  #include <sys/mach_mmu.h>
  #if defined(__xpv)
  #include <sys/hypervisor.h>
  #endif
  #include <sys/contract/process_impl.h>
+ #include <sys/brand.h>
  
  #define USER    0x10000         /* user-mode flag added to trap type */
  
  static const char *trap_type_mnemonic[] = {
          "de",   "db",   "2",    "bp",
*** 860,869 ****
--- 861,881 ----
                                  goto out;
                          do_watch_step(vaddr, sz, rw, 0, 0);
                          fault_type = F_INVAL;
                  }
  
+                 /*
+                  * Allow the brand to interpose on invalid memory accesses
+                  * prior to running the native pagefault handler.  If this
+                  * brand hook returns zero, it was able to handle the fault
+                  * completely.  Otherwise, drive on and call pagefault().
+                  */
+                 if (PROC_IS_BRANDED(p) && BROP(p)->b_pagefault != NULL &&
+                     BROP(p)->b_pagefault(p, lwp, addr, fault_type, rw) == 0) {
+                         goto out;
+                 }
+ 
                  res = pagefault(addr, fault_type, rw, 0);
  
                  /*
                   * If pagefault() succeeded, ok.
                   * Otherwise attempt to grow the stack.