1 /* Support for GNU properties.  AArch64 version.
2    Copyright (C) 2018-2022 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4 
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9 
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14 
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, see
17    <https://www.gnu.org/licenses/>.  */
18 
19 #ifndef _DL_PROP_H
20 #define _DL_PROP_H
21 
22 extern void _dl_bti_protect (struct link_map *, int) attribute_hidden;
23 
24 extern void _dl_bti_check (struct link_map *, const char *)
25     attribute_hidden;
26 
27 static inline void __attribute__ ((always_inline))
_rtld_main_check(struct link_map * m,const char * program)28 _rtld_main_check (struct link_map *m, const char *program)
29 {
30   _dl_bti_check (m, program);
31 }
32 
33 static inline void __attribute__ ((always_inline))
_dl_open_check(struct link_map * m)34 _dl_open_check (struct link_map *m)
35 {
36   _dl_bti_check (m, NULL);
37 }
38 
39 static inline void __attribute__ ((always_inline))
_dl_process_pt_note(struct link_map * l,int fd,const ElfW (Phdr)* ph)40 _dl_process_pt_note (struct link_map *l, int fd, const ElfW(Phdr) *ph)
41 {
42 }
43 
44 static inline int
_dl_process_gnu_property(struct link_map * l,int fd,uint32_t type,uint32_t datasz,void * data)45 _dl_process_gnu_property (struct link_map *l, int fd, uint32_t type,
46 			  uint32_t datasz, void *data)
47 {
48   if (!GLRO(dl_aarch64_cpu_features).bti)
49     /* Skip note processing.  */
50     return 0;
51 
52   if (type == GNU_PROPERTY_AARCH64_FEATURE_1_AND)
53     {
54       /* Stop if the property note is ill-formed.  */
55       if (datasz != 4)
56 	return 0;
57 
58       unsigned int feature_1 = *(unsigned int *) data;
59       if (feature_1 & GNU_PROPERTY_AARCH64_FEATURE_1_BTI)
60 	_dl_bti_protect (l, fd);
61 
62       /* Stop if we processed the property note.  */
63       return 0;
64     }
65   /* Continue.  */
66   return 1;
67 }
68 
69 #endif /* _DL_PROP_H */
70