[tables] Redefine methods for accessing linker tables

Intel's C compiler (icc) chokes on the zero-length arrays that we
currently use as part of the mechanism for accessing linker table
entries.  Abstract away the zero-length arrays, to make a port to icc
easier.

Introduce macros such as for_each_table_entry() to simplify the common
case of iterating over all entries in a linker table.

Represent table names as #defined string constants rather than
unquoted literals; this avoids visual confusion between table names
and C variable or type names, and also allows us to force a
compilation error in the event of incorrect table names.
This commit is contained in:
Michael Brown
2009-03-12 19:41:40 +00:00
parent 3ed468e0c5
commit 1266d7902b
48 changed files with 239 additions and 264 deletions

View File

@@ -36,12 +36,6 @@
*
*/
/** Registered ARP protocols */
static struct arp_net_protocol arp_net_protocols[0]
__table_start ( struct arp_net_protocol, arp_net_protocols );
static struct arp_net_protocol arp_net_protocols_end[0]
__table_end ( struct arp_net_protocol, arp_net_protocols );
/** An ARP cache entry */
struct arp_entry {
/** Network-layer protocol */
@@ -176,8 +170,7 @@ int arp_resolve ( struct net_device *netdev, struct net_protocol *net_protocol,
static struct arp_net_protocol * arp_find_protocol ( uint16_t net_proto ) {
struct arp_net_protocol *arp_net_protocol;
for ( arp_net_protocol = arp_net_protocols ;
arp_net_protocol < arp_net_protocols_end ; arp_net_protocol++ ) {
for_each_table_entry ( arp_net_protocol, ARP_NET_PROTOCOLS ) {
if ( arp_net_protocol->net_protocol->net_proto == net_proto ) {
return arp_net_protocol;
}

View File

@@ -36,12 +36,6 @@
*
*/
/** Registered network-layer protocols */
static struct net_protocol net_protocols[0]
__table_start ( struct net_protocol, net_protocols );
static struct net_protocol net_protocols_end[0]
__table_end ( struct net_protocol, net_protocols );
/** List of network devices */
struct list_head net_devices = LIST_HEAD_INIT ( net_devices );
@@ -538,8 +532,7 @@ int net_rx ( struct io_buffer *iobuf, struct net_device *netdev,
struct net_protocol *net_protocol;
/* Hand off to network-layer protocol, if any */
for ( net_protocol = net_protocols ; net_protocol < net_protocols_end ;
net_protocol++ ) {
for_each_table_entry ( net_protocol, NET_PROTOCOLS ) {
if ( net_protocol->net_proto == net_proto ) {
return net_protocol->rx ( iobuf, netdev, ll_source );
}

View File

@@ -14,18 +14,6 @@
* TCP/IP transport-network layer interface
*/
/** Registered network-layer protocols that support TCP/IP */
static struct tcpip_net_protocol tcpip_net_protocols[0]
__table_start ( struct tcpip_net_protocol, tcpip_net_protocols );
static struct tcpip_net_protocol tcpip_net_protocols_end[0]
__table_end ( struct tcpip_net_protocol, tcpip_net_protocols );
/** Registered transport-layer protocols that support TCP/IP */
static struct tcpip_protocol tcpip_protocols[0]
__table_start ( struct tcpip_protocol, tcpip_protocols );
static struct tcpip_protocol tcpip_protocols_end[0]
__table_end ( struct tcpip_protocol, tcpip_protocols );
/** Process a received TCP/IP packet
*
* @v iobuf I/O buffer
@@ -48,7 +36,7 @@ int tcpip_rx ( struct io_buffer *iobuf, uint8_t tcpip_proto,
struct tcpip_protocol *tcpip;
/* Hand off packet to the appropriate transport-layer protocol */
for ( tcpip = tcpip_protocols; tcpip < tcpip_protocols_end; tcpip++ ) {
for_each_table_entry ( tcpip, TCPIP_PROTOCOLS ) {
if ( tcpip->tcpip_proto == tcpip_proto ) {
DBG ( "TCP/IP received %s packet\n", tcpip->name );
return tcpip->rx ( iobuf, st_src, st_dest, pshdr_csum );
@@ -76,8 +64,7 @@ int tcpip_tx ( struct io_buffer *iobuf, struct tcpip_protocol *tcpip_protocol,
struct tcpip_net_protocol *tcpip_net;
/* Hand off packet to the appropriate network-layer protocol */
for ( tcpip_net = tcpip_net_protocols ;
tcpip_net < tcpip_net_protocols_end ; tcpip_net++ ) {
for_each_table_entry ( tcpip_net, TCPIP_NET_PROTOCOLS ) {
if ( tcpip_net->sa_family == st_dest->st_family ) {
DBG ( "TCP/IP sending %s packet\n", tcpip_net->name );
return tcpip_net->tx ( iobuf, tcpip_protocol, st_src,

View File

@@ -88,10 +88,6 @@ static uint8_t dhcp_request_options_data[] = {
DHCP_END
};
/** DHCP feature codes */
static uint8_t dhcp_features[0] __table_start ( uint8_t, dhcp_features );
static uint8_t dhcp_features_end[0] __table_end ( uint8_t, dhcp_features );
/** Version number feature */
FEATURE_VERSION ( VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH );
@@ -884,6 +880,7 @@ int dhcp_create_request ( struct dhcp_packet *dhcppkt,
struct dhcp_netdev_desc dhcp_desc;
struct dhcp_client_id client_id;
struct dhcp_client_uuid client_uuid;
uint8_t *dhcp_features;
size_t dhcp_features_len;
size_t ll_addr_len;
ssize_t len;
@@ -903,7 +900,8 @@ int dhcp_create_request ( struct dhcp_packet *dhcppkt,
dhcppkt->dhcphdr->ciaddr = ciaddr;
/* Add options to identify the feature list */
dhcp_features_len = ( dhcp_features_end - dhcp_features );
dhcp_features = table_start ( uint8_t, DHCP_FEATURES );
dhcp_features_len = table_num_entries ( uint8_t, DHCP_FEATURES );
if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_EB_ENCAP, dhcp_features,
dhcp_features_len ) ) != 0 ) {
DBG ( "DHCP could not set features list option: %s\n",