1e66f31c5Sopenharmony_ci/* Copyright libuv project contributors. All rights reserved. 2e66f31c5Sopenharmony_ci * 3e66f31c5Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a copy 4e66f31c5Sopenharmony_ci * of this software and associated documentation files (the "Software"), to 5e66f31c5Sopenharmony_ci * deal in the Software without restriction, including without limitation the 6e66f31c5Sopenharmony_ci * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7e66f31c5Sopenharmony_ci * sell copies of the Software, and to permit persons to whom the Software is 8e66f31c5Sopenharmony_ci * furnished to do so, subject to the following conditions: 9e66f31c5Sopenharmony_ci * 10e66f31c5Sopenharmony_ci * The above copyright notice and this permission notice shall be included in 11e66f31c5Sopenharmony_ci * all copies or substantial portions of the Software. 12e66f31c5Sopenharmony_ci * 13e66f31c5Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14e66f31c5Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15e66f31c5Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16e66f31c5Sopenharmony_ci * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17e66f31c5Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18e66f31c5Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19e66f31c5Sopenharmony_ci * IN THE SOFTWARE. 20e66f31c5Sopenharmony_ci */ 21e66f31c5Sopenharmony_ci 22e66f31c5Sopenharmony_ci#include "uv.h" 23e66f31c5Sopenharmony_ci#include "internal.h" 24e66f31c5Sopenharmony_ci 25e66f31c5Sopenharmony_ci#include <stdio.h> 26e66f31c5Sopenharmony_ci#include <stdint.h> 27e66f31c5Sopenharmony_ci#include <stdlib.h> 28e66f31c5Sopenharmony_ci#include <string.h> 29e66f31c5Sopenharmony_ci#include <errno.h> 30e66f31c5Sopenharmony_ci 31e66f31c5Sopenharmony_ci#include <sys/types.h> 32e66f31c5Sopenharmony_ci#include <sys/socket.h> 33e66f31c5Sopenharmony_ci#include <sys/ioctl.h> 34e66f31c5Sopenharmony_ci#include <net/if.h> 35e66f31c5Sopenharmony_ci#include <netinet/in.h> 36e66f31c5Sopenharmony_ci#include <arpa/inet.h> 37e66f31c5Sopenharmony_ci 38e66f31c5Sopenharmony_ci#include <sys/time.h> 39e66f31c5Sopenharmony_ci#include <unistd.h> 40e66f31c5Sopenharmony_ci#include <fcntl.h> 41e66f31c5Sopenharmony_ci#include <utmp.h> 42e66f31c5Sopenharmony_ci#include <libgen.h> 43e66f31c5Sopenharmony_ci 44e66f31c5Sopenharmony_ci#include <sys/protosw.h> 45e66f31c5Sopenharmony_ci#include <procinfo.h> 46e66f31c5Sopenharmony_ci#include <sys/proc.h> 47e66f31c5Sopenharmony_ci#include <sys/procfs.h> 48e66f31c5Sopenharmony_ci 49e66f31c5Sopenharmony_ci#include <ctype.h> 50e66f31c5Sopenharmony_ci 51e66f31c5Sopenharmony_ci#include <sys/mntctl.h> 52e66f31c5Sopenharmony_ci#include <sys/vmount.h> 53e66f31c5Sopenharmony_ci#include <limits.h> 54e66f31c5Sopenharmony_ci#include <strings.h> 55e66f31c5Sopenharmony_ci#include <sys/vnode.h> 56e66f31c5Sopenharmony_ci 57e66f31c5Sopenharmony_ci#include <as400_protos.h> 58e66f31c5Sopenharmony_ci#include <as400_types.h> 59e66f31c5Sopenharmony_ci 60e66f31c5Sopenharmony_cichar* original_exepath = NULL; 61e66f31c5Sopenharmony_ciuv_mutex_t process_title_mutex; 62e66f31c5Sopenharmony_ciuv_once_t process_title_mutex_once = UV_ONCE_INIT; 63e66f31c5Sopenharmony_ci 64e66f31c5Sopenharmony_citypedef struct { 65e66f31c5Sopenharmony_ci int bytes_available; 66e66f31c5Sopenharmony_ci int bytes_returned; 67e66f31c5Sopenharmony_ci char current_date_and_time[8]; 68e66f31c5Sopenharmony_ci char system_name[8]; 69e66f31c5Sopenharmony_ci char elapsed_time[6]; 70e66f31c5Sopenharmony_ci char restricted_state_flag; 71e66f31c5Sopenharmony_ci char reserved; 72e66f31c5Sopenharmony_ci int percent_processing_unit_used; 73e66f31c5Sopenharmony_ci int jobs_in_system; 74e66f31c5Sopenharmony_ci int percent_permanent_addresses; 75e66f31c5Sopenharmony_ci int percent_temporary_addresses; 76e66f31c5Sopenharmony_ci int system_asp; 77e66f31c5Sopenharmony_ci int percent_system_asp_used; 78e66f31c5Sopenharmony_ci int total_auxiliary_storage; 79e66f31c5Sopenharmony_ci int current_unprotected_storage_used; 80e66f31c5Sopenharmony_ci int maximum_unprotected_storage_used; 81e66f31c5Sopenharmony_ci int percent_db_capability; 82e66f31c5Sopenharmony_ci int main_storage_size; 83e66f31c5Sopenharmony_ci int number_of_partitions; 84e66f31c5Sopenharmony_ci int partition_identifier; 85e66f31c5Sopenharmony_ci int reserved1; 86e66f31c5Sopenharmony_ci int current_processing_capacity; 87e66f31c5Sopenharmony_ci char processor_sharing_attribute; 88e66f31c5Sopenharmony_ci char reserved2[3]; 89e66f31c5Sopenharmony_ci int number_of_processors; 90e66f31c5Sopenharmony_ci int active_jobs_in_system; 91e66f31c5Sopenharmony_ci int active_threads_in_system; 92e66f31c5Sopenharmony_ci int maximum_jobs_in_system; 93e66f31c5Sopenharmony_ci int percent_temporary_256mb_segments_used; 94e66f31c5Sopenharmony_ci int percent_temporary_4gb_segments_used; 95e66f31c5Sopenharmony_ci int percent_permanent_256mb_segments_used; 96e66f31c5Sopenharmony_ci int percent_permanent_4gb_segments_used; 97e66f31c5Sopenharmony_ci int percent_current_interactive_performance; 98e66f31c5Sopenharmony_ci int percent_uncapped_cpu_capacity_used; 99e66f31c5Sopenharmony_ci int percent_shared_processor_pool_used; 100e66f31c5Sopenharmony_ci long main_storage_size_long; 101e66f31c5Sopenharmony_ci} SSTS0200; 102e66f31c5Sopenharmony_ci 103e66f31c5Sopenharmony_ci 104e66f31c5Sopenharmony_citypedef struct { 105e66f31c5Sopenharmony_ci char header[208]; 106e66f31c5Sopenharmony_ci unsigned char loca_adapter_address[12]; 107e66f31c5Sopenharmony_ci} LIND0500; 108e66f31c5Sopenharmony_ci 109e66f31c5Sopenharmony_ci 110e66f31c5Sopenharmony_citypedef struct { 111e66f31c5Sopenharmony_ci int bytes_provided; 112e66f31c5Sopenharmony_ci int bytes_available; 113e66f31c5Sopenharmony_ci char msgid[7]; 114e66f31c5Sopenharmony_ci} errcode_s; 115e66f31c5Sopenharmony_ci 116e66f31c5Sopenharmony_ci 117e66f31c5Sopenharmony_cistatic const unsigned char e2a[256] = { 118e66f31c5Sopenharmony_ci 0, 1, 2, 3, 156, 9, 134, 127, 151, 141, 142, 11, 12, 13, 14, 15, 119e66f31c5Sopenharmony_ci 16, 17, 18, 19, 157, 133, 8, 135, 24, 25, 146, 143, 28, 29, 30, 31, 120e66f31c5Sopenharmony_ci 128, 129, 130, 131, 132, 10, 23, 27, 136, 137, 138, 139, 140, 5, 6, 7, 121e66f31c5Sopenharmony_ci 144, 145, 22, 147, 148, 149, 150, 4, 152, 153, 154, 155, 20, 21, 158, 26, 122e66f31c5Sopenharmony_ci 32, 160, 161, 162, 163, 164, 165, 166, 167, 168, 91, 46, 60, 40, 43, 33, 123e66f31c5Sopenharmony_ci 38, 169, 170, 171, 172, 173, 174, 175, 176, 177, 93, 36, 42, 41, 59, 94, 124e66f31c5Sopenharmony_ci 45, 47, 178, 179, 180, 181, 182, 183, 184, 185, 124, 44, 37, 95, 62, 63, 125e66f31c5Sopenharmony_ci 186, 187, 188, 189, 190, 191, 192, 193, 194, 96, 58, 35, 64, 39, 61, 34, 126e66f31c5Sopenharmony_ci 195, 97, 98, 99, 100, 101, 102, 103, 104, 105, 196, 197, 198, 199, 200, 201, 127e66f31c5Sopenharmony_ci 202, 106, 107, 108, 109, 110, 111, 112, 113, 114, 203, 204, 205, 206, 207, 208, 128e66f31c5Sopenharmony_ci 209, 126, 115, 116, 117, 118, 119, 120, 121, 122, 210, 211, 212, 213, 214, 215, 129e66f31c5Sopenharmony_ci 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 130e66f31c5Sopenharmony_ci 123, 65, 66, 67, 68, 69, 70, 71, 72, 73, 232, 233, 234, 235, 236, 237, 131e66f31c5Sopenharmony_ci 125, 74, 75, 76, 77, 78, 79, 80, 81, 82, 238, 239, 240, 241, 242, 243, 132e66f31c5Sopenharmony_ci 92, 159, 83, 84, 85, 86, 87, 88, 89, 90, 244, 245, 246, 247, 248, 249, 133e66f31c5Sopenharmony_ci 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 250, 251, 252, 253, 254, 255}; 134e66f31c5Sopenharmony_ci 135e66f31c5Sopenharmony_ci 136e66f31c5Sopenharmony_cistatic const unsigned char a2e[256] = { 137e66f31c5Sopenharmony_ci 0, 1, 2, 3, 55, 45, 46, 47, 22, 5, 37, 11, 12, 13, 14, 15, 138e66f31c5Sopenharmony_ci 16, 17, 18, 19, 60, 61, 50, 38, 24, 25, 63, 39, 28, 29, 30, 31, 139e66f31c5Sopenharmony_ci 64, 79, 127, 123, 91, 108, 80, 125, 77, 93, 92, 78, 107, 96, 75, 97, 140e66f31c5Sopenharmony_ci 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 122, 94, 76, 126, 110, 111, 141e66f31c5Sopenharmony_ci 124, 193, 194, 195, 196, 197, 198, 199, 200, 201, 209, 210, 211, 212, 213, 214, 142e66f31c5Sopenharmony_ci 215, 216, 217, 226, 227, 228, 229, 230, 231, 232, 233, 74, 224, 90, 95, 109, 143e66f31c5Sopenharmony_ci 121, 129, 130, 131, 132, 133, 134, 135, 136, 137, 145, 146, 147, 148, 149, 150, 144e66f31c5Sopenharmony_ci 151, 152, 153, 162, 163, 164, 165, 166, 167, 168, 169, 192, 106, 208, 161, 7, 145e66f31c5Sopenharmony_ci 32, 33, 34, 35, 36, 21, 6, 23, 40, 41, 42, 43, 44, 9, 10, 27, 146e66f31c5Sopenharmony_ci 48, 49, 26, 51, 52, 53, 54, 8, 56, 57, 58, 59, 4, 20, 62, 225, 147e66f31c5Sopenharmony_ci 65, 66, 67, 68, 69, 70, 71, 72, 73, 81, 82, 83, 84, 85, 86, 87, 148e66f31c5Sopenharmony_ci 88, 89, 98, 99, 100, 101, 102, 103, 104, 105, 112, 113, 114, 115, 116, 117, 149e66f31c5Sopenharmony_ci 118, 119, 120, 128, 138, 139, 140, 141, 142, 143, 144, 154, 155, 156, 157, 158, 150e66f31c5Sopenharmony_ci 159, 160, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 151e66f31c5Sopenharmony_ci 184, 185, 186, 187, 188, 189, 190, 191, 202, 203, 204, 205, 206, 207, 218, 219, 152e66f31c5Sopenharmony_ci 220, 221, 222, 223, 234, 235, 236, 237, 238, 239, 250, 251, 252, 253, 254, 255}; 153e66f31c5Sopenharmony_ci 154e66f31c5Sopenharmony_ci 155e66f31c5Sopenharmony_cistatic void iconv_e2a(unsigned char src[], unsigned char dst[], size_t length) { 156e66f31c5Sopenharmony_ci size_t i; 157e66f31c5Sopenharmony_ci for (i = 0; i < length; i++) 158e66f31c5Sopenharmony_ci dst[i] = e2a[src[i]]; 159e66f31c5Sopenharmony_ci} 160e66f31c5Sopenharmony_ci 161e66f31c5Sopenharmony_ci 162e66f31c5Sopenharmony_cistatic void iconv_a2e(const char* src, unsigned char dst[], size_t length) { 163e66f31c5Sopenharmony_ci size_t srclen; 164e66f31c5Sopenharmony_ci size_t i; 165e66f31c5Sopenharmony_ci 166e66f31c5Sopenharmony_ci srclen = strlen(src); 167e66f31c5Sopenharmony_ci if (srclen > length) 168e66f31c5Sopenharmony_ci srclen = length; 169e66f31c5Sopenharmony_ci for (i = 0; i < srclen; i++) 170e66f31c5Sopenharmony_ci dst[i] = a2e[src[i]]; 171e66f31c5Sopenharmony_ci /* padding the remaining part with spaces */ 172e66f31c5Sopenharmony_ci for (; i < length; i++) 173e66f31c5Sopenharmony_ci dst[i] = a2e[' ']; 174e66f31c5Sopenharmony_ci} 175e66f31c5Sopenharmony_ci 176e66f31c5Sopenharmony_civoid init_process_title_mutex_once(void) { 177e66f31c5Sopenharmony_ci uv_mutex_init(&process_title_mutex); 178e66f31c5Sopenharmony_ci} 179e66f31c5Sopenharmony_ci 180e66f31c5Sopenharmony_cistatic int get_ibmi_system_status(SSTS0200* rcvr) { 181e66f31c5Sopenharmony_ci /* rcvrlen is input parameter 2 to QWCRSSTS */ 182e66f31c5Sopenharmony_ci unsigned int rcvrlen = sizeof(*rcvr); 183e66f31c5Sopenharmony_ci unsigned char format[8], reset_status[10]; 184e66f31c5Sopenharmony_ci 185e66f31c5Sopenharmony_ci /* format is input parameter 3 to QWCRSSTS */ 186e66f31c5Sopenharmony_ci iconv_a2e("SSTS0200", format, sizeof(format)); 187e66f31c5Sopenharmony_ci /* reset_status is input parameter 4 */ 188e66f31c5Sopenharmony_ci iconv_a2e("*NO", reset_status, sizeof(reset_status)); 189e66f31c5Sopenharmony_ci 190e66f31c5Sopenharmony_ci /* errcode is input parameter 5 to QWCRSSTS */ 191e66f31c5Sopenharmony_ci errcode_s errcode; 192e66f31c5Sopenharmony_ci 193e66f31c5Sopenharmony_ci /* qwcrssts_pointer is the 16-byte tagged system pointer to QWCRSSTS */ 194e66f31c5Sopenharmony_ci ILEpointer __attribute__((aligned(16))) qwcrssts_pointer; 195e66f31c5Sopenharmony_ci 196e66f31c5Sopenharmony_ci /* qwcrssts_argv is the array of argument pointers to QWCRSSTS */ 197e66f31c5Sopenharmony_ci void* qwcrssts_argv[6]; 198e66f31c5Sopenharmony_ci 199e66f31c5Sopenharmony_ci /* Set the IBM i pointer to the QSYS/QWCRSSTS *PGM object */ 200e66f31c5Sopenharmony_ci int rc = _RSLOBJ2(&qwcrssts_pointer, RSLOBJ_TS_PGM, "QWCRSSTS", "QSYS"); 201e66f31c5Sopenharmony_ci 202e66f31c5Sopenharmony_ci if (rc != 0) 203e66f31c5Sopenharmony_ci return rc; 204e66f31c5Sopenharmony_ci 205e66f31c5Sopenharmony_ci /* initialize the QWCRSSTS returned info structure */ 206e66f31c5Sopenharmony_ci memset(rcvr, 0, sizeof(*rcvr)); 207e66f31c5Sopenharmony_ci 208e66f31c5Sopenharmony_ci /* initialize the QWCRSSTS error code structure */ 209e66f31c5Sopenharmony_ci memset(&errcode, 0, sizeof(errcode)); 210e66f31c5Sopenharmony_ci errcode.bytes_provided = sizeof(errcode); 211e66f31c5Sopenharmony_ci 212e66f31c5Sopenharmony_ci /* initialize the array of argument pointers for the QWCRSSTS API */ 213e66f31c5Sopenharmony_ci qwcrssts_argv[0] = rcvr; 214e66f31c5Sopenharmony_ci qwcrssts_argv[1] = &rcvrlen; 215e66f31c5Sopenharmony_ci qwcrssts_argv[2] = &format; 216e66f31c5Sopenharmony_ci qwcrssts_argv[3] = &reset_status; 217e66f31c5Sopenharmony_ci qwcrssts_argv[4] = &errcode; 218e66f31c5Sopenharmony_ci qwcrssts_argv[5] = NULL; 219e66f31c5Sopenharmony_ci 220e66f31c5Sopenharmony_ci /* Call the IBM i QWCRSSTS API from PASE */ 221e66f31c5Sopenharmony_ci rc = _PGMCALL(&qwcrssts_pointer, qwcrssts_argv, 0); 222e66f31c5Sopenharmony_ci 223e66f31c5Sopenharmony_ci return rc; 224e66f31c5Sopenharmony_ci} 225e66f31c5Sopenharmony_ci 226e66f31c5Sopenharmony_ci 227e66f31c5Sopenharmony_ciuint64_t uv_get_free_memory(void) { 228e66f31c5Sopenharmony_ci SSTS0200 rcvr; 229e66f31c5Sopenharmony_ci 230e66f31c5Sopenharmony_ci if (get_ibmi_system_status(&rcvr)) 231e66f31c5Sopenharmony_ci return 0; 232e66f31c5Sopenharmony_ci 233e66f31c5Sopenharmony_ci return (uint64_t)rcvr.main_storage_size * 1024ULL; 234e66f31c5Sopenharmony_ci} 235e66f31c5Sopenharmony_ci 236e66f31c5Sopenharmony_ci 237e66f31c5Sopenharmony_ciuint64_t uv_get_total_memory(void) { 238e66f31c5Sopenharmony_ci SSTS0200 rcvr; 239e66f31c5Sopenharmony_ci 240e66f31c5Sopenharmony_ci if (get_ibmi_system_status(&rcvr)) 241e66f31c5Sopenharmony_ci return 0; 242e66f31c5Sopenharmony_ci 243e66f31c5Sopenharmony_ci return (uint64_t)rcvr.main_storage_size * 1024ULL; 244e66f31c5Sopenharmony_ci} 245e66f31c5Sopenharmony_ci 246e66f31c5Sopenharmony_ci 247e66f31c5Sopenharmony_ciuint64_t uv_get_constrained_memory(void) { 248e66f31c5Sopenharmony_ci return 0; /* Memory constraints are unknown. */ 249e66f31c5Sopenharmony_ci} 250e66f31c5Sopenharmony_ci 251e66f31c5Sopenharmony_ci 252e66f31c5Sopenharmony_ciuint64_t uv_get_available_memory(void) { 253e66f31c5Sopenharmony_ci return uv_get_free_memory(); 254e66f31c5Sopenharmony_ci} 255e66f31c5Sopenharmony_ci 256e66f31c5Sopenharmony_ci 257e66f31c5Sopenharmony_civoid uv_loadavg(double avg[3]) { 258e66f31c5Sopenharmony_ci SSTS0200 rcvr; 259e66f31c5Sopenharmony_ci 260e66f31c5Sopenharmony_ci if (get_ibmi_system_status(&rcvr)) { 261e66f31c5Sopenharmony_ci avg[0] = avg[1] = avg[2] = 0; 262e66f31c5Sopenharmony_ci return; 263e66f31c5Sopenharmony_ci } 264e66f31c5Sopenharmony_ci 265e66f31c5Sopenharmony_ci /* The average (in tenths) of the elapsed time during which the processing 266e66f31c5Sopenharmony_ci * units were in use. For example, a value of 411 in binary would be 41.1%. 267e66f31c5Sopenharmony_ci * This percentage could be greater than 100% for an uncapped partition. 268e66f31c5Sopenharmony_ci */ 269e66f31c5Sopenharmony_ci double processing_unit_used_percent = 270e66f31c5Sopenharmony_ci rcvr.percent_processing_unit_used / 1000.0; 271e66f31c5Sopenharmony_ci 272e66f31c5Sopenharmony_ci avg[0] = avg[1] = avg[2] = processing_unit_used_percent; 273e66f31c5Sopenharmony_ci} 274e66f31c5Sopenharmony_ci 275e66f31c5Sopenharmony_ci 276e66f31c5Sopenharmony_ciint uv_resident_set_memory(size_t* rss) { 277e66f31c5Sopenharmony_ci *rss = 0; 278e66f31c5Sopenharmony_ci return 0; 279e66f31c5Sopenharmony_ci} 280e66f31c5Sopenharmony_ci 281e66f31c5Sopenharmony_ci 282e66f31c5Sopenharmony_ciint uv_uptime(double* uptime) { 283e66f31c5Sopenharmony_ci return UV_ENOSYS; 284e66f31c5Sopenharmony_ci} 285e66f31c5Sopenharmony_ci 286e66f31c5Sopenharmony_ci 287e66f31c5Sopenharmony_ciint uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { 288e66f31c5Sopenharmony_ci unsigned int numcpus, idx = 0; 289e66f31c5Sopenharmony_ci uv_cpu_info_t* cpu_info; 290e66f31c5Sopenharmony_ci 291e66f31c5Sopenharmony_ci *cpu_infos = NULL; 292e66f31c5Sopenharmony_ci *count = 0; 293e66f31c5Sopenharmony_ci 294e66f31c5Sopenharmony_ci numcpus = sysconf(_SC_NPROCESSORS_ONLN); 295e66f31c5Sopenharmony_ci 296e66f31c5Sopenharmony_ci *cpu_infos = uv__malloc(numcpus * sizeof(uv_cpu_info_t)); 297e66f31c5Sopenharmony_ci if (!*cpu_infos) { 298e66f31c5Sopenharmony_ci return UV_ENOMEM; 299e66f31c5Sopenharmony_ci } 300e66f31c5Sopenharmony_ci 301e66f31c5Sopenharmony_ci cpu_info = *cpu_infos; 302e66f31c5Sopenharmony_ci for (idx = 0; idx < numcpus; idx++) { 303e66f31c5Sopenharmony_ci cpu_info->speed = 0; 304e66f31c5Sopenharmony_ci cpu_info->model = uv__strdup("unknown"); 305e66f31c5Sopenharmony_ci cpu_info->cpu_times.user = 0; 306e66f31c5Sopenharmony_ci cpu_info->cpu_times.sys = 0; 307e66f31c5Sopenharmony_ci cpu_info->cpu_times.idle = 0; 308e66f31c5Sopenharmony_ci cpu_info->cpu_times.irq = 0; 309e66f31c5Sopenharmony_ci cpu_info->cpu_times.nice = 0; 310e66f31c5Sopenharmony_ci cpu_info++; 311e66f31c5Sopenharmony_ci } 312e66f31c5Sopenharmony_ci *count = numcpus; 313e66f31c5Sopenharmony_ci 314e66f31c5Sopenharmony_ci return 0; 315e66f31c5Sopenharmony_ci} 316e66f31c5Sopenharmony_ci 317e66f31c5Sopenharmony_ci 318e66f31c5Sopenharmony_cistatic int get_ibmi_physical_address(const char* line, char (*phys_addr)[6]) { 319e66f31c5Sopenharmony_ci LIND0500 rcvr; 320e66f31c5Sopenharmony_ci /* rcvrlen is input parameter 2 to QDCRLIND */ 321e66f31c5Sopenharmony_ci unsigned int rcvrlen = sizeof(rcvr); 322e66f31c5Sopenharmony_ci unsigned char format[8], line_name[10]; 323e66f31c5Sopenharmony_ci unsigned char mac_addr[sizeof(rcvr.loca_adapter_address)]; 324e66f31c5Sopenharmony_ci int c[6]; 325e66f31c5Sopenharmony_ci 326e66f31c5Sopenharmony_ci /* format is input parameter 3 to QDCRLIND */ 327e66f31c5Sopenharmony_ci iconv_a2e("LIND0500", format, sizeof(format)); 328e66f31c5Sopenharmony_ci 329e66f31c5Sopenharmony_ci /* line_name is input parameter 4 to QDCRLIND */ 330e66f31c5Sopenharmony_ci iconv_a2e(line, line_name, sizeof(line_name)); 331e66f31c5Sopenharmony_ci 332e66f31c5Sopenharmony_ci /* err is input parameter 5 to QDCRLIND */ 333e66f31c5Sopenharmony_ci errcode_s err; 334e66f31c5Sopenharmony_ci 335e66f31c5Sopenharmony_ci /* qwcrssts_pointer is the 16-byte tagged system pointer to QDCRLIND */ 336e66f31c5Sopenharmony_ci ILEpointer __attribute__((aligned(16))) qdcrlind_pointer; 337e66f31c5Sopenharmony_ci 338e66f31c5Sopenharmony_ci /* qwcrssts_argv is the array of argument pointers to QDCRLIND */ 339e66f31c5Sopenharmony_ci void* qdcrlind_argv[6]; 340e66f31c5Sopenharmony_ci 341e66f31c5Sopenharmony_ci /* Set the IBM i pointer to the QSYS/QDCRLIND *PGM object */ 342e66f31c5Sopenharmony_ci int rc = _RSLOBJ2(&qdcrlind_pointer, RSLOBJ_TS_PGM, "QDCRLIND", "QSYS"); 343e66f31c5Sopenharmony_ci 344e66f31c5Sopenharmony_ci if (rc != 0) 345e66f31c5Sopenharmony_ci return rc; 346e66f31c5Sopenharmony_ci 347e66f31c5Sopenharmony_ci /* initialize the QDCRLIND returned info structure */ 348e66f31c5Sopenharmony_ci memset(&rcvr, 0, sizeof(rcvr)); 349e66f31c5Sopenharmony_ci 350e66f31c5Sopenharmony_ci /* initialize the QDCRLIND error code structure */ 351e66f31c5Sopenharmony_ci memset(&err, 0, sizeof(err)); 352e66f31c5Sopenharmony_ci err.bytes_provided = sizeof(err); 353e66f31c5Sopenharmony_ci 354e66f31c5Sopenharmony_ci /* initialize the array of argument pointers for the QDCRLIND API */ 355e66f31c5Sopenharmony_ci qdcrlind_argv[0] = &rcvr; 356e66f31c5Sopenharmony_ci qdcrlind_argv[1] = &rcvrlen; 357e66f31c5Sopenharmony_ci qdcrlind_argv[2] = &format; 358e66f31c5Sopenharmony_ci qdcrlind_argv[3] = &line_name; 359e66f31c5Sopenharmony_ci qdcrlind_argv[4] = &err; 360e66f31c5Sopenharmony_ci qdcrlind_argv[5] = NULL; 361e66f31c5Sopenharmony_ci 362e66f31c5Sopenharmony_ci /* Call the IBM i QDCRLIND API from PASE */ 363e66f31c5Sopenharmony_ci rc = _PGMCALL(&qdcrlind_pointer, qdcrlind_argv, 0); 364e66f31c5Sopenharmony_ci if (rc != 0) 365e66f31c5Sopenharmony_ci return rc; 366e66f31c5Sopenharmony_ci 367e66f31c5Sopenharmony_ci if (err.bytes_available > 0) { 368e66f31c5Sopenharmony_ci return -1; 369e66f31c5Sopenharmony_ci } 370e66f31c5Sopenharmony_ci 371e66f31c5Sopenharmony_ci /* convert ebcdic loca_adapter_address to ascii first */ 372e66f31c5Sopenharmony_ci iconv_e2a(rcvr.loca_adapter_address, mac_addr, 373e66f31c5Sopenharmony_ci sizeof(rcvr.loca_adapter_address)); 374e66f31c5Sopenharmony_ci 375e66f31c5Sopenharmony_ci /* convert loca_adapter_address(char[12]) to phys_addr(char[6]) */ 376e66f31c5Sopenharmony_ci int r = sscanf(mac_addr, "%02x%02x%02x%02x%02x%02x", 377e66f31c5Sopenharmony_ci &c[0], &c[1], &c[2], &c[3], &c[4], &c[5]); 378e66f31c5Sopenharmony_ci 379e66f31c5Sopenharmony_ci if (r == ARRAY_SIZE(c)) { 380e66f31c5Sopenharmony_ci (*phys_addr)[0] = c[0]; 381e66f31c5Sopenharmony_ci (*phys_addr)[1] = c[1]; 382e66f31c5Sopenharmony_ci (*phys_addr)[2] = c[2]; 383e66f31c5Sopenharmony_ci (*phys_addr)[3] = c[3]; 384e66f31c5Sopenharmony_ci (*phys_addr)[4] = c[4]; 385e66f31c5Sopenharmony_ci (*phys_addr)[5] = c[5]; 386e66f31c5Sopenharmony_ci } else { 387e66f31c5Sopenharmony_ci memset(*phys_addr, 0, sizeof(*phys_addr)); 388e66f31c5Sopenharmony_ci rc = -1; 389e66f31c5Sopenharmony_ci } 390e66f31c5Sopenharmony_ci return rc; 391e66f31c5Sopenharmony_ci} 392e66f31c5Sopenharmony_ci 393e66f31c5Sopenharmony_ci 394e66f31c5Sopenharmony_ciint uv_interface_addresses(uv_interface_address_t** addresses, int* count) { 395e66f31c5Sopenharmony_ci uv_interface_address_t* address; 396e66f31c5Sopenharmony_ci struct ifaddrs_pase *ifap = NULL, *cur; 397e66f31c5Sopenharmony_ci int inet6, r = 0; 398e66f31c5Sopenharmony_ci 399e66f31c5Sopenharmony_ci *count = 0; 400e66f31c5Sopenharmony_ci *addresses = NULL; 401e66f31c5Sopenharmony_ci 402e66f31c5Sopenharmony_ci if (Qp2getifaddrs(&ifap)) 403e66f31c5Sopenharmony_ci return UV_ENOSYS; 404e66f31c5Sopenharmony_ci 405e66f31c5Sopenharmony_ci /* The first loop to get the size of the array to be allocated */ 406e66f31c5Sopenharmony_ci for (cur = ifap; cur; cur = cur->ifa_next) { 407e66f31c5Sopenharmony_ci if (!(cur->ifa_addr->sa_family == AF_INET6 || 408e66f31c5Sopenharmony_ci cur->ifa_addr->sa_family == AF_INET)) 409e66f31c5Sopenharmony_ci continue; 410e66f31c5Sopenharmony_ci 411e66f31c5Sopenharmony_ci if (!(cur->ifa_flags & IFF_UP && cur->ifa_flags & IFF_RUNNING)) 412e66f31c5Sopenharmony_ci continue; 413e66f31c5Sopenharmony_ci 414e66f31c5Sopenharmony_ci (*count)++; 415e66f31c5Sopenharmony_ci } 416e66f31c5Sopenharmony_ci 417e66f31c5Sopenharmony_ci if (*count == 0) { 418e66f31c5Sopenharmony_ci Qp2freeifaddrs(ifap); 419e66f31c5Sopenharmony_ci return 0; 420e66f31c5Sopenharmony_ci } 421e66f31c5Sopenharmony_ci 422e66f31c5Sopenharmony_ci /* Alloc the return interface structs */ 423e66f31c5Sopenharmony_ci *addresses = uv__calloc(*count, sizeof(**addresses)); 424e66f31c5Sopenharmony_ci if (*addresses == NULL) { 425e66f31c5Sopenharmony_ci Qp2freeifaddrs(ifap); 426e66f31c5Sopenharmony_ci return UV_ENOMEM; 427e66f31c5Sopenharmony_ci } 428e66f31c5Sopenharmony_ci address = *addresses; 429e66f31c5Sopenharmony_ci 430e66f31c5Sopenharmony_ci /* The second loop to fill in the array */ 431e66f31c5Sopenharmony_ci for (cur = ifap; cur; cur = cur->ifa_next) { 432e66f31c5Sopenharmony_ci if (!(cur->ifa_addr->sa_family == AF_INET6 || 433e66f31c5Sopenharmony_ci cur->ifa_addr->sa_family == AF_INET)) 434e66f31c5Sopenharmony_ci continue; 435e66f31c5Sopenharmony_ci 436e66f31c5Sopenharmony_ci if (!(cur->ifa_flags & IFF_UP && cur->ifa_flags & IFF_RUNNING)) 437e66f31c5Sopenharmony_ci continue; 438e66f31c5Sopenharmony_ci 439e66f31c5Sopenharmony_ci address->name = uv__strdup(cur->ifa_name); 440e66f31c5Sopenharmony_ci 441e66f31c5Sopenharmony_ci inet6 = (cur->ifa_addr->sa_family == AF_INET6); 442e66f31c5Sopenharmony_ci 443e66f31c5Sopenharmony_ci if (inet6) { 444e66f31c5Sopenharmony_ci address->address.address6 = *((struct sockaddr_in6*)cur->ifa_addr); 445e66f31c5Sopenharmony_ci address->netmask.netmask6 = *((struct sockaddr_in6*)cur->ifa_netmask); 446e66f31c5Sopenharmony_ci address->netmask.netmask6.sin6_family = AF_INET6; 447e66f31c5Sopenharmony_ci } else { 448e66f31c5Sopenharmony_ci address->address.address4 = *((struct sockaddr_in*)cur->ifa_addr); 449e66f31c5Sopenharmony_ci address->netmask.netmask4 = *((struct sockaddr_in*)cur->ifa_netmask); 450e66f31c5Sopenharmony_ci address->netmask.netmask4.sin_family = AF_INET; 451e66f31c5Sopenharmony_ci } 452e66f31c5Sopenharmony_ci address->is_internal = cur->ifa_flags & IFF_LOOPBACK ? 1 : 0; 453e66f31c5Sopenharmony_ci if (!address->is_internal) { 454e66f31c5Sopenharmony_ci int rc = -1; 455e66f31c5Sopenharmony_ci size_t name_len = strlen(address->name); 456e66f31c5Sopenharmony_ci /* To get the associated MAC address, we must convert the address to a 457e66f31c5Sopenharmony_ci * line description. Normally, the name field contains the line 458e66f31c5Sopenharmony_ci * description name, but for VLANs it has the VLAN appended with a 459e66f31c5Sopenharmony_ci * period. Since object names can also contain periods and numbers, there 460e66f31c5Sopenharmony_ci * is no way to know if a returned name is for a VLAN or not. eg. 461e66f31c5Sopenharmony_ci * *LIND ETH1.1 and *LIND ETH1, VLAN 1 both have the same name: ETH1.1 462e66f31c5Sopenharmony_ci * 463e66f31c5Sopenharmony_ci * Instead, we apply the same heuristic used by some of the XPF ioctls: 464e66f31c5Sopenharmony_ci * - names > 10 *must* contain a VLAN 465e66f31c5Sopenharmony_ci * - assume names <= 10 do not contain a VLAN and try directly 466e66f31c5Sopenharmony_ci * - if >10 or QDCRLIND returned an error, try to strip off a VLAN 467e66f31c5Sopenharmony_ci * and try again 468e66f31c5Sopenharmony_ci * - if we still get an error or couldn't find a period, leave the MAC as 469e66f31c5Sopenharmony_ci * 00:00:00:00:00:00 470e66f31c5Sopenharmony_ci */ 471e66f31c5Sopenharmony_ci if (name_len <= 10) { 472e66f31c5Sopenharmony_ci /* Assume name does not contain a VLAN ID */ 473e66f31c5Sopenharmony_ci rc = get_ibmi_physical_address(address->name, &address->phys_addr); 474e66f31c5Sopenharmony_ci } 475e66f31c5Sopenharmony_ci 476e66f31c5Sopenharmony_ci if (name_len > 10 || rc != 0) { 477e66f31c5Sopenharmony_ci /* The interface name must contain a VLAN ID suffix. Attempt to strip 478e66f31c5Sopenharmony_ci * it off so we can get the line description to pass to QDCRLIND. 479e66f31c5Sopenharmony_ci */ 480e66f31c5Sopenharmony_ci char* temp_name = uv__strdup(address->name); 481e66f31c5Sopenharmony_ci char* dot = strrchr(temp_name, '.'); 482e66f31c5Sopenharmony_ci if (dot != NULL) { 483e66f31c5Sopenharmony_ci *dot = '\0'; 484e66f31c5Sopenharmony_ci if (strlen(temp_name) <= 10) { 485e66f31c5Sopenharmony_ci rc = get_ibmi_physical_address(temp_name, &address->phys_addr); 486e66f31c5Sopenharmony_ci } 487e66f31c5Sopenharmony_ci } 488e66f31c5Sopenharmony_ci uv__free(temp_name); 489e66f31c5Sopenharmony_ci } 490e66f31c5Sopenharmony_ci } 491e66f31c5Sopenharmony_ci 492e66f31c5Sopenharmony_ci address++; 493e66f31c5Sopenharmony_ci } 494e66f31c5Sopenharmony_ci 495e66f31c5Sopenharmony_ci Qp2freeifaddrs(ifap); 496e66f31c5Sopenharmony_ci return r; 497e66f31c5Sopenharmony_ci} 498e66f31c5Sopenharmony_ci 499e66f31c5Sopenharmony_ci 500e66f31c5Sopenharmony_civoid uv_free_interface_addresses(uv_interface_address_t* addresses, int count) { 501e66f31c5Sopenharmony_ci int i; 502e66f31c5Sopenharmony_ci 503e66f31c5Sopenharmony_ci for (i = 0; i < count; ++i) { 504e66f31c5Sopenharmony_ci uv__free(addresses[i].name); 505e66f31c5Sopenharmony_ci } 506e66f31c5Sopenharmony_ci 507e66f31c5Sopenharmony_ci uv__free(addresses); 508e66f31c5Sopenharmony_ci} 509e66f31c5Sopenharmony_ci 510e66f31c5Sopenharmony_cichar** uv_setup_args(int argc, char** argv) { 511e66f31c5Sopenharmony_ci char exepath[UV__PATH_MAX]; 512e66f31c5Sopenharmony_ci char* s; 513e66f31c5Sopenharmony_ci size_t size; 514e66f31c5Sopenharmony_ci 515e66f31c5Sopenharmony_ci if (argc > 0) { 516e66f31c5Sopenharmony_ci /* Use argv[0] to determine value for uv_exepath(). */ 517e66f31c5Sopenharmony_ci size = sizeof(exepath); 518e66f31c5Sopenharmony_ci if (uv__search_path(argv[0], exepath, &size) == 0) { 519e66f31c5Sopenharmony_ci uv_once(&process_title_mutex_once, init_process_title_mutex_once); 520e66f31c5Sopenharmony_ci uv_mutex_lock(&process_title_mutex); 521e66f31c5Sopenharmony_ci original_exepath = uv__strdup(exepath); 522e66f31c5Sopenharmony_ci uv_mutex_unlock(&process_title_mutex); 523e66f31c5Sopenharmony_ci } 524e66f31c5Sopenharmony_ci } 525e66f31c5Sopenharmony_ci 526e66f31c5Sopenharmony_ci return argv; 527e66f31c5Sopenharmony_ci} 528e66f31c5Sopenharmony_ci 529e66f31c5Sopenharmony_ciint uv_set_process_title(const char* title) { 530e66f31c5Sopenharmony_ci return 0; 531e66f31c5Sopenharmony_ci} 532e66f31c5Sopenharmony_ci 533e66f31c5Sopenharmony_ciint uv_get_process_title(char* buffer, size_t size) { 534e66f31c5Sopenharmony_ci if (buffer == NULL || size == 0) 535e66f31c5Sopenharmony_ci return UV_EINVAL; 536e66f31c5Sopenharmony_ci 537e66f31c5Sopenharmony_ci buffer[0] = '\0'; 538e66f31c5Sopenharmony_ci return 0; 539e66f31c5Sopenharmony_ci} 540e66f31c5Sopenharmony_ci 541e66f31c5Sopenharmony_civoid uv__process_title_cleanup(void) { 542e66f31c5Sopenharmony_ci} 543