jdk

Форк
0
/
libodm_aix.cpp 
121 строка · 4.3 Кб
1
/*
2
 * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
3
 * Copyright (c) 2015, 2019 SAP SE. All rights reserved.
4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
 *
6
 * This code is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU General Public License version 2 only, as
8
 * published by the Free Software Foundation.
9
 *
10
 * This code is distributed in the hope that it will be useful, but WITHOUT
11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13
 * version 2 for more details (a copy is included in the LICENSE file that
14
 * accompanied this code).
15
 *
16
 * You should have received a copy of the GNU General Public License version
17
 * 2 along with this work; if not, write to the Free Software Foundation,
18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
 *
20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21
 * or visit www.oracle.com if you need additional information or have any
22
 * questions.
23
 *
24
 */
25

26
#include "libodm_aix.hpp"
27
#include "misc_aix.hpp"
28
#include <stdlib.h>
29
#include <dlfcn.h>
30
#include <string.h>
31
#include "runtime/arguments.hpp"
32
#include "runtime/os.hpp"
33

34

35
dynamicOdm::dynamicOdm() {
36
  const char* libodmname = "/usr/lib/libodm.a(shr_64.o)";
37
  char ebuf[512];
38
  _libhandle = os::dll_load(libodmname, ebuf, sizeof(ebuf));
39

40
  if (!_libhandle) {
41
    trcVerbose("Cannot load %s (error %s)", libodmname, ebuf);
42
    return;
43
  }
44
  _odm_initialize  = (fun_odm_initialize )dlsym(_libhandle, "odm_initialize" );
45
  _odm_set_path    = (fun_odm_set_path   )dlsym(_libhandle, "odm_set_path"   );
46
  _odm_mount_class = (fun_odm_mount_class)dlsym(_libhandle, "odm_mount_class");
47
  _odm_get_obj     = (fun_odm_get_obj    )dlsym(_libhandle, "odm_get_obj"    );
48
  _odm_terminate   = (fun_odm_terminate  )dlsym(_libhandle, "odm_terminate"  );
49
  if (!_odm_initialize || !_odm_set_path || !_odm_mount_class || !_odm_get_obj || !_odm_terminate) {
50
    trcVerbose("Couldn't find all required odm symbols from %s", libodmname);
51
    os::dll_unload(_libhandle);
52
    _libhandle = nullptr;
53
    return;
54
  }
55
}
56

57
dynamicOdm::~dynamicOdm() {
58
  if (_libhandle) { os::dll_unload(_libhandle); }
59
}
60

61

62
void odmWrapper::clean_data() { if (_data) { free(_data); _data = nullptr; } }
63

64

65
int odmWrapper::class_offset(const char *field, bool is_aix_5)
66
{
67
  assert(has_class(), "initialization");
68
  for (int i = 0; i < odm_class()->nelem; i++) {
69
    if (strcmp(odm_class()->elem[i].elemname, field) == 0) {
70
      int offset = odm_class()->elem[i].offset;
71
      if (is_aix_5) { offset += LINK_VAL_OFFSET; }
72
      return offset;
73
    }
74
  }
75
  return -1;
76
}
77

78

79
void odmWrapper::determine_os_kernel_version(uint32_t* p_ver) {
80
  int major_aix_version = ((*p_ver) >> 24) & 0xFF,
81
      minor_aix_version = ((*p_ver) >> 16) & 0xFF;
82
  assert(*p_ver, "must be initialized");
83

84
  odmWrapper odm("product", "/usr/lib/objrepos"); // could also use "lpp"
85
  if (!odm.has_class()) {
86
    trcVerbose("try_determine_os_kernel_version: odm init problem");
87
    return;
88
  }
89
  int voff, roff, moff, foff;
90
  bool is_aix_5 = (major_aix_version == 5);
91
  voff = odm.class_offset("ver", is_aix_5);
92
  roff = odm.class_offset("rel", is_aix_5);
93
  moff = odm.class_offset("mod", is_aix_5);
94
  foff = odm.class_offset("fix", is_aix_5);
95
  if (voff == -1 || roff == -1 || moff == -1 || foff == -1) {
96
    trcVerbose("try_determine_os_kernel_version: could not get offsets");
97
    return;
98
  }
99
  if (!odm.retrieve_obj("name='bos.mp64'")) {
100
    trcVerbose("try_determine_os_kernel_version: odm_get_obj failed");
101
    return;
102
  }
103
  int version, release, modification, fix_level;
104
  do {
105
    version      = odm.read_short(voff);
106
    release      = odm.read_short(roff);
107
    modification = odm.read_short(moff);
108
    fix_level    = odm.read_short(foff);
109
    trcVerbose("odm found version: %d.%d.%d.%d", version, release, modification, fix_level);
110
    if (version >> 8 != 0 || release >> 8 != 0 || modification >> 8 != 0 || fix_level >> 8 != 0) {
111
      trcVerbose("8 bit numbers expected");
112
      return;
113
    }
114
  } while (odm.retrieve_obj());
115

116
  if (version != major_aix_version || release != minor_aix_version) {
117
    trcVerbose("version determined by odm does not match uname");
118
    return;
119
  }
120
  *p_ver = version << 24 | release << 16 | modification << 8 | fix_level;
121
}
122

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.