Path: blob/master/src/hotspot/os/aix/libodm_aix.hpp
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// Encapsulates the libodm library and provides more convenient interfaces.2627#ifndef OS_AIX_LIBODM_AIX_HPP28#define OS_AIX_LIBODM_AIX_HPP2930#include <odmi.h>313233// The purpose of this code is to dynamically load the libodm library34// instead of statically linking against it. The library is AIX-specific.35// It only exists on AIX, not on PASE. In order to share binaries36// between AIX and PASE, we can't directly link against it.3738typedef int (*fun_odm_initialize )(void);39typedef char* (*fun_odm_set_path )(char*);40typedef CLASS_SYMBOL (*fun_odm_mount_class)(char*);41typedef void* (*fun_odm_get_obj )(CLASS_SYMBOL, char*, void*, int);42typedef int (*fun_odm_terminate )(void);4344class dynamicOdm {45void *_libhandle;46protected:47fun_odm_initialize _odm_initialize;48fun_odm_set_path _odm_set_path;49fun_odm_mount_class _odm_mount_class;50fun_odm_get_obj _odm_get_obj;51fun_odm_terminate _odm_terminate;52public:53dynamicOdm();54~dynamicOdm();55bool odm_loaded() {return _libhandle != NULL; }56};575859// We provide a more convenient interface for odm access and60// especially to determine the exact AIX kernel version.6162class odmWrapper : private dynamicOdm {63CLASS_SYMBOL _odm_class;64char *_data;65bool _initialized;66void clean_data();6768public:69// Make sure everything gets initialized and cleaned up properly.70explicit odmWrapper(const char* odm_class_name, const char* odm_path = NULL) : _odm_class((CLASS_SYMBOL)-1),71_data(NULL), _initialized(false) {72if (!odm_loaded()) { return; }73_initialized = ((*_odm_initialize)() != -1);74if (_initialized) {75// should we free what odm_set_path returns, man page suggests it76// see https://www.ibm.com/support/knowledgecenter/en/ssw_aix_71/o_bostechref/odm_set_path.html77if (odm_path) { (*_odm_set_path)((char*)odm_path); }78_odm_class = (*_odm_mount_class)((char*)odm_class_name);79}80}81~odmWrapper() {82if (_initialized) { (*_odm_terminate)(); clean_data(); }83}8485CLASS_SYMBOL odm_class() { return _odm_class; }86bool has_class() { return odm_class() != (CLASS_SYMBOL)-1; }87int class_offset(const char *field, bool is_aix_5);88char* data() { return _data; }8990char* retrieve_obj(const char* name = NULL) {91clean_data();92char *cnp = (char*)(void*)(*_odm_get_obj)(odm_class(), (char*) name, NULL, (name == NULL) ? ODM_NEXT : ODM_FIRST);93if (cnp != (char*)-1) { _data = cnp; }94return data();95}9697int read_short(int offs) {98short *addr = (short*)(data() + offs);99return *addr;100}101102// Determine the exact AIX kernel version as 4 byte value.103// The high order 2 bytes must be initialized already. They can be determined by uname.104static void determine_os_kernel_version(uint32_t* p_ver);105};106107#endif // OS_AIX_LIBODM_AIX_HPP108109110