diff --git a/home/nipa/nipa_out/909408/ynl/new-code/binder_genl-user.c b/home/nipa/nipa_out/909408/ynl/new-code/binder_genl-user.c new file mode 100644 index 000000000000..a7afb50eebc5 --- /dev/null +++ b/home/nipa/nipa_out/909408/ynl/new-code/binder_genl-user.c @@ -0,0 +1,254 @@ +// SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/binder_genl.yaml */ +/* YNL-GEN user source */ + +#include +#include +#include "binder_genl-user.h" +#include "ynl.h" +#include + +#include + +/* Enums */ +static const char * const binder_genl_op_strmap[] = { + [BINDER_GENL_CMD_SET] = "set", + [BINDER_GENL_CMD_REPORT] = "report", +}; + +const char *binder_genl_op_str(int op) +{ + if (op < 0 || op >= (int)YNL_ARRAY_SIZE(binder_genl_op_strmap)) + return NULL; + return binder_genl_op_strmap[op]; +} + +static const char * const binder_genl_flag_strmap[] = { + [0] = "failed", + [1] = "delayed", + [2] = "spam", + [3] = "override", +}; + +const char *binder_genl_flag_str(enum binder_genl_flag value) +{ + value = ffs(value) - 1; + if (value < 0 || value >= (int)YNL_ARRAY_SIZE(binder_genl_flag_strmap)) + return NULL; + return binder_genl_flag_strmap[value]; +} + +/* Policies */ +const struct ynl_policy_attr binder_genl_cmd_policy[BINDER_GENL_A_CMD_MAX + 1] = { + [BINDER_GENL_A_CMD_CONTEXT] = { .name = "context", .type = YNL_PT_NUL_STR, }, + [BINDER_GENL_A_CMD_PID] = { .name = "pid", .type = YNL_PT_U32, }, + [BINDER_GENL_A_CMD_FLAGS] = { .name = "flags", .type = YNL_PT_U32, }, +}; + +const struct ynl_policy_nest binder_genl_cmd_nest = { + .max_attr = BINDER_GENL_A_CMD_MAX, + .table = binder_genl_cmd_policy, +}; + +const struct ynl_policy_attr binder_genl_report_policy[BINDER_GENL_A_REPORT_MAX + 1] = { + [BINDER_GENL_A_REPORT_CONTEXT] = { .name = "context", .type = YNL_PT_NUL_STR, }, + [BINDER_GENL_A_REPORT_ERR] = { .name = "err", .type = YNL_PT_U32, }, + [BINDER_GENL_A_REPORT_FROM_PID] = { .name = "from_pid", .type = YNL_PT_U32, }, + [BINDER_GENL_A_REPORT_FROM_TID] = { .name = "from_tid", .type = YNL_PT_U32, }, + [BINDER_GENL_A_REPORT_TO_PID] = { .name = "to_pid", .type = YNL_PT_U32, }, + [BINDER_GENL_A_REPORT_TO_TID] = { .name = "to_tid", .type = YNL_PT_U32, }, + [BINDER_GENL_A_REPORT_REPLY] = { .name = "reply", .type = YNL_PT_U32, }, + [BINDER_GENL_A_REPORT_FLAGS] = { .name = "flags", .type = YNL_PT_U32, }, + [BINDER_GENL_A_REPORT_CODE] = { .name = "code", .type = YNL_PT_U32, }, + [BINDER_GENL_A_REPORT_DATA_SIZE] = { .name = "data_size", .type = YNL_PT_U32, }, +}; + +const struct ynl_policy_nest binder_genl_report_nest = { + .max_attr = BINDER_GENL_A_REPORT_MAX, + .table = binder_genl_report_policy, +}; + +/* Common nested types */ +/* ============== BINDER_GENL_CMD_SET ============== */ +/* BINDER_GENL_CMD_SET - do */ +void binder_genl_set_req_free(struct binder_genl_set_req *req) +{ + free(req->context); + free(req); +} + +void binder_genl_set_rsp_free(struct binder_genl_set_rsp *rsp) +{ + free(rsp->context); + free(rsp); +} + +int binder_genl_set_rsp_parse(const struct nlmsghdr *nlh, + struct ynl_parse_arg *yarg) +{ + struct binder_genl_set_rsp *dst; + const struct nlattr *attr; + + dst = yarg->data; + + ynl_attr_for_each(attr, nlh, yarg->ys->family->hdr_len) { + unsigned int type = ynl_attr_type(attr); + + if (type == BINDER_GENL_A_CMD_CONTEXT) { + unsigned int len; + + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + + len = strnlen(ynl_attr_get_str(attr), ynl_attr_data_len(attr)); + dst->_present.context_len = len; + dst->context = malloc(len + 1); + memcpy(dst->context, ynl_attr_get_str(attr), len); + dst->context[len] = 0; + } else if (type == BINDER_GENL_A_CMD_PID) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.pid = 1; + dst->pid = ynl_attr_get_u32(attr); + } else if (type == BINDER_GENL_A_CMD_FLAGS) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.flags = 1; + dst->flags = ynl_attr_get_u32(attr); + } + } + + return YNL_PARSE_CB_OK; +} + +struct binder_genl_set_rsp * +binder_genl_set(struct ynl_sock *ys, struct binder_genl_set_req *req) +{ + struct ynl_req_state yrs = { .yarg = { .ys = ys, }, }; + struct binder_genl_set_rsp *rsp; + struct nlmsghdr *nlh; + int err; + + nlh = ynl_gemsg_start_req(ys, ys->family_id, BINDER_GENL_CMD_SET, 1); + ys->req_policy = &binder_genl_cmd_nest; + yrs.yarg.rsp_policy = &binder_genl_cmd_nest; + + if (req->_present.context_len) + ynl_attr_put_str(nlh, BINDER_GENL_A_CMD_CONTEXT, req->context); + if (req->_present.pid) + ynl_attr_put_u32(nlh, BINDER_GENL_A_CMD_PID, req->pid); + if (req->_present.flags) + ynl_attr_put_u32(nlh, BINDER_GENL_A_CMD_FLAGS, req->flags); + + rsp = calloc(1, sizeof(*rsp)); + yrs.yarg.data = rsp; + yrs.cb = binder_genl_set_rsp_parse; + yrs.rsp_cmd = BINDER_GENL_CMD_SET; + + err = ynl_exec(ys, nlh, &yrs); + if (err < 0) + goto err_free; + + return rsp; + +err_free: + binder_genl_set_rsp_free(rsp); + return NULL; +} + +/* BINDER_GENL_CMD_REPORT - event */ +int binder_genl_report_rsp_parse(const struct nlmsghdr *nlh, + struct ynl_parse_arg *yarg) +{ + struct binder_genl_report_rsp *dst; + const struct nlattr *attr; + + dst = yarg->data; + + ynl_attr_for_each(attr, nlh, yarg->ys->family->hdr_len) { + unsigned int type = ynl_attr_type(attr); + + if (type == BINDER_GENL_A_REPORT_CONTEXT) { + unsigned int len; + + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + + len = strnlen(ynl_attr_get_str(attr), ynl_attr_data_len(attr)); + dst->_present.context_len = len; + dst->context = malloc(len + 1); + memcpy(dst->context, ynl_attr_get_str(attr), len); + dst->context[len] = 0; + } else if (type == BINDER_GENL_A_REPORT_ERR) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.err = 1; + dst->err = ynl_attr_get_u32(attr); + } else if (type == BINDER_GENL_A_REPORT_FROM_PID) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.from_pid = 1; + dst->from_pid = ynl_attr_get_u32(attr); + } else if (type == BINDER_GENL_A_REPORT_FROM_TID) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.from_tid = 1; + dst->from_tid = ynl_attr_get_u32(attr); + } else if (type == BINDER_GENL_A_REPORT_TO_PID) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.to_pid = 1; + dst->to_pid = ynl_attr_get_u32(attr); + } else if (type == BINDER_GENL_A_REPORT_TO_TID) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.to_tid = 1; + dst->to_tid = ynl_attr_get_u32(attr); + } else if (type == BINDER_GENL_A_REPORT_REPLY) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.reply = 1; + dst->reply = ynl_attr_get_u32(attr); + } else if (type == BINDER_GENL_A_REPORT_FLAGS) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.flags = 1; + dst->flags = ynl_attr_get_u32(attr); + } else if (type == BINDER_GENL_A_REPORT_CODE) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.code = 1; + dst->code = ynl_attr_get_u32(attr); + } else if (type == BINDER_GENL_A_REPORT_DATA_SIZE) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.data_size = 1; + dst->data_size = ynl_attr_get_u32(attr); + } + } + + return YNL_PARSE_CB_OK; +} + +void binder_genl_report_free(struct binder_genl_report *rsp) +{ + free(rsp->obj.context); + free(rsp); +} + +static const struct ynl_ntf_info binder_genl_ntf_info[] = { + [BINDER_GENL_CMD_REPORT] = { + .alloc_sz = sizeof(struct binder_genl_report), + .cb = binder_genl_report_rsp_parse, + .policy = &binder_genl_report_nest, + .free = (void *)binder_genl_report_free, + }, +}; + +const struct ynl_family ynl_binder_genl_family = { + .name = "binder_genl", + .hdr_len = sizeof(struct genlmsghdr), + .ntf_info = binder_genl_ntf_info, + .ntf_info_size = YNL_ARRAY_SIZE(binder_genl_ntf_info), +}; diff --git a/home/nipa/nipa_out/909408/ynl/new-code/binder_genl-user.h b/home/nipa/nipa_out/909408/ynl/new-code/binder_genl-user.h new file mode 100644 index 000000000000..3f632fff042d --- /dev/null +++ b/home/nipa/nipa_out/909408/ynl/new-code/binder_genl-user.h @@ -0,0 +1,123 @@ +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */ +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/binder_genl.yaml */ +/* YNL-GEN user header */ + +#ifndef _LINUX_BINDER_GENL_GEN_H +#define _LINUX_BINDER_GENL_GEN_H + +#include +#include +#include +#include + +struct ynl_sock; + +extern const struct ynl_family ynl_binder_genl_family; + +/* Enums */ +const char *binder_genl_op_str(int op); +const char *binder_genl_flag_str(enum binder_genl_flag value); + +/* Common nested types */ +/* ============== BINDER_GENL_CMD_SET ============== */ +/* BINDER_GENL_CMD_SET - do */ +struct binder_genl_set_req { + struct { + __u32 context_len; + __u32 pid:1; + __u32 flags:1; + } _present; + + char *context; + __u32 pid; + __u32 flags; +}; + +static inline struct binder_genl_set_req *binder_genl_set_req_alloc(void) +{ + return calloc(1, sizeof(struct binder_genl_set_req)); +} +void binder_genl_set_req_free(struct binder_genl_set_req *req); + +static inline void +binder_genl_set_req_set_context(struct binder_genl_set_req *req, + const char *context) +{ + free(req->context); + req->_present.context_len = strlen(context); + req->context = malloc(req->_present.context_len + 1); + memcpy(req->context, context, req->_present.context_len); + req->context[req->_present.context_len] = 0; +} +static inline void +binder_genl_set_req_set_pid(struct binder_genl_set_req *req, __u32 pid) +{ + req->_present.pid = 1; + req->pid = pid; +} +static inline void +binder_genl_set_req_set_flags(struct binder_genl_set_req *req, __u32 flags) +{ + req->_present.flags = 1; + req->flags = flags; +} + +struct binder_genl_set_rsp { + struct { + __u32 context_len; + __u32 pid:1; + __u32 flags:1; + } _present; + + char *context; + __u32 pid; + __u32 flags; +}; + +void binder_genl_set_rsp_free(struct binder_genl_set_rsp *rsp); + +/* + * Set flags from user space. + */ +struct binder_genl_set_rsp * +binder_genl_set(struct ynl_sock *ys, struct binder_genl_set_req *req); + +/* BINDER_GENL_CMD_REPORT - event */ +struct binder_genl_report_rsp { + struct { + __u32 context_len; + __u32 err:1; + __u32 from_pid:1; + __u32 from_tid:1; + __u32 to_pid:1; + __u32 to_tid:1; + __u32 reply:1; + __u32 flags:1; + __u32 code:1; + __u32 data_size:1; + } _present; + + char *context; + __u32 err; + __u32 from_pid; + __u32 from_tid; + __u32 to_pid; + __u32 to_tid; + __u32 reply; + __u32 flags; + __u32 code; + __u32 data_size; +}; + +struct binder_genl_report { + __u16 family; + __u8 cmd; + struct ynl_ntf_base_type *next; + void (*free)(struct binder_genl_report *ntf); + struct binder_genl_report_rsp obj __attribute__((aligned(8))); +}; + +void binder_genl_report_free(struct binder_genl_report *rsp); + +#endif /* _LINUX_BINDER_GENL_GEN_H */