arduino / arduino/ArduinoCore-mbed

SDRAM.begin can be repeated, possibly corrupting static allocation

Open
#1,105 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
411
Forks
225
PR merge metrics
No merged PRs in 30d

Description

Hello!
it seems that SDRAM.begin can be repeated with different parameters without warning. For example:


```
SDRAM.begin(SDRAM_START_ADDRESS + 2 * 1024 * 1024);
// 2MB of contiguous memory available at the beginning

uint32_t* framebuffer = (uint32_t*)SDRAM_START_ADDRESS;

// We can't allocate anymore the huge 7MB array
SDRAM.begin(SDRAM_START_ADDRESS);

uint8_t* myVeryBigArray = (uint8_t*)SDRAM.malloc(7 * 1024 * 1024);
if (myVeryBigArray == NULL) {
Serial.println("Oops, too big :)");
}
```

allocates 7MB without error

That can be problematic when - for example - Arduino_H7_Video for Arduino GIGA internally allocates nearly all SDRAM for framebuffers

```
#if defined(ARDUINO_GIGA)
/* Configure SDRAM */
SDRAM.begin(dsi_getFramebufferEnd());
#endif

```
and the user is not prevented from re-initializing it

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at the SDRAM.begin and SDRAM.malloc entry points, then inspect the Arduino_H7_Video initialization that calls SDRAM.begin(dsi_getFramebufferEnd()). Reproduce the two begin calls followed by the 7MB allocation; done means repeated initialization no longer silently permits an allocation that conflicts with the earlier static allocation.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
embedded-iot
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.