Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(c) 2025 Huawei Technologies Co., Ltd 3 : : */ 4 : : 5 : : #include "internal.h" 6 : : 7 : : 8 : : #define APP_EAL_INIT_ARG_SIZE_MAX sizeof("--log-level=lib.eal:warning") 9 : : 10 : : static const char APP_EAL_INIT_ARGS[][APP_EAL_INIT_ARG_SIZE_MAX] = { 11 : : "--log-level=lib.eal:warning", 12 : : "--no-huge", 13 : : "--no-pci", 14 : : "--no-hpet", 15 : : "--no-shconf", 16 : : }; 17 : : 18 : : #define APP_EAL_INIT_ARGC (/* program name */ 1 + RTE_DIM(APP_EAL_INIT_ARGS)) 19 : : 20 : : int 21 : 0 : get_eal_init_argc(void) 22 : : { 23 : 0 : return APP_EAL_INIT_ARGC; 24 : : } 25 : : 26 : : /* 27 : : * We cannot just return literal strings here, because rte_eal_init accepts 28 : : * an array of mutable pointers to mutable strings, so literals won't work. 29 : : * Instead we build a copy of APP_EAL_INIT_ARGS in a static mutable area. 30 : : */ 31 : : char** 32 : 0 : get_eal_init_argv(char *prog_name) 33 : : { 34 : : /* Static arrays for mutable copies of actual args */ 35 : : static char mutable_args[RTE_DIM(APP_EAL_INIT_ARGS)] 36 : : [APP_EAL_INIT_ARG_SIZE_MAX]; 37 : : /* 38 : : * Static array for pointers to args. First element will hold pointer 39 : : * to the prog_name, last will be set to NULL, the rest will point to 40 : : * elements of mutable_args with index one smaller. 41 : : */ 42 : : static char *mutable_ptrs[APP_EAL_INIT_ARGC + /* terminating NULL */ 1]; 43 : : 44 : 0 : mutable_ptrs[0] = prog_name; 45 : 0 : for (int argi = 0; argi != RTE_DIM(APP_EAL_INIT_ARGS); ++argi) { 46 : 0 : const char * const const_arg = APP_EAL_INIT_ARGS[argi]; 47 : 0 : char * const mutable_arg = mutable_args[argi]; 48 : : const int snprintf_rc = snprintf(mutable_arg, 49 : : APP_EAL_INIT_ARG_SIZE_MAX, "%s", const_arg); 50 : 0 : RTE_VERIFY(snprintf_rc >= 0 && 51 : : (size_t)snprintf_rc < APP_EAL_INIT_ARG_SIZE_MAX); 52 : 0 : mutable_ptrs[1 + argi] = mutable_arg; 53 : : } 54 : 0 : mutable_ptrs[RTE_DIM(mutable_ptrs) - 1] = NULL; 55 : : 56 : 0 : return mutable_ptrs; 57 : : }