Skip to content

Commit e31b000

Browse files
committed
Split pyfb_vinfo into a secure and unsecure version
As in commit 2774517 a deadlock has been fixed caused by the pyfb_vinfo function to get the display resolution, this commit splits this function into two versions: pyfb_vinfo and pyfb_svinfo. The pyfb_svinfo is only for external usage while the other one is for internal usage to get the actual display resolution.
1 parent 1c5f308 commit e31b000

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

native/framebuffers.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ void pyfb_close(uint8_t fbnum) {
223223
unlock(framebuffers[fbnum].fb_lock);
224224
}
225225

226-
void pyfb_vinfo(uint8_t fbnum, struct pyfb_videomode_info* info_ptr) {
226+
void pyfb_svinfo(uint8_t fbnum, struct pyfb_videomode_info* info_ptr) {
227227
// first test if this device number is valid.
228228
if(fbnum >= MAX_FRAMEBUFFERS) {
229229
return;
@@ -236,6 +236,10 @@ void pyfb_vinfo(uint8_t fbnum, struct pyfb_videomode_info* info_ptr) {
236236
unlock(framebuffers[fbnum].fb_lock);
237237
}
238238

239+
void __APISTATUS_internal pyfb_vinfo(uint8_t fbnum, struct pyfb_videomode_info* info_ptr) {
240+
memcpy(info_ptr, &framebuffers[fbnum].fb_info.vinfo, sizeof(struct fb_var_screeninfo));
241+
}
242+
239243
int pyfb_flushBuffer(uint8_t fbnum) {
240244
// first test if this device number is valid
241245
if(fbnum >= MAX_FRAMEBUFFERS) {

native/module_pyfb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ static PyObject* pyfunc_pyfb_getResolution(PyObject* self, PyObject* args) {
177177

178178
// Else build the tuple of the resolution info and return it
179179
struct pyfb_videomode_info vinfo;
180-
pyfb_vinfo((uint8_t)fbnum_c, &vinfo);
180+
pyfb_svinfo((uint8_t)fbnum_c, &vinfo);
181181

182182
// check if valid
183183
if(vinfo.fb_size_b == 0) {

native/paint.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,6 @@ void __APISTATUS_internal pyfb_sdrawLine(uint8_t fbnum,
8484
return;
8585
}
8686

87-
struct pyfb_videomode_info vinfo;
88-
pyfb_vinfo(fbnum, &vinfo);
89-
9087
// Ok, then lock
9188
pyfb_fblock(fbnum);
9289

@@ -99,6 +96,8 @@ void __APISTATUS_internal pyfb_sdrawLine(uint8_t fbnum,
9996
}
10097

10198
// check if all values are valid
99+
struct pyfb_videomode_info vinfo;
100+
pyfb_vinfo(fbnum, &vinfo);
102101
unsigned long int xres = vinfo.vinfo.xres;
103102
unsigned long int yres = vinfo.vinfo.yres;
104103

native/pyframebuffer.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,27 @@ extern void pyfb_close(uint8_t fbnum);
197197
* Returns the videomode info of a specific framebuffer. If the framebuffer is not
198198
* opened, then the @c pyfb_videomode_info.fb_size_b field will be @c 0 . If it is
199199
* not 0, then the structure is valid and the framebuffer is opened.
200+
*
201+
* This is the secure version of pyfb_vinfo as it locks the framebuffer before
202+
* collecting the data.
203+
*
204+
* @param fbnum The framebuffer number to get the infos of
205+
* @param info_ptr The pointer to copy the videmode info to
206+
*/
207+
extern void pyfb_svinfo(uint8_t fbnum, struct pyfb_videomode_info* info_ptr);
208+
209+
/**
210+
* Returns the videomode info of a specific framebuffer. If the framebuffer is not
211+
* opened, then the @c pyfb_videomode_info.fb_size_b field will be @c 0 . If it is
212+
* not 0, then the structure is valid and the framebuffer is opened.
213+
*
214+
* This is the insecure version of pyfb_vinfo as it not locks the framebuffer before
215+
* collecting the data.
200216
*
201217
* @param fbnum The framebuffer number to get the infos of
202218
* @param info_ptr The pointer to copy the videmode info to
203219
*/
204-
extern void pyfb_vinfo(uint8_t fbnum, struct pyfb_videomode_info* info_ptr);
220+
extern void __APISTATUS_internal pyfb_vinfo(uint8_t fbnum, struct pyfb_videomode_info* info_ptr);
205221

206222
/**
207223
* Paints a single pixel to the framebuffer. This function is secure because before

0 commit comments

Comments
 (0)