Skip to content

Commit db60246

Browse files
committed
Auto merge of #2294 - devnexen:fbsd_malloc_api, r=JohnTitor
freebsd add additional allocator api.
2 parents b6e0cbe + dcfd6fe commit db60246

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

libc-test/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,6 +1728,7 @@ fn test_freebsd(target: &str) {
17281728
"link.h",
17291729
"locale.h",
17301730
"machine/reg.h",
1731+
"malloc_np.h",
17311732
"mqueue.h",
17321733
"net/bpf.h",
17331734
"net/if.h",

libc-test/semver/freebsd.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,10 @@ MADV_PROTECT
645645
MADV_RANDOM
646646
MADV_SEQUENTIAL
647647
MADV_WILLNEED
648+
MALLOCX_ARENA
649+
MALLOCX_ALIGN
650+
MALLOCX_TCACHE
651+
MALLOCX_ZERO
648652
MAP_COPY
649653
MAP_EXCL
650654
MAP_FILE
@@ -1361,6 +1365,7 @@ clock_settime
13611365
cmsgcred
13621366
cmsghdr
13631367
daemon
1368+
dallocx
13641369
difftime
13651370
dirfd
13661371
dl_iterate_phdr
@@ -1393,6 +1398,12 @@ fdatasync
13931398
fdopendir
13941399
fexecve
13951400
fflags_t
1401+
ffs
1402+
ffsl
1403+
ffsll
1404+
fls
1405+
flsl
1406+
flsll
13961407
fmemopen
13971408
forkpty
13981409
freeifaddrs
@@ -1464,6 +1475,10 @@ login_tty
14641475
lutimes
14651476
lwpid_t
14661477
madvise
1478+
mallctl
1479+
mallctlbymib
1480+
mallctlnametomib
1481+
mallocx
14671482
memmem
14681483
memrchr
14691484
memset_s
@@ -1496,6 +1511,7 @@ msgqnum_t
14961511
msgrcv
14971512
msgsnd
14981513
msqid_ds
1514+
nallocx
14991515
newlocale
15001516
nice
15011517
nl_item
@@ -1588,6 +1604,7 @@ pututxline
15881604
pwritev
15891605
qsort
15901606
querylocale
1607+
rallocx
15911608
rand
15921609
readdir_r
15931610
readlinkat
@@ -1606,9 +1623,11 @@ regmatch_t
16061623
regoff_t
16071624
rtprio
16081625
rtprio_thread
1626+
sallocx
16091627
sched_getscheduler
16101628
sched_param
16111629
sched_setscheduler
1630+
sdallocx
16121631
seekdir
16131632
sem_close
16141633
sem_destroy
@@ -1675,4 +1694,5 @@ utmpx
16751694
vm_size_t
16761695
wait4
16771696
waitid
1697+
xallocx
16781698
xucred

src/unix/bsd/freebsdlike/freebsd/mod.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,8 @@ pub const RFLINUXTHPN: ::c_int = 65536;
13011301
pub const RFTSIGZMB: ::c_int = 524288;
13021302
pub const RFSPAWN: ::c_int = 2147483648;
13031303

1304+
pub const MALLOCX_ZERO: ::c_int = 0x40;
1305+
13041306
const_fn! {
13051307
{const} fn _ALIGN(p: usize) -> usize {
13061308
(p + _ALIGNBYTES) & !_ALIGNBYTES
@@ -1340,6 +1342,18 @@ f! {
13401342
as ::c_uint
13411343
}
13421344

1345+
pub fn MALLOCX_ALIGN(lg: ::c_uint) -> ::c_int {
1346+
ffsl(lg as ::c_long - 1)
1347+
}
1348+
1349+
pub {const} fn MALLOCX_TCACHE(tc: ::c_int) -> ::c_int {
1350+
(tc + 2) << 8 as ::c_int
1351+
}
1352+
1353+
pub {const} fn MALLOCX_ARENA(a: ::c_int) -> ::c_int {
1354+
(a + 1) << 20 as ::c_int
1355+
}
1356+
13431357
pub fn SOCKCREDSIZE(ngrps: usize) -> usize {
13441358
let ngrps = if ngrps > 0 {
13451359
ngrps - 1
@@ -1695,6 +1709,47 @@ extern "C" {
16951709
pub fn cap_rights_contains(big: *const cap_rights_t, little: *const cap_rights_t) -> bool;
16961710

16971711
pub fn reallocarray(ptr: *mut ::c_void, nmemb: ::size_t, size: ::size_t) -> *mut ::c_void;
1712+
1713+
pub fn ffs(value: ::c_int) -> ::c_int;
1714+
pub fn ffsl(value: ::c_long) -> ::c_int;
1715+
pub fn ffsll(value: ::c_longlong) -> ::c_int;
1716+
pub fn fls(value: ::c_int) -> ::c_int;
1717+
pub fn flsl(value: ::c_long) -> ::c_int;
1718+
pub fn flsll(value: ::c_longlong) -> ::c_int;
1719+
pub fn malloc_usable_size(ptr: *const ::c_void) -> ::size_t;
1720+
pub fn malloc_stats_print(
1721+
write_cb: unsafe extern "C" fn(*mut ::c_void, *const ::c_char),
1722+
cbopaque: *mut ::c_void,
1723+
opt: *const ::c_char,
1724+
);
1725+
pub fn mallctl(
1726+
name: *const ::c_char,
1727+
oldp: *mut ::c_void,
1728+
oldlenp: *mut ::size_t,
1729+
newp: *mut ::c_void,
1730+
newlen: ::size_t,
1731+
) -> ::c_int;
1732+
pub fn mallctlnametomib(
1733+
name: *const ::c_char,
1734+
mibp: *mut ::size_t,
1735+
miplen: *mut ::size_t,
1736+
) -> ::c_int;
1737+
pub fn mallctlbymib(
1738+
mib: *const ::size_t,
1739+
mible: ::size_t,
1740+
oldp: *mut ::c_void,
1741+
oldlenp: *mut ::size_t,
1742+
newp: *mut ::c_void,
1743+
newlen: ::size_t,
1744+
) -> ::c_int;
1745+
pub fn mallocx(size: ::size_t, flags: ::c_int) -> *mut ::c_void;
1746+
pub fn rallocx(ptr: *mut ::c_void, size: ::size_t, flags: ::c_int) -> *mut ::c_void;
1747+
pub fn xallocx(ptr: *mut ::c_void, size: ::size_t, extra: ::size_t, flags: ::c_int)
1748+
-> ::size_t;
1749+
pub fn sallocx(ptr: *const ::c_void, flags: ::c_int) -> ::size_t;
1750+
pub fn dallocx(ptr: *mut ::c_void, flags: ::c_int);
1751+
pub fn sdallocx(ptr: *mut ::c_void, size: ::size_t, flags: ::c_int);
1752+
pub fn nallocx(size: ::size_t, flags: ::c_int) -> ::size_t;
16981753
}
16991754

17001755
#[link(name = "util")]

0 commit comments

Comments
 (0)