/* vif.h * * This is the hypervisor end of the network code. The net_ring structure * stored in each vif is placed on a shared page to interact with the guest VM. * * Copyright (c) 2002-2003, A K Warfield and K A Fraser */ #ifndef __XENO_VIF_H__ #define __XENO_VIF_H__ /* virtual network interface struct and associated defines. */ /* net_vif_st is the larger struct that describes a virtual network interface * it contains a pointer to the net_ring_t structure that needs to be on a * shared page between the hypervisor and guest. The vif struct is private * to the hypervisor and is used primarily as a container to allow routing * and interface administration. This define should eventually be moved to * a non-shared interface file, as it is of no relevance to the guest. */ #include #include extern struct net_device *the_dev; /* * shadow ring structures are used to protect the descriptors from * tampering after they have been passed to the hypervisor. * * TX_RING_SIZE and RX_RING_SIZE are defined in the shared network.h. */ typedef struct rx_shadow_entry_st { unsigned short id; unsigned short flush_count; /* 16 bits should be enough */ unsigned long pte_ptr; unsigned long buf_pfn; } rx_shadow_entry_t; typedef struct tx_shadow_entry_st { unsigned short id; unsigned short size; void *header; unsigned long payload; } tx_shadow_entry_t; typedef struct net_vif_st { /* The shared rings and indexes. */ net_ring_t *shared_rings; net_idx_t *shared_idxs; /* The private rings and indexes. */ rx_shadow_entry_t rx_shadow_ring[RX_RING_SIZE]; unsigned int rx_prod; /* More buffers for filling go here. */ unsigned int rx_cons; /* Next buffer to fill is here. */ tx_shadow_entry_t tx_shadow_ring[TX_RING_SIZE]; unsigned int tx_prod; /* More packets for sending go here. */ unsigned int tx_idx; /* Next packet to send is here. */ unsigned int tx_cons; /* Next packet to create response for is here. */ /* Private indexes into shared ring. */ unsigned int rx_req_cons; unsigned int rx_resp_prod; /* private version of shared variable */ unsigned int tx_req_cons; unsigned int tx_resp_prod; /* private version of shared variable */ /* Miscellaneous private stuff. */ struct task_struct *domain; unsigned int idx; /* index within domain */ struct list_head list; /* scheduling list */ atomic_t refcnt; spinlock_t rx_lock, tx_lock; unsigned char vmac[ETH_ALEN]; } net_vif_t; #define get_vif(_v) (atomic_inc(&(_v)->refcnt)) #define put_vif(_v) \ do { \ if ( atomic_dec_and_test(&(_v)->refcnt) ) destroy_net_vif(_v); \ } while (0) \ /* vif prototypes */ net_vif_t *create_net_vif(int domain); void destroy_net_vif(net_vif_t *vif); void unlink_net_vif(net_vif_t *vif); net_vif_t *net_get_target_vif(u8 *data, unsigned int len, net_vif_t *src_vif); net_vif_t *find_vif_by_id(unsigned long id); /* * Return values from net_get_target_vif: * VIF_PHYS -- Send to physical NIC * VIF_DROP -- Drop this packet * others -- Send to specified VIF (reference held on return) */ #define VIF_PHYS ((net_vif_t *)0) #define VIF_DROP ((net_vif_t *)1) #endif /* __XENO_VIF_H__ */ ace1dcc9d16f3661c8f95dff56f5f582b6bc'>cpp/utils.py
blob: eab36eec335ebaa603051b7bc5186c87a8f78f81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python
#
# Copyright 2007 Neal Norwitz
# Portions Copyright 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Generic utilities for C++ parsing."""

__author__ = 'nnorwitz@google.com (Neal Norwitz)'


import sys


# Set to True to see the start/end token indices.
DEBUG = True


def ReadFile(filename, print_error=True):
    """Returns the contents of a file."""
    try:
        fp = open(filename)
        try:
            return fp.read()
        finally:
            fp.close()
    except IOError:
        if print_error:
            print('Error reading %s: %s' % (filename, sys.exc_info()[1]))
        return None