iPXE
Functions
stdlib.h File Reference
#include <stdint.h>
#include <assert.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
unsigned long strtoul (const char *string, char **endp, int base)
 Convert string to numeric value.
unsigned long long strtoull (const char *string, char **endp, int base)
 Convert string to numeric value.
void *__malloc malloc (size_t size)
 Allocate memory.
void * realloc (void *old_ptr, size_t new_size)
 Reallocate memory.
void free (void *ptr)
 Free memory.
void *__malloc zalloc (size_t len)
 Allocate cleared memory.
static void *__malloc calloc (size_t nmemb, size_t size)
 Allocate cleared memory.
long int random (void)
 Generate a pseudo-random number between 0 and 2147483647L or 2147483562?
void srandom (unsigned int seed)
 Seed the pseudo-random number generator.
static int rand (void)
static void srand (unsigned int seed)
static __attribute__ ((always_inline)) int abs(int value)
int system (const char *command)
 Execute command line.
__asmcall int main (void)
 Main entry point.

Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
unsigned long strtoul ( const char *  string,
char **  endp,
int  base 
)

Convert string to numeric value.

Parameters:
stringString
endpEnd pointer (or NULL)
baseNumeric base (or zero to autodetect)
Return values:
valueNumeric value

Definition at line 441 of file string.c.

References base, digit_value(), strtoul_pre(), and value.

Referenced by aoe_parse_uri(), bzimage_parse_cmdline(), bzimage_parse_cpio_cmdline(), efi_snp_hii_store(), fc_aton(), fc_id_aton(), ftp_parse_value(), ftp_reply(), gdbserial_init(), http_parse_content_length(), http_parse_retry_after(), http_parse_status(), http_rx_chunk_len(), ib_srp_parse_integer(), inet6_aton(), inet_aton(), iscsi_handle_chap_i_value(), iscsi_handle_targetaddress_value(), iscsi_parse_root_path(), mac_address_from_string_specs(), parse_int_setting(), parse_integer(), parse_setting_tag(), pnm_ascii(), scsi_parse_lun(), slam_parse_multicast_address(), string_test_exec(), tftp_process_blksize(), tftp_process_multicast(), tftp_process_tsize(), uri_decode(), uri_port(), and xenstore_read_num().

                                                                    {
        unsigned long value = 0;
        unsigned int digit;
        int negate;

        /* Preprocess string */
        string = strtoul_pre ( string, &negate, &base );

        /* Process digits */
        for ( ; ; string++ ) {
                digit = digit_value ( *string );
                if ( digit >= ( unsigned int ) base )
                        break;
                value = ( ( value * base ) + digit );
        }

        /* Negate value if, applicable */
        if ( negate )
                value = -value;

        /* Fill in end pointer, if applicable */
        if ( endp )
                *endp = ( ( char * ) string );

        return value;
}
unsigned long long strtoull ( const char *  string,
char **  endp,
int  base 
)

Convert string to numeric value.

Parameters:
stringString
endpEnd pointer (or NULL)
baseNumeric base (or zero to autodetect)
Return values:
valueNumeric value

Definition at line 476 of file string.c.

References base, digit_value(), strtoul_pre(), and value.

                                                                          {
        unsigned long long value = 0;
        unsigned int digit;
        int negate;

        /* Preprocess string */
        string = strtoul_pre ( string, &negate, &base );

        /* Process digits */
        for ( ; ; string++ ) {
                digit = digit_value ( *string );
                if ( digit >= ( unsigned int ) base )
                        break;
                value = ( ( value * base ) + digit );
        }

        /* Negate value if, applicable */
        if ( negate )
                value = -value;

        /* Fill in end pointer, if applicable */
        if ( endp )
                *endp = ( ( char * ) string );

        return value;
}
void* __malloc malloc ( size_t  size)

Allocate memory.

Parameters:
sizeRequested size
Return values:
ptrMemory, or NULL

Allocates memory with no particular alignment requirement. ptr will be aligned to at least a multiple of sizeof(void*).

Definition at line 583 of file malloc.c.

References ASSERTED, DBGC, heap, NULL, and realloc().

Referenced by add_ipv4_miniroute(), add_tls(), aes_unwrap(), aes_wrap(), alloc_iob_raw(), apply_dns_search(), ath5k_hw_rfregs_init(), chap_init(), cmdline_init(), cms_parse_signature_value(), deflate_test_exec(), der_asn1(), derwin(), dhcpv6_rx(), dupwin(), efi_download_start(), efi_local_check_volume_name(), efi_local_len(), eisabus_probe(), fc_ulp_login(), fetch_setting_copy(), format_uri_alloc(), http_format_ntlm_auth(), int13_hook(), ipoib_map_remac(), isabus_probe(), isapnpbus_probe(), iscsi_rx_buffered_data(), iscsi_scsi_command(), jme_alloc_rx_resources(), jme_alloc_tx_resources(), loopback_test(), mcabus_probe(), memcpy_test_speed(), mlx_memory_alloc_priv(), net80211_probe_start(), net80211_register(), newwin(), nfs_uri_symlink(), ntlm_authenticate_okx(), ocsp_response(), ocsp_uri_string(), parse_kv(), parse_net_args(), pci_vpd_resize(), pcibus_probe(), peerblk_decrypt(), peerblk_parse_header(), pem_asn1(), rsa_alloc(), sandev_parse_iso9660(), storef_setting(), storen_setting(), strndup(), t509bus_probe(), tls_assemble_block(), tls_assemble_stream(), uhci_enqueue(), usb_config_descriptor(), usb_get_string_descriptor(), usbio_config(), usbio_path(), vasprintf(), vesafb_mode_list(), vmbus_open(), wpa_make_rsn_ie(), wpa_start(), and zalloc().

                              {
        void *ptr;

        ptr = realloc ( NULL, size );
        if ( ASSERTED ) {
                DBGC ( &heap, "Possible memory corruption detected from %p\n",
                       __builtin_return_address ( 0 ) );
        }
        return ptr;
}
void* realloc ( void *  old_ptr,
size_t  new_size 
)

Reallocate memory.

Parameters:
old_ptrMemory previously allocated by malloc(), or NULL
new_sizeRequested size
Return values:
new_ptrAllocated memory, or NULL

Allocates memory with no particular alignment requirement. new_ptr will be aligned to at least a multiple of sizeof(void*). If old_ptr is non-NULL, then the contents of the newly allocated memory will be the same as the contents of the previously allocated memory, up to the minimum of the old and new sizes. The old memory will be freed.

If allocation fails the previously allocated block is left untouched and NULL is returned.

Calling realloc() with a new size of zero is a valid way to free a memory block.

Definition at line 521 of file malloc.c.

References alloc_memblock(), assert, ASSERTED, container_of, autosized_block::data, data, DBGC, free_memblock(), heap, memcpy(), NOWHERE, NULL, offsetof, autosized_block::size, VALGRIND_FREELIKE_BLOCK, VALGRIND_MAKE_MEM_DEFINED, VALGRIND_MAKE_MEM_NOACCESS, and VALGRIND_MALLOCLIKE_BLOCK.

Referenced by asn1_grow(), bitmap_resize(), cachedhcp_init(), dhcpopt_init(), efi_ifr_op(), efi_ifr_string(), free(), ibft_alloc_string(), ibft_install(), line_buffer(), malloc(), nvo_realloc(), process_script(), and xferbuf_malloc_realloc().

                                                  {
        struct autosized_block *old_block;
        struct autosized_block *new_block;
        size_t old_total_size;
        size_t new_total_size;
        size_t old_size;
        void *new_ptr = NOWHERE;

        /* Allocate new memory if necessary.  If allocation fails,
         * return without touching the old block.
         */
        if ( new_size ) {
                new_total_size = ( new_size +
                                   offsetof ( struct autosized_block, data ) );
                if ( new_total_size < new_size )
                        return NULL;
                new_block = alloc_memblock ( new_total_size, 1, 0 );
                if ( ! new_block )
                        return NULL;
                new_block->size = new_total_size;
                VALGRIND_MAKE_MEM_NOACCESS ( &new_block->size,
                                             sizeof ( new_block->size ) );
                new_ptr = &new_block->data;
                VALGRIND_MALLOCLIKE_BLOCK ( new_ptr, new_size, 0, 0 );
        }
        
        /* Copy across relevant part of the old data region (if any),
         * then free it.  Note that at this point either (a) new_ptr
         * is valid, or (b) new_size is 0; either way, the memcpy() is
         * valid.
         */
        if ( old_ptr && ( old_ptr != NOWHERE ) ) {
                old_block = container_of ( old_ptr, struct autosized_block,
                                           data );
                VALGRIND_MAKE_MEM_DEFINED ( &old_block->size,
                                            sizeof ( old_block->size ) );
                old_total_size = old_block->size;
                assert ( old_total_size != 0 );
                old_size = ( old_total_size -
                             offsetof ( struct autosized_block, data ) );
                memcpy ( new_ptr, old_ptr,
                         ( ( old_size < new_size ) ? old_size : new_size ) );
                VALGRIND_FREELIKE_BLOCK ( old_ptr, 0 );
                free_memblock ( old_block, old_total_size );
        }

        if ( ASSERTED ) {
                DBGC ( &heap, "Possible memory corruption detected from %p\n",
                       __builtin_return_address ( 0 ) );
        }
        return new_ptr;
}
void free ( void *  ptr)

Free memory.

Parameters:
ptrMemory allocated by malloc(), or NULL

Memory allocated with malloc_dma() cannot be freed with free(); it must be freed with free_dma() instead.

If ptr is NULL, no action is taken.

Definition at line 604 of file malloc.c.

References ASSERTED, DBGC, heap, and realloc().

                        {

        realloc ( ptr, 0 );
        if ( ASSERTED ) {
                DBGC ( &heap, "Possible memory corruption detected from %p\n",
                       __builtin_return_address ( 0 ) );
        }
}
void* __malloc zalloc ( size_t  size)

Allocate cleared memory.

Parameters:
sizeRequested size
Return values:
ptrAllocated memory

Allocate memory as per malloc(), and zero it.

This function name is non-standard, but pretty intuitive. zalloc(size) is always equivalent to calloc(1,size)

Definition at line 624 of file malloc.c.

References ASSERTED, data, DBGC, heap, malloc(), and memset().

Referenced by add_menu_item(), add_parameter(), alloc_ibdev(), alloc_image(), alloc_netdev(), alloc_pixbuf(), alloc_sandev(), alloc_usb(), alloc_usb_bus(), alloc_usb_hub(), aoecmd_create(), aoedev_open(), ar9300_eeprom_restore_internal(), arbel_alloc(), arbel_create_cq(), arbel_create_qp(), ata_open(), atadev_command(), ath5k_hw_attach(), ath5k_probe(), ath9k_init_softc(), ath_descdma_setup(), atl1e_setup_ring_resources(), autovivify_child_settings(), block_translate(), cachedhcp_init(), calloc(), cms_parse(), cms_signature(), concat_args(), create_downloader(), create_menu(), create_parameters(), create_pinger(), create_validator(), dhcp_deliver(), dhcpv6_register(), dns_resolv(), efi_block_boot_image(), efi_block_install(), efi_driver_start(), efi_file_open(), efi_image_cmdline(), efi_image_path(), efi_local_open(), efi_pxe_install(), efi_snp_hii_fetch(), efi_snp_hii_install(), efi_snp_hii_process(), efi_snp_hii_store(), efi_snp_probe(), efi_usb_install(), efi_usb_open(), efi_usb_probe(), efipci_start(), ehci_endpoint_open(), ehci_probe(), ehci_ring_alloc(), eoib_create_peer(), exanic_probe(), fc_els_create(), fc_ns_query(), fc_peer_create(), fc_port_open(), fc_ulp_create(), fc_xchg_create(), fcoe_probe(), fcpdev_open(), fcpdev_scsi_command(), fetch_string_setting_copy_alloc(), fetchf_setting_copy(), flexboot_nodnic_create_cq(), flexboot_nodnic_create_qp(), flexboot_nodnic_eth_open(), flexboot_nodnic_probe(), fragment_reassemble(), ftp_open(), generic_settings_store(), golan_alloc(), golan_create_cq(), golan_create_qp_aux(), guestinfo_fetch_type(), guestinfo_net_probe(), hermon_alloc(), hermon_create_cq(), hermon_create_qp(), http_connect(), http_open(), http_open_post_uri(), hub_probe(), hv_probe(), hvm_probe(), hw_open(), ib_cmrc_open(), ib_create_conn(), ib_create_cq(), ib_create_madx(), ib_create_mi(), ib_create_path(), ib_create_qp(), ib_mcast_attach(), ib_srp_open(), ibft_install(), init_mlx_utils(), ipv6_add_miniroute(), ipv6_register_settings(), iscsi_open(), linda_create_send_wq(), mlx_memory_zalloc_priv(), ndp_register_settings(), neighbour_create(), net80211_handle_mgmt(), net80211_prepare_assoc(), net80211_probe_start(), net80211_probe_step(), net80211_step_associate(), nfs_open(), nii_map(), numeric_resolv(), ocsp_check(), ocsp_uri_string(), open(), parse_uri(), peerblk_open(), peerdisc_create(), peerdisc_discovered(), peermux_filter(), ping_open(), png_pixbuf(), pxe_menu_parse(), qib7322_create_send_bufs(), qib7322_create_send_wq(), qib7322_probe(), rc80211_init(), resolv(), resolv_setting(), rtl818x_probe(), scsi_open(), scsidev_command(), sec80211_install(), sis190_mii_probe(), skge_probe(), skge_ring_alloc(), sky2_probe(), sky2_up(), slam_open(), srp_open(), srpdev_scsi_command(), start_dhcp(), start_dhcpv6(), start_ipv6conf(), start_ntp(), start_pxebs(), tcp_open(), tftp_core_open(), tg3_alloc_consistent(), tls_send_certificate(), tls_set_cipher(), txnic_bgx_probe(), txnic_pf_probe(), udp_open_common(), uhci_endpoint_open(), uhci_probe(), undipci_probe(), undirom_probe(), uri_dup(), usb_probe_all(), usbio_endpoint_open(), usbio_interfaces(), usbio_interrupt_open(), usbio_start(), usbkbd_probe(), validator_start_download(), virtnet_open_legacy(), virtnet_open_modern(), vmbus_probe(), vmbus_probe_channels(), vp_alloc_vq(), vxge_hw_device_initialize(), x509_alloc_chain(), x509_append(), x509_certificate(), xcm_create(), xenbus_probe_device(), xenstore_response(), xfer_open_named_socket(), xhci_bus_open(), xhci_device_open(), xhci_endpoint_open(), xhci_probe(), xhci_ring_alloc(), xsigo_ib_probe(), and xve_create().

                              {
        void *data;

        data = malloc ( size );
        if ( data )
                memset ( data, 0, size );
        if ( ASSERTED ) {
                DBGC ( &heap, "Possible memory corruption detected from %p\n",
                       __builtin_return_address ( 0 ) );
        }
        return data;
}
static void* __malloc calloc ( size_t  nmemb,
size_t  size 
) [inline, static]

Allocate cleared memory.

Parameters:
nmembNumber of members
sizeSize of each member
Return values:
ptrAllocated memory

Allocate memory as per malloc(), and zero it.

This is implemented as a static inline, with the body of the function in zalloc(), since in most cases nmemb will be 1 and doing the multiply is just wasteful.

Definition at line 45 of file stdlib.h.

References zalloc().

Referenced by ath5k_desc_alloc(), ath5k_eeprom_convert_pcal_info_2413(), ath5k_eeprom_convert_pcal_info_5111(), ath5k_eeprom_convert_pcal_info_5112(), and slk_init().

                                                                   {
        return zalloc ( nmemb * size );
}
long int random ( void  )

Generate a pseudo-random number between 0 and 2147483647L or 2147483562?

Return values:
randPseudo-random number

Definition at line 30 of file random.c.

References currticks(), rnd_seed, and srandom().

Referenced by arbel_alloc_qpn(), cipher_cost(), digest_cost(), dns_send_packet(), efi_pxe_udp_write(), efi_snp_hii_random_guid(), eth_random_addr(), forcedeth_open(), hermon_alloc_qpn(), http_digest_authenticate(), ib_create_conn(), ib_create_qp(), inject_corruption_nonzero(), inject_fault_nonzero(), iscsi_handle_chap_c_value(), iscsi_open_connection(), loopback_test(), memcpy_test_speed(), ntlm_response(), peerdisc_create(), profile_test_exec(), rand(), start_dhcp(), start_dhcpv6(), tcp_open(), tcpip_bind(), tcpip_random_okx(), tls_new_server_hello(), tls_send_client_hello(), vmbus_open(), and wep_encrypt().

                         {
        int32_t q;

        if ( ! rnd_seed ) /* Initialize linear congruential generator */
                srandom ( currticks() );

        /* simplified version of the LCG given in Bruce Schneier's
           "Applied Cryptography" */
        q = ( rnd_seed / 53668 );
        rnd_seed = ( 40014 * ( rnd_seed - 53668 * q ) - 12211 * q );
        if ( rnd_seed < 0 )
                rnd_seed += 2147483563L;
        return rnd_seed;
}
void srandom ( unsigned int  seed)

Seed the pseudo-random number generator.

Parameters:
seedSeed value

Definition at line 19 of file random.c.

References rnd_seed.

Referenced by random(), srand(), and tcpip_random_okx().

                                   {
        rnd_seed = seed;
        if ( ! rnd_seed )
                rnd_seed = 4; /* Chosen by fair dice roll */
}
static int rand ( void  ) [inline, static]

Definition at line 59 of file stdlib.h.

References random().

Referenced by cipher_cost(), digest_cost(), mlx_utils_rand_priv(), oncrpc_init_session(), and register_netdev().

                                {
        return random();
}
static void srand ( unsigned int  seed) [inline, static]

Definition at line 63 of file stdlib.h.

References srandom().

Referenced by cipher_cost(), digest_cost(), and register_netdev().

                                               {
        srandom ( seed );
}
static __attribute__ ( (always_inline)  ) [inline, static]

Definition at line 74 of file stdlib.h.

                                                                      {
        return __builtin_abs ( value );
}
int system ( const char *  command)

Execute command line.

Parameters:
commandCommand line
Return values:
rcReturn status code

Execute the named command and arguments.

Definition at line 287 of file exec.c.

References command_terminator(), count, ENOMEM, execv(), expand_tokens(), free, free_tokens(), NULL, rc, SHELL_STOP_COMMAND, shell_stopped(), split_command(), and strdup().

                                   {
        int count = split_command ( ( char * ) command, NULL );
        char *all_tokens[ count + 1 ];
        int ( * process_next ) ( int rc );
        char *command_copy;
        char **tokens;
        int argc;
        int process;
        int rc = 0;

        /* Create modifiable copy of command */
        command_copy = strdup ( command );
        if ( ! command_copy )
                return -ENOMEM;

        /* Split command into tokens */
        split_command ( command_copy, all_tokens );
        all_tokens[count] = NULL;

        /* Process individual commands */
        process = 1;
        for ( tokens = all_tokens ; ; tokens += ( argc + 1 ) ) {

                /* Find command terminator */
                argc = command_terminator ( tokens, &process_next );

                /* Expand tokens and execute command */
                if ( process ) {
                        char *argv[ argc + 1 ];

                        /* Expand tokens */
                        if ( ( rc = expand_tokens ( argc, tokens, argv ) ) != 0)
                                break;
                        argv[argc] = NULL;

                        /* Execute command */
                        rc = execv ( argv[0], argv );

                        /* Free tokens */
                        free_tokens ( argv );
                }

                /* Stop processing, if applicable */
                if ( shell_stopped ( SHELL_STOP_COMMAND ) )
                        break;

                /* Stop processing if we have reached the end of the
                 * command.
                 */
                if ( ! process_next )
                        break;

                /* Determine whether or not to process next command */
                process = process_next ( rc );
        }

        /* Free modified copy of command */
        free ( command_copy );

        return rc;
}
__asmcall int main ( void  )

Main entry point.

Return values:
rcReturn status code

Definition at line 28 of file main.c.

References initialise(), ipxe(), NULL, printf(), product_short_name, rc, shutdown_exit(), and startup().

Referenced by _efi_start().

                            {
        int rc;

        /* Perform one-time-only initialisation (e.g. heap) */
        initialise();

        /* Some devices take an unreasonably long time to initialise */
        printf ( "%s initialising devices...", product_short_name );
        startup();
        printf ( "ok\n" );

        /* Attempt to boot */
        if ( ( rc = ipxe ( NULL ) ) != 0 )
                goto err_ipxe;

 err_ipxe:
        shutdown_exit();
        return rc;
}