Revision 7d3505c5 vl.c

b/vl.c
28 28
#include <fcntl.h>
29 29
#include <signal.h>
30 30
#include <time.h>
31
#include <malloc.h>
32 31
#include <errno.h>
33 32
#include <sys/time.h>
34 33

  
35 34
#ifndef _WIN32
36 35
#include <sys/times.h>
37 36
#include <sys/wait.h>
38
#include <pty.h>
39 37
#include <termios.h>
40 38
#include <sys/poll.h>
41 39
#include <sys/mman.h>
42 40
#include <sys/ioctl.h>
43 41
#include <sys/socket.h>
42
#ifdef _BSD
43
#include <sys/stat.h>
44
#include <libutil.h>
45
#else
44 46
#include <linux/if.h>
45 47
#include <linux/if_tun.h>
48
#include <pty.h>
49
#include <malloc.h>
46 50
#include <linux/rtc.h>
47 51
#endif
52
#endif
48 53

  
49 54
#if defined(CONFIG_SLIRP)
50 55
#include "libslirp.h"
51 56
#endif
52 57

  
53 58
#ifdef _WIN32
59
#include <malloc.h>
54 60
#include <sys/timeb.h>
55 61
#include <windows.h>
56 62
#define getopt_long_only getopt_long
......
58 64
#endif
59 65

  
60 66
#ifdef CONFIG_SDL
67
#if defined(__linux__)
61 68
/* SDL use the pthreads and they modify sigaction. We don't
62 69
   want that. */
63
#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)
70
#if (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2))
64 71
extern void __libc_sigaction();
65 72
#define sigaction(sig, act, oact) __libc_sigaction(sig, act, oact)
66 73
#else
67 74
extern void __sigaction();
68 75
#define sigaction(sig, act, oact) __sigaction(sig, act, oact)
69 76
#endif
77
#endif /* __linux__ */
70 78
#endif /* CONFIG_SDL */
71 79

  
72 80
#include "disas.h"
......
637 645
#ifdef _WIN32
638 646
        return GetTickCount();
639 647
#else
640
        /* XXX: portability among Linux hosts */
641
        if (timer_freq == 100) {
642
            return times(NULL) * 10;
643
        } else {
644
            return ((int64_t)times(NULL) * 1000) / timer_freq;
648
        {
649
            struct tms tp;
650

  
651
            /* Note that using gettimeofday() is not a good solution
652
               for timers because its value change when the date is
653
               modified. */
654
            if (timer_freq == 100) {
655
                return times(&tp) * 10;
656
            } else {
657
                return ((int64_t)times(&tp) * 1000) / timer_freq;
658
            }
645 659
        }
646 660
#endif
647 661
    default:
......
964 978
#endif /* CONFIG_SLIRP */
965 979

  
966 980
#if !defined(_WIN32)
981
#ifdef _BSD
982
static int tun_open(char *ifname, int ifname_size)
983
{
984
    int fd;
985
    char *dev;
986
    struct stat s;
967 987

  
988
    fd = open("/dev/tap", O_RDWR);
989
    if (fd < 0) {
990
        fprintf(stderr, "warning: could not open /dev/tap: no virtual network emulation\n");
991
        return -1;
992
    }
993

  
994
    fstat(fd, &s);
995
    dev = devname(s.st_rdev, S_IFCHR);
996
    pstrcpy(ifname, ifname_size, dev);
997

  
998
    fcntl(fd, F_SETFL, O_NONBLOCK);
999
    return fd;
1000
}
1001
#else
968 1002
static int tun_open(char *ifname, int ifname_size)
969 1003
{
970 1004
    struct ifreq ifr;
......
989 1023
    fcntl(fd, F_SETFL, O_NONBLOCK);
990 1024
    return fd;
991 1025
}
1026
#endif
992 1027

  
993 1028
static void tun_send_packet(NetDriverState *nd, const uint8_t *buf, int size)
994 1029
{
......
2248 2283
    phys_ram_size = ram_size + vga_ram_size;
2249 2284

  
2250 2285
#ifdef CONFIG_SOFTMMU
2286
#ifdef _BSD
2287
    /* mallocs are always aligned on BSD. */
2288
    phys_ram_base = malloc(phys_ram_size);
2289
#else
2251 2290
    phys_ram_base = memalign(TARGET_PAGE_SIZE, phys_ram_size);
2291
#endif
2252 2292
    if (!phys_ram_base) {
2253 2293
        fprintf(stderr, "Could not allocate physical memory\n");
2254 2294
        exit(1);

Also available in: Unified diff