Changeset View
Standalone View
sys/sys/ctf.h
/* $OpenBSD: ctf.h,v 1.5 2017/08/13 14:56:05 nayden Exp $ */ | /* $OpenBSD: ctf.h,v 1.5 2017/08/13 14:56:05 nayden Exp $ */ | ||||
/*- | /*- | ||||
* SPDX-License-Identifier: ISC | * SPDX-License-Identifier: ISC | ||||
* | * | ||||
* Copyright (c) 2016 Martin Pieuchot <mpi@openbsd.org> | * Copyright (c) 2016 Martin Pieuchot <mpi@openbsd.org> | ||||
* Copyright (c) 2022 The FreeBSD Foundation | |||||
* | * | ||||
* Permission to use, copy, modify, and distribute this software for any | * Permission to use, copy, modify, and distribute this software for any | ||||
* purpose with or without fee is hereby granted, provided that the above | * purpose with or without fee is hereby granted, provided that the above | ||||
* copyright notice and this permission notice appear in all copies. | * copyright notice and this permission notice appear in all copies. | ||||
* | * | ||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||||
Show All 37 Lines | |||||
#define CTF_F_COMPRESS (1 << 0) /* zlib compression */ | #define CTF_F_COMPRESS (1 << 0) /* zlib compression */ | ||||
typedef struct ctf_lblent { | typedef struct ctf_lblent { | ||||
__uint32_t ctl_label; | __uint32_t ctl_label; | ||||
__uint32_t ctl_typeidx; | __uint32_t ctl_typeidx; | ||||
} ctf_lblent_t; | } ctf_lblent_t; | ||||
typedef struct ctf_stype { | struct ctf_stype_v2 { | ||||
__uint32_t ctt_name; | __uint32_t ctt_name; | ||||
__uint16_t ctt_info; | __uint16_t ctt_info; | ||||
union { | union { | ||||
__uint16_t _size; | __uint16_t _size; | ||||
__uint16_t _type; | __uint16_t _type; | ||||
} _u; | } _u; | ||||
} ctf_stype_t; | }; | ||||
typedef struct ctf_type { | struct ctf_stype_v3 { | ||||
__uint32_t ctt_name; | __uint32_t ctt_name; | ||||
__uint32_t ctt_info; | |||||
union { | |||||
__uint32_t _size; | |||||
__uint32_t _type; | |||||
} _u; | |||||
}; | |||||
struct ctf_type_v2 { | |||||
__uint32_t ctt_name; | |||||
__uint16_t ctt_info; | __uint16_t ctt_info; | ||||
union { | union { | ||||
__uint16_t _size; | __uint16_t _size; | ||||
__uint16_t _type; | __uint16_t _type; | ||||
} _u; | } _u; | ||||
__uint32_t ctt_lsizehi; | __uint32_t ctt_lsizehi; | ||||
__uint32_t ctt_lsizelo; | __uint32_t ctt_lsizelo; | ||||
} ctf_type_t; | }; | ||||
struct ctf_type_v3 { | |||||
__uint32_t ctt_name; | |||||
__uint32_t ctt_info; | |||||
union { | |||||
__uint32_t _size; | |||||
__uint32_t _type; | |||||
} _u; | |||||
__uint32_t ctt_lsizehi; | |||||
__uint32_t ctt_lsizelo; | |||||
}; | |||||
#define ctt_size _u._size | #define ctt_size _u._size | ||||
#define ctt_type _u._type | #define ctt_type _u._type | ||||
typedef struct ctf_array { | struct ctf_array_v2 { | ||||
__uint16_t cta_contents; | __uint16_t cta_contents; | ||||
__uint16_t cta_index; | __uint16_t cta_index; | ||||
__uint32_t cta_nelems; | __uint32_t cta_nelems; | ||||
} ctf_array_t; | }; | ||||
typedef struct ctf_member { | struct ctf_array_v3 { | ||||
__uint32_t cta_contents; | |||||
__uint32_t cta_index; | |||||
__uint32_t cta_nelems; | |||||
}; | |||||
struct ctf_member_v2 { | |||||
__uint32_t ctm_name; | __uint32_t ctm_name; | ||||
__uint16_t ctm_type; | __uint16_t ctm_type; | ||||
__uint16_t ctm_offset; | __uint16_t ctm_offset; | ||||
} ctf_member_t; | }; | ||||
typedef struct ctf_lmember { | struct ctf_member_v3 { | ||||
__uint32_t ctm_name; | |||||
__uint32_t ctm_type; | |||||
__uint32_t ctm_offset; | |||||
}; | |||||
struct ctf_lmember_v2 { | |||||
__uint32_t ctlm_name; | __uint32_t ctlm_name; | ||||
__uint16_t ctlm_type; | __uint16_t ctlm_type; | ||||
__uint16_t ctlm_pad; | __uint16_t ctlm_pad; | ||||
__uint32_t ctlm_offsethi; | __uint32_t ctlm_offsethi; | ||||
__uint32_t ctlm_offsetlo; | __uint32_t ctlm_offsetlo; | ||||
} ctf_lmember_t; | }; | ||||
#define CTF_LSTRUCT_THRESH 8192 | struct ctf_lmember_v3 { | ||||
__uint32_t ctlm_name; | |||||
__uint32_t ctlm_type; | |||||
__uint32_t ctlm_offsethi; | |||||
__uint32_t ctlm_offsetlo; | |||||
}; | |||||
#define CTF_V2_LSTRUCT_THRESH (1 << 13) | |||||
#define CTF_V3_LSTRUCT_THRESH (1 << 29) | |||||
typedef struct ctf_enum { | typedef struct ctf_enum { | ||||
__uint32_t cte_name; | __uint32_t cte_name; | ||||
__int32_t cte_value; | __int32_t cte_value; | ||||
} ctf_enum_t; | } ctf_enum_t; | ||||
#define CTF_MAGIC 0xcff1 | #define CTF_MAGIC 0xcff1 | ||||
#define CTF_VERSION CTF_VERSION_2 | #define CTF_VERSION CTF_VERSION_2 | ||||
#define CTF_VERSION_3 3 | |||||
domagoj.stolfa_gmail.com: Curious... Have you tried to change this to `CTF_VERSION_3` to see what happens with this patch… | |||||
Done Inline ActionsOne of the subsequent patches in this series does exactly this. It does not work at this point in the series since libctf etc. are not yet patched. markj: One of the subsequent patches in this series does exactly this. It does not work at this point… | |||||
#define CTF_VERSION_2 2 | #define CTF_VERSION_2 2 | ||||
#define CTF_VERSION_1 1 | #define CTF_VERSION_1 1 | ||||
#define CTF_MAX_NAME 0x7fffffff | #define CTF_MAX_NAME 0x7fffffff | ||||
#define CTF_MAX_VLEN 0x03ff | |||||
#define CTF_MAX_SIZE 0xfffe | |||||
#define CTF_LSIZE_SENT (CTF_MAX_SIZE + 1) /* sentinel for cts vs ctt */ | |||||
#define CTF_PARENT_SHIFT 15 | #define CTF_V2_MAX_VLEN 0x03ff | ||||
#define CTF_MAX_TYPE 0xffff | #define CTF_V2_MAX_SIZE 0xfffe | ||||
#define CTF_TYPE_ISPARENT(id) ((id) < 0x8000) | #define CTF_V2_LSIZE_SENT (CTF_V2_MAX_SIZE + 1) /* sentinel for cts vs ctt */ | ||||
#define CTF_TYPE_ISCHILD(id) ((id) > 0x7fff) | |||||
#define CTF_TYPE_TO_INDEX(t) ((t) & 0x7fff) | |||||
#define CTF_INDEX_TO_TYPE(t, c) (((t) & 0x7fff) | ((c) != 0 ? 0x8000 : 0)) | |||||
#define CTF_TYPE_INFO(k, r, l) \ | #define CTF_V3_MAX_VLEN 0x00ffffff | ||||
((k) << 11) | ((r) != 0 ? (1 << 10) : 0) | ((l) & ((1 << 10) - 1)) | #define CTF_V3_MAX_SIZE 0xfffffffeu | ||||
#define CTF_V3_LSIZE_SENT (CTF_V3_MAX_SIZE + 1) | |||||
#define CTF_V2_PARENT_SHIFT 15 | |||||
#define CTF_V2_MAX_TYPE 0xffff | |||||
#define CTF_V2_TYPE_ISPARENT(id) ((id) < 0x8000) | |||||
#define CTF_V2_TYPE_ISCHILD(id) ((id) > 0x7fff) | |||||
#define CTF_V2_TYPE_TO_INDEX(type) ((type) & 0x7fff) | |||||
#define CTF_V2_INDEX_TO_TYPE(type, ischild) \ | |||||
(((type) & 0x7fff) | ((ischild) != 0 ? 0x8000 : 0)) | |||||
#define CTF_V2_TYPE_INFO(kind, isroot, vlen) \ | |||||
(((kind) << 11) | ((isroot) != 0 ? (1 << 10) : 0) | \ | |||||
((vlen) & CTF_V2_MAX_VLEN)) | |||||
#define CTF_V3_PARENT_SHIFT 31 | |||||
#define CTF_V3_MAX_TYPE 0xfffffffeu | |||||
#define CTF_V3_TYPE_ISPARENT(id) ((__uint32_t)(id) < 0x80000000u) | |||||
#define CTF_V3_TYPE_ISCHILD(id) ((__uint32_t)(id) > 0x7fffffffu) | |||||
#define CTF_V3_TYPE_TO_INDEX(type) ((type) & 0x7fffffffu) | |||||
#define CTF_V3_INDEX_TO_TYPE(type, ischild) \ | |||||
(((type) & 0x7fffffffu) | ((ischild) != 0 ? 0x80000000u : 0)) | |||||
#define CTF_V3_TYPE_INFO(kind, isroot, vlen) \ | |||||
(((kind) << 26) | ((isroot) != 0 ? (1 << 25) : 0) | \ | |||||
((vlen) & CTF_V3_MAX_VLEN)) | |||||
#define CTF_STRTAB_0 0 | #define CTF_STRTAB_0 0 | ||||
#define CTF_STRTAB_1 1 | #define CTF_STRTAB_1 1 | ||||
#define CTF_TYPE_NAME(t, o) (((t) << 31) | ((o) & ((1u << 31) - 1))) | #define CTF_TYPE_NAME(t, o) (((t) << 31) | ((o) & ((1u << 31) - 1))) | ||||
Done Inline ActionsSince there's already a diff against these, I wonder if adding some clarification on what k, r and l are? The other macros are fairly obvious, but this one had me puzzled until I looked at the man page and found: #define CTF_TYPE_INFO(kind, isroot, vlen) \ (((kind) << 11) | (((isroot) ? 1 : 0) << 10) | ((vlen) & CTF_MAX_VLEN)) which is a much clearer description of the macro than this version. domagoj.stolfa_gmail.com: Since there's already a diff against these, I wonder if adding some clarification on what `k`… | |||||
/* | /* | ||||
* Info macro. | * Info macro. | ||||
*/ | */ | ||||
Done Inline ActionsSame as above domagoj.stolfa_gmail.com: Same as above | |||||
#define CTF_INFO_VLEN(i) (((i) & CTF_MAX_VLEN)) | #define CTF_V2_INFO_VLEN(i) ((i) & CTF_V2_MAX_VLEN) | ||||
#define CTF_INFO_ISROOT(i) (((i) & 0x0400) >> 10) | #define CTF_V2_INFO_ISROOT(i) (((i) & 0x0400) >> 10) | ||||
#define CTF_INFO_KIND(i) (((i) & 0xf800) >> 11) | #define CTF_V2_INFO_KIND(i) (((i) & 0xf800) >> 11) | ||||
#define CTF_V3_INFO_VLEN(i) ((i) & CTF_V3_MAX_VLEN) | |||||
#define CTF_V3_INFO_ISROOT(i) (((i) & 0x02000000) >> 25) | |||||
#define CTF_V3_INFO_KIND(i) (((i) & 0xfc000000) >> 26) | |||||
#define CTF_K_UNKNOWN 0 | #define CTF_K_UNKNOWN 0 | ||||
#define CTF_K_INTEGER 1 | #define CTF_K_INTEGER 1 | ||||
#define CTF_K_FLOAT 2 | #define CTF_K_FLOAT 2 | ||||
#define CTF_K_POINTER 3 | #define CTF_K_POINTER 3 | ||||
#define CTF_K_ARRAY 4 | #define CTF_K_ARRAY 4 | ||||
#define CTF_K_FUNCTION 5 | #define CTF_K_FUNCTION 5 | ||||
#define CTF_K_STRUCT 6 | #define CTF_K_STRUCT 6 | ||||
#define CTF_K_UNION 7 | #define CTF_K_UNION 7 | ||||
#define CTF_K_ENUM 8 | #define CTF_K_ENUM 8 | ||||
#define CTF_K_FORWARD 9 | #define CTF_K_FORWARD 9 | ||||
#define CTF_K_TYPEDEF 10 | #define CTF_K_TYPEDEF 10 | ||||
#define CTF_K_VOLATILE 11 | #define CTF_K_VOLATILE 11 | ||||
#define CTF_K_CONST 12 | #define CTF_K_CONST 12 | ||||
#define CTF_K_RESTRICT 13 | #define CTF_K_RESTRICT 13 | ||||
#define CTF_K_MAX 31 | #define CTF_K_MAX 63 | ||||
/* | /* | ||||
* Integer/Float Encoding macro. | * Integer/Float Encoding macro. | ||||
*/ | */ | ||||
#define _CTF_ENCODING(e) (((e) & 0xff000000) >> 24) | #define _CTF_ENCODING(e) (((e) & 0xff000000) >> 24) | ||||
#define _CTF_OFFSET(e) (((e) & 0x00ff0000) >> 16) | #define _CTF_OFFSET(e) (((e) & 0x00ff0000) >> 16) | ||||
#define _CTF_BITS(e) (((e) & 0x0000ffff)) | #define _CTF_BITS(e) (((e) & 0x0000ffff)) | ||||
#define _CTF_DATA(encoding, offset, bits) \ | #define _CTF_DATA(encoding, offset, bits) \ | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
/* | /* | ||||
* Member macro. | * Member macro. | ||||
*/ | */ | ||||
#define CTF_LMEM_OFFSET(m) \ | #define CTF_LMEM_OFFSET(m) \ | ||||
(((__uint64_t)(m)->ctlm_offsethi) << 32 | (m)->ctlm_offsetlo) | (((__uint64_t)(m)->ctlm_offsethi) << 32 | (m)->ctlm_offsetlo) | ||||
#define CTF_OFFSET_TO_LMEMHI(off) ((__uint32_t)((__uint64_t)(off) >> 32)) | #define CTF_OFFSET_TO_LMEMHI(off) ((__uint32_t)((__uint64_t)(off) >> 32)) | ||||
#define CTF_OFFSET_TO_LMEMLO(off) ((__uint32_t)(off)) | #define CTF_OFFSET_TO_LMEMLO(off) ((__uint32_t)(off)) | ||||
/* | |||||
* Compatibility for pre-v3 code. | |||||
*/ | |||||
typedef struct ctf_array_v2 ctf_array_t; | |||||
Not Done Inline ActionsHave you tried changing this to v3? Does it break anything? In other words, could we at some point in the future change these typedefs and have things "magically" just be better? domagoj.stolfa_gmail.com: Have you tried changing this to v3? Does it break anything? In other words, could we at some… | |||||
Done Inline ActionsAt the end of this series, these typedefs are not used at all and could possibly be removed. There's no sensible way to use them; it's better to provide accessors which know the backing CTF version and can cast a void * to the versioned type. For instance, at the end of the series, libctf's ctf_lookup_by_id() returns a void * that can be passed to ctf_get_ctt_size() etc. markj: At the end of this series, these typedefs are not used at all and could possibly be removed. | |||||
typedef struct ctf_member_v2 ctf_member_t; | |||||
typedef struct ctf_lmember_v2 ctf_lmember_t; | |||||
typedef struct ctf_type_v2 ctf_type_t; | |||||
typedef struct ctf_stype_v2 ctf_stype_t; | |||||
#define CTF_INFO_KIND CTF_V2_INFO_KIND | |||||
#define CTF_INFO_VLEN CTF_V2_INFO_VLEN | |||||
#define CTF_INFO_ISROOT CTF_V2_INFO_ISROOT | |||||
#define CTF_TYPE_INFO CTF_V2_TYPE_INFO | |||||
#define CTF_TYPE_ISPARENT CTF_V2_TYPE_ISPARENT | |||||
#define CTF_TYPE_ISCHILD CTF_V2_TYPE_ISCHILD | |||||
#define CTF_TYPE_TO_INDEX CTF_V2_TYPE_TO_INDEX | |||||
#define CTF_INDEX_TO_TYPE CTF_V2_INDEX_TO_TYPE | |||||
#define CTF_LSIZE_SENT CTF_V2_LSIZE_SENT | |||||
#define CTF_LSTRUCT_THRESH CTF_V2_LSTRUCT_THRESH | |||||
#define CTF_MAX_SIZE CTF_V2_MAX_SIZE | |||||
#define CTF_MAX_TYPE CTF_V2_MAX_TYPE | |||||
#define CTF_MAX_VLEN CTF_V2_MAX_VLEN | |||||
#endif /* _SYS_CTF_H_ */ | #endif /* _SYS_CTF_H_ */ |
Curious... Have you tried to change this to CTF_VERSION_3 to see what happens with this patch stack applied? Do things just work?