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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
|
-- This are the types for OpenBSD
local require, error, assert, tonumber, tostring,
setmetatable, pairs, ipairs, unpack, rawget, rawset,
pcall, type, table, string =
require, error, assert, tonumber, tostring,
setmetatable, pairs, ipairs, unpack, rawget, rawset,
pcall, type, table, string
local abi = require "syscall.abi"
local ffi = require "ffi"
require "syscall.ffitypes"
local version = require "syscall.openbsd.version".version
local defs = {}
local function append(str) defs[#defs + 1] = str end
append [[
typedef int32_t clockid_t;
typedef uint32_t fflags_t;
typedef uint64_t fsblkcnt_t;
typedef uint64_t fsfilcnt_t;
typedef int32_t id_t;
typedef long key_t;
typedef int32_t lwpid_t;
typedef uint32_t mode_t;
typedef int accmode_t;
typedef int nl_item;
typedef uint32_t nlink_t;
typedef int64_t rlim_t;
typedef uint8_t sa_family_t;
typedef long suseconds_t;
typedef unsigned int useconds_t;
typedef int cpuwhich_t;
typedef int cpulevel_t;
typedef int cpusetid_t;
typedef uint32_t dev_t;
typedef uint32_t fixpt_t;
typedef unsigned int nfds_t;
typedef int64_t daddr_t;
typedef int32_t timer_t;
]]
if version <= 201311 then append [[
typedef uint32_t ino_t;
typedef int32_t time_t;
typedef int32_t clock_t;
]] else append [[
typedef uint64_t ino_t;
typedef int64_t time_t;
typedef int64_t clock_t;
]] end
append [[
typedef unsigned int tcflag_t;
typedef unsigned int speed_t;
typedef char * caddr_t;
/* can be changed, TODO also should be long */
typedef uint32_t __fd_mask;
typedef struct fd_set {
__fd_mask fds_bits[32];
} fd_set;
typedef struct __sigset {
uint32_t sig[1]; // note renamed to match Linux
} sigset_t;
// typedef unsigned int sigset_t; /* this is correct TODO fix */
struct cmsghdr {
socklen_t cmsg_len;
int cmsg_level;
int cmsg_type;
char cmsg_data[?];
};
struct msghdr {
void *msg_name;
socklen_t msg_namelen;
struct iovec *msg_iov;
int msg_iovlen;
void *msg_control;
socklen_t msg_controllen;
int msg_flags;
};
struct timespec {
time_t tv_sec;
long tv_nsec;
};
struct timeval {
time_t tv_sec;
suseconds_t tv_usec;
};
struct itimerspec {
struct timespec it_interval;
struct timespec it_value;
};
struct itimerval {
struct timeval it_interval;
struct timeval it_value;
};
struct sockaddr {
uint8_t sa_len;
sa_family_t sa_family;
char sa_data[14];
};
struct sockaddr_storage {
uint8_t ss_len;
sa_family_t ss_family;
unsigned char __ss_pad1[6];
uint64_t __ss_pad2;
unsigned char __ss_pad3[240];
};
struct sockaddr_in {
uint8_t sin_len;
sa_family_t sin_family;
in_port_t sin_port;
struct in_addr sin_addr;
int8_t sin_zero[8];
};
struct sockaddr_in6 {
uint8_t sin6_len;
sa_family_t sin6_family;
in_port_t sin6_port;
uint32_t sin6_flowinfo;
struct in6_addr sin6_addr;
uint32_t sin6_scope_id;
};
struct sockaddr_un {
uint8_t sun_len;
sa_family_t sun_family;
char sun_path[104];
};
struct pollfd {
int fd;
short events;
short revents;
};
]]
if version <= 201311 then append [[
struct stat {
dev_t st_dev;
ino_t st_ino;
mode_t st_mode;
nlink_t st_nlink;
uid_t st_uid;
gid_t st_gid;
dev_t st_rdev;
int32_t st_lspare0;
struct timespec st_atim;
struct timespec st_mtim;
struct timespec st_ctim;
off_t st_size;
int64_t st_blocks;
uint32_t st_blksize;
uint32_t st_flags;
uint32_t st_gen;
int32_t st_lspare1;
struct timespec __st_birthtim;
int64_t st_qspare[2];
};
]] else append [[
struct stat {
mode_t st_mode;
dev_t st_dev;
ino_t st_ino;
nlink_t st_nlink;
uid_t st_uid;
gid_t st_gid;
dev_t st_rdev;
struct timespec st_atim;
struct timespec st_mtim;
struct timespec st_ctim;
off_t st_size;
int64_t st_blocks;
uint32_t st_blksize;
uint32_t st_flags;
uint32_t st_gen;
struct timespec __st_birthtim;
};
]] end append [[
struct rusage {
struct timeval ru_utime;
struct timeval ru_stime;
long ru_maxrss;
long ru_ixrss;
long ru_idrss;
long ru_isrss;
long ru_minflt;
long ru_majflt;
long ru_nswap;
long ru_inblock;
long ru_oublock;
long ru_msgsnd;
long ru_msgrcv;
long ru_nsignals;
long ru_nvcsw;
long ru_nivcsw;
};
struct flock {
off_t l_start;
off_t l_len;
pid_t l_pid;
short l_type;
short l_whence;
};
struct termios {
tcflag_t c_iflag;
tcflag_t c_oflag;
tcflag_t c_cflag;
tcflag_t c_lflag;
cc_t c_cc[20];
speed_t c_ispeed;
speed_t c_ospeed;
};
]]
if version <= 201311 then append [[
struct dirent {
uint32_t d_fileno;
uint16_t d_reclen;
uint8_t d_type;
uint8_t d_namlen;
char d_name[255 + 1];
};
struct kevent {
unsigned int ident;
short filter;
unsigned short flags;
unsigned int fflags;
int data;
void *udata;
};
]] else append [[
struct dirent {
uint64_t d_fileno;
int64_t d_off;
uint16_t d_reclen;
uint8_t d_type;
uint8_t d_namlen;
char __d_padding[4];
char d_name[255 + 1];
};
struct kevent {
intptr_t ident;
short filter;
unsigned short flags;
unsigned int fflags;
int64_t data;
void *udata;
};
]] end
append [[
union sigval {
int sival_int;
void *sival_ptr;
};
static const int SI_MAXSZ = 128;
static const int SI_PAD = ((SI_MAXSZ / sizeof (int)) - 3);
typedef struct {
int si_signo;
int si_code;
int si_errno;
union {
int _pad[SI_PAD];
struct {
pid_t _pid;
union {
struct {
uid_t _uid;
union sigval _value;
} _kill;
struct {
clock_t _utime;
int _status;
clock_t _stime;
} _cld;
} _pdata;
} _proc;
struct {
caddr_t _addr;
int _trapno;
} _fault;
} _data;
} siginfo_t;
struct sigaction {
union {
void (*__sa_handler)(int);
void (*__sa_sigaction)(int, siginfo_t *, void *);
} __sigaction_u;
sigset_t sa_mask;
int sa_flags;
};
]]
-- functions
append [[
int reboot(int howto);
int ioctl(int d, unsigned long request, void *arg);
int fstatat(int dirfd, const char *pathname, struct stat *buf, int flags);
/* not syscalls, but using for now */
int grantpt(int fildes);
int unlockpt(int fildes);
char *ptsname(int fildes);
]]
if version >= 201405 then
append [[
int getdents(int fd, void *buf, size_t nbytes);
]]
end
local s = table.concat(defs, "")
ffi.cdef(s)
require "syscall.bsd.ffi"
|