1 // SPDX-License-Identifier: GPL-2.0
2 
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <unistd.h>
6 #include <stdint.h>
7 #include <sys/prctl.h>
8 #include <sys/utsname.h>
9 
10 #define SHIFT_TAG(tag)		((uint64_t)(tag) << 56)
11 #define SET_TAG(ptr, tag)	(((uint64_t)(ptr) & ~SHIFT_TAG(0xff)) | \
12 					SHIFT_TAG(tag))
13 
14 int main(void)
15 {
16 	static int tbi_enabled = 0;
17 	unsigned long tag = 0;
18 	struct utsname *ptr;
19 	int err;
20 
21 	if (prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE, 0, 0, 0) == 0)
22 		tbi_enabled = 1;
23 	ptr = (struct utsname *)malloc(sizeof(*ptr));
24 	if (tbi_enabled)
25 		tag = 0x42;
26 	ptr = (struct utsname *)SET_TAG(ptr, tag);
27 	err = uname(ptr);
28 	free(ptr);
29 
30 	return err;
31 }
32