A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

plugins: Simplify plugin/codec API versioning

Replace the minimum version bound with a check on the size of
the API struct. The version only needs to be incremented for
ABI breaking changes. Additions to the API won't need to touch
the version number, resulting in fewer merge conflicts.

Change-Id: I916a04a7bf5890dcf5d615ce30087643165f8e1f

+49 -37
+3 -2
apps/codecs.c
··· 203 203 return CODEC_ERROR; 204 204 } 205 205 206 - if (hdr->api_version > CODEC_API_VERSION 207 - || hdr->api_version < CODEC_MIN_API_VERSION) { 206 + if (hdr->api_version != CODEC_API_VERSION || 207 + c_hdr->api_size > sizeof(struct codec_api)) 208 + { 208 209 logf("codec api version error"); 209 210 lc_close(curr_handle); 210 211 curr_handle = NULL;
+4 -4
apps/plugin.c
··· 864 864 } 865 865 866 866 p_hdr = lc_get_header(current_plugin_handle); 867 - 868 867 hdr = p_hdr ? &p_hdr->lc_hdr : NULL; 869 - 870 868 871 869 if (hdr == NULL 872 870 || hdr->magic != PLUGIN_MAGIC ··· 881 879 splash(HZ*2, ID2P(LANG_PLUGIN_WRONG_MODEL)); 882 880 return -1; 883 881 } 884 - if (hdr->api_version > PLUGIN_API_VERSION 885 - || hdr->api_version < PLUGIN_MIN_API_VERSION) 882 + 883 + if (hdr->api_version != PLUGIN_API_VERSION || 884 + p_hdr->api_size > sizeof(struct plugin_api)) 886 885 { 887 886 lc_close(current_plugin_handle); 888 887 splash(HZ*2, ID2P(LANG_PLUGIN_WRONG_VERSION)); 889 888 return -1; 890 889 } 890 + 891 891 #if (CONFIG_PLATFORM & PLATFORM_NATIVE) 892 892 /* tlsf crashes observed on arm with 0x4 aligned addresses */ 893 893 plugin_size = ALIGN_UP(hdr->end_addr - pluginbuf, 0x8);
+11 -10
apps/plugin.h
··· 157 157 158 158 #define PLUGIN_MAGIC 0x526F634B /* RocK */ 159 159 160 - /* increase this every time the api struct changes */ 161 - #define PLUGIN_API_VERSION 265 162 - 163 - /* update this to latest version if a change to the api struct breaks 164 - backwards compatibility (and please take the opportunity to sort in any 165 - new function which are "waiting" at the end of the function table) */ 166 - #define PLUGIN_MIN_API_VERSION 260 160 + /* 161 + * Increment this whenever a change breaks the plugin ABI, 162 + * when this happens please take the opportunity to sort in 163 + * any new functions "waiting" at the end of the list. 164 + */ 165 + #define PLUGIN_API_VERSION 266 167 166 168 167 /* 239 Marks the removal of ARCHOS HWCODEC and CHARCELL */ 169 168 ··· 962 961 struct lc_header lc_hdr; /* must be the first */ 963 962 enum plugin_status(*entry_point)(const void*); 964 963 const struct plugin_api **api; 964 + size_t api_size; 965 965 }; 966 966 967 967 #ifdef PLUGIN ··· 973 973 const struct plugin_header __header \ 974 974 __attribute__ ((section (".header")))= { \ 975 975 { PLUGIN_MAGIC, TARGET_ID, PLUGIN_API_VERSION, \ 976 - plugin_start_addr, plugin_end_addr }, plugin__start, &rb }; 976 + plugin_start_addr, plugin_end_addr, }, \ 977 + plugin__start, &rb, sizeof(struct plugin_api) }; 977 978 #else /* PLATFORM_HOSTED */ 978 979 #define PLUGIN_HEADER \ 979 980 const struct plugin_api *rb DATA_ATTR; \ 980 981 const struct plugin_header __header \ 981 982 __attribute__((visibility("default"))) = { \ 982 - { PLUGIN_MAGIC, TARGET_ID, PLUGIN_API_VERSION, NULL, NULL }, \ 983 - plugin__start, &rb }; 983 + { PLUGIN_MAGIC, TARGET_ID, PLUGIN_API_VERSION, NULL, NULL }, \ 984 + plugin__start, &rb, sizeof(struct plugin_api) }; 984 985 #endif /* CONFIG_PLATFORM */ 985 986 #endif /* PLUGIN */ 986 987
+4 -1
apps/plugins/imageviewer/image_decoder.c
··· 155 155 goto error_close; 156 156 } 157 157 158 - if (lc_hdr->api_version != IMGDEC_API_VERSION) 158 + if (lc_hdr->api_version != IMGDEC_API_VERSION || 159 + hdr->img_api_size > sizeof(struct imgdec_api) || 160 + hdr->plugin_api_version != PLUGIN_API_VERSION || 161 + hdr->plugin_api_size > sizeof(struct plugin_api)) 159 162 { 160 163 rb->splashf(2*HZ, "%s decoder: Incompatible version.", name); 161 164 goto error_close;
+10 -4
apps/plugins/imageviewer/imageviewer.h
··· 136 136 int x, int y, int width, int height); 137 137 }; 138 138 139 - #define IMGDEC_API_VERSION (PLUGIN_API_VERSION << 4 | 0) 139 + #define IMGDEC_API_VERSION 1 140 140 141 141 /* image decoder header */ 142 142 struct imgdec_header { 143 143 struct lc_header lc_hdr; /* must be the first */ 144 144 const struct image_decoder *decoder; 145 145 const struct plugin_api **api; 146 + unsigned short plugin_api_version; 147 + size_t plugin_api_size; 146 148 const struct imgdec_api **img_api; 149 + size_t img_api_size; 147 150 }; 148 151 149 152 #ifdef IMGDEC ··· 157 160 const struct imgdec_header __header \ 158 161 __attribute__ ((section (".header")))= { \ 159 162 { PLUGIN_MAGIC, TARGET_ID, IMGDEC_API_VERSION, \ 160 - plugin_start_addr, plugin_end_addr }, &image_decoder, &rb, &iv }; 163 + plugin_start_addr, plugin_end_addr, }, &image_decoder, \ 164 + &rb, PLUGIN_API_VERSION, sizeof(struct plugin_api), \ 165 + &iv, sizeof(struct imgdec_api) }; 161 166 #else /* PLATFORM_HOSTED */ 162 167 #define IMGDEC_HEADER \ 163 168 const struct plugin_api *rb DATA_ATTR; \ 164 169 const struct imgdec_api *iv DATA_ATTR; \ 165 170 const struct imgdec_header __header \ 166 171 __attribute__((visibility("default"))) = { \ 167 - { PLUGIN_MAGIC, TARGET_ID, IMGDEC_API_VERSION, \ 168 - NULL, NULL }, &image_decoder, &rb, &iv }; 172 + { PLUGIN_MAGIC, TARGET_ID, IMGDEC_API_VERSION, NULL, NULL }, \ 173 + &image_decoder, &rb, PLUGIN_API_VERSION, sizeof(struct plugin_api), \ 174 + &iv, sizeof(struct imgdec_api), }; 169 175 #endif /* CONFIG_PLATFORM */ 170 176 #endif 171 177
+2 -3
apps/plugins/lib/overlay.c
··· 83 83 goto error_close; 84 84 } 85 85 86 - 87 - if (hdr->api_version > PLUGIN_API_VERSION 88 - || hdr->api_version < PLUGIN_MIN_API_VERSION) 86 + if (hdr->api_version != PLUGIN_API_VERSION || 87 + p_hdr->api_size > sizeof(struct plugin_api)) 89 88 { 90 89 rb->splashf(2*HZ, "%s overlay: Incompatible version.", name); 91 90 goto error_close;
+15 -13
lib/rbcodec/codecs/codecs.h
··· 71 71 /* magic for encoder codecs */ 72 72 #define CODEC_ENC_MAGIC 0x52454E43 /* RENC */ 73 73 74 - /* increase this every time the api struct changes */ 75 - #define CODEC_API_VERSION 49 76 - 77 - /* update this to latest version if a change to the api struct breaks 78 - backwards compatibility (and please take the opportunity to sort in any 79 - new function which are "waiting" at the end of the function table) */ 80 - #define CODEC_MIN_API_VERSION 49 74 + /* 75 + * Increment this whenever a change breaks the codec ABI, 76 + * when this happens please take the opportunity to sort in 77 + * any new functions "waiting" at the end of the list. 78 + */ 79 + #define CODEC_API_VERSION 50 81 80 82 81 /* reasons for calling codec main entrypoint */ 83 82 enum codec_entry_call_reason { ··· 228 227 enum codec_status(*entry_point)(enum codec_entry_call_reason reason); 229 228 enum codec_status(*run_proc)(void); 230 229 struct codec_api **api; 230 + size_t api_size; 231 231 void * rec_extension[]; /* extension for encoders */ 232 232 }; 233 233 ··· 241 241 const struct codec_header __header \ 242 242 __attribute__ ((section (".header")))= { \ 243 243 { CODEC_MAGIC, TARGET_ID, CODEC_API_VERSION, \ 244 - plugin_start_addr, plugin_end_addr }, codec_start, \ 245 - codec_run, &ci }; 244 + plugin_start_addr, plugin_end_addr }, \ 245 + codec_start, codec_run, &ci, sizeof(struct codec_api) }; 246 246 /* encoders */ 247 247 #define CODEC_ENC_HEADER \ 248 248 const struct codec_header __header \ 249 249 __attribute__ ((section (".header")))= { \ 250 250 { CODEC_ENC_MAGIC, TARGET_ID, CODEC_API_VERSION, \ 251 - plugin_start_addr, plugin_end_addr }, codec_start, \ 252 - codec_run, &ci, { enc_callback } }; 251 + plugin_start_addr, plugin_end_addr }, \ 252 + codec_start, codec_run, &ci, sizeof(struct codec_api), \ 253 + { enc_callback } }; 253 254 254 255 #else /* def SIMULATOR */ 255 256 /* decoders */ ··· 257 258 const struct codec_header __header \ 258 259 __attribute__((visibility("default"))) = { \ 259 260 { CODEC_MAGIC, TARGET_ID, CODEC_API_VERSION, NULL, NULL }, \ 260 - codec_start, codec_run, &ci }; 261 + codec_start, codec_run, &ci, sizeof(struct codec_api) }; 261 262 /* encoders */ 262 263 #define CODEC_ENC_HEADER \ 263 264 const struct codec_header __header \ 264 265 __attribute__((visibility("default"))) = { \ 265 266 { CODEC_ENC_MAGIC, TARGET_ID, CODEC_API_VERSION, NULL, NULL }, \ 266 - codec_start, codec_run, &ci, { enc_callback } }; 267 + codec_start, codec_run, &ci, sizeof(struct codec_api), \ 268 + { enc_callback } }; 267 269 #endif /* SIMULATOR */ 268 270 #endif /* CODEC */ 269 271