preliminary description of kdbus syscalls

This commit is contained in:
Dmitry Vyukov 2015-10-16 18:16:10 +02:00
parent 587db99baa
commit f8f416fb8f
11 changed files with 641 additions and 18 deletions

View File

@ -371,4 +371,20 @@ call_t syscalls[] = {
{"sched_getattr", __NR_sched_getattr},
{"sched_setattr", __NR_sched_setattr},
{"sched_yield", __NR_sched_yield},
{"ioctl$kdbus_bus_make", __NR_ioctl},
{"ioctl$kdbus_ep_make", __NR_ioctl},
{"ioctl$kdbus_ep_update", __NR_ioctl},
{"ioctl$kdbus_hello", __NR_ioctl},
{"ioctl$kdbus_name_acquire", __NR_ioctl},
{"ioctl$kdbus_name_release", __NR_ioctl},
{"ioctl$kdbus_free", __NR_ioctl},
{"ioctl$kdbus_recv", __NR_ioctl},
{"ioctl$kdbus_send", __NR_ioctl},
{"ioctl$kdbus_update", __NR_ioctl},
{"ioctl$kdbus_bye", __NR_ioctl},
{"ioctl$kdbus_conn_info", __NR_ioctl},
{"ioctl$kdbus_bus_info", __NR_ioctl},
{"ioctl$kdbus_list", __NR_ioctl},
{"ioctl$kdbus_match_add", __NR_ioctl},
{"ioctl$kdbus_match_remove", __NR_ioctl},
};

View File

@ -205,7 +205,7 @@ func assignTypeAndDir(c *Call) {
}
func sanitizeCall(c *Call) {
switch c.Meta.Name {
switch c.Meta.CallName {
case "mmap":
// Add MAP_FIXED flag, otherwise it produces non-deterministic results.
addr := c.Args[0]
@ -245,6 +245,13 @@ func sanitizeCall(c *Call) {
if cmd.Val == SYSLOG_ACTION_CONSOLE_OFF || cmd.Val == SYSLOG_ACTION_CONSOLE_ON {
cmd.Val = SYSLOG_ACTION_SIZE_UNREAD
}
case "ioctl":
cmd := c.Args[1]
// Freeze kills machine. Though, it is an interesting functions,
// so we need to test it somehow (TODO).
if uint32(cmd.Val) == uint32(FIFREEZE) {
cmd.Val = FITHAW
}
case "exit", "exit_group":
code := c.Args[0]
// These codes are reserved by executor.

View File

@ -288,6 +288,107 @@ const (
KCMP_SIGHAND = 4
KCMP_SYSVSEM = 6
KCMP_VM = 1
KDBUS_ATTACH_ANY = 18446744073709551615
KDBUS_ATTACH_AUDIT = 4096
KDBUS_ATTACH_AUXGROUPS = 8
KDBUS_ATTACH_CAPS = 1024
KDBUS_ATTACH_CGROUP = 512
KDBUS_ATTACH_CMDLINE = 256
KDBUS_ATTACH_CONN_DESCRIPTION = 8192
KDBUS_ATTACH_CREDS = 2
KDBUS_ATTACH_EXE = 128
KDBUS_ATTACH_NAMES = 16
KDBUS_ATTACH_PIDS = 4
KDBUS_ATTACH_PID_COMM = 64
KDBUS_ATTACH_SECLABEL = 2048
KDBUS_ATTACH_TID_COMM = 32
KDBUS_ATTACH_TIMESTAMP = 1
KDBUS_CMD_BUS_CREATOR_INFO = 2147784069
KDBUS_CMD_BUS_MAKE = 1074042112
KDBUS_CMD_BYEBYE = 1074042242
KDBUS_CMD_CONN_INFO = 2147784068
KDBUS_CMD_ENDPOINT_MAKE = 1074042128
KDBUS_CMD_ENDPOINT_UPDATE = 1074042129
KDBUS_CMD_FREE = 1074042243
KDBUS_CMD_HELLO = 3221525888
KDBUS_CMD_LIST = 2147784070
KDBUS_CMD_MATCH_ADD = 1074042288
KDBUS_CMD_MATCH_REMOVE = 1074042289
KDBUS_CMD_NAME_ACQUIRE = 1074042272
KDBUS_CMD_NAME_RELEASE = 1074042273
KDBUS_CMD_RECV = 2147784081
KDBUS_CMD_SEND = 1074042256
KDBUS_CMD_UPDATE = 1074042241
KDBUS_HELLO_ACCEPT_FD = 1
KDBUS_HELLO_ACTIVATOR = 2
KDBUS_HELLO_MONITOR = 8
KDBUS_HELLO_POLICY_HOLDER = 4
KDBUS_IOCTL_MAGIC = 149
KDBUS_ITEM_ATTACH_FLAGS_RECV = 13
KDBUS_ITEM_ATTACH_FLAGS_SEND = 12
KDBUS_ITEM_AUDIT = 4108
KDBUS_ITEM_AUXGROUPS = 4099
KDBUS_ITEM_BLOOM_FILTER = 8
KDBUS_ITEM_BLOOM_MASK = 9
KDBUS_ITEM_BLOOM_PARAMETER = 7
KDBUS_ITEM_CANCEL_FD = 6
KDBUS_ITEM_CAPS = 4106
KDBUS_ITEM_CGROUP = 4105
KDBUS_ITEM_CMDLINE = 4104
KDBUS_ITEM_CONN_DESCRIPTION = 4109
KDBUS_ITEM_CREDS = 4097
KDBUS_ITEM_DST_ID = 16
KDBUS_ITEM_DST_NAME = 10
KDBUS_ITEM_EXE = 4103
KDBUS_ITEM_FDS = 5
KDBUS_ITEM_ID = 14
KDBUS_ITEM_ID_ADD = 32771
KDBUS_ITEM_ID_REMOVE = 32772
KDBUS_ITEM_MAKE_NAME = 11
KDBUS_ITEM_NAME = 15
KDBUS_ITEM_NAME_ADD = 32768
KDBUS_ITEM_NAME_CHANGE = 32770
KDBUS_ITEM_NAME_REMOVE = 32769
KDBUS_ITEM_NEGOTIATE = 1
KDBUS_ITEM_OWNED_NAME = 4100
KDBUS_ITEM_PAYLOAD_MEMFD = 4
KDBUS_ITEM_PAYLOAD_OFF = 3
KDBUS_ITEM_PAYLOAD_VEC = 2
KDBUS_ITEM_PIDS = 4098
KDBUS_ITEM_PID_COM = 4102
KDBUS_ITEM_POLICY_ACCESS = 8192
KDBUS_ITEM_REPLY_DEAD = 32774
KDBUS_ITEM_REPLY_TIMEOUT = 32773
KDBUS_ITEM_SECLABEL = 4107
KDBUS_ITEM_TID_COMM = 4101
KDBUS_ITEM_TIMESTAMP = 4096
KDBUS_LIST_ACTIVATORS = 4
KDBUS_LIST_NAMES = 2
KDBUS_LIST_QUEUED = 8
KDBUS_LIST_UNIQUE = 1
KDBUS_MAKE_ACCESS_GROUP = 1
KDBUS_MAKE_ACCESS_WORLD = 2
KDBUS_MATCH_REPLACE = 1
KDBUS_MSG_EXPECT_REPLY = 1
KDBUS_MSG_NO_AUTO_START = 2
KDBUS_MSG_SIGNAL = 4
KDBUS_NAME_ACQUIRED = 64
KDBUS_NAME_ACTIVATOR = 16
KDBUS_NAME_ALLOW_REPLACEMENT = 2
KDBUS_NAME_IN_QUEUE = 8
KDBUS_NAME_PRIMARY = 32
KDBUS_NAME_QUEUE = 4
KDBUS_NAME_REPLACE_EXISTING = 1
KDBUS_POLICY_ACCESS_GROUP = 2
KDBUS_POLICY_ACCESS_NULL = 0
KDBUS_POLICY_ACCESS_USER = 1
KDBUS_POLICY_ACCESS_WORLD = 3
KDBUS_POLICY_OWN = 2
KDBUS_POLICY_SEE = 0
KDBUS_POLICY_TALK = 1
KDBUS_RECV_RETURN_DROPPED_MSGS = 2
KDBUS_RECV_RETURN_INCOMPLETE_FDS = 1
KDBUS_SEND_SYNC_REPLY = 1
KEXEC_ARCH_386 = 196608
KEXEC_ARCH_ARM = 2621440
KEXEC_ARCH_IA_64 = 3276800

View File

@ -149,6 +149,8 @@ func (p *Prog) Mutate(rs rand.Source, ncalls int, ct *ChoiceTable) {
}
case sys.LenType:
panic("bad arg returned by mutationArgs: LenType")
case sys.ConstType:
panic("bad arg returned by mutationArgs: ConstType")
default:
panic(fmt.Sprintf("bad arg returned by mutationArgs: %#v, type=%#v", *arg, arg.Type))
}
@ -301,6 +303,9 @@ func mutationArgs(c *Call) (args, bases []*Arg, parents []*[]*Arg) {
case sys.LenType:
// Size is updated when the size-of arg change.
return
case sys.ConstType:
// Well, this is const.
return
}
if arg.Dir == DirOut {
return

View File

@ -208,7 +208,8 @@ func foreachArgType(meta *sys.Call, f func(sys.Type, ArgDir)) {
rec(f, d)
}
case sys.ResourceType, sys.FileoffType, sys.BufferType,
sys.VmaType, sys.LenType, sys.FlagsType, sys.IntType, sys.FilenameType:
sys.VmaType, sys.LenType, sys.FlagsType, sys.ConstType,
sys.IntType, sys.FilenameType:
default:
panic("unknown type")
}

View File

@ -61,6 +61,8 @@ func (a *Arg) Size(typ sys.Type) uintptr {
return typ1.TypeSize
case sys.FlagsType:
return typ1.TypeSize
case sys.ConstType:
return typ1.TypeSize
case sys.FileoffType:
return typ1.TypeSize
case sys.ResourceType:

View File

@ -561,7 +561,19 @@ func (r *randGen) generateArgs(s *state, types []sys.Type, dir ArgDir) ([]*Arg,
sizes[typ.Name()] = size
}
}
// Pass 2: fill in size arguments.
// Pass 2: calculate size of the whole struct.
// Now we know sizes of all non-size arguments and size arguments are const-size.
var parentSize uintptr
for i, typ := range types {
parentSize += args[i].Size(typ)
}
if sizes["parent"] != nil {
panic("parent is reserved len name")
}
sizes["parent"] = constArg(parentSize)
// Pass 3: fill in size arguments.
for i, typ := range types {
if a, ok := typ.(sys.LenType); ok {
size := sizes[a.Buf]
@ -581,7 +593,7 @@ func (r *randGen) generateArg(s *state, typ sys.Type, dir ArgDir, sizes map[stri
// in subsequent calls. For the same reason we do generate pointer/array/struct
// output arguments (their elements can be referenced in subsequent calls).
switch typ.(type) {
case sys.IntType, sys.FlagsType, sys.FileoffType, sys.ResourceType:
case sys.IntType, sys.FlagsType, sys.ConstType, sys.FileoffType, sys.ResourceType:
return constArg(0), nil, nil
}
}
@ -668,6 +680,8 @@ func (r *randGen) generateArg(s *state, typ sys.Type, dir ArgDir, sizes map[stri
return arg, pageSizeArg(npages, 0), nil
case sys.FlagsType:
return constArg(r.flags(a.Vals)), nil, nil
case sys.ConstType:
return constArg(a.Val), nil, nil
case sys.IntType:
v := r.randInt()
switch a.Kind {

View File

@ -210,6 +210,12 @@ type FlagsType struct {
Vals []uintptr
}
type ConstType struct {
TypeCommon
TypeSize uintptr
Val uintptr
}
type IntKind int
const (

File diff suppressed because one or more lines are too long

View File

@ -146,7 +146,7 @@ mlock(addr vma, size len[addr])
munlock(addr vma, size len[addr])
mlockall(flags flags[mlockall_flags])
munlockall()
memfd_create(name string, flags flags[memfd_flags])
memfd_create(name string, flags flags[memfd_flags]) fd
unshare(flags flags[clone_flags])
kcmp(pid1 pid, pid2 pid, type flags[kcmp_flags], fd1 fd, fd2 fd)
@ -1433,3 +1433,441 @@ define F_SEAL_WRITE 0x0008
#define __NR_sched_get_priority_max 146
#define __NR_sched_get_priority_min 147
ioctl$kdbus_bus_make(fd fd, cmd const[KDBUS_CMD_BUS_MAKE], arg ptr[in, kdbus_cmd_bus_make])
ioctl$kdbus_ep_make(fd fd, cmd const[KDBUS_CMD_ENDPOINT_MAKE], arg ptr[in, kdbus_cmd_ep_make])
ioctl$kdbus_ep_update(fd fd, cmd const[KDBUS_CMD_ENDPOINT_UPDATE], arg ptr[in, kdbus_cmd_ep_update])
ioctl$kdbus_hello(fd fd, cmd const[KDBUS_CMD_HELLO], arg ptr[in, kdbus_cmd_hello])
ioctl$kdbus_name_acquire(fd fd, cmd const[KDBUS_CMD_NAME_ACQUIRE], arg ptr[in, kdbus_cmd_name_acquire])
ioctl$kdbus_name_release(fd fd, cmd const[KDBUS_CMD_NAME_RELEASE], arg ptr[in, kdbus_cmd_name_release])
ioctl$kdbus_free(fd fd, cmd const[KDBUS_CMD_FREE], arg ptr[in, kdbus_cmd_free])
ioctl$kdbus_recv(fd fd, cmd const[KDBUS_CMD_RECV], arg ptr[in, kdbus_cmd_recv])
ioctl$kdbus_send(fd fd, cmd const[KDBUS_CMD_SEND], arg ptr[in, kdbus_cmd_send])
ioctl$kdbus_update(fd fd, cmd const[KDBUS_CMD_UPDATE], arg ptr[in, kdbus_cmd_update])
ioctl$kdbus_bye(fd fd, cmd const[KDBUS_CMD_BYEBYE], arg ptr[in, kdbus_cmd_bye])
ioctl$kdbus_conn_info(fd fd, cmd const[KDBUS_CMD_CONN_INFO], arg ptr[in, kdbus_cmd_info])
ioctl$kdbus_bus_info(fd fd, cmd const[KDBUS_CMD_BUS_CREATOR_INFO], arg ptr[in, kdbus_cmd_info])
ioctl$kdbus_list(fd fd, cmd const[KDBUS_CMD_LIST], arg ptr[in, kdbus_cmd_list])
ioctl$kdbus_match_add(fd fd, cmd const[KDBUS_CMD_MATCH_ADD], arg ptr[in, kdbus_cmd_match])
ioctl$kdbus_match_remove(fd fd, cmd const[KDBUS_CMD_MATCH_REMOVE], arg ptr[in, kdbus_cmd_match])
kdbus_cmd_bus_make {
size len[parent, int64]
flags flags[kdbus_make_flags, int64]
rflags const[0, int64]
bloom kdbus_bloom_parameter
name kdbus_make_name_parameter
}
kdbus_cmd_ep_make {
size len[parent, int64]
flags flags[kdbus_make_flags, int64]
rflags const[0, int64]
name kdbus_make_name_parameter
}
kdbus_cmd_ep_update {
size len[parent, int64]
flags flags[kdbus_make_flags, int64]
rflags const[0, int64]
name kdbus_make_name_parameter
policy kdbus_policy_parameter
}
kdbus_cmd_hello {
size len[parent, int64]
flags flags[kdbus_hello_flags, int64]
rflags const[0, int64]
sflags flags[kdbus_attach_flags, int64]
rflags flags[kdbus_attach_flags, int64]
bflags int64
id int64
poolsz int64
off int64
isize int64
id0 int64
id1 int64
name kdbus_make_name_parameter
policy kdbus_policy_parameter
pids kdbus_pids_parameter
creds kdbus_creds_parameter
seclab kdbus_seclabel_parameter
}
kdbus_cmd_bye {
size len[parent, int64]
flags const[0, int64]
rflags const[0, int64]
}
kdbus_cmd_list {
size len[parent, int64]
flags flags[kdbus_list_flags, int64]
rflags const[0, int64]
off int64
lsize const[0, int64]
}
kdbus_cmd_update {
size len[parent, int64]
flags flags[kdbus_name_flags, int64]
rflags const[0, int64]
name kdbus_make_name_parameter
policy kdbus_policy_parameter
attach kdbus_attach_flags_parameter
}
kdbus_cmd_name_acquire {
size len[parent, int64]
flags flags[kdbus_name_flags, int64]
rflags const[0, int64]
name kdbus_make_name_parameter
}
kdbus_cmd_name_release {
size len[parent, int64]
flags const[0, int64]
rflags const[0, int64]
name kdbus_make_name_parameter
}
kdbus_cmd_match {
size len[parent, int64]
flags flags[kdbus_match_flags, int64]
rflags const[0, int64]
# TODO: this needs to match between add and remove
cookie int64
bloom kdbus_bloom_parameter
name0 kdbus_name_parameter
name1 kdbus_name_parameter
name2 kdbus_name_parameter
name3 kdbus_name_parameter
idadd kdbus_id_change_parameter
idremov kdbus_id_change_parameter
id kdbus_id_parameter
dstid kdbus_id_parameter
}
kdbus_cmd_free {
size len[parent, int64]
flags int64
rflags const[0, int64]
off int64
# TODO: followed by arbitrary sequence of parameters
}
kdbus_cmd_recv {
size len[parent, int64]
flags flags[kdbus_recv_flags, int64]
rflags const[0, int64]
prio int64
dropped int64
msg kdbus_msg_info
# TODO: followed by arbitrary sequence of parameters
}
kdbus_cmd_send {
size len[parent, int64]
flags flags[kdbus_send_flags, int64]
rflags const[0, int64]
msg ptr[in, kdbus_msg]
reply kdbus_msg_info
fd kdbus_fd_parameter
}
kdbus_msg {
size len[parent, int64]
flags flags[kdbus_msg_flags, int64]
rflags const[0, int64]
vec0 kdbus_payload_vec
vec1 kdbus_payload_vec
memfd0 kdbus_payload_memfd
memfd1 kdbus_payload_memfd
fds kdbus_fd_parameter
bloom kdbus_bloom_parameter
dname kdbus_dst_name_parameter
}
kdbus_msg_info {
off int64
size int64
rflags const[0, int64]
}
kdbus_cmd_info {
size len[parent, int64]
flags const[0, int64]
rflags const[0, int64]
# TODO: this is connection id, need to extract it from somewhere
id int64
aflags flags[kdbus_attach_flags, int64]
# TODO: off is offset in the caller's pool buffer where the kdbus_info struct result is stored.
# It needs to be passed to KDBUS_CMD_FREE, so it should be a resource.
off int64
isize const[0, int64]
# TODO: name is optional if id is specified
name kdbus_make_name_parameter
}
kdbus_bloom_parameter {
size len[parent, int64]
type const[KDBUS_ITEM_BLOOM_PARAMETER, int64]
bsize int64
hash int64
}
kdbus_make_name_parameter {
size len[parent, int64]
type const[KDBUS_ITEM_MAKE_NAME, int64]
# TODO: this is embed strz buffer of variable-length
name int64
}
kdbus_dst_name_parameter {
size len[parent, int64]
type const[KDBUS_ITEM_DST_NAME, int64]
# TODO: this is embed strz buffer of variable-length
name int64
}
kdbus_name_parameter {
size len[parent, int64]
type flags[kdbus_name_params, int64]
flags flags[kdbus_name_flags, int64]
# TODO: this is embed var-len string
name int64
}
kdbus_negotiate_parameter {
size len[parent, int64]
type const[KDBUS_ITEM_NEGOTIATE, int64]
}
kdbus_policy_parameter {
size len[parent, int64]
type const[KDBUS_ITEM_POLICY_ACCESS, int64]
ptype flags[kdbus_policy_access, int64]
access flags[kdbus_policy_flags, int64]
id uid
}
kdbus_attach_flags_parameter {
size len[parent, int64]
type flags[kdbug_attach_type, int64]
flags flags[kdbus_attach_flags, int64]
}
kdbus_fd_parameter {
size len[parent, int64]
type const[KDBUS_ITEM_CANCEL_FD, int64]
# TODO: this can be embed var-len array
fd fd
}
kdbus_pids_parameter {
size len[parent, int64]
type const[KDBUS_ITEM_PIDS, int64]
pid pid
pad0 int32
tid pid
pad1 int32
ppid pid
pad2 int32
}
kdbus_creds_parameter {
size len[parent, int64]
type const[KDBUS_ITEM_CREDS, int64]
uid uid
pad0 int32
euid uid
pad1 int32
suid uid
pad2 int32
fsuid uid
pad3 int32
gid uid
pad4 int32
egid uid
pad5 int32
sgid uid
pad6 int32
fsgid uid
pad7 int32
}
kdbus_seclabel_parameter {
size len[parent, int64]
type const[KDBUS_ITEM_SECLABEL, int64]
# TODO: this is some var-len string of unknown nature
label int64
}
kdbus_payload_vec {
size len[parent, int64]
type const[KDBUS_ITEM_PAYLOAD_VEC, int64]
size len[data, int64]
data buffer[in]
}
kdbus_payload_memfd {
size len[parent, int64]
type const[KDBUS_ITEM_PAYLOAD_MEMFD, int64]
start int64
size int64
fd fd
pad int32
}
kdbus_id_change_parameter {
size len[parent, int64]
type flags[kdbus_id_change_type, int64]
id const[0, int64]
flags const[0, int64]
}
kdbus_id_parameter {
size len[parent, int64]
type flags[kdbus_id_type, int64]
# TODO: what is this id?
id int64
}
kdbus_make_flags = KDBUS_MAKE_ACCESS_GROUP, KDBUS_MAKE_ACCESS_WORLD
kdbus_hello_flags = KDBUS_HELLO_ACCEPT_FD, KDBUS_HELLO_ACTIVATOR, KDBUS_HELLO_POLICY_HOLDER, KDBUS_HELLO_MONITOR
kdbus_attach_flags = KDBUS_ATTACH_TIMESTAMP, KDBUS_ATTACH_CREDS, KDBUS_ATTACH_PIDS, KDBUS_ATTACH_AUXGROUPS, KDBUS_ATTACH_NAMES, KDBUS_ATTACH_TID_COMM, KDBUS_ATTACH_PID_COMM, KDBUS_ATTACH_EXE, KDBUS_ATTACH_CMDLINE, KDBUS_ATTACH_CGROUP, KDBUS_ATTACH_CAPS, KDBUS_ATTACH_SECLABEL, KDBUS_ATTACH_AUDIT, KDBUS_ATTACH_CONN_DESCRIPTION, KDBUS_ATTACH_ANY
kdbus_name_flags = KDBUS_NAME_REPLACE_EXISTING, KDBUS_NAME_ALLOW_REPLACEMENT, KDBUS_NAME_QUEUE, KDBUS_NAME_IN_QUEUE, KDBUS_NAME_ACTIVATOR, KDBUS_NAME_PRIMARY, KDBUS_NAME_ACQUIRED
kdbus_recv_flags = KDBUS_RECV_RETURN_INCOMPLETE_FDS, KDBUS_RECV_RETURN_DROPPED_MSGS
kdbus_send_flags = KDBUS_SEND_SYNC_REPLY
kdbus_policy_access = KDBUS_POLICY_ACCESS_NULL, KDBUS_POLICY_ACCESS_USER, KDBUS_POLICY_ACCESS_GROUP, KDBUS_POLICY_ACCESS_WORLD
kdbus_policy_flags = KDBUS_POLICY_OWN, KDBUS_POLICY_TALK, KDBUS_POLICY_SEE
kdbug_attach_type = KDBUS_ITEM_ATTACH_FLAGS_SEND, KDBUS_ITEM_ATTACH_FLAGS_RECV
kdbus_msg_flags = KDBUS_MSG_EXPECT_REPLY, KDBUS_MSG_NO_AUTO_START, KDBUS_MSG_SIGNAL
kdbus_list_flags = KDBUS_LIST_UNIQUE, KDBUS_LIST_NAMES, KDBUS_LIST_ACTIVATORS, KDBUS_LIST_QUEUED
kdbus_match_flags = KDBUS_MATCH_REPLACE
kdbus_name_params = KDBUS_ITEM_NAME, KDBUS_ITEM_NAME_ADD, KDBUS_ITEM_NAME_REMOVE, KDBUS_ITEM_NAME_CHANGE
kdbus_id_change_type = KDBUS_ITEM_ID_ADD, KDBUS_ITEM_ID_REMOVE
kdbus_id_type = KDBUS_ITEM_ID, KDBUS_ITEM_DST_ID
define KDBUS_IOCTL_MAGIC 0x95
define KDBUS_CMD_BUS_MAKE _IOW(KDBUS_IOCTL_MAGIC, 0x00, int)
define KDBUS_CMD_ENDPOINT_MAKE _IOW(KDBUS_IOCTL_MAGIC, 0x10, int)
define KDBUS_CMD_ENDPOINT_UPDATE _IOW(KDBUS_IOCTL_MAGIC, 0x11, int)
define KDBUS_CMD_HELLO _IOWR(KDBUS_IOCTL_MAGIC, 0x80, int)
define KDBUS_CMD_UPDATE _IOW(KDBUS_IOCTL_MAGIC, 0x81, int)
define KDBUS_CMD_BYEBYE _IOW(KDBUS_IOCTL_MAGIC, 0x82, int)
define KDBUS_CMD_FREE _IOW(KDBUS_IOCTL_MAGIC, 0x83, int)
define KDBUS_CMD_CONN_INFO _IOR(KDBUS_IOCTL_MAGIC, 0x84, int)
define KDBUS_CMD_BUS_CREATOR_INFO _IOR(KDBUS_IOCTL_MAGIC, 0x85, int)
define KDBUS_CMD_LIST _IOR(KDBUS_IOCTL_MAGIC, 0x86, int)
define KDBUS_CMD_SEND _IOW(KDBUS_IOCTL_MAGIC, 0x90, int)
define KDBUS_CMD_RECV _IOR(KDBUS_IOCTL_MAGIC, 0x91, int)
define KDBUS_CMD_NAME_ACQUIRE _IOW(KDBUS_IOCTL_MAGIC, 0xa0, int)
define KDBUS_CMD_NAME_RELEASE _IOW(KDBUS_IOCTL_MAGIC, 0xa1, int)
define KDBUS_CMD_MATCH_ADD _IOW(KDBUS_IOCTL_MAGIC, 0xb0, int)
define KDBUS_CMD_MATCH_REMOVE _IOW(KDBUS_IOCTL_MAGIC, 0xb1, int)
define KDBUS_MAKE_ACCESS_GROUP (1ULL << 0)
define KDBUS_MAKE_ACCESS_WORLD (1ULL << 1)
define KDBUS_HELLO_ACCEPT_FD (1ULL << 0)
define KDBUS_HELLO_ACTIVATOR (1ULL << 1)
define KDBUS_HELLO_POLICY_HOLDER (1ULL << 2)
define KDBUS_HELLO_MONITOR (1ULL << 3)
define KDBUS_ATTACH_TIMESTAMP 1ULL << 0
define KDBUS_ATTACH_CREDS 1ULL << 1
define KDBUS_ATTACH_PIDS 1ULL << 2
define KDBUS_ATTACH_AUXGROUPS 1ULL << 3
define KDBUS_ATTACH_NAMES 1ULL << 4
define KDBUS_ATTACH_TID_COMM 1ULL << 5
define KDBUS_ATTACH_PID_COMM 1ULL << 6
define KDBUS_ATTACH_EXE 1ULL << 7
define KDBUS_ATTACH_CMDLINE 1ULL << 8
define KDBUS_ATTACH_CGROUP 1ULL << 9
define KDBUS_ATTACH_CAPS 1ULL << 10
define KDBUS_ATTACH_SECLABEL 1ULL << 11
define KDBUS_ATTACH_AUDIT 1ULL << 12
define KDBUS_ATTACH_CONN_DESCRIPTION 1ULL << 13
define KDBUS_ATTACH_ANY ~0ULL
define KDBUS_NAME_REPLACE_EXISTING 1ULL << 0
define KDBUS_NAME_ALLOW_REPLACEMENT 1ULL << 1
define KDBUS_NAME_QUEUE 1ULL << 2
define KDBUS_NAME_IN_QUEUE 1ULL << 3
define KDBUS_NAME_ACTIVATOR 1ULL << 4
define KDBUS_NAME_PRIMARY 1ULL << 5
define KDBUS_NAME_ACQUIRED 1ULL << 6
define KDBUS_RECV_RETURN_INCOMPLETE_FDS 1ULL << 0
define KDBUS_RECV_RETURN_DROPPED_MSGS 1ULL << 1
define KDBUS_SEND_SYNC_REPLY 1ULL << 0
define KDBUS_LIST_UNIQUE 1ULL << 0
define KDBUS_LIST_NAMES 1ULL << 1
define KDBUS_LIST_ACTIVATORS 1ULL << 2
define KDBUS_LIST_QUEUED 1ULL << 3
define KDBUS_POLICY_ACCESS_NULL 0
define KDBUS_POLICY_ACCESS_USER 1
define KDBUS_POLICY_ACCESS_GROUP 2
define KDBUS_POLICY_ACCESS_WORLD 3
define KDBUS_POLICY_SEE 0
define KDBUS_POLICY_TALK 1
define KDBUS_POLICY_OWN 2
define KDBUS_MATCH_REPLACE 1ULL << 0
define KDBUS_MSG_EXPECT_REPLY 1ULL << 0
define KDBUS_MSG_NO_AUTO_START 1ULL << 1
define KDBUS_MSG_SIGNAL 1ULL << 2
define KDBUS_ITEM_NEGOTIATE 1
define KDBUS_ITEM_PAYLOAD_VEC 2
define KDBUS_ITEM_PAYLOAD_OFF 3
define KDBUS_ITEM_PAYLOAD_MEMFD 4
define KDBUS_ITEM_FDS 5
define KDBUS_ITEM_CANCEL_FD 6
define KDBUS_ITEM_BLOOM_PARAMETER 7
define KDBUS_ITEM_BLOOM_FILTER 8
define KDBUS_ITEM_BLOOM_MASK 9
define KDBUS_ITEM_DST_NAME 10
define KDBUS_ITEM_MAKE_NAME 11
define KDBUS_ITEM_ATTACH_FLAGS_SEND 12
define KDBUS_ITEM_ATTACH_FLAGS_RECV 13
define KDBUS_ITEM_ID 14
define KDBUS_ITEM_NAME 15
define KDBUS_ITEM_DST_ID 16
define KDBUS_ITEM_TIMESTAMP (0x1000 + 0)
define KDBUS_ITEM_CREDS (0x1000 + 1)
define KDBUS_ITEM_PIDS (0x1000 + 2)
define KDBUS_ITEM_AUXGROUPS (0x1000 + 3)
define KDBUS_ITEM_OWNED_NAME (0x1000 + 4)
define KDBUS_ITEM_TID_COMM (0x1000 + 5)
define KDBUS_ITEM_PID_COM (0x1000 + 6)
define KDBUS_ITEM_EXE (0x1000 + 7)
define KDBUS_ITEM_CMDLINE (0x1000 + 8)
define KDBUS_ITEM_CGROUP (0x1000 + 9)
define KDBUS_ITEM_CAPS (0x1000 + 10)
define KDBUS_ITEM_SECLABEL (0x1000 + 11)
define KDBUS_ITEM_AUDIT (0x1000 + 12)
define KDBUS_ITEM_CONN_DESCRIPTION (0x1000 + 13)
define KDBUS_ITEM_POLICY_ACCESS (0x2000 + 0)
define KDBUS_ITEM_NAME_ADD (0x8000 + 0)
define KDBUS_ITEM_NAME_REMOVE (0x8000 + 1)
define KDBUS_ITEM_NAME_CHANGE (0x8000 + 2)
define KDBUS_ITEM_ID_ADD (0x8000 + 3)
define KDBUS_ITEM_ID_REMOVE (0x8000 + 4)
define KDBUS_ITEM_REPLY_TIMEOUT (0x8000 + 5)
define KDBUS_ITEM_REPLY_DEAD (0x8000 + 6)

View File

@ -31,7 +31,7 @@ func main() {
intFlags, flagVals := compileFlags(includes, defines, flags)
out := new(bytes.Buffer)
generate(syscalls, structs, unnamed, intFlags, out)
generate(syscalls, structs, unnamed, intFlags, flagVals, out)
writeSource("sys.go", out.Bytes())
out = new(bytes.Buffer)
@ -60,7 +60,7 @@ type Flag struct {
Values []string
}
func generate(syscalls []Syscall, structs map[string]Struct, unnamed map[string][]string, flags map[string][]string, out io.Writer) {
func generate(syscalls []Syscall, structs map[string]Struct, unnamed map[string][]string, flags map[string][]string, flagVals map[string]string, out io.Writer) {
fmt.Fprintf(out, "// AUTOGENERATED FILE\n")
fmt.Fprintf(out, "package sys\n\n")
@ -69,21 +69,21 @@ func generate(syscalls []Syscall, structs map[string]Struct, unnamed map[string]
fmt.Fprintf(out, "&Call{ID: %v, Name: \"%v\", CallName: \"%v\"", i, s.Name, s.CallName)
if len(s.Ret) != 0 {
fmt.Fprintf(out, ", Ret: ")
generateArg("ret", s.Ret[0], s.Ret[1:], structs, unnamed, flags, false, out)
generateArg("ret", s.Ret[0], s.Ret[1:], structs, unnamed, flags, flagVals, false, out)
}
fmt.Fprintf(out, ", Args: []Type{")
for i, a := range s.Args {
if i != 0 {
fmt.Fprintf(out, ", ")
}
generateArg(a[0], a[1], a[2:], structs, unnamed, flags, false, out)
generateArg(a[0], a[1], a[2:], structs, unnamed, flags, flagVals, false, out)
}
fmt.Fprintf(out, "}},\n")
}
fmt.Fprintf(out, "}\n")
}
func generateArg(name, typ string, a []string, structs map[string]Struct, unnamed map[string][]string, flags map[string][]string, isField bool, out io.Writer) {
func generateArg(name, typ string, a []string, structs map[string]Struct, unnamed map[string][]string, flags map[string][]string, flagVals map[string]string, isField bool, out io.Writer) {
name = "\"" + name + "\""
opt := false
for i, v := range a {
@ -220,6 +220,23 @@ func generateArg(name, typ string, a []string, structs map[string]Struct, unname
failf("unknown flag %v", a[0])
}
fmt.Fprintf(out, "FlagsType{%v, TypeSize: %v, Vals: []uintptr{%v}}", common(), size, strings.Join(vals, ","))
case "const":
var size uint64
if isField {
if want := 2; len(a) != want {
failf("wrong number of arguments for %v arg %v, want %v, got %v", typ, name, want, len(a))
}
size = typeToSize(a[1])
} else {
if want := 1; len(a) != want {
failf("wrong number of arguments for %v arg %v, want %v, got %v", typ, name, want, len(a))
}
}
val := flagVals[a[0]]
if val == "" {
val = a[0]
}
fmt.Fprintf(out, "ConstType{%v, TypeSize: %v, Val: uintptr(%v)}", common(), size, val)
case "int8", "int16", "int32", "int64", "intptr":
if want := 0; len(a) != want {
failf("wrong number of arguments for %v arg %v, want %v, got %v", typ, name, want, len(a))
@ -246,16 +263,16 @@ func generateArg(name, typ string, a []string, structs map[string]Struct, unname
if want := 1; len(a) != want {
failf("wrong number of arguments for %v arg %v, want %v, got %v", typ, name, want, len(a))
}
fmt.Fprintf(out, "ArrayType{%v, Type: %v}", common(), generateType(a[0], structs, unnamed, flags))
fmt.Fprintf(out, "ArrayType{%v, Type: %v}", common(), generateType(a[0], structs, unnamed, flags, flagVals))
case "ptr":
if want := 2; len(a) != want {
failf("wrong number of arguments for %v arg %v, want %v, got %v", typ, name, want, len(a))
}
fmt.Fprintf(out, "PtrType{%v, Type: %v, Dir: %v}", common(), generateType(a[1], structs, unnamed, flags), fmtDir(a[0]))
fmt.Fprintf(out, "PtrType{%v, Type: %v, Dir: %v}", common(), generateType(a[1], structs, unnamed, flags, flagVals), fmtDir(a[0]))
default:
if strings.HasPrefix(typ, "unnamed") {
if inner, ok := unnamed[typ]; ok {
generateArg("", inner[0], inner[1:], structs, unnamed, flags, isField, out)
generateArg("", inner[0], inner[1:], structs, unnamed, flags, flagVals, isField, out)
return
}
failf("unknown unnamed type '%v'", typ)
@ -266,7 +283,7 @@ func generateArg(name, typ string, a []string, structs map[string]Struct, unname
if i != 0 {
fmt.Fprintf(out, ", ")
}
generateArg(a[0], a[1], a[2:], structs, unnamed, flags, true, out)
generateArg(a[0], a[1], a[2:], structs, unnamed, flags, flagVals, true, out)
}
fmt.Fprintf(out, "}}")
return
@ -275,9 +292,9 @@ func generateArg(name, typ string, a []string, structs map[string]Struct, unname
}
}
func generateType(typ string, structs map[string]Struct, unnamed map[string][]string, flags map[string][]string) string {
func generateType(typ string, structs map[string]Struct, unnamed map[string][]string, flags map[string][]string, flagVals map[string]string) string {
buf := new(bytes.Buffer)
generateArg("", typ, nil, structs, unnamed, flags, true, buf)
generateArg("", typ, nil, structs, unnamed, flags, flagVals, true, buf)
return buf.String()
}
@ -545,7 +562,7 @@ func parse(in io.Reader) (includes []string, defines map[string]string, syscalls
if defines[key] != "" {
failf("%v define is defined multiple times", key)
}
defines[key] = string(val)
defines[key] = fmt.Sprintf("(%s)", val)
} else {
switch p.Char() {
case '(':