Path: blob/master/src/hotspot/os/aix/libodm_aix.cpp
40930 views
/*1* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2015, 2019 SAP SE. 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 it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 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 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425#include "libodm_aix.hpp"26#include "misc_aix.hpp"27#include <stdlib.h>28#include <dlfcn.h>29#include <string.h>30#include "runtime/arguments.hpp"313233dynamicOdm::dynamicOdm() {34const char *libodmname = "/usr/lib/libodm.a(shr_64.o)";35_libhandle = dlopen(libodmname, RTLD_MEMBER | RTLD_NOW);36if (!_libhandle) {37trcVerbose("Couldn't open %s", libodmname);38return;39}40_odm_initialize = (fun_odm_initialize )dlsym(_libhandle, "odm_initialize" );41_odm_set_path = (fun_odm_set_path )dlsym(_libhandle, "odm_set_path" );42_odm_mount_class = (fun_odm_mount_class)dlsym(_libhandle, "odm_mount_class");43_odm_get_obj = (fun_odm_get_obj )dlsym(_libhandle, "odm_get_obj" );44_odm_terminate = (fun_odm_terminate )dlsym(_libhandle, "odm_terminate" );45if (!_odm_initialize || !_odm_set_path || !_odm_mount_class || !_odm_get_obj || !_odm_terminate) {46trcVerbose("Couldn't find all required odm symbols from %s", libodmname);47dlclose(_libhandle);48_libhandle = NULL;49return;50}51}5253dynamicOdm::~dynamicOdm() {54if (_libhandle) { dlclose(_libhandle); }55}565758void odmWrapper::clean_data() { if (_data) { free(_data); _data = NULL; } }596061int odmWrapper::class_offset(const char *field, bool is_aix_5)62{63assert(has_class(), "initialization");64for (int i = 0; i < odm_class()->nelem; i++) {65if (strcmp(odm_class()->elem[i].elemname, field) == 0) {66int offset = odm_class()->elem[i].offset;67if (is_aix_5) { offset += LINK_VAL_OFFSET; }68return offset;69}70}71return -1;72}737475void odmWrapper::determine_os_kernel_version(uint32_t* p_ver) {76int major_aix_version = ((*p_ver) >> 24) & 0xFF,77minor_aix_version = ((*p_ver) >> 16) & 0xFF;78assert(*p_ver, "must be initialized");7980odmWrapper odm("product", "/usr/lib/objrepos"); // could also use "lpp"81if (!odm.has_class()) {82trcVerbose("try_determine_os_kernel_version: odm init problem");83return;84}85int voff, roff, moff, foff;86bool is_aix_5 = (major_aix_version == 5);87voff = odm.class_offset("ver", is_aix_5);88roff = odm.class_offset("rel", is_aix_5);89moff = odm.class_offset("mod", is_aix_5);90foff = odm.class_offset("fix", is_aix_5);91if (voff == -1 || roff == -1 || moff == -1 || foff == -1) {92trcVerbose("try_determine_os_kernel_version: could not get offsets");93return;94}95if (!odm.retrieve_obj("name='bos.mp64'")) {96trcVerbose("try_determine_os_kernel_version: odm_get_obj failed");97return;98}99int version, release, modification, fix_level;100do {101version = odm.read_short(voff);102release = odm.read_short(roff);103modification = odm.read_short(moff);104fix_level = odm.read_short(foff);105trcVerbose("odm found version: %d.%d.%d.%d", version, release, modification, fix_level);106if (version >> 8 != 0 || release >> 8 != 0 || modification >> 8 != 0 || fix_level >> 8 != 0) {107trcVerbose("8 bit numbers expected");108return;109}110} while (odm.retrieve_obj());111112if (version != major_aix_version || release != minor_aix_version) {113trcVerbose("version determined by odm does not match uname");114return;115}116*p_ver = version << 24 | release << 16 | modification << 8 | fix_level;117}118119120