freebsd.hh revision 10810:683ab55819fd
1/*
2 * Copyright (c) 2015 Ruslan Bukin <br@bsdpad.com>
3 * All rights reserved.
4 *
5 * This software was developed by the University of Cambridge Computer
6 * Laboratory as part of the CTSRD Project, with support from the UK Higher
7 * Education Innovation Fund (HEIF).
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are
11 * met: redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer;
13 * redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution;
16 * neither the name of the copyright holders nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#ifndef __ARCH_ARM_FREEBSD_FREEBSD_HH__
34#define __ARCH_ARM_FREEBSD_FREEBSD_HH__
35
36#include "kern/freebsd/freebsd.hh"
37
38class ArmFreebsd32 : public FreeBSD
39{
40  public:
41
42    /// This table maps the target open() flags to the corresponding
43    /// host open() flags.
44    static OpenFlagTransTable openFlagTable[];
45
46    /// Number of entries in openFlagTable[].
47    static const int NUM_OPEN_FLAGS;
48
49    //@{
50    /// Basic ARM FreeBSD types
51    typedef uint32_t size_t;
52    typedef uint32_t off_t;
53    typedef int32_t time_t;
54    typedef int32_t clock_t;
55    //@}
56
57    //@{
58    /// open(2) flag values.
59    static const int TGT_O_RDONLY    = 0x00000000; //!< O_RDONLY
60    static const int TGT_O_WRONLY    = 0x00000001; //!< O_WRONLY
61    static const int TGT_O_RDWR      = 0x00000002; //!< O_RDWR
62    static const int TGT_O_CREAT     = 0x00000200; //!< O_CREAT
63    static const int TGT_O_EXCL      = 0x00000800; //!< O_EXCL
64    static const int TGT_O_NOCTTY    = 0x00008000; //!< O_NOCTTY
65    static const int TGT_O_TRUNC     = 0x00000400; //!< O_TRUNC
66    static const int TGT_O_APPEND    = 0x00000008; //!< O_APPEND
67    static const int TGT_O_NONBLOCK  = 0x00000004; //!< O_NONBLOCK
68    static const int TGT_O_SYNC      = 0x00000080; //!< O_SYNC
69    static const int TGT_FASYNC      = 0x00000040; //!< FASYNC
70    static const int TGT_O_DIRECT    = 0x00010000; //!< O_DIRECT
71    static const int TGT_O_DIRECTORY = 0x00020000; //!< O_DIRECTORY
72    static const int TGT_O_NOFOLLOW  = 0x00000100; //!< O_NOFOLLOW
73    static const int TGT_O_CLOEXEC   = 0x00100000; //!< O_CLOEXEC
74    //@}
75
76    /// For mmap().
77    static const unsigned TGT_MAP_ANONYMOUS = 0x1000;
78    static const unsigned TGT_MAP_FIXED     = 0x0010;
79
80    /// Limit struct for getrlimit/setrlimit.
81    struct rlimit {
82        uint32_t  rlim_cur;     //!< soft limit
83        uint32_t  rlim_max;     //!< hard limit
84    };
85
86    /// For gettimeofday().
87    struct timeval {
88        int32_t tv_sec;         //!< seconds
89        int32_t tv_usec;        //!< microseconds
90    };
91
92    // For writev/readv
93    struct tgt_iovec {
94        uint32_t iov_base; // void *
95        uint32_t iov_len;
96    };
97
98    /*
99     * sizeof st 120
100     * sizeof st_dev 4
101     * sizeof st_ino 4
102     * sizeof st_mode 2
103     * sizeof st_nlink 2
104     * sizeof st_uid 4
105     * sizeof st_gid 4
106     * sizeof st_rdev 4
107     * sizeof st_atim 16
108     * sizeof st_size 8
109     * sizeof st_blocks 8
110     * sizeof st_blksize 4
111     * sizeof st_flags 4
112     * sizeof st_gen 4
113     * sizeof st_lspare 4
114     */
115
116    typedef struct {
117        uint32_t   st_dev;
118        uint32_t   st_ino;
119        uint16_t   st_mode;
120        uint16_t   st_nlink;
121        uint32_t   st_uid;
122        uint32_t   st_gid;
123        uint32_t   st_rdev;
124        uint64_t   st_atimeX;
125        uint64_t   st_atime_nsec;
126        uint64_t   st_mtimeX;
127        uint64_t   st_mtime_nsec;
128        uint64_t   st_ctimeX;
129        uint64_t   st_ctime_nsec;
130        uint64_t   st_size;
131        uint64_t   st_blocks;
132        uint32_t   st_blksize;
133        uint32_t   st_flags;
134        uint32_t   st_gen;
135        uint32_t   st_lspare;
136        uint64_t   st_birthtimX;
137        uint64_t   st_birthtim;
138    } tgt_stat;
139
140    typedef struct {
141        uint32_t   st_dev;
142        uint32_t   st_ino;
143        uint16_t   st_mode;
144        uint16_t   st_nlink;
145        uint32_t   st_uid;
146        uint32_t   st_gid;
147        uint32_t   st_rdev;
148        uint64_t   st_atimeX;
149        uint64_t   st_atime_nsec;
150        uint64_t   st_mtimeX;
151        uint64_t   st_mtime_nsec;
152        uint64_t   st_ctimeX;
153        uint64_t   st_ctime_nsec;
154        uint64_t   st_size;
155        uint64_t   st_blocks;
156        uint32_t   st_blksize;
157        uint32_t   st_flags;
158        uint32_t   st_gen;
159        uint32_t   st_lspare;
160        uint64_t   st_birthtimX;
161        uint64_t   st_birthtim;
162    } tgt_stat64;
163
164    /// For getrusage().
165    struct rusage {
166        struct timeval ru_utime;        //!< user time used
167        struct timeval ru_stime;        //!< system time used
168        int32_t ru_maxrss;              //!< max rss
169        int32_t ru_ixrss;               //!< integral shared memory size
170        int32_t ru_idrss;               //!< integral unshared data "
171        int32_t ru_isrss;               //!< integral unshared stack "
172        int32_t ru_minflt;              //!< page reclaims - total vmfaults
173        int32_t ru_majflt;              //!< page faults
174        int32_t ru_nswap;               //!< swaps
175        int32_t ru_inblock;             //!< block input operations
176        int32_t ru_oublock;             //!< block output operations
177        int32_t ru_msgsnd;              //!< messages sent
178        int32_t ru_msgrcv;              //!< messages received
179        int32_t ru_nsignals;            //!< signals received
180        int32_t ru_nvcsw;               //!< voluntary context switches
181        int32_t ru_nivcsw;              //!< involuntary "
182    };
183
184    /// For times().
185    struct tms {
186        int32_t tms_utime;      //!< user time
187        int32_t tms_stime;      //!< system time
188        int32_t tms_cutime;     //!< user time of children
189        int32_t tms_cstime;     //!< system time of children
190    };
191};
192
193class ArmFreebsd64 : public FreeBSD
194{
195  public:
196
197    /// This table maps the target open() flags to the corresponding
198    /// host open() flags.
199    static OpenFlagTransTable openFlagTable[];
200
201    /// Number of entries in openFlagTable[].
202    static const int NUM_OPEN_FLAGS;
203
204    //@{
205    /// Basic ARM FreeBSD types
206    typedef uint64_t size_t;
207    typedef uint64_t off_t;
208    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