diff options
author | otto <> | 2018-11-21 06:57:04 +0000 |
---|---|---|
committer | otto <> | 2018-11-21 06:57:04 +0000 |
commit | 9d3c55760e9cc7dca8b55958537265f1162dc63c (patch) | |
tree | 6410826e21b5251b799d88942013e9629d773c3d /src/lib/libc/stdlib/malloc.c | |
parent | 02826236d6b2d590f7d31af8a7b01f56f6ea2a6a (diff) | |
download | openbsd-9d3c55760e9cc7dca8b55958537265f1162dc63c.tar.gz openbsd-9d3c55760e9cc7dca8b55958537265f1162dc63c.tar.bz2 openbsd-9d3c55760e9cc7dca8b55958537265f1162dc63c.zip |
Introducing malloc_usable_size() was a mistake. While some other
libs have it, it is a function that is considered harmful, so:
Delete malloc_usable_size(). It is a function that blurs the line
between malloc managed memory and application managed memory and
exposes some of the internal workings of malloc. If an application
relies on that, it is likely to break using another implementation
of malloc. If you want usable size x, just allocate x bytes. ok
deraadt@ and other devs
Diffstat (limited to 'src/lib/libc/stdlib/malloc.c')
-rw-r--r-- | src/lib/libc/stdlib/malloc.c | 79 |
1 files changed, 1 insertions, 78 deletions
diff --git a/src/lib/libc/stdlib/malloc.c b/src/lib/libc/stdlib/malloc.c index 513defccbc..0912b904b8 100644 --- a/src/lib/libc/stdlib/malloc.c +++ b/src/lib/libc/stdlib/malloc.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: malloc.c,v 1.253 2018/11/19 22:50:24 guenther Exp $ */ | 1 | /* $OpenBSD: malloc.c,v 1.254 2018/11/21 06:57:04 otto Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2008, 2010, 2011, 2016 Otto Moerbeek <otto@drijf.net> | 3 | * Copyright (c) 2008, 2010, 2011, 2016 Otto Moerbeek <otto@drijf.net> |
4 | * Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org> | 4 | * Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org> |
@@ -1466,83 +1466,6 @@ freezero(void *ptr, size_t sz) | |||
1466 | } | 1466 | } |
1467 | DEF_WEAK(freezero); | 1467 | DEF_WEAK(freezero); |
1468 | 1468 | ||
1469 | static size_t | ||
1470 | osize(struct dir_info *argpool, void *p) | ||
1471 | { | ||
1472 | struct dir_info *pool; | ||
1473 | struct region_info *r; | ||
1474 | char *saved_function; | ||
1475 | size_t sz; | ||
1476 | int i; | ||
1477 | |||
1478 | pool = argpool; | ||
1479 | r = find(pool, p); | ||
1480 | if (r == NULL) { | ||
1481 | if (mopts.malloc_mt) { | ||
1482 | for (i = 0; i < _MALLOC_MUTEXES; i++) { | ||
1483 | if (i == argpool->mutex) | ||
1484 | continue; | ||
1485 | pool->active--; | ||
1486 | _MALLOC_UNLOCK(pool->mutex); | ||
1487 | pool = mopts.malloc_pool[i]; | ||
1488 | _MALLOC_LOCK(pool->mutex); | ||
1489 | pool->active++; | ||
1490 | r = find(pool, p); | ||
1491 | if (r != NULL) { | ||
1492 | saved_function = pool->func; | ||
1493 | pool->func = argpool->func; | ||
1494 | break; | ||
1495 | } | ||
1496 | } | ||
1497 | } | ||
1498 | if (r == NULL) | ||
1499 | wrterror(argpool, "bogus pointer (double free?) %p", p); | ||
1500 | } | ||
1501 | |||
1502 | REALSIZE(sz, r); | ||
1503 | if (sz > MALLOC_MAXCHUNK) { | ||
1504 | if (MALLOC_MOVE_COND(sz)) | ||
1505 | sz = MALLOC_PAGESIZE - ((char *)p - (char *)r->p); | ||
1506 | else | ||
1507 | sz = PAGEROUND(sz); | ||
1508 | } | ||
1509 | if (argpool != pool) { | ||
1510 | pool->active--; | ||
1511 | pool->func = saved_function; | ||
1512 | _MALLOC_UNLOCK(pool->mutex); | ||
1513 | _MALLOC_LOCK(argpool->mutex); | ||
1514 | argpool->active++; | ||
1515 | } | ||
1516 | return sz; | ||
1517 | } | ||
1518 | |||
1519 | size_t | ||
1520 | malloc_usable_size(void *ptr) | ||
1521 | { | ||
1522 | struct dir_info *d; | ||
1523 | int saved_errno = errno; | ||
1524 | size_t sz; | ||
1525 | |||
1526 | /* This is legal. */ | ||
1527 | if (ptr == NULL) | ||
1528 | return 0; | ||
1529 | |||
1530 | d = getpool(); | ||
1531 | if (d == NULL) | ||
1532 | wrterror(d, "malloc_usable_size() called before allocation"); | ||
1533 | _MALLOC_LOCK(d->mutex); | ||
1534 | d->func = "malloc_usable_size"; | ||
1535 | if (d->active++) { | ||
1536 | malloc_recurse(d); | ||
1537 | return 0; | ||
1538 | } | ||
1539 | sz = osize(d, ptr); | ||
1540 | d->active--; | ||
1541 | _MALLOC_UNLOCK(d->mutex); | ||
1542 | errno = saved_errno; | ||
1543 | return sz; | ||
1544 | } | ||
1545 | |||
1546 | static void * | 1469 | static void * |
1547 | orealloc(struct dir_info *argpool, void *p, size_t newsz, void *f) | 1470 | orealloc(struct dir_info *argpool, void *p, size_t newsz, void *f) |
1548 | { | 1471 | { |