1 /*
   2  * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "logging/log.hpp"
  27 #include "runtime/interfaceSupport.inline.hpp"
  28 #include "runtime/os.inline.hpp"
  29 #include "services/attachListener.hpp"
  30 #include "services/dtraceAttacher.hpp"
  31 #include "utilities/vmError.hpp"
  32 
  33 #include <door.h>
  34 #include <limits.h>
  35 #include <string.h>
  36 #include <signal.h>
  37 #include <sys/types.h>
  38 #include <sys/socket.h>
  39 #include <sys/stat.h>
  40 
  41 // stropts.h uses STR in stream ioctl defines
  42 #undef STR
  43 #include <stropts.h>
  44 #undef STR
  45 #define STR(a) #a
  46 
  47 // The attach mechanism on Solaris is implemented using the Doors IPC
  48 // mechanism. The first tool to attempt to attach causes the attach
  49 // listener thread to startup. This thread creats a door that is
  50 // associated with a function that enqueues an operation to the attach
  51 // listener. The door is attached to a file in the file system so that
  52 // client (tools) can locate it. To enqueue an operation to the VM the
  53 // client calls through the door which invokes the enqueue function in
  54 // this process. The credentials of the client are checked and if the
  55 // effective uid matches this process then the operation is enqueued.
  56 // When an operation completes the attach listener is required to send the
  57 // operation result and any result data to the client. In this implementation
  58 // the result is returned via a UNIX domain socket. A pair of connected
  59 // sockets (socketpair) is created in the enqueue function and the file
  60 // descriptor for one of the sockets is returned to the client as the
  61 // return from the door call. The other end is retained in this process.
  62 // When the operation completes the result is sent to the client and
  63 // the socket is closed.
  64 
  65 // forward reference
  66 class SolarisAttachOperation;
  67 
  68 class SolarisAttachListener: AllStatic {
  69  private:
  70 
  71   // the path to which we attach the door file descriptor
  72   static char _door_path[PATH_MAX+1];
  73   static volatile bool _has_door_path;
  74 
  75   // door descriptor returned by door_create
  76   static int _door_descriptor;
  77 
  78   static void set_door_path(char* path) {
  79     if (path == NULL) {
  80       _has_door_path = false;
  81     } else {
  82       strncpy(_door_path, path, PATH_MAX);
  83       _door_path[PATH_MAX] = '\0';      // ensure it's nul terminated
  84       _has_door_path = true;
  85     }
  86   }
  87 
  88   static void set_door_descriptor(int dd)               { _door_descriptor = dd; }
  89 
  90   // mutex to protect operation list
  91   static mutex_t _mutex;
  92 
  93   // semaphore to wakeup listener thread
  94   static sema_t _wakeup;
  95 
  96   static mutex_t* mutex()                               { return &_mutex; }
  97   static sema_t* wakeup()                               { return &_wakeup; }
  98 
  99   // enqueued operation list
 100   static SolarisAttachOperation* _head;
 101   static SolarisAttachOperation* _tail;
 102 
 103   static SolarisAttachOperation* head()                 { return _head; }
 104   static void set_head(SolarisAttachOperation* head)    { _head = head; }
 105 
 106   static SolarisAttachOperation* tail()                 { return _tail; }
 107   static void set_tail(SolarisAttachOperation* tail)    { _tail = tail; }
 108 
 109   // create the door
 110   static int create_door();
 111 
 112  public:
 113   enum {
 114     ATTACH_PROTOCOL_VER = 1                             // protocol version
 115   };
 116   enum {
 117     ATTACH_ERROR_BADREQUEST     = 100,                  // error code returned by
 118     ATTACH_ERROR_BADVERSION     = 101,                  // the door call
 119     ATTACH_ERROR_RESOURCE       = 102,
 120     ATTACH_ERROR_INTERNAL       = 103,
 121     ATTACH_ERROR_DENIED         = 104
 122   };
 123 
 124   // initialize the listener
 125   static int init();
 126 
 127   static bool has_door_path()                           { return _has_door_path; }
 128   static char* door_path()                              { return _door_path; }
 129   static int door_descriptor()                          { return _door_descriptor; }
 130 
 131   // enqueue an operation
 132   static void enqueue(SolarisAttachOperation* op);
 133 
 134   // dequeue an operation
 135   static SolarisAttachOperation* dequeue();
 136 };
 137 
 138 
 139 // SolarisAttachOperation is an AttachOperation that additionally encapsulates
 140 // a socket connection to the requesting client/tool. SolarisAttachOperation
 141 // can additionally be held in a linked list.
 142 
 143 class SolarisAttachOperation: public AttachOperation {
 144  private:
 145   friend class SolarisAttachListener;
 146 
 147   // connection to client
 148   int _socket;
 149 
 150   // linked list support
 151   SolarisAttachOperation* _next;
 152 
 153   SolarisAttachOperation* next()                         { return _next; }
 154   void set_next(SolarisAttachOperation* next)            { _next = next; }
 155 
 156  public:
 157   void complete(jint res, bufferedStream* st);
 158 
 159   int socket() const                                     { return _socket; }
 160   void set_socket(int s)                                 { _socket = s; }
 161 
 162   SolarisAttachOperation(char* name) : AttachOperation(name) {
 163     set_socket(-1);
 164     set_next(NULL);
 165   }
 166 };
 167 
 168 // statics
 169 char SolarisAttachListener::_door_path[PATH_MAX+1];
 170 volatile bool SolarisAttachListener::_has_door_path;
 171 int SolarisAttachListener::_door_descriptor = -1;
 172 mutex_t SolarisAttachListener::_mutex;
 173 sema_t SolarisAttachListener::_wakeup;
 174 SolarisAttachOperation* SolarisAttachListener::_head = NULL;
 175 SolarisAttachOperation* SolarisAttachListener::_tail = NULL;
 176 
 177 // Supporting class to help split a buffer into individual components
 178 class ArgumentIterator : public StackObj {
 179  private:
 180   char* _pos;
 181   char* _end;
 182  public:
 183   ArgumentIterator(char* arg_buffer, size_t arg_size) {
 184     _pos = arg_buffer;
 185     _end = _pos + arg_size - 1;
 186   }
 187   char* next() {
 188     if (*_pos == '\0') {
 189       return NULL;
 190     }
 191     char* res = _pos;
 192     char* next_pos = strchr(_pos, '\0');
 193     if (next_pos < _end)  {
 194       next_pos++;
 195     }
 196     _pos = next_pos;
 197     return res;
 198   }
 199 };
 200 
 201 // Calls from the door function to check that the client credentials
 202 // match this process. Returns 0 if credentials okay, otherwise -1.
 203 static int check_credentials() {
 204   ucred_t *cred_info = NULL;
 205   int ret = -1; // deny by default
 206 
 207   // get client credentials
 208   if (door_ucred(&cred_info) == -1) {
 209     return -1; // unable to get them, deny
 210   }
 211 
 212   // get our euid/eguid (probably could cache these)
 213   uid_t euid = geteuid();
 214   gid_t egid = getegid();
 215 
 216   // get euid/egid from ucred_free
 217   uid_t ucred_euid = ucred_geteuid(cred_info);
 218   gid_t ucred_egid = ucred_getegid(cred_info);
 219 
 220   // check that the effective uid/gid matches
 221   if (ucred_euid == euid && ucred_egid == egid) {
 222     ret =  0;  // allow
 223   }
 224 
 225   ucred_free(cred_info);
 226   return ret;
 227 }
 228 
 229 
 230 // Parses the argument buffer to create an AttachOperation that we should
 231 // enqueue to the attach listener.
 232 // The buffer is expected to be formatted as follows:
 233 // <ver>0<cmd>0<arg>0<arg>0<arg>0
 234 // where <ver> is the version number (must be "1"), <cmd> is the command
 235 // name ("load, "datadump", ...) and <arg> is an argument.
 236 //
 237 static SolarisAttachOperation* create_operation(char* argp, size_t arg_size, int* err) {
 238   // assume bad request until parsed
 239   *err = SolarisAttachListener::ATTACH_ERROR_BADREQUEST;
 240 
 241   if (arg_size < 2 || argp[arg_size-1] != '\0') {
 242     return NULL;   // no ver or not null terminated
 243   }
 244 
 245   // Use supporting class to iterate over the buffer
 246   ArgumentIterator args(argp, arg_size);
 247 
 248   // First check the protocol version
 249   char* ver = args.next();
 250   if (ver == NULL) {
 251     return NULL;
 252   }
 253   if (atoi(ver) != SolarisAttachListener::ATTACH_PROTOCOL_VER) {
 254     *err = SolarisAttachListener::ATTACH_ERROR_BADVERSION;
 255     return NULL;
 256   }
 257 
 258   // Get command name and create the operation
 259   char* name = args.next();
 260   if (name == NULL || strlen(name) > AttachOperation::name_length_max) {
 261     return NULL;
 262   }
 263   SolarisAttachOperation* op = new SolarisAttachOperation(name);
 264 
 265   // Iterate over the arguments
 266   for (int i=0; i<AttachOperation::arg_count_max; i++) {
 267     char* arg = args.next();
 268     if (arg == NULL) {
 269       op->set_arg(i, NULL);
 270     } else {
 271       if (strlen(arg) > AttachOperation::arg_length_max) {
 272         delete op;
 273         return NULL;
 274       }
 275       op->set_arg(i, arg);
 276     }
 277   }
 278 
 279   // return operation
 280   *err = 0;
 281   return op;
 282 }
 283 
 284 // create special operation to indicate all clients have detached
 285 static SolarisAttachOperation* create_detachall_operation() {
 286   return new SolarisAttachOperation(AttachOperation::detachall_operation_name());
 287 }
 288 
 289 // This is door function which the client executes via a door_call.
 290 extern "C" {
 291   static void enqueue_proc(void* cookie, char* argp, size_t arg_size,
 292                            door_desc_t* dt, uint_t n_desc)
 293   {
 294     int return_fd = -1;
 295     SolarisAttachOperation* op = NULL;
 296 
 297     // no listener
 298     jint res = 0;
 299     if (!AttachListener::is_initialized()) {
 300       // how did we get here?
 301       debug_only(warning("door_call when not enabled"));
 302       res = (jint)SolarisAttachListener::ATTACH_ERROR_INTERNAL;
 303     }
 304 
 305     // check client credentials
 306     if (res == 0) {
 307       if (check_credentials() != 0) {
 308         res = (jint)SolarisAttachListener::ATTACH_ERROR_DENIED;
 309       }
 310     }
 311 
 312     // if we are stopped at ShowMessageBoxOnError then maybe we can
 313     // load a diagnostic library
 314     if (res == 0 && VMError::is_error_reported()) {
 315       if (ShowMessageBoxOnError) {
 316         // TBD - support loading of diagnostic library here
 317       }
 318 
 319       // can't enqueue operation after fatal error
 320       res = (jint)SolarisAttachListener::ATTACH_ERROR_RESOURCE;
 321     }
 322 
 323     // create the operation
 324     if (res == 0) {
 325       int err;
 326       op = create_operation(argp, arg_size, &err);
 327       res = (op == NULL) ? (jint)err : 0;
 328     }
 329 
 330     // create a pair of connected sockets. Store the file descriptor
 331     // for one end in the operation and enqueue the operation. The
 332     // file descriptor for the other end wil be returned to the client.
 333     if (res == 0) {
 334       int s[2];
 335       if (socketpair(PF_UNIX, SOCK_STREAM, 0, s) < 0) {
 336         delete op;
 337         res = (jint)SolarisAttachListener::ATTACH_ERROR_RESOURCE;
 338       } else {
 339         op->set_socket(s[0]);
 340         return_fd = s[1];
 341         SolarisAttachListener::enqueue(op);
 342       }
 343     }
 344 
 345     // Return 0 (success) + file descriptor, or non-0 (error)
 346     if (res == 0) {
 347       door_desc_t desc;
 348       // DOOR_RELEASE flag makes sure fd is closed after passing it to
 349       // the client.  See door_return(3DOOR) man page.
 350       desc.d_attributes = DOOR_DESCRIPTOR | DOOR_RELEASE;
 351       desc.d_data.d_desc.d_descriptor = return_fd;
 352       door_return((char*)&res, sizeof(res), &desc, 1);
 353     } else {
 354       door_return((char*)&res, sizeof(res), NULL, 0);
 355     }
 356   }
 357 }
 358 
 359 // atexit hook to detach the door and remove the file
 360 extern "C" {
 361   static void listener_cleanup() {
 362     static int cleanup_done;
 363     if (!cleanup_done) {
 364       cleanup_done = 1;
 365       int dd = SolarisAttachListener::door_descriptor();
 366       if (dd >= 0) {
 367         ::close(dd);
 368       }
 369       if (SolarisAttachListener::has_door_path()) {
 370         char* path = SolarisAttachListener::door_path();
 371         ::fdetach(path);
 372         ::unlink(path);
 373       }
 374     }
 375   }
 376 }
 377 
 378 // Create the door
 379 int SolarisAttachListener::create_door() {
 380   char door_path[PATH_MAX+1];
 381   char initial_path[PATH_MAX+1];
 382   int fd, res;
 383 
 384   // register exit function
 385   ::atexit(listener_cleanup);
 386 
 387   // create the door descriptor
 388   int dd = ::door_create(enqueue_proc, NULL, 0);
 389   if (dd < 0) {
 390     return -1;
 391   }
 392 
 393   // create initial file to attach door descriptor
 394   snprintf(door_path, sizeof(door_path), "%s/.java_pid%d",
 395            os::get_temp_directory(), os::current_process_id());
 396   snprintf(initial_path, sizeof(initial_path), "%s.tmp", door_path);
 397   RESTARTABLE(::creat(initial_path, S_IRUSR | S_IWUSR), fd);
 398   if (fd == -1) {
 399     log_debug(attach)("attempt to create door file %s failed (%d)", initial_path, errno);
 400     ::door_revoke(dd);
 401     return -1;
 402   }
 403   assert(fd >= 0, "bad file descriptor");
 404   ::close(fd);
 405 
 406   // attach the door descriptor to the file
 407   if ((res = ::fattach(dd, initial_path)) == -1) {
 408     // if busy then detach and try again
 409     if (errno == EBUSY) {
 410       ::fdetach(initial_path);
 411       res = ::fattach(dd, initial_path);
 412     }
 413     if (res == -1) {
 414       log_debug(attach)("unable to create door - fattach failed (%d)", errno);
 415       ::door_revoke(dd);
 416       dd = -1;
 417     }
 418   }
 419 
 420   // rename file so that clients can attach
 421   if (dd >= 0) {
 422     if (::rename(initial_path, door_path) == -1) {
 423         ::close(dd);
 424         ::fdetach(initial_path);
 425         log_debug(attach)("unable to create door - rename %s to %s failed (%d)", errno);
 426         dd = -1;
 427     }
 428   }
 429   if (dd >= 0) {
 430     set_door_descriptor(dd);
 431     set_door_path(door_path);
 432     log_trace(attach)("door file %s created succesfully", door_path);
 433   } else {
 434     // unable to create door, attach it to file, or rename file into place
 435     ::unlink(initial_path);
 436     return -1;
 437   }
 438 
 439   return 0;
 440 }
 441 
 442 // Initialization - create the door, locks, and other initialization
 443 int SolarisAttachListener::init() {
 444   if (create_door()) {
 445     return -1;
 446   }
 447 
 448   int status = os::Solaris::mutex_init(&_mutex);
 449   assert_status(status==0, status, "mutex_init");
 450 
 451   status = ::sema_init(&_wakeup, 0, NULL, NULL);
 452   assert_status(status==0, status, "sema_init");
 453 
 454   set_head(NULL);
 455   set_tail(NULL);
 456 
 457   return 0;
 458 }
 459 
 460 // Dequeue an operation
 461 SolarisAttachOperation* SolarisAttachListener::dequeue() {
 462   for (;;) {
 463     int res;
 464 
 465     // wait for somebody to enqueue something
 466     while ((res = ::sema_wait(wakeup())) == EINTR)
 467       ;
 468     if (res) {
 469       warning("sema_wait failed: %s", os::strerror(res));
 470       return NULL;
 471     }
 472 
 473     // lock the list
 474     res = os::Solaris::mutex_lock(mutex());
 475     assert(res == 0, "mutex_lock failed");
 476 
 477     // remove the head of the list
 478     SolarisAttachOperation* op = head();
 479     if (op != NULL) {
 480       set_head(op->next());
 481       if (head() == NULL) {
 482         set_tail(NULL);
 483       }
 484     }
 485 
 486     // unlock
 487     os::Solaris::mutex_unlock(mutex());
 488 
 489     // if we got an operation when return it.
 490     if (op != NULL) {
 491       return op;
 492     }
 493   }
 494 }
 495 
 496 // Enqueue an operation
 497 void SolarisAttachListener::enqueue(SolarisAttachOperation* op) {
 498   // lock list
 499   int res = os::Solaris::mutex_lock(mutex());
 500   assert(res == 0, "mutex_lock failed");
 501 
 502   // enqueue at tail
 503   op->set_next(NULL);
 504   if (head() == NULL) {
 505     set_head(op);
 506   } else {
 507     tail()->set_next(op);
 508   }
 509   set_tail(op);
 510 
 511   // wakeup the attach listener
 512   RESTARTABLE(::sema_post(wakeup()), res);
 513   assert(res == 0, "sema_post failed");
 514 
 515   // unlock
 516   os::Solaris::mutex_unlock(mutex());
 517 }
 518 
 519 
 520 // support function - writes the (entire) buffer to a socket
 521 static int write_fully(int s, char* buf, int len) {
 522   do {
 523     int n = ::write(s, buf, len);
 524     if (n == -1) {
 525       if (errno != EINTR) return -1;
 526     } else {
 527       buf += n;
 528       len -= n;
 529     }
 530   }
 531   while (len > 0);
 532   return 0;
 533 }
 534 
 535 // Complete an operation by sending the operation result and any result
 536 // output to the client. At this time the socket is in blocking mode so
 537 // potentially we can block if there is a lot of data and the client is
 538 // non-responsive. For most operations this is a non-issue because the
 539 // default send buffer is sufficient to buffer everything. In the future
 540 // if there are operations that involves a very big reply then it the
 541 // socket could be made non-blocking and a timeout could be used.
 542 
 543 void SolarisAttachOperation::complete(jint res, bufferedStream* st) {
 544   if (this->socket() >= 0) {
 545     JavaThread* thread = JavaThread::current();
 546     ThreadBlockInVM tbivm(thread);
 547 
 548     thread->set_suspend_equivalent();
 549     // cleared by handle_special_suspend_equivalent_condition() or
 550     // java_suspend_self() via check_and_wait_while_suspended()
 551 
 552     // write operation result
 553     char msg[32];
 554     sprintf(msg, "%d\n", res);
 555     int rc = write_fully(this->socket(), msg, strlen(msg));
 556 
 557     // write any result data
 558     if (rc == 0) {
 559       write_fully(this->socket(), (char*) st->base(), st->size());
 560       ::shutdown(this->socket(), 2);
 561     }
 562 
 563     // close socket and we're done
 564     ::close(this->socket());
 565 
 566     // were we externally suspended while we were waiting?
 567     thread->check_and_wait_while_suspended();
 568   }
 569   delete this;
 570 }
 571 
 572 
 573 // AttachListener functions
 574 
 575 AttachOperation* AttachListener::dequeue() {
 576   JavaThread* thread = JavaThread::current();
 577   ThreadBlockInVM tbivm(thread);
 578 
 579   thread->set_suspend_equivalent();
 580   // cleared by handle_special_suspend_equivalent_condition() or
 581   // java_suspend_self() via check_and_wait_while_suspended()
 582 
 583   AttachOperation* op = SolarisAttachListener::dequeue();
 584 
 585   // were we externally suspended while we were waiting?
 586   thread->check_and_wait_while_suspended();
 587 
 588   return op;
 589 }
 590 
 591 
 592 // Performs initialization at vm startup
 593 // For Solaris we remove any stale .java_pid file which could cause
 594 // an attaching process to think we are ready to receive a door_call
 595 // before we are properly initialized
 596 
 597 void AttachListener::vm_start() {
 598   char fn[PATH_MAX+1];
 599   struct stat64 st;
 600   int ret;
 601 
 602   int n = snprintf(fn, sizeof(fn), "%s/.java_pid%d",
 603            os::get_temp_directory(), os::current_process_id());
 604   assert(n < sizeof(fn), "java_pid file name buffer overflow");
 605 
 606   RESTARTABLE(::stat64(fn, &st), ret);
 607   if (ret == 0) {
 608     ret = ::unlink(fn);
 609     if (ret == -1) {
 610       log_debug(attach)("Failed to remove stale attach pid file at %s", fn);
 611     }
 612   }
 613 }
 614 
 615 int AttachListener::pd_init() {
 616   JavaThread* thread = JavaThread::current();
 617   ThreadBlockInVM tbivm(thread);
 618 
 619   thread->set_suspend_equivalent();
 620   // cleared by handle_special_suspend_equivalent_condition() or
 621   // java_suspend_self()
 622 
 623   int ret_code = SolarisAttachListener::init();
 624 
 625   // were we externally suspended while we were waiting?
 626   thread->check_and_wait_while_suspended();
 627 
 628   return ret_code;
 629 }
 630 
 631 // Attach Listener is started lazily except in the case when
 632 // +ReduseSignalUsage is used
 633 bool AttachListener::init_at_startup() {
 634   if (ReduceSignalUsage) {
 635     return true;
 636   } else {
 637     return false;
 638   }
 639 }
 640 
 641 // If the file .attach_pid<pid> exists in the working directory
 642 // or /tmp then this is the trigger to start the attach mechanism
 643 bool AttachListener::is_init_trigger() {
 644   if (init_at_startup() || is_initialized()) {
 645     return false;               // initialized at startup or already initialized
 646   }
 647   char fn[PATH_MAX+1];
 648   sprintf(fn, ".attach_pid%d", os::current_process_id());
 649   int ret;
 650   struct stat64 st;
 651   RESTARTABLE(::stat64(fn, &st), ret);
 652   if (ret == -1) {
 653     log_trace(attach)("Failed to find attach file: %s, trying alternate", fn);
 654     snprintf(fn, sizeof(fn), "%s/.attach_pid%d",
 655              os::get_temp_directory(), os::current_process_id());
 656     RESTARTABLE(::stat64(fn, &st), ret);
 657     if (ret == -1) {
 658       log_debug(attach)("Failed to find attach file: %s", fn);
 659     }
 660   }
 661   if (ret == 0) {
 662     // simple check to avoid starting the attach mechanism when
 663     // a bogus user creates the file
 664     if (st.st_uid == geteuid()) {
 665       init();
 666       return true;
 667     }
 668   }
 669   return false;
 670 }
 671 
 672 // if VM aborts then detach/cleanup
 673 void AttachListener::abort() {
 674   listener_cleanup();
 675 }
 676 
 677 void AttachListener::pd_data_dump() {
 678   os::signal_notify(SIGQUIT);
 679 }
 680 
 681 static jint enable_dprobes(AttachOperation* op, outputStream* out) {
 682   const char* probe = op->arg(0);
 683   if (probe == NULL || probe[0] == '\0') {
 684     out->print_cr("No probe specified");
 685     return JNI_ERR;
 686   } else {
 687     char *end;
 688     long val = strtol(probe, &end, 10);
 689     if (end == probe || val < 0 || val > INT_MAX) {
 690       out->print_cr("invalid probe type");
 691       return JNI_ERR;
 692     } else {
 693       int probe_typess = (int) val;
 694       DTrace::enable_dprobes(probe_typess);
 695       return JNI_OK;
 696     }
 697   }
 698 }
 699 
 700 // platform specific operations table
 701 static AttachOperationFunctionInfo funcs[] = {
 702   { "enabledprobes", enable_dprobes },
 703   { NULL, NULL }
 704 };
 705 
 706 AttachOperationFunctionInfo* AttachListener::pd_find_operation(const char* name) {
 707   int i;
 708   for (i = 0; funcs[i].name != NULL; i++) {
 709     if (strcmp(funcs[i].name, name) == 0) {
 710       return &funcs[i];
 711     }
 712   }
 713   return NULL;
 714 }
 715 
 716 // Solaris specific global flag set. Currently, we support only
 717 // changing ExtendedDTraceProbes flag.
 718 jint AttachListener::pd_set_flag(AttachOperation* op, outputStream* out) {
 719   const char* name = op->arg(0);
 720   assert(name != NULL, "flag name should not be null");
 721   bool flag = true;
 722   const char* arg1;
 723   if ((arg1 = op->arg(1)) != NULL) {
 724     char *end;
 725     flag = (strtol(arg1, &end, 10) != 0);
 726     if (arg1 == end) {
 727       out->print_cr("flag value has to be an integer");
 728       return JNI_ERR;
 729     }
 730   }
 731 
 732   if (strcmp(name, "ExtendedDTraceProbes") == 0) {
 733     DTrace::set_extended_dprobes(flag);
 734     return JNI_OK;
 735   }
 736 
 737   if (strcmp(name, "DTraceMonitorProbes") == 0) {
 738     DTrace::set_monitor_dprobes(flag);
 739     return JNI_OK;
 740   }
 741 
 742   out->print_cr("flag '%s' cannot be changed", name);
 743   return JNI_ERR;
 744 }
 745 
 746 void AttachListener::pd_detachall() {
 747   DTrace::detach_all_clients();
 748 }