File: c.lua

package info (click to toggle)
lua-ljsyscall 0.12-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,732 kB
  • sloc: ansic: 434; sh: 59; makefile: 3
file content (90 lines) | stat: -rw-r--r-- 2,452 bytes parent folder | download | duplicates (3)
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
-- This sets up the table of C functions for BSD
-- We need to override functions that are versioned as the old ones selected otherwise

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 version = require "syscall.netbsd.version".version

local ffi = require "ffi"

local function inlibc_fn(k) return ffi.C[k] end

-- Syscalls that just return ENOSYS but are in libc.
local nosys_calls
if version == 6 then nosys_calls = {
  openat = true,
  faccessat = true,
  symlinkat = true,
  mkdirat = true,
  unlinkat = true,
  renameat = true,
  fstatat = true,
  fchmodat = true,
  fchownat = true,
  mkfifoat = true,
  mknodat = true,
}
end

local C = setmetatable({}, {
  __index = function(C, k)
    if nosys_calls and nosys_calls[k] then return nil end
    if pcall(inlibc_fn, k) then
      C[k] = ffi.C[k] -- add to table, so no need for this slow path again
      return C[k]
    else
      return nil
    end
  end
})

-- for NetBSD we use libc names not syscalls, as assume you will have libc linked or statically linked with all symbols exported.
-- this is so we can use NetBSD libc even where syscalls have been redirected to rump calls.

-- use new versions
C.mount = C.__mount50
C.stat = C.__stat50
C.fstat = C.__fstat50
C.lstat = C.__lstat50
C.getdents = C.__getdents30
C.socket = C.__socket30
C.select = C.__select50
C.pselect = C.__pselect50
C.fhopen = C.__fhopen40
C.fhstat = C.__fhstat50
C.fhstatvfs1 = C.__fhstatvfs140
C.utimes = C.__utimes50
C.posix_fadvise = C.__posix_fadvise50
C.lutimes = C.__lutimes50
C.futimes = C.__futimes50
C.getfh = C.__getfh30
C.kevent = C.__kevent50
C.mknod = C.__mknod50
C.pollts = C.__pollts50

C.gettimeofday = C.__gettimeofday50
C.settimeofday = C.__settimeofday50
C.adjtime = C.__adjtime50
C.setitimer = C.__setitimer50
C.getitimer = C.__getitimer50
C.clock_gettime = C.__clock_gettime50
C.clock_settime = C.__clock_settime50
C.clock_getres = C.__clock_getres50
C.nanosleep = C.__nanosleep50
C.timer_settime = C.__timer_settime50
C.timer_gettime = C.__timer_gettime50

-- use underlying syscall not wrapper
C.getcwd = C.__getcwd

C.sigaction = C.__libc_sigaction14 -- TODO not working I think need to use tramp_sigaction, see also netbsd pause()

return C