~ubuntu-branches/ubuntu/saucy/bochs/saucy-proposed

« back to all changes in this revision

Viewing changes to plugin.cc

  • Committer: Bazaar Package Importer
  • Author(s): David Futcher
  • Date: 2009-04-30 07:46:11 UTC
  • mfrom: (1.1.11 upstream) (4.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090430074611-6dih80a5mk2uvxhk
Tags: 2.3.7+20090416-1ubuntu1
* Merge from debian unstable (LP: #370427), remaining changes:
  - debian/patches/12_no-ssp.patch: Build bios with -fno-stack-protector
  - Add Replaces/Conflicts for bochsbios-qemu (<< 2.3.6-2)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/////////////////////////////////////////////////////////////////////////
2
 
// $Id: plugin.cc,v 1.25 2008/02/15 22:05:38 sshwarts Exp $
 
2
// $Id: plugin.cc,v 1.29 2009/01/10 11:30:20 vruppert Exp $
 
3
/////////////////////////////////////////////////////////////////////////
 
4
//
 
5
//  Copyright (C) 2009  The Bochs Project
 
6
//
 
7
//  This library is free software; you can redistribute it and/or
 
8
//  modify it under the terms of the GNU Lesser General Public
 
9
//  License as published by the Free Software Foundation; either
 
10
//  version 2 of the License, or (at your option) any later version.
 
11
//
 
12
//  This library is distributed in the hope that it will be useful,
 
13
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
//  Lesser General Public License for more details.
 
16
//
 
17
//  You should have received a copy of the GNU Lesser General Public
 
18
//  License along with this library; if not, write to the Free Software
 
19
//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
20
//
3
21
/////////////////////////////////////////////////////////////////////////
4
22
//
5
23
// This file defines the plugin and plugin-device registration functions and
343
361
 
344
362
void plugin_load(char *name, char *args, plugintype_t type)
345
363
{
346
 
  plugin_t *plugin;
 
364
  plugin_t *plugin, *temp;
 
365
 
 
366
  if (plugins != NULL) {
 
367
    temp = plugins;
 
368
 
 
369
    while (temp != NULL) {
 
370
      if (!strcmp(name, temp->name)) {
 
371
        BX_PANIC(("plugin '%s' already loaded", name));
 
372
        return;
 
373
      }
 
374
      temp = temp->next;
 
375
    }
 
376
  }
347
377
 
348
378
  plugin = (plugin_t *)malloc (sizeof(plugin_t));
349
379
  if (!plugin)
375
405
    return;
376
406
  }
377
407
 
378
 
  sprintf(buf, PLUGIN_INIT_FMT_STRING, name);
 
408
  if (type != PLUGTYPE_USER) {
 
409
    sprintf(buf, PLUGIN_INIT_FMT_STRING, name);
 
410
  } else {
 
411
    sprintf(buf, PLUGIN_INIT_FMT_STRING, "user");
 
412
  }
379
413
  plugin->plugin_init =
380
414
      (int (*)(struct _plugin_t *, enum plugintype_t, int, char *[])) /* monster typecast */
381
415
      lt_dlsym (plugin->handle, buf);
384
418
    plugin_abort ();
385
419
  }
386
420
 
387
 
  sprintf(buf, PLUGIN_FINI_FMT_STRING, name);
 
421
  if (type != PLUGTYPE_USER) {
 
422
    sprintf(buf, PLUGIN_FINI_FMT_STRING, name);
 
423
  } else {
 
424
    sprintf(buf, PLUGIN_FINI_FMT_STRING, "user");
 
425
  }
388
426
  plugin->plugin_fini = (void (*)(void)) lt_dlsym (plugin->handle, buf);
389
 
  if (plugin->plugin_init == NULL) {
 
427
  if (plugin->plugin_fini == NULL) {
390
428
    pluginlog->panic("could not find plugin_fini: %s", lt_dlerror ());
391
429
    plugin_abort();
392
430
  }
403
441
  else
404
442
  {
405
443
   /* Non-empty list.  Add to end. */
406
 
   plugin_t *temp = plugins;
 
444
   temp = plugins;
407
445
 
408
446
   while (temp->next)
409
447
      temp = temp->next;
460
498
#if BX_PLUGINS
461
499
  pluginlog = new logfunctions();
462
500
  pluginlog->put("PLGIN");
463
 
  pluginlog->settype(PLUGINLOG);
464
501
  int status = lt_dlinit ();
465
502
  if (status != 0) {
466
503
    BX_ERROR (("initialization error in ltdl library (for loading plugins)"));
521
558
}
522
559
 
523
560
/************************************************************************/
 
561
/* Plugin system: Remove registered plugin device                       */
 
562
/************************************************************************/
 
563
 
 
564
void pluginUnregisterDeviceDevmodel(plugin_t *plugin)
 
565
{
 
566
  device_t *device, *prev = NULL;
 
567
 
 
568
  for (device = devices; device; device = device->next) {
 
569
    if (device->plugin == plugin) {
 
570
      if (prev == NULL) {
 
571
        devices = device->next;
 
572
      } else {
 
573
        prev->next = device->next;
 
574
      }
 
575
      free(device);
 
576
      break;
 
577
    } else {
 
578
      prev = device;
 
579
    }
 
580
  }
 
581
}
 
582
 
 
583
/************************************************************************/
524
584
/* Plugin system: Check if a plugin is loaded                           */
525
585
/************************************************************************/
526
586
 
545
605
{
546
606
  char *namecopy = new char[1+strlen(name)];
547
607
  strcpy(namecopy, name);
548
 
  plugin_load(namecopy, "", type);
 
608
  plugin_load(namecopy, (char*)"", type);
549
609
  return 0;
550
610
}
551
611
 
552
 
void bx_unload_plugin(const char *name)
 
612
void bx_unload_plugin(const char *name, bx_bool devflag)
553
613
{
554
614
  plugin_t *plugin, *prev = NULL;
555
615
 
556
616
  for (plugin = plugins; plugin; plugin = plugin->next) {
557
617
    if (!strcmp(plugin->name, name)) {
 
618
      if (devflag) {
 
619
        pluginUnregisterDeviceDevmodel(plugin);
 
620
      }
558
621
      plugin = plugin_unload(plugin);
559
622
      if (prev == NULL) {
560
623
        plugins = plugin;
578
641
{
579
642
  device_t *device;
580
643
 
581
 
  // two loops
582
 
  for (device = devices; device; device = device->next)
583
 
  {
584
 
    pluginlog->info("init_mem of '%s' plugin device by virtual method",device->name);
585
 
    device->devmodel->init_mem(BX_MEM(0));
586
 
  }
587
 
 
588
 
  for (device = devices; device; device = device->next)
589
 
  {
 
644
#if BX_PLUGINS
 
645
  for (device = devices; device; device = device->next) {
 
646
    if (device->plugin->type == PLUGTYPE_OPTIONAL) {
 
647
      pluginlog->info("init_dev of '%s' plugin device by virtual method",device->name);
 
648
      device->devmodel->init();
 
649
    }
 
650
  }
 
651
  for (device = devices; device; device = device->next) {
 
652
    if (device->plugin->type == PLUGTYPE_USER) {
 
653
      pluginlog->info("init_dev of '%s' plugin device by virtual method",device->name);
 
654
      device->devmodel->init();
 
655
    }
 
656
  }
 
657
#else
 
658
  for (device = devices; device; device = device->next) {
590
659
    pluginlog->info("init_dev of '%s' plugin device by virtual method",device->name);
591
660
    device->devmodel->init();
592
661
  }
 
662
#endif
593
663
}
594
664
 
595
665
/**************************************************************************/
599
669
void bx_reset_plugins(unsigned signal)
600
670
{
601
671
  device_t *device;
602
 
  for (device = devices; device; device = device->next)
603
 
  {
 
672
 
 
673
#if BX_PLUGINS
 
674
  for (device = devices; device; device = device->next) {
 
675
    if (device->plugin->type == PLUGTYPE_OPTIONAL) {
 
676
      pluginlog->info("reset of '%s' plugin device by virtual method",device->name);
 
677
      device->devmodel->reset(signal);
 
678
    }
 
679
  }
 
680
  for (device = devices; device; device = device->next) {
 
681
    if (device->plugin->type == PLUGTYPE_USER) {
 
682
      pluginlog->info("reset of '%s' plugin device by virtual method",device->name);
 
683
      device->devmodel->reset(signal);
 
684
    }
 
685
  }
 
686
#else
 
687
  for (device = devices; device; device = device->next) {
604
688
    pluginlog->info("reset of '%s' plugin device by virtual method",device->name);
605
689
    device->devmodel->reset(signal);
606
690
  }
 
691
#endif
607
692
}
608
693
 
609
694
/*******************************************************/
618
703
  while (device != NULL) {
619
704
    if (device->plugin != NULL) {
620
705
#if BX_PLUGINS
621
 
      bx_unload_plugin(device->name);
 
706
      bx_unload_plugin(device->name, 0);
622
707
#endif
623
708
    } else {
624
709
      delete device->devmodel;
637
722
void bx_plugins_register_state()
638
723
{
639
724
  device_t *device;
640
 
  for (device = devices; device; device = device->next)
641
 
  {
 
725
 
 
726
#if BX_PLUGINS
 
727
  for (device = devices; device; device = device->next) {
 
728
    if (device->plugin->type == PLUGTYPE_OPTIONAL) {
 
729
      pluginlog->info("register state of '%s' plugin device by virtual method",device->name);
 
730
      device->devmodel->register_state();
 
731
    }
 
732
  }
 
733
  for (device = devices; device; device = device->next) {
 
734
    if (device->plugin->type == PLUGTYPE_USER) {
 
735
      pluginlog->info("register state of '%s' plugin device by virtual method",device->name);
 
736
      device->devmodel->register_state();
 
737
    }
 
738
  }
 
739
#else
 
740
  for (device = devices; device; device = device->next) {
642
741
    pluginlog->info("register state of '%s' plugin device by virtual method",device->name);
643
742
    device->devmodel->register_state();
644
743
  }
 
744
#endif
645
745
}
646
746
 
647
747
/***************************************************************************/
651
751
void bx_plugins_after_restore_state()
652
752
{
653
753
  device_t *device;
654
 
  for (device = devices; device; device = device->next)
655
 
  {
 
754
 
 
755
#if BX_PLUGINS
 
756
  for (device = devices; device; device = device->next) {
 
757
    if (device->plugin->type == PLUGTYPE_OPTIONAL) {
 
758
      device->devmodel->after_restore_state();
 
759
    }
 
760
  }
 
761
  for (device = devices; device; device = device->next) {
 
762
    if (device->plugin->type == PLUGTYPE_USER) {
 
763
      device->devmodel->after_restore_state();
 
764
    }
 
765
  }
 
766
#else
 
767
  for (device = devices; device; device = device->next) {
656
768
    device->devmodel->after_restore_state();
657
769
  }
 
770
#endif
658
771
}
659
772
 
660
773
}