mailing list of musl libc
 help / color / mirror / code / Atom feed
* (OT?) replying two years later (was: Removing sbrk and brk)
@ 2016-04-13 13:39 u-uy74
  0 siblings, 0 replies; only message in thread
From: u-uy74 @ 2016-04-13 13:39 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 1207 bytes --]

This is not about musl but about a musl-compatibility of some
respectable software :)

2014-02-21 23:34 GMT+1 Daniel Cegiełka wrote:
> 2014-02-21 18:09 GMT+01:00 Rich Felker <dalias@...ifal.cx>:
> 
> > Then it didn't work before either; it was silently corrupting memory.
> > The only difference now is that you know that it's not working.
> 
> Thank you for your response and I understand the reasons.
> In my free time I will try to fix ex/vi ...

FWIIW.

I did not find anyone else having built a working ex-vi with musl.

As a quick hack, given the absence of threading:
an additional file sbrk.c (attached)
and "make MALLOC=sbrk.o" do the trick for ex-vi, at least on ia32.

(I also removed the "poolsbrk(0);" call from ex.c and exrecover.c,
instead of adding a dummy function. A more elaborated fake sbrk might
use it for initialization of course.)

May be this will be useful to someone, while building old stuff.
This may also further mitigate the motivation/need for sbrk() in musl.

Allocating "a lot of" unused memory should not hurt much on modern Linux
with MMU, adding support for negative increments is straightforward
if there are programs making heavy use of such a feature.

Cheers,
Rune

[-- Attachment #2: sbrk.c --]
[-- Type: text/plain, Size: 597 bytes --]

/*
 * fake sbrk implementation by RL @ Aetey Global Technologies AB
 * 2016-04-13
 * put in public domain by the author
 */

#include <errno.h>
#include <sys/types.h>

/* preallocate 10 Mbyte */
#define POOLSIZE 10485760

static char brkspace[POOLSIZE];
static int  brki = 0;

void *sbrk(intptr_t incr) {
  int prev;
/* do not mind leaking memory on negative incr,
 * ex does not seem to use this */
  if (incr <= 0)
    return (void *)(brkspace+brki);
  if (incr > POOLSIZE-brki) {
    errno = ENOMEM;
    return (void *)-1;
  }
  prev = brki;
  brki += incr;
  return (void *)(brkspace+prev);
}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2016-04-13 13:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-13 13:39 (OT?) replying two years later (was: Removing sbrk and brk) u-uy74

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).