freebsd.hh revision 11381:516213d2f0cf
112952Sgabeblack@google.com/*
212952Sgabeblack@google.com * Copyright (c) 2015 Ruslan Bukin <br@bsdpad.com>
312952Sgabeblack@google.com * All rights reserved.
412952Sgabeblack@google.com *
512952Sgabeblack@google.com * This software was developed by the University of Cambridge Computer
612952Sgabeblack@google.com * Laboratory as part of the CTSRD Project, with support from the UK Higher
712952Sgabeblack@google.com * Education Innovation Fund (HEIF).
812952Sgabeblack@google.com *
912952Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
1012952Sgabeblack@google.com * modification, are permitted provided that the following conditions are
1112952Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
1212952Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
1312952Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
1412952Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1512952Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1612952Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1712952Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1812952Sgabeblack@google.com * this software without specific prior written permission.
1912952Sgabeblack@google.com *
2012952Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2112952Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2212952Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2312952Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2412952Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2512952Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2612952Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2712952Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2812952Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2912952Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3012952Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3112952Sgabeblack@google.com */
3212952Sgabeblack@google.com
3312952Sgabeblack@google.com#ifndef __ARCH_ARM_FREEBSD_FREEBSD_HH__
3412952Sgabeblack@google.com#define __ARCH_ARM_FREEBSD_FREEBSD_HH__
3512952Sgabeblack@google.com
3612952Sgabeblack@google.com#include "kern/freebsd/freebsd.hh"
3712952Sgabeblack@google.com
3812952Sgabeblack@google.comclass ArmFreebsd32 : public FreeBSD
3912952Sgabeblack@google.com{
4012952Sgabeblack@google.com  public:
4112952Sgabeblack@google.com
4212952Sgabeblack@google.com    /// This table maps the target open() flags to the corresponding
4312952Sgabeblack@google.com    /// host open() flags.
4412952Sgabeblack@google.com    static SyscallFlagTransTable openFlagTable[];
4512952Sgabeblack@google.com
4612952Sgabeblack@google.com    /// Number of entries in openFlagTable[].
4712952Sgabeblack@google.com    static const int NUM_OPEN_FLAGS;
4812952Sgabeblack@google.com
4912952Sgabeblack@google.com    //@{
5012952Sgabeblack@google.com    /// Basic ARM FreeBSD types
5112952Sgabeblack@google.com    typedef uint32_t size_t;
5212952Sgabeblack@google.com    typedef uint32_t off_t;
5312952Sgabeblack@google.com    typedef int32_t time_t;
5412952Sgabeblack@google.com    typedef int32_t clock_t;
5512952Sgabeblack@google.com    //@}
5612952Sgabeblack@google.com
5712952Sgabeblack@google.com    //@{
5812952Sgabeblack@google.com    /// open(2) flag values.
5912952Sgabeblack@google.com    static const int TGT_O_RDONLY    = 0x00000000; //!< O_RDONLY
6012952Sgabeblack@google.com    static const int TGT_O_WRONLY    = 0x00000001; //!< O_WRONLY
6112952Sgabeblack@google.com    static const int TGT_O_RDWR      = 0x00000002; //!< O_RDWR
6212952Sgabeblack@google.com    static const int TGT_O_CREAT     = 0x00000200; //!< O_CREAT
6312952Sgabeblack@google.com    static const int TGT_O_EXCL      = 0x00000800; //!< O_EXCL
6412952Sgabeblack@google.com    static const int TGT_O_NOCTTY    = 0x00008000; //!< O_NOCTTY
6512952Sgabeblack@google.com    static const int TGT_O_TRUNC     = 0x00000400; //!< O_TRUNC
6612952Sgabeblack@google.com    static const int TGT_O_APPEND    = 0x00000008; //!< O_APPEND
6712952Sgabeblack@google.com    static const int TGT_O_NONBLOCK  = 0x00000004; //!< O_NONBLOCK
6812952Sgabeblack@google.com    static const int TGT_O_SYNC      = 0x00000080; //!< O_SYNC
6912952Sgabeblack@google.com    static const int TGT_FASYNC      = 0x00000040; //!< FASYNC
7012952Sgabeblack@google.com    static const int TGT_O_DIRECT    = 0x00010000; //!< O_DIRECT
7112952Sgabeblack@google.com    static const int TGT_O_DIRECTORY = 0x00020000; //!< O_DIRECTORY
7212952Sgabeblack@google.com    static const int TGT_O_NOFOLLOW  = 0x00000100; //!< O_NOFOLLOW
7312952Sgabeblack@google.com    static const int TGT_O_CLOEXEC   = 0x00100000; //!< O_CLOEXEC
7412952Sgabeblack@google.com    //@}
7512952Sgabeblack@google.com
7612952Sgabeblack@google.com    /// For mmap().
7712952Sgabeblack@google.com    static const unsigned TGT_MAP_ANONYMOUS = 0x1000;
7812952Sgabeblack@google.com    static const unsigned TGT_MAP_FIXED     = 0x0010;
7912952Sgabeblack@google.com
8012952Sgabeblack@google.com    /// Limit struct for getrlimit/setrlimit.
8112952Sgabeblack@google.com    struct rlimit {
8212952Sgabeblack@google.com        uint32_t  rlim_cur;     //!< soft limit
8312952Sgabeblack@google.com        uint32_t  rlim_max;     //!< hard limit
8412952Sgabeblack@google.com    };
8512952Sgabeblack@google.com
8612952Sgabeblack@google.com    /// For gettimeofday().
8712952Sgabeblack@google.com    struct timeval {
8812952Sgabeblack@google.com        int32_t tv_sec;         //!< seconds
8912952Sgabeblack@google.com        int32_t tv_usec;        //!< microseconds
9012952Sgabeblack@google.com    };
9112952Sgabeblack@google.com
9212952Sgabeblack@google.com    // For writev/readv
9312952Sgabeblack@google.com    struct tgt_iovec {
9412952Sgabeblack@google.com        uint32_t iov_base; // void *
9512952Sgabeblack@google.com        uint32_t iov_len;
9612952Sgabeblack@google.com    };
9712952Sgabeblack@google.com
9812952Sgabeblack@google.com    /*
9912952Sgabeblack@google.com     * sizeof st 120
10012952Sgabeblack@google.com     * sizeof st_dev 4
10112952Sgabeblack@google.com     * sizeof st_ino 4
10212952Sgabeblack@google.com     * sizeof st_mode 2
10312952Sgabeblack@google.com     * sizeof st_nlink 2
10412952Sgabeblack@google.com     * sizeof st_uid 4
10512952Sgabeblack@google.com     * sizeof st_gid 4
10612952Sgabeblack@google.com     * sizeof st_rdev 4
10712952Sgabeblack@google.com     * sizeof st_atim 16
10812952Sgabeblack@google.com     * sizeof st_size 8
10912952Sgabeblack@google.com     * sizeof st_blocks 8
11012952Sgabeblack@google.com     * sizeof st_blksize 4
11112952Sgabeblack@google.com     * sizeof st_flags 4
11212952Sgabeblack@google.com     * sizeof st_gen 4
11312952Sgabeblack@google.com     * sizeof st_lspare 4
11412952Sgabeblack@google.com     */
11512952Sgabeblack@google.com
11612952Sgabeblack@google.com    typedef struct {
11712952Sgabeblack@google.com        uint32_t   st_dev;
11812952Sgabeblack@google.com        uint32_t   st_ino;
11912952Sgabeblack@google.com        uint16_t   st_mode;
12012952Sgabeblack@google.com        uint16_t   st_nlink;
12112952Sgabeblack@google.com        uint32_t   st_uid;
12212952Sgabeblack@google.com        uint32_t   st_gid;
12312952Sgabeblack@google.com        uint32_t   st_rdev;
12412952Sgabeblack@google.com        uint64_t   st_atimeX;
12512952Sgabeblack@google.com        uint64_t   st_atime_nsec;
12612952Sgabeblack@google.com        uint64_t   st_mtimeX;
12712952Sgabeblack@google.com        uint64_t   st_mtime_nsec;
12812952Sgabeblack@google.com        uint64_t   st_ctimeX;
12912952Sgabeblack@google.com        uint64_t   st_ctime_nsec;
13012952Sgabeblack@google.com        uint64_t   st_size;
13112952Sgabeblack@google.com        uint64_t   st_blocks;
13212952Sgabeblack@google.com        uint32_t   st_blksize;
13312952Sgabeblack@google.com        uint32_t   st_flags;
13412952Sgabeblack@google.com        uint32_t   st_gen;
13512952Sgabeblack@google.com        uint32_t   st_lspare;
13612952Sgabeblack@google.com        uint64_t   st_birthtimX;
13712952Sgabeblack@google.com        uint64_t   st_birthtim;
13812952Sgabeblack@google.com    } tgt_stat;
13912952Sgabeblack@google.com
14012952Sgabeblack@google.com    typedef struct {
14112952Sgabeblack@google.com        uint32_t   st_dev;
14212952Sgabeblack@google.com        uint32_t   st_ino;
14312952Sgabeblack@google.com        uint16_t   st_mode;
14412952Sgabeblack@google.com        uint16_t   st_nlink;
14512952Sgabeblack@google.com        uint32_t   st_uid;
14612952Sgabeblack@google.com        uint32_t   st_gid;
14712952Sgabeblack@google.com        uint32_t   st_rdev;
14812952Sgabeblack@google.com        uint64_t   st_atimeX;
14912952Sgabeblack@google.com        uint64_t   st_atime_nsec;
15012952Sgabeblack@google.com        uint64_t   st_mtimeX;
15112952Sgabeblack@google.com        uint64_t   st_mtime_nsec;
15212952Sgabeblack@google.com        uint64_t   st_ctimeX;
15312952Sgabeblack@google.com        uint64_t   st_ctime_nsec;
15412952Sgabeblack@google.com        uint64_t   st_size;
15512952Sgabeblack@google.com        uint64_t   st_blocks;
15612952Sgabeblack@google.com        uint32_t   st_blksize;
15712952Sgabeblack@google.com        uint32_t   st_flags;
15812952Sgabeblack@google.com        uint32_t   st_gen;
15912952Sgabeblack@google.com        uint32_t   st_lspare;
16012952Sgabeblack@google.com        uint64_t   st_birthtimX;
16112952Sgabeblack@google.com        uint64_t   st_birthtim;
16212952Sgabeblack@google.com    } tgt_stat64;
16312952Sgabeblack@google.com
16412952Sgabeblack@google.com    /// For getrusage().
16512952Sgabeblack@google.com    struct rusage {
16612952Sgabeblack@google.com        struct timeval ru_utime;        //!< user time used
16712952Sgabeblack@google.com        struct timeval ru_stime;        //!< system time used
16812952Sgabeblack@google.com        int32_t ru_maxrss;              //!< max rss
16912952Sgabeblack@google.com        int32_t ru_ixrss;               //!< integral shared memory size
17012952Sgabeblack@google.com        int32_t ru_idrss;               //!< integral unshared data "
17112952Sgabeblack@google.com        int32_t ru_isrss;               //!< integral unshared stack "
17212952Sgabeblack@google.com        int32_t ru_minflt;              //!< page reclaims - total vmfaults
17312952Sgabeblack@google.com        int32_t ru_majflt;              //!< page faults
17412952Sgabeblack@google.com        int32_t ru_nswap;               //!< swaps
17512952Sgabeblack@google.com        int32_t ru_inblock;             //!< block input operations
17612952Sgabeblack@google.com        int32_t ru_oublock;             //!< block output operations
17712952Sgabeblack@google.com        int32_t ru_msgsnd;              //!< messages sent
17812952Sgabeblack@google.com        int32_t ru_msgrcv;              //!< messages received
17912952Sgabeblack@google.com        int32_t ru_nsignals;            //!< signals received
18012952Sgabeblack@google.com        int32_t ru_nvcsw;               //!< voluntary context switches
18112952Sgabeblack@google.com        int32_t ru_nivcsw;              //!< involuntary "
18212952Sgabeblack@google.com    };
18312952Sgabeblack@google.com
18412952Sgabeblack@google.com    /// For times().
18512952Sgabeblack@google.com    struct tms {
18612952Sgabeblack@google.com        int32_t tms_utime;      //!< user time
18712952Sgabeblack@google.com        int32_t tms_stime;      //!< system time
18812952Sgabeblack@google.com        int32_t tms_cutime;     //!< user time of children
18912952Sgabeblack@google.com        int32_t tms_cstime;     //!< system time of children
19012952Sgabeblack@google.com    };
19112952Sgabeblack@google.com};
19212952Sgabeblack@google.com
19312952Sgabeblack@google.comclass ArmFreebsd64 : public FreeBSD
19412952Sgabeblack@google.com{
19512952Sgabeblack@google.com  public:
19612952Sgabeblack@google.com
19712952Sgabeblack@google.com    /// This table maps the target open() flags to the corresponding
19812952Sgabeblack@google.com    /// host open() flags.
19912952Sgabeblack@google.com    static SyscallFlagTransTable openFlagTable[];
20012952Sgabeblack@google.com
20112952Sgabeblack@google.com    /// Number of entries in openFlagTable[].
20212952Sgabeblack@google.com    static const int NUM_OPEN_FLAGS;
20312952Sgabeblack@google.com
20412952Sgabeblack@google.com    //@{
20512952Sgabeblack@google.com    /// Basic ARM FreeBSD types
20612952Sgabeblack@google.com    typedef uint64_t size_t;
20712952Sgabeblack@google.com    typedef uint64_t off_t;
20812952Sgabeblack@google.com    typedef int64_t time_t;
209    typedef int64_t clock_t;
210    //@}
211
212    //@{
213    /// open(2) flag values.
214    static const int TGT_O_RDONLY    = 0x00000000; //!< O_RDONLY
215    static const int TGT_O_WRONLY    = 0x00000001; //!< O_WRONLY
216    static const int TGT_O_RDWR      = 0x00000002; //!< O_RDWR
217    static const int TGT_O_CREAT     = 0x00000200; //!< O_CREAT
218    static const int TGT_O_EXCL      = 0x00000800; //!< O_EXCL
219    static const int TGT_O_NOCTTY    = 0x00008000; //!< O_NOCTTY
220    static const int TGT_O_TRUNC     = 0x00000400; //!< O_TRUNC
221    static const int TGT_O_APPEND    = 0x00000008; //!< O_APPEND
222    static const int TGT_O_NONBLOCK  = 0x00000004; //!< O_NONBLOCK
223    static const int TGT_O_SYNC      = 0x00000080; //!< O_SYNC
224    static const int TGT_FASYNC      = 0x00000040; //!< FASYNC
225    static const int TGT_O_DIRECT    = 0x00010000; //!< O_DIRECT
226    static const int TGT_O_DIRECTORY = 0x00020000; //!< O_DIRECTORY
227    static const int TGT_O_NOFOLLOW  = 0x00000100; //!< O_NOFOLLOW
228    static const int TGT_O_CLOEXEC   = 0x00100000; //!< O_CLOEXEC
229    //@}
230
231    /// For mmap().
232    static const unsigned TGT_MAP_ANONYMOUS = 0x1000;
233    static const unsigned TGT_MAP_FIXED     = 0x0010;
234
235    //@{
236    /// For getrusage().
237    static const int TGT_RUSAGE_SELF = 0;
238    static const int TGT_RUSAGE_CHILDREN = -1;
239    static const int TGT_RUSAGE_THREAD = 1;
240    //@}
241
242    /// Resource enumeration for getrlimit().
243    enum rlimit_resources {
244        TGT_RLIMIT_CPU = 0,
245        TGT_RLIMIT_FSIZE = 1,
246        TGT_RLIMIT_DATA = 2,
247        TGT_RLIMIT_STACK = 3,
248        TGT_RLIMIT_CORE = 4,
249        TGT_RLIMIT_RSS = 5,
250        TGT_RLIMIT_MEMLOCK = 6,
251        TGT_RLIMIT_NPROC = 7,
252        TGT_RLIMIT_NOFILE = 8,
253        TGT_RLIMIT_SBSIZE = 9,
254        TGT_RLIMIT_VMEM = 10,
255        TGT_RLIMIT_AS = TGT_RLIMIT_VMEM,
256        TGT_RLIMIT_NPTS = 11,
257        TGT_RLIMIT_SWAP = 12,
258        TGT_RLIMIT_KQUEUES = 13
259    };
260
261    /// Limit struct for getrlimit/setrlimit.
262    struct rlimit {
263        uint64_t  rlim_cur;     //!< soft limit
264        uint64_t  rlim_max;     //!< hard limit
265    };
266
267    /// For gettimeofday().
268    struct timeval {
269        int64_t tv_sec;         //!< seconds
270        int64_t tv_usec;        //!< microseconds
271    };
272
273    // For writev/readv
274    struct tgt_iovec {
275        uint64_t iov_base; // void *
276        uint64_t iov_len;
277    };
278
279    typedef struct {
280        uint32_t   st_dev;
281        uint32_t   st_ino;
282        uint16_t   st_mode;
283        uint16_t   st_nlink;
284        uint32_t   st_uid;
285        uint32_t   st_gid;
286        uint32_t   st_rdev;
287        uint64_t   st_atimeX;
288        uint64_t   st_atime_nsec;
289        uint64_t   st_mtimeX;
290        uint64_t   st_mtime_nsec;
291        uint64_t   st_ctimeX;
292        uint64_t   st_ctime_nsec;
293        uint64_t   st_size;
294        uint64_t   st_blocks;
295        uint32_t   st_blksize;
296        uint32_t   st_flags;
297        uint32_t   st_gen;
298        uint32_t   st_lspare;
299        uint64_t   st_birthtimX;
300        uint64_t   st_birthtim;
301    } tgt_stat;
302
303    typedef struct {
304        uint32_t   st_dev;
305        uint32_t   st_ino;
306        uint16_t   st_mode;
307        uint16_t   st_nlink;
308        uint32_t   st_uid;
309        uint32_t   st_gid;
310        uint32_t   st_rdev;
311        uint64_t   st_atimeX;
312        uint64_t   st_atime_nsec;
313        uint64_t   st_mtimeX;
314        uint64_t   st_mtime_nsec;
315        uint64_t   st_ctimeX;
316        uint64_t   st_ctime_nsec;
317        uint64_t   st_size;
318        uint64_t   st_blocks;
319        uint32_t   st_blksize;
320        uint32_t   st_flags;
321        uint32_t   st_gen;
322        uint32_t   st_lspare;
323        uint64_t   st_birthtimX;
324        uint64_t   st_birthtim;
325    } tgt_stat64;
326
327    /// For getrusage().
328    struct rusage {
329        struct timeval ru_utime;        //!< user time used
330        struct timeval ru_stime;        //!< system time used
331        int64_t ru_maxrss;              //!< max rss
332        int64_t ru_ixrss;               //!< integral shared memory size
333        int64_t ru_idrss;               //!< integral unshared data "
334        int64_t ru_isrss;               //!< integral unshared stack "
335        int64_t ru_minflt;              //!< page reclaims - total vmfaults
336        int64_t ru_majflt;              //!< page faults
337        int64_t ru_nswap;               //!< swaps
338        int64_t ru_inblock;             //!< block input operations
339        int64_t ru_oublock;             //!< block output operations
340        int64_t ru_msgsnd;              //!< messages sent
341        int64_t ru_msgrcv;              //!< messages received
342        int64_t ru_nsignals;            //!< signals received
343        int64_t ru_nvcsw;               //!< voluntary context switches
344        int64_t ru_nivcsw;              //!< involuntary "
345    };
346
347    /// For times().
348    struct tms {
349        int64_t tms_utime;      //!< user time
350        int64_t tms_stime;      //!< system time
351        int64_t tms_cutime;     //!< user time of children
352        int64_t tms_cstime;     //!< system time of children
353    };
354};
355
356#endif
357