iPXE
assert.h File Reference

Assertions. More...

Go to the source code of this file.

Macros

#define ASSERTING   1
#define ASSERTED   ( ASSERTING && ( assertion_failures != 0 ) )
#define assert(condition)
 Assert a condition at run-time.
#define static_assert(x)
 Assert a condition at build time.
#define build_assert(condition)
 Assert a condition at build time (after dead code elimination).

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
int __attribute__ ((format(printf, 1, 2))) assert_printf(const char *fmt
 printf() for assertions
int asm ("printf")

Variables

unsigned int assertion_failures
 Number of assertion failures triggered.

Detailed Description

Assertions.

This file provides two assertion macros: assert() (for run-time assertions) and linker_assert() (for link-time assertions).

Definition in file assert.h.

Macro Definition Documentation

◆ ASSERTING

#define ASSERTING   1

Definition at line 20 of file assert.h.

Referenced by check_blocks(), and heap_free_block().

◆ ASSERTED

#define ASSERTED   ( ASSERTING && ( assertion_failures != 0 ) )

Definition at line 26 of file assert.h.

Referenced by free(), heap_realloc(), malloc(), zalloc(), and zfree().

◆ assert

#define assert ( condition)
Value:
do { \
if ( ASSERTING && ! (condition) ) { \
assert_printf ( "assert(%s) failed at %s line %d\n", \
#condition, __FILE__, __LINE__ ); \
} \
} while ( 0 )
unsigned int assertion_failures
Number of assertion failures triggered.
Definition assert.c:35
#define ASSERTING
Definition assert.h:20

Assert a condition at run-time.

If the condition is not true, a debug message will be printed. Assertions only take effect when debugging is enabled for the object in which the assertion is compiled (see DBG()).

Assertions are non-terminating even when enabled. Execution will continue, since in a debug build this is often more useful to the developer than terminating immediately (and, as a bootloader, there is often no defined way to terminate the program other than by rebooting the system). However, all behaviour after the first assertion has triggered should be considered to be undefined.

Assertion conditions will always be compile-checked even when debugging is not enabled, and can therefore serve as consumers of otherwise unused variables. The assertion condition is removed by dead code elimination when debugging is disabled. Assertion conditions must therefore not have side effects.

Definition at line 61 of file assert.h.

61#define assert( condition ) \
62 do { \
63 if ( ASSERTING && ! (condition) ) { \
64 assert_printf ( "assert(%s) failed at %s line %d\n", \
65 #condition, __FILE__, __LINE__ ); \
66 assertion_failures++; \
67 } \
68 } while ( 0 )

Referenced by __attribute__(), __attribute__(), __attribute__(), _print_label(), a3c90x_internal_ReadEeprom(), acm_transmit(), adaptive_proportion_test_init(), aes_decrypt(), aes_encrypt(), alloc_form(), alloc_iob_raw(), ansicol_set(), ansicol_set_pair(), aoecmd_ata_cmd(), aoecmd_cfg_cmd(), aoecmd_free(), aoecmd_tx(), arbel_alloc_icm(), arbel_close(), arbel_cmd(), arbel_complete(), arbel_map_vpm(), arbel_post_send(), arbel_start_firmware(), asn1_okx(), asn1_parse_cbc(), atadev_read_capacity(), ath5k_handle_rx(), atl_rx_ring_fill(), axge_in_complete(), bigint_add_okx(), bigint_is_geq_okx(), bigint_mod_exp_okx(), bigint_mod_exp_raw(), bigint_mod_invert_raw(), bigint_montgomery_okx(), bigint_montgomery_raw(), bigint_montgomery_relaxed_raw(), bigint_multiply_okx(), bigint_ntoa_raw(), bigint_reduce_okx(), bigint_reduce_raw(), bigint_subtract_okx(), bigint_swap_okx(), bios_ansi_seq(), bios_handle_ed(), bnxt_rx_process(), bzimage_exec(), bzimage_load_initrds(), cachedhcp_record(), cachedhcp_recycle(), cbc_decrypt(), cbc_encrypt(), cbc_xor(), cgem_refill_rx(), chap_init(), chap_respond(), chap_update(), check_blocks(), cipher_cost(), cms_parse_enveloped(), cms_test_exec(), cms_verify_padding(), cms_verify_signer(), com32_exec_loop(), comboot_exec_loop(), concat_args(), cpio_name_len(), deflate_accumulate(), deflate_bin(), deflate_consume(), deflate_inflate(), deflate_init(), delete_character(), der_asn1(), des_decrypt(), des_encrypt(), des_setkey(), dhcp_create_request(), dhcppkt_init(), dhcpv6_rx(), dhcpv6_tx(), disklog_open(), disklog_putchar(), dma_op_free(), dma_op_ufree(), dma_op_unmap(), DMAAPI_INLINE(), drbg_generate(), drbg_instantiate(), drbg_reseed(), drbg_uninstantiate(), dt_remove_node(), dwgpio_probe(), dwmac_create_ring(), dwmac_poll_rx(), dwmac_refill_rx(), eap_rx_md5(), eap_rx_mschapv2_success(), eap_tx_nak(), eapol_eap_rx(), ecam_read(), ecam_write(), ecb_decrypt(), ecb_encrypt(), ecm_probe(), edit_setting(), eepro_transmit(), efab_fill_rx_queue(), efab_receive(), efab_transmit(), efab_transmit_done(), efi_bofm_start(), efi_bofm_stop(), efi_cacert_shutdown(), efi_close_by_child(), efi_close_by_driver(), efi_close_unsafe(), efi_driver_stop(), efi_file_install(), efi_file_path_claim(), efi_file_path_install(), efi_file_read(), efi_handle_ed(), efi_image_exec(), efi_install_table(), efi_local_open_path(), efi_local_step(), efi_netdev_path(), efi_open_by_child_untyped(), efi_open_by_driver_untyped(), efi_open_unsafe_untyped(), efi_open_untyped(), efi_pxe_udp_deliver(), efi_snp_add_claim(), efi_snp_set_mode(), efi_urealloc(), efi_usb_close(), efi_usb_free_all(), efi_usb_path(), efi_usb_probe(), efi_usb_remove(), efi_usb_sync_transfer(), efi_vlan_find(), efidev_free(), efifb_draw(), efipci_dma_map(), efipci_stop(), efirng_get_noise(), efisig_find(), efx_hunt_alloc_special_buffer(), efx_hunt_receive(), efx_hunt_rxq_fill(), efx_hunt_transmit(), efx_hunt_transmit_done(), ehci_bus_close(), ehci_bus_open(), ehci_bus_poll(), ehci_dequeue(), ehci_device_address(), ehci_endpoint_capabilities(), ehci_endpoint_message(), ehci_endpoint_reset(), ehci_enqueue(), ehci_remove(), ehci_ring_fill(), ehci_ring_free(), elliptic_agree(), elliptic_share(), ena_create_sq(), ena_poll_rx(), ena_poll_tx(), ena_refill_rx(), ena_transmit(), entropy_enable(), entropy_enable_and_test(), eoib_transmit(), eth_slow_lacp_rx(), exanic_expired(), exanic_i2c_read_bit(), exanic_i2c_write_bit(), exanic_probe_port(), expand_tokens(), falcon_alloc_special_buffer(), falcon_mdio_read(), falcon_mdio_write(), falcon_spi_rw(), fbcon_handle_ed(), fbcon_init(), fbcon_scroll(), fc_els_free(), fc_els_step(), fc_peer_close(), fc_peer_decrement(), fc_peer_examine(), fc_peer_login(), fc_ulp_attach(), fc_ulp_close(), fc_ulp_login(), fc_xchg_free(), fcoe_expired(), fcpcmd_recv_rddata(), fcpcmd_send_cmnd(), fcpcmd_send_wrdata(), fcpdev_identify_device(), fcpdev_scsi_command(), fdt_child(), fdt_describe(), fdt_insert(), fdt_insert_nop(), fdt_nop(), fdt_phandle(), fdt_property(), fdt_set(), fdt_urealloc(), fdtmem_len(), fdtmem_register(), fdtmem_relocate(), fetch_setting_alloc(), fetchf_setting(), fetchf_setting_copy(), fetchn_setting(), ffdhe(), ffdhe_has_params(), find_strings_terminator(), flexboot_nodnic_complete(), flexboot_nodnic_post_send(), format_busdevfn_setting(), free_image(), free_iob(), free_netdev(), free_tls(), free_tls_session(), free_usb(), free_usb_bus(), free_usb_hub(), gcm_multiply_x_8(), gcm_setiv(), gdbserial_recv(), gdbudp_ensure_netdev_open(), generic_settings_clear(), get_entropy_input_tmp(), golan_complete(), golan_provide_pages(), guestinfo_fetch_type(), guestrpc_command(), gve_alloc_qpl(), gve_alloc_queue(), gve_create_queue(), gve_offset(), gve_poll_rx(), gve_poll_tx(), gve_probe(), gve_refill_rx(), gve_transmit(), gzip_extract(), hash_df(), heap_alloc_block(), heap_free_block(), heap_populate(), heap_realloc(), hermon_close(), hermon_cmd(), hermon_complete(), hermon_map_icm(), hermon_map_vpm(), hermon_mod_stat_cfg(), hermon_post_send(), hermon_set_port_type(), hermon_start_firmware(), history_append(), history_cleanup(), history_free(), hkdf_expand(), hkdf_extract(), hmac_drbg_generate(), hmac_drbg_instantiate(), hmac_drbg_reseed(), hmac_drbg_update(), hmac_drbg_update_key(), hmac_drbg_update_value(), http_block_read(), http_conn_close(), http_connect(), http_format_basic_auth(), http_format_digest_auth(), http_format_ntlm_auth(), http_init_transfer_chunked(), http_open_uri(), http_parse_headers(), http_rx_chunk_data(), http_transfer_complete(), http_tx_request(), hub_remove(), hunt_mcdi_copyin(), hv_post_message(), hv_wait_for_message(), hvm_ioremap(), ib_destroy_cq(), ib_destroy_qp(), ib_mcast_attach(), ib_mcast_detach(), ib_mcast_join(), ib_mcast_leave(), ib_mi_send(), ib_open(), ib_pull(), ibft_fill_target_chap(), ibft_fill_target_reverse_chap(), ibft_install(), icert_certs(), icert_encode(), icm_align(), icm_align(), icmp_tx_echo_reply(), icplus_read_eeprom(), icplus_refill_rx(), image_asn1(), image_exec(), image_replace(), imux_tx(), imux_tx_tcp(), init_i2c_bit_basher(), init_spi_bit_basher(), initrd_load(), initrd_load_all(), initrd_swap(), int13_device_path_info(), int13_guess_geometry(), int22(), intel_read_eeprom(), intel_refill_rx(), intelvf_mbox_msg(), intelxl_admin_command(), intelxl_refill_rx(), iob_map_rx(), iob_pad(), iob_pull(), iob_split(), ioremap_pages(), iounmap_pages(), ipair_expired(), ipair_window_changed(), ipv4_route_okx(), ipv6_add_miniroute(), iscsi_build_login_request_strings(), iscsi_fetch_settings(), iscsi_open_connection(), iscsi_rx_buffered_data(), iscsi_rx_data_in(), iscsi_scsi_done(), iscsi_socket_deliver(), iscsi_start_command(), iscsi_start_login(), iscsi_start_tx(), iscsi_tx_data_out(), iscsi_tx_step(), jump_scroll(), jump_scroll_key(), jump_scroll_move(), kill_eol(), kill_sol(), kill_word(), last_opened_ibdev(), last_opened_netdev(), layout_form(), linda_complete_recv(), linda_complete_send(), linda_ib_epb_mod_reg(), linda_ib_epb_ram_xfer(), linda_post_recv(), linda_post_send(), line_buffer(), lkrn_exec(), lldp_probe(), longjmp_okx(), main_loop(), malloc_phys_offset(), mdhash_final(), memcpy_test_speed(), memmap_update(), menu_loop(), mime_decode_base64(), mime_parse_attribute(), mktime(), mnpnet_event(), mschapv2_challenge_response(), multiboot_load_raw(), myson_refill_rx(), natsemi_refill_rx(), nbi_process_segments(), ncm_probe(), ndp_register_settings(), neighbour_destroy(), neighbour_discard(), neighbour_free(), net80211_change_channel(), net80211_mgmt_dequeue(), net80211_prepare_assoc(), net80211_prepare_probe(), net80211_probe_start(), net80211_set_rate_idx(), netdev_fetch_bustype(), netdev_priv_offset(), netdev_tx_flush(), netfront_create_ring(), netfront_open(), netfront_pull(), netfront_push(), netvsc_create_ring(), netvsc_destroy_ring(), netvsc_transmit(), nii_get_init_info(), numerate_int_setting(), nvs_read(), nvs_write(), ocsp_check(), ocsp_uri_string(), ocsp_validate(), parse_fc_port(), parse_fc_port_id(), parse_gdb_transport(), parse_integer(), parse_netdev(), parse_netdev_configurator(), parse_setting(), parse_settings(), parse_string(), parse_uuid(), pci_msix_map(), pci_vpd_resize(), peerblk_decrypt(), peerblk_dequeue(), peerblk_enqueue(), peerblk_expired(), peerblk_parse_block(), peerblk_parse_header(), peerblk_reset(), peerdisc_destroy(), peerdisc_open(), peerdist_discovery_reply_values(), peerdist_info(), peerdist_info_block(), peerdist_info_hash_ntoa(), peerdist_info_segment(), peerdist_info_segment_hash(), peerdist_info_v1(), peerdist_info_v1_block(), peerdist_info_v1_block_offset(), peerdist_info_v1_segment(), peerdist_info_v2(), peerdist_info_v2_block(), peerdist_info_v2_segment(), peermux_block_deliver(), pem_asn1(), pem_marker(), phantom_clp_cmd(), phantom_crb_access_128m(), phantom_crb_access_2m(), phantom_crb_access_32m(), phantom_dmesg(), phantom_fetch_setting(), phantom_poll(), phantom_probe(), phantom_refill_rx_ring(), phantom_store_setting(), phantom_transmit(), ping_rx(), pit8254_speaker_delay(), pixbuf_okx(), png_interlace(), png_pixels(), png_pixels_pass(), png_scanline_len(), png_unfilter(), png_unfilter_pass(), pnm_type(), pool_add(), pool_expired(), profile_update(), pubkey_test_get_random(), pxe_fake_cached_info(), pxe_menu_boot(), pxe_netdev_close(), pxe_netdev_open(), pxe_udp_deliver(), pxenv_udp_read(), pxenv_undi_get_information(), qib7322_ahb_mod_reg(), qib7322_complete_recv(), qib7322_complete_send(), qib7322_post_recv(), qib7322_post_send(), qib7322_probe(), rdc_refill_rx(), read(), readline_history(), realtek_refill_rx(), register_image(), register_settings(), register_usb(), register_usb_bus(), reparse_options(), repetition_count_test_init(), rfc_tcpip_chksum(), rndis_tx_defer(), route_ipv4_print(), rsa_pkcs1_encode(), rsa_pss_encode(), rtc_unhook_isr(), run_tests(), sandev_command(), sandev_command_read_capacity(), sandev_command_rw(), sandev_free(), sandev_reopen(), save_setting(), sdi_exec(), show_menu(), shuffle(), skge_up(), skge_xmit_frame(), sky2_status_intr(), sky2_tx_complete(), slam_parse_multicast_address(), slam_pull_header(), slam_put_value(), smbios_fetch(), smbios_string(), smbios_structure(), smbios_version(), spi_bit_rw(), srp_open(), srpcmd_free(), startup_test_init(), storef_setting(), storen_setting(), tcp_close(), tcp_expired(), tcp_rx_opts(), tcp_rx_seq(), tcp_wait_expired(), tcp_xmit_sack(), tcpip_random_okx(), test_ok(), tg3_rx_complete(), threewire_read(), threewire_write(), timer_expired(), tls_cipherstream_deliver(), tls_client_hello(), tls_generate_keys(), tls_generate_master_secret(), tls_generate_resumption_master(), tls_new_ciphertext(), tls_new_record(), tls_newdata_process_data(), tls_newdata_process_header(), tls_restart(), tls_resume_secret(), tls_send_client_key_exchange_pubkey(), tls_send_record(), tls_set_cipher(), tls_set_digest(), tls_set_kdf_master(), tls_tx_step(), tls_verify_dh_params(), txnic_complete_sqe(), txnic_lmac_probe(), txnic_lmac_probe_all(), txnic_lmac_remove(), txnic_lmac_remove_all(), txnic_refill_rq(), ucode_exec(), ucode_status(), ucode_update_all(), uhci_bus_close(), uhci_bus_open(), uhci_dequeue(), uhci_device_address(), uhci_endpoint_message(), uhci_endpoint_poll(), uhci_endpoint_stream(), uhci_enqueue(), uhci_remove(), uhci_restart(), uhci_ring_fill(), uhci_ring_free(), uheap_find(), uheap_resize(), undinet_call(), undinet_hook_isr(), undinet_poll(), undinet_probe(), undinet_unhook_isr(), unregister_sandev(), unregister_usb(), unregister_usb_bus(), usb_attached(), usb_complete_err(), usb_control(), usb_deconfigure(), usb_describe(), usb_endpoint_close(), usb_endpoint_reset(), usb_flush(), usb_free_address(), usb_hotplug(), usb_message(), usb_prefill(), usb_probe_all(), usb_refill_limit(), usb_remove_all(), usbblk_in_complete(), usbblk_in_data(), usbblk_in_refill(), usbblk_in_status(), usbblk_open(), usbblk_out_command(), usbblk_out_complete(), usbblk_out_data(), usbblk_out_refill(), usbblk_start(), usbio_close(), usbio_endpoint_message(), usbio_interfaces(), usbio_interrupt_callback(), usbio_interrupt_poll(), usbio_open(), usbkbd_consume(), usbkbd_fill(), utf8_accumulate(), validator_append(), validator_start_ocsp(), validator_step(), validator_xfer_close(), virtio_legacy_enable(), virtio_legacy_negotiate(), virtio_net_complete(), virtio_net_submit(), virtio_pci_enable(), vmbus_open(), vmbus_poll(), vmbus_probe(), vmbus_remove_channels(), vmbus_send(), vmbus_send_cancellation(), vmbus_send_completion(), vmbus_send_control(), vmbus_send_data(), vmbus_xfer_page_iobufs(), vmxnet3_refill_rx(), vmxnet3_transmit(), vxge_hw_device_terminate(), weierstrass_add_ladder(), weierstrass_add_raw(), weierstrass_exec(), write_cmd(), x25519_invert(), x509_check_signature(), x509_found(), x509_free_chain(), x509_set_valid(), x509_test_exec(), xcm_free(), xengrant_alloc(), xengrant_free(), xenstore_request(), xferbuf_void_realloc(), xhci_address_device_input(), xhci_bus_close(), xhci_command_free(), xhci_complete(), xhci_dcbaa_free(), xhci_dequeue(), xhci_device_open(), xhci_endpoint_message(), xhci_endpoint_open(), xhci_enqueue(), xhci_enqueue_multi(), xhci_fail(), xhci_init(), xhci_port_status(), xhci_ring_alloc(), xhci_ring_free(), xhci_ring_remaining(), xhci_scratchpad_alloc(), xhci_scratchpad_free(), xhci_transfer(), xsigo_free(), and zfree().

◆ static_assert

#define static_assert ( x)
Value:
_Static_assert( x, #x )
static unsigned int x
Definition pixbuf.h:63

Assert a condition at build time.

If the compiler cannot prove that the condition is true, the build will fail with an error message.

Definition at line 77 of file assert.h.

◆ build_assert

#define build_assert ( condition)
Value:
do { \
if ( ! (condition) ) { \
extern void __attribute__ (( warning ( \
"build_assert(" #condition ") failed" \
) )) _C2 ( build_assert_, __LINE__ ) ( void ); \
_C2 ( build_assert_, __LINE__ ) (); \
} \
} while ( 0 )
#define __attribute__(x)
Definition compiler.h:10
#define _C2(x, y)
Concatenate expanded arguments.
Definition compiler.h:48

Assert a condition at build time (after dead code elimination).

If the compiler cannot prove that the condition is true, the build will fail with an error message.

This macro is iPXE-specific. Do not use this macro in code intended to be portable.

Definition at line 88 of file assert.h.

88#define build_assert( condition ) \
89 do { \
90 if ( ! (condition) ) { \
91 extern void __attribute__ (( warning ( \
92 "build_assert(" #condition ") failed" \
93 ) )) _C2 ( build_assert_, __LINE__ ) ( void ); \
94 _C2 ( build_assert_, __LINE__ ) (); \
95 } \
96 } while ( 0 )

Referenced by asn1_built(), entropy_adaptive_proportion_cutoff(), entropy_init(), entropy_repetition_count_cutoff(), entropy_startup_test_count(), gcm_setiv(), get_entropy_input(), gve_alloc_qpl(), gve_describe(), init_heap(), linda_init_recv(), linda_post_recv(), md4_compress(), md5_compress(), qib7322_init_recv(), qib7322_post_recv(), sha1_compress(), sha256_compress(), sha512_compress(), ucode_update_all(), x25519_add(), and x25519_subtract().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ __attribute__()

int __attribute__ ( (format(printf, 1, 2)) ) const
extern

printf() for assertions

This function exists so that the assert() macro can expand to printf() calls without dragging the printf() prototype into scope.

As far as the compiler is concerned, assert_printf() and printf() are completely unrelated calls; it's only at the assembly stage that references to the assert_printf symbol are collapsed into references to the printf symbol.

References format, and printf().

◆ asm()

int asm ( "printf" )

References asm(), and fmt.

Variable Documentation

◆ assertion_failures

unsigned int assertion_failures
extern

Number of assertion failures triggered.

Definition at line 35 of file assert.c.

Referenced by run_tests().