Print this page
OS-3820 lxbrand ptrace(2): the next generation
OS-3685 lxbrand PTRACE_O_TRACEFORK race condition
OS-3834 lxbrand 64-bit strace(1) reports 64-bit process as using x32 ABI
OS-3794 lxbrand panic on init signal death
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Bryan Cantrill <bryan@joyent.com>
OS-3280 need a way to specify the root of a native system in the lx brand
OS-3279 lx brand should allow delegated datasets
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>


 321         .pop_priv       = Ppriv_live,
 322         .pop_psinfo     = Ppsinfo_live,
 323         .pop_lstatus    = Plstatus_live,
 324         .pop_lpsinfo    = Plpsinfo_live,
 325         .pop_platform   = Pplatform_live,
 326         .pop_uname      = Puname_live,
 327         .pop_zonename   = Pzonename_live,
 328         .pop_execname   = Pexecname_live,
 329 #if defined(__i386) || defined(__amd64)
 330         .pop_ldt        = Pldt_live
 331 #endif
 332 };
 333 
 334 /*
 335  * This is the library's .init handler.
 336  */
 337 #pragma init(_libproc_init)
 338 void
 339 _libproc_init(void)
 340 {


 341         _libproc_debug = getenv("LIBPROC_DEBUG") != NULL;
 342         _libproc_no_qsort = getenv("LIBPROC_NO_QSORT") != NULL;
 343         _libproc_incore_elf = getenv("LIBPROC_INCORE_ELF") != NULL;
 344 




 345         (void) sigfillset(&blockable_sigs);
 346         (void) sigdelset(&blockable_sigs, SIGKILL);
 347         (void) sigdelset(&blockable_sigs, SIGSTOP);
 348 }
 349 
 350 void
 351 Pset_procfs_path(const char *path)
 352 {
 353         (void) snprintf(procfs_path, sizeof (procfs_path), "%s", path);
 354 }
 355 
 356 /*
 357  * Call set_minfd() once before calling dupfd() several times.
 358  * We assume that the application will not reduce its current file
 359  * descriptor limit lower than 512 once it has set at least that value.
 360  */
 361 int
 362 set_minfd(void)
 363 {
 364         static mutex_t minfd_lock = DEFAULTMUTEX;


1743                 break;
1744         case PR_FAULTED:
1745                 dprintf("%s: FAULTED %s\n", caller,
1746                     proc_fltname(lsp->pr_what, name, sizeof (name)));
1747                 break;
1748         case PR_SYSENTRY:
1749                 dprintf("%s: SYSENTRY %s\n", caller,
1750                     proc_sysname(lsp->pr_what, name, sizeof (name)));
1751                 break;
1752         case PR_SYSEXIT:
1753                 dprintf("%s: SYSEXIT %s\n", caller,
1754                     proc_sysname(lsp->pr_what, name, sizeof (name)));
1755                 break;
1756         case PR_JOBCONTROL:
1757                 dprintf("%s: JOBCONTROL %s\n", caller,
1758                     proc_signame(lsp->pr_what, name, sizeof (name)));
1759                 break;
1760         case PR_SUSPENDED:
1761                 dprintf("%s: SUSPENDED\n", caller);
1762                 break;



1763         default:
1764                 dprintf("%s: Unknown\n", caller);
1765                 break;
1766         }
1767 
1768         if (lsp->pr_cursig)
1769                 dprintf("%s: p_cursig  = %d\n", caller, lsp->pr_cursig);
1770 
1771         bits = *((uint32_t *)&lsp->pr_lwppend);
1772         if (bits)
1773                 dprintf("%s: pr_lwppend = 0x%.8X\n", caller, bits);
1774 }
1775 
1776 /* debugging */
1777 static void
1778 prdump(struct ps_prochandle *P)
1779 {
1780         uint32_t bits;
1781 
1782         prldump("Pstopstatus", &P->status.pr_lwp);


1922         /*
1923          * If the process was already stopped coming into Pstopstatus(),
1924          * then don't use its PC to set P->sysaddr since it may have been
1925          * changed since the time the process originally stopped.
1926          */
1927         if (old_state == PS_STOP)
1928                 return (0);
1929 
1930         switch (P->status.pr_lwp.pr_why) {
1931         case PR_SYSENTRY:
1932         case PR_SYSEXIT:
1933                 if (Pissyscall_prev(P, P->status.pr_lwp.pr_reg[R_PC],
1934                     &P->sysaddr) == 0)
1935                         P->sysaddr = P->status.pr_lwp.pr_reg[R_PC];
1936                 break;
1937         case PR_REQUESTED:
1938         case PR_SIGNALLED:
1939         case PR_FAULTED:
1940         case PR_JOBCONTROL:
1941         case PR_SUSPENDED:

1942                 break;
1943         default:
1944                 errno = EPROTO;
1945                 return (-1);
1946         }
1947 
1948         return (0);
1949 }
1950 
1951 /*
1952  * Wait for the process to stop for any reason.
1953  */
1954 int
1955 Pwait(struct ps_prochandle *P, uint_t msec)
1956 {
1957         return (Pstopstatus(P, PCWSTOP, msec));
1958 }
1959 
1960 /*
1961  * Direct the process to stop; wait for it to stop.


3496                 if (request == PCNULL || request == PCDSTOP || msec != 0)
3497                         return (0);
3498                 dprintf("Lstopstatus: LWP is not stopped\n");
3499                 errno = EPROTO;
3500                 return (-1);
3501         }
3502 
3503         L->lwp_state = PS_STOP;
3504 
3505         if (_libproc_debug)     /* debugging */
3506                 prldump("Lstopstatus", &L->lwp_status);
3507 
3508         switch (L->lwp_status.pr_why) {
3509         case PR_SYSENTRY:
3510         case PR_SYSEXIT:
3511         case PR_REQUESTED:
3512         case PR_SIGNALLED:
3513         case PR_FAULTED:
3514         case PR_JOBCONTROL:
3515         case PR_SUSPENDED:

3516                 break;
3517         default:
3518                 errno = EPROTO;
3519                 return (-1);
3520         }
3521 
3522         return (0);
3523 }
3524 
3525 /*
3526  * Wait for the LWP to stop for any reason.
3527  */
3528 int
3529 Lwait(struct ps_lwphandle *L, uint_t msec)
3530 {
3531         return (Lstopstatus(L, PCWSTOP, msec));
3532 }
3533 
3534 /*
3535  * Direct the LWP to stop; wait for it to stop.




 321         .pop_priv       = Ppriv_live,
 322         .pop_psinfo     = Ppsinfo_live,
 323         .pop_lstatus    = Plstatus_live,
 324         .pop_lpsinfo    = Plpsinfo_live,
 325         .pop_platform   = Pplatform_live,
 326         .pop_uname      = Puname_live,
 327         .pop_zonename   = Pzonename_live,
 328         .pop_execname   = Pexecname_live,
 329 #if defined(__i386) || defined(__amd64)
 330         .pop_ldt        = Pldt_live
 331 #endif
 332 };
 333 
 334 /*
 335  * This is the library's .init handler.
 336  */
 337 #pragma init(_libproc_init)
 338 void
 339 _libproc_init(void)
 340 {
 341         const char *root;
 342 
 343         _libproc_debug = getenv("LIBPROC_DEBUG") != NULL;
 344         _libproc_no_qsort = getenv("LIBPROC_NO_QSORT") != NULL;
 345         _libproc_incore_elf = getenv("LIBPROC_INCORE_ELF") != NULL;
 346 
 347         if ((root = zone_get_nroot()) != NULL)
 348                 (void) snprintf(procfs_path, sizeof (procfs_path), "%s/proc",
 349                     root);
 350 
 351         (void) sigfillset(&blockable_sigs);
 352         (void) sigdelset(&blockable_sigs, SIGKILL);
 353         (void) sigdelset(&blockable_sigs, SIGSTOP);
 354 }
 355 
 356 void
 357 Pset_procfs_path(const char *path)
 358 {
 359         (void) snprintf(procfs_path, sizeof (procfs_path), "%s", path);
 360 }
 361 
 362 /*
 363  * Call set_minfd() once before calling dupfd() several times.
 364  * We assume that the application will not reduce its current file
 365  * descriptor limit lower than 512 once it has set at least that value.
 366  */
 367 int
 368 set_minfd(void)
 369 {
 370         static mutex_t minfd_lock = DEFAULTMUTEX;


1749                 break;
1750         case PR_FAULTED:
1751                 dprintf("%s: FAULTED %s\n", caller,
1752                     proc_fltname(lsp->pr_what, name, sizeof (name)));
1753                 break;
1754         case PR_SYSENTRY:
1755                 dprintf("%s: SYSENTRY %s\n", caller,
1756                     proc_sysname(lsp->pr_what, name, sizeof (name)));
1757                 break;
1758         case PR_SYSEXIT:
1759                 dprintf("%s: SYSEXIT %s\n", caller,
1760                     proc_sysname(lsp->pr_what, name, sizeof (name)));
1761                 break;
1762         case PR_JOBCONTROL:
1763                 dprintf("%s: JOBCONTROL %s\n", caller,
1764                     proc_signame(lsp->pr_what, name, sizeof (name)));
1765                 break;
1766         case PR_SUSPENDED:
1767                 dprintf("%s: SUSPENDED\n", caller);
1768                 break;
1769         case PR_BRAND:
1770                 dprintf("%s: BRANDPRIVATE (%d)\n", caller, lsp->pr_what);
1771                 break;
1772         default:
1773                 dprintf("%s: Unknown\n", caller);
1774                 break;
1775         }
1776 
1777         if (lsp->pr_cursig)
1778                 dprintf("%s: p_cursig  = %d\n", caller, lsp->pr_cursig);
1779 
1780         bits = *((uint32_t *)&lsp->pr_lwppend);
1781         if (bits)
1782                 dprintf("%s: pr_lwppend = 0x%.8X\n", caller, bits);
1783 }
1784 
1785 /* debugging */
1786 static void
1787 prdump(struct ps_prochandle *P)
1788 {
1789         uint32_t bits;
1790 
1791         prldump("Pstopstatus", &P->status.pr_lwp);


1931         /*
1932          * If the process was already stopped coming into Pstopstatus(),
1933          * then don't use its PC to set P->sysaddr since it may have been
1934          * changed since the time the process originally stopped.
1935          */
1936         if (old_state == PS_STOP)
1937                 return (0);
1938 
1939         switch (P->status.pr_lwp.pr_why) {
1940         case PR_SYSENTRY:
1941         case PR_SYSEXIT:
1942                 if (Pissyscall_prev(P, P->status.pr_lwp.pr_reg[R_PC],
1943                     &P->sysaddr) == 0)
1944                         P->sysaddr = P->status.pr_lwp.pr_reg[R_PC];
1945                 break;
1946         case PR_REQUESTED:
1947         case PR_SIGNALLED:
1948         case PR_FAULTED:
1949         case PR_JOBCONTROL:
1950         case PR_SUSPENDED:
1951         case PR_BRAND:
1952                 break;
1953         default:
1954                 errno = EPROTO;
1955                 return (-1);
1956         }
1957 
1958         return (0);
1959 }
1960 
1961 /*
1962  * Wait for the process to stop for any reason.
1963  */
1964 int
1965 Pwait(struct ps_prochandle *P, uint_t msec)
1966 {
1967         return (Pstopstatus(P, PCWSTOP, msec));
1968 }
1969 
1970 /*
1971  * Direct the process to stop; wait for it to stop.


3506                 if (request == PCNULL || request == PCDSTOP || msec != 0)
3507                         return (0);
3508                 dprintf("Lstopstatus: LWP is not stopped\n");
3509                 errno = EPROTO;
3510                 return (-1);
3511         }
3512 
3513         L->lwp_state = PS_STOP;
3514 
3515         if (_libproc_debug)     /* debugging */
3516                 prldump("Lstopstatus", &L->lwp_status);
3517 
3518         switch (L->lwp_status.pr_why) {
3519         case PR_SYSENTRY:
3520         case PR_SYSEXIT:
3521         case PR_REQUESTED:
3522         case PR_SIGNALLED:
3523         case PR_FAULTED:
3524         case PR_JOBCONTROL:
3525         case PR_SUSPENDED:
3526         case PR_BRAND:
3527                 break;
3528         default:
3529                 errno = EPROTO;
3530                 return (-1);
3531         }
3532 
3533         return (0);
3534 }
3535 
3536 /*
3537  * Wait for the LWP to stop for any reason.
3538  */
3539 int
3540 Lwait(struct ps_lwphandle *L, uint_t msec)
3541 {
3542         return (Lstopstatus(L, PCWSTOP, msec));
3543 }
3544 
3545 /*
3546  * Direct the LWP to stop; wait for it to stop.