freebsd.hh revision 11383
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 SyscallFlagTransTable 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_SHARED    = 0x0001;
78    static const unsigned TGT_MAP_PRIVATE   = 0x0002;
79    static const unsigned TGT_MAP_ANONYMOUS = 0x1000;
80    static const unsigned TGT_MAP_FIXED     = 0x0010;
81
82    /// Limit struct for getrlimit/setrlimit.
83    struct rlimit {
84        uint32_t  rlim_cur;     //!< soft limit
85        uint32_t  rlim_max;     //!< hard limit
86    };
87
88    /// For gettimeofday().
89    struct timeval {
90        int32_t tv_sec;         //!< seconds
91        int32_t tv_usec;        //!< microseconds
92    };
93
94    // For writev/readv
95    struct tgt_iovec {
96        uint32_t iov_base; // void *
97        uint32_t iov_len;
98    };
99
100    /*
101     * sizeof st 120
102     * sizeof st_dev 4
103     * sizeof st_ino 4
104     * sizeof st_mode 2
105     * sizeof st_nlink 2
106     * sizeof st_uid 4
107     * sizeof st_gid 4
108     * sizeof st_rdev 4
109     * sizeof st_atim 16
110     * sizeof st_size 8
111     * sizeof st_blocks 8
112     * sizeof st_blksize 4
113     * sizeof st_flags 4
114     * sizeof st_gen 4
115     * sizeof st_lspare 4
116     */
117
118    typedef struct {
119        uint32_t   st_dev;
120        uint32_t   st_ino;
121        uint16_t   st_mode;
122        uint16_t   st_nlink;
123        uint32_t   st_uid;
124        uint32_t   st_gid;
125        uint32_t   st_rdev;
126        uint64_t   st_atimeX;
127        uint64_t   st_atime_nsec;
128        uint64_t   st_mtimeX;
129        uint64_t   st_mtime_nsec;
130        uint64_t   st_ctimeX;
131        uint64_t   st_ctime_nsec;
132        uint64_t   st_size;
133        uint64_t   st_blocks;
134        uint32_t   st_blksize;
135        uint32_t   st_flags;
136        uint32_t   st_gen;
137        uint32_t   st_lspare;
138        uint64_t   st_birthtimX;
139        uint64_t   st_birthtim;
140    } tgt_stat;
141
142    typedef struct {
143        uint32_t   st_dev;
144        uint32_t   st_ino;
145        uint16_t   st_mode;
146        uint16_t   st_nlink;
147        uint32_t   st_uid;
148        uint32_t   st_gid;
149        uint32_t   st_rdev;
150        uint64_t   st_atimeX;
151        uint64_t   st_atime_nsec;
152        uint64_t   st_mtimeX;
153        uint64_t   st_mtime_nsec;
154        uint64_t   st_ctimeX;
155        uint64_t   st_ctime_nsec;
156        uint64_t   st_size;
157        uint64_t   st_blocks;
158        uint32_t   st_blksize;
159        uint32_t   st_flags;
160        uint32_t   st_gen;
161        uint32_t   st_lspare;
162        uint64_t   st_birthtimX;
163        uint64_t   st_birthtim;
164    } tgt_stat64;
165
166    /// For getrusage().
167    struct rusage {
168        struct timeval ru_utime;        //!< user time used
169        struct timeval ru_stime;        //!< system time used
170        int32_t ru_maxrss;              //!< max rss
171        int32_t ru_ixrss;               //!< integral shared memory size
172        int32_t ru_idrss;               //!< integral unshared data "
173        int32_t ru_isrss;               //!< integral unshared stack "
174        int32_t ru_minflt;              //!< page reclaims - total vmfaults
175        int32_t ru_majflt;              //!< page faults
176        int32_t ru_nswap;               //!< swaps
177        int32_t ru_inblock;             //!< block input operations
178        int32_t ru_oublock;             //!< block output operations
179        int32_t ru_msgsnd;              //!< messages sent
180        int32_t ru_msgrcv;              //!< messages received
181        int32_t ru_nsignals;            //!< signals received
182        int32_t ru_nvcsw;               //!< voluntary context switches
183        int32_t ru_nivcsw;              //!< involuntary "
184    };
185
186    /// For times().
187    struct tms {
188        int32_t tms_utime;      //!< user time
189        int32_t tms_stime;      //!< system time
190        int32_t tms_cutime;     //!< user time of children
191        int32_t tms_cstime;     //!< system time of children
192    };
193};
194
195class ArmFreebsd64 : public FreeBSD
196{
197  public:
198
199    /// This table maps the target open() flags to the corresponding
200    /// host open() flags.
201    static SyscallFlagTransTable openFlagTable[];
202
203    /// Number of entries in openFlagTable[].
204    static const int NUM_OPEN_FLAGS;
205
206    //@{
207    /// Basic ARM FreeBSD types
208    typedef uint64_t size_t;
209    typedef uint64_t off_t;
210    typedef int64_t time_t;
211    typedef int64_t clock_t;
212    //@}
213
214    //@{
215    /// open(2) flag values.
216    static const int TGT_O_RDONLY    = 0x00000000; //!< O_RDONLY
217    static const int TGT_O_WRONLY    = 0x00000001; //!< O_WRONLY
218    static const int TGT_O_RDWR      = 0x00000002; //!< O_RDWR
219    static const int TGT_O_CREAT     = 0x00000200; //!< O_CREAT
220    static const int TGT_O_EXCL      = 0x00000800; //!< O_EXCL
221    static const int TGT_O_NOCTTY    = 0x00008000; //!< O_NOCTTY
222    static const int TGT_O_TRUNC     = 0x00000400; //!< O_TRUNC
223    static const int TGT_O_APPEND    = 0x00000008; //!< O_APPEND
224    static const int TGT_O_NONBLOCK  = 0x00000004; //!< O_NONBLOCK
225    static const int TGT_O_SYNC      = 0x00000080; //!< O_SYNC
226    static const int TGT_FASYNC      = 0x00000040; //!< FASYNC
227    static const int TGT_O_DIRECT    = 0x00010000; //!< O_DIRECT
228    static const int TGT_O_DIRECTORY = 0x00020000; //!< O_DIRECTORY
229    static const int TGT_O_NOFOLLOW  = 0x00000100; //!< O_NOFOLLOW
230    static const int TGT_O_CLOEXEC   = 0x00100000; //!< O_CLOEXEC
231    //@}
232
233    /// For mmap().
234    static const unsigned TGT_MAP_SHARED    = 0x0001;
235    static const unsigned TGT_MAP_PRIVATE   = 0x0002;
236    static const unsigned TGT_MAP_ANONYMOUS = 0x1000;
237    static const unsigned TGT_MAP_FIXED     = 0x0010;
238
239    //@{
240    /// For getrusage().
241    static const int TGT_RUSAGE_SELF = 0;
242    static const int TGT_RUSAGE_CHILDREN = -1;
243    static const int TGT_RUSAGE_THREAD = 1;
244    //@}
245
246    /// Resource enumeration for getrlimit().
247    enum rlimit_resources {
248        TGT_RLIMIT_CPU = 0,
249        TGT_RLIMIT_FSIZE = 1,
250        TGT_RLIMIT_DATA = 2,
251        TGT_RLIMIT_STACK = 3,
252        TGT_RLIMIT_CORE = 4,
253        TGT_RLIMIT_RSS = 5,
254        TGT_RLIMIT_MEMLOCK = 6,
255        TGT_RLIMIT_NPROC = 7,
256        TGT_RLIMIT_NOFILE = 8,
257        TGT_RLIMIT_SBSIZE = 9,
258        TGT_RLIMIT_VMEM = 10,
259        TGT_RLIMIT_AS = TGT_RLIMIT_VMEM,
260        TGT_RLIMIT_NPTS = 11,
261        TGT_RLIMIT_SWAP = 12,
262        TGT_RLIMIT_KQUEUES = 13
263    };
264
265    /// Limit struct for getrlimit/setrlimit.
266    struct rlimit {
267        uint64_t  rlim_cur;     //!< soft limit
268        uint64_t  rlim_max;     //!< hard limit
269    };
270
271    /// For gettimeofday().
272    struct timeval {
273        int64_t tv_sec;         //!< seconds
274        int64_t tv_usec;        //!< microseconds
275    };
276
277    // For writev/readv
278    struct tgt_iovec {
279        uint64_t iov_base; // void *
280        uint64_t iov_len;
281    };
282
283    typedef struct {
284        uint32_t   st_dev;
285        uint32_t   st_ino;
286        uint16_t   st_mode;
287        uint16_t   st_nlink;
288        uint32_t   st_uid;
289        uint32_t   st_gid;
290        uint32_t   st_rdev;
291        uint64_t   st_atimeX;
292        uint64_t   st_atime_nsec;
293        uint64_t   st_mtimeX;
294        uint64_t   st_mtime_nsec;
295        uint64_t   st_ctimeX;
296        uint64_t   st_ctime_nsec;
297        uint64_t   st_size;
298        uint64_t   st_blocks;
299        uint32_t   st_blksize;
300        uint32_t   st_flags;
301        uint32_t   st_gen;
302        uint32_t   st_lspare;
303        uint64_t   st_birthtimX;
304        uint64_t   st_birthtim;
305    } tgt_stat;
306
307    typedef struct {
308        uint32_t   st_dev;
309        uint32_t   st_ino;
310        uint16_t   st_mode;
311        uint16_t   st_nlink;
312        uint32_t   st_uid;
313        uint32_t   st_gid;
314        uint32_t   st_rdev;
315        uint64_t   st_atimeX;
316        uint64_t   st_atime_nsec;
317        uint64_t   st_mtimeX;
318        uint64_t   st_mtime_nsec;
319        uint64_t   st_ctimeX;
320        uint64_t   st_ctime_nsec;
321        uint64_t   st_size;
322        uint64_t   st_blocks;
323        uint32_t   st_blksize;
324        uint32_t   st_flags;
325        uint32_t   st_gen;
326        uint32_t   st_lspare;
327        uint64_t   st_birthtimX;
328        uint64_t   st_birthtim;
329    } tgt_stat64;
330
331    /// For getrusage().
332    struct rusage {
333        struct timeval ru_utime;        //!< user time used
334        struct timeval ru_stime;        //!< system time used
335        int64_t ru_maxrss;              //!< max rss
336        int64_t ru_ixrss;               //!< integral shared memory size
337        int64_t ru_idrss;               //!< integral unshared data "
338        int64_t ru_isrss;               //!< integral unshared stack "
339        int64_t ru_minflt;              //!< page reclaims - total vmfaults
340        int64_t ru_majflt;              //!< page faults
341        int64_t ru_nswap;               //!< swaps
342        int64_t ru_inblock;             //!< block input operations
343        int64_t ru_oublock;             //!< block output operations
344        int64_t ru_msgsnd;              //!< messages sent
345        int64_t ru_msgrcv;              //!< messages received
346        int64_t ru_nsignals;            //!< signals received
347        int64_t ru_nvcsw;               //!< voluntary context switches
348        int64_t ru_nivcsw;              //!< involuntary "
349    };
350
351    /// For times().
352    struct tms {
353        int64_t tms_utime;      //!< user time
354        int64_t tms_stime;      //!< system time
355        int64_t tms_cutime;     //!< user time of children
356        int64_t tms_cstime;     //!< system time of children
357    };
358};
359
360#endif
361