Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,21 @@ macro_rules! offset_of {
}};
}

/// Defines constants with an accompanying doc comment pointing out their
/// instability, and links to the crate documentation for usage guidelines.
macro_rules! ct {
($($it:item)+) => {
$(
/// This constant, among others often used in C for the purposes of denoting the
/// latest value or limit in a set of constants, is likely to change upstream.
/// For correct usage, see the [crate-level documentation][docs].
///
/// [docs]: index.html#usage-recommendations
$it
)+
};
}

#[cfg(test)]
mod tests {
use core::any::TypeId;
Expand Down
83 changes: 48 additions & 35 deletions src/unix/bsd/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3733,7 +3733,11 @@ pub const MNT_NOWAIT: c_int = 2;

// <mach/thread_policy.h>
pub const THREAD_STANDARD_POLICY: c_int = 1;
pub const THREAD_STANDARD_POLICY_COUNT: c_int = 0;

ct! {
pub const THREAD_STANDARD_POLICY_COUNT: c_int = 0;
}

pub const THREAD_EXTENDED_POLICY: c_int = 1;
pub const THREAD_TIME_CONSTRAINT_POLICY: c_int = 2;
pub const THREAD_PRECEDENCE_POLICY: c_int = 3;
Expand Down Expand Up @@ -3795,7 +3799,11 @@ pub const VM_PAGE_QUERY_PAGE_CS_NX: i32 = 0x400;

// mach/task_info.h
pub const TASK_THREAD_TIMES_INFO: u32 = 3;
pub const HOST_CPU_LOAD_INFO_COUNT: u32 = 4;

ct! {
pub const HOST_CPU_LOAD_INFO_COUNT: u32 = 4;
}

pub const MACH_TASK_BASIC_INFO: u32 = 20;

pub const MACH_PORT_NULL: i32 = 0;
Expand Down Expand Up @@ -3858,7 +3866,10 @@ pub const COPYFILE_STATE_DST_BSIZE: c_int = 12;
pub const COPYFILE_STATE_BSIZE: c_int = 13;

// <sys/attr.h>
pub const ATTR_BIT_MAP_COUNT: c_ushort = 5;
ct! {
pub const ATTR_BIT_MAP_COUNT: c_ushort = 5;
}

pub const FSOPT_NOFOLLOW: u32 = 0x1;
pub const FSOPT_NOFOLLOW_ANY: u32 = 0x800;
pub const FSOPT_REPORT_FULLSIZE: u32 = 0x4;
Expand Down Expand Up @@ -4029,38 +4040,40 @@ const fn __DARWIN_ALIGN32(p: usize) -> usize {
(p + __DARWIN_ALIGNBYTES32) & !__DARWIN_ALIGNBYTES32
}

pub const THREAD_EXTENDED_POLICY_COUNT: mach_msg_type_number_t =
(size_of::<thread_extended_policy_data_t>() / size_of::<integer_t>()) as mach_msg_type_number_t;
pub const THREAD_TIME_CONSTRAINT_POLICY_COUNT: mach_msg_type_number_t =
(size_of::<thread_time_constraint_policy_data_t>() / size_of::<integer_t>())
as mach_msg_type_number_t;
pub const THREAD_PRECEDENCE_POLICY_COUNT: mach_msg_type_number_t =
(size_of::<thread_precedence_policy_data_t>() / size_of::<integer_t>())
as mach_msg_type_number_t;
pub const THREAD_AFFINITY_POLICY_COUNT: mach_msg_type_number_t =
(size_of::<thread_affinity_policy_data_t>() / size_of::<integer_t>()) as mach_msg_type_number_t;
pub const THREAD_BACKGROUND_POLICY_COUNT: mach_msg_type_number_t =
(size_of::<thread_background_policy_data_t>() / size_of::<integer_t>())
as mach_msg_type_number_t;
pub const THREAD_LATENCY_QOS_POLICY_COUNT: mach_msg_type_number_t =
(size_of::<thread_latency_qos_policy_data_t>() / size_of::<integer_t>())
as mach_msg_type_number_t;
pub const THREAD_THROUGHPUT_QOS_POLICY_COUNT: mach_msg_type_number_t =
(size_of::<thread_throughput_qos_policy_data_t>() / size_of::<integer_t>())
as mach_msg_type_number_t;
pub const THREAD_BASIC_INFO_COUNT: mach_msg_type_number_t =
(size_of::<thread_basic_info_data_t>() / size_of::<integer_t>()) as mach_msg_type_number_t;
pub const THREAD_IDENTIFIER_INFO_COUNT: mach_msg_type_number_t =
(size_of::<thread_identifier_info_data_t>() / size_of::<integer_t>()) as mach_msg_type_number_t;
pub const THREAD_EXTENDED_INFO_COUNT: mach_msg_type_number_t =
(size_of::<thread_extended_info_data_t>() / size_of::<integer_t>()) as mach_msg_type_number_t;

pub const TASK_THREAD_TIMES_INFO_COUNT: u32 =
(size_of::<task_thread_times_info_data_t>() / size_of::<natural_t>()) as u32;
pub const MACH_TASK_BASIC_INFO_COUNT: u32 =
(size_of::<mach_task_basic_info_data_t>() / size_of::<natural_t>()) as u32;
pub const HOST_VM_INFO64_COUNT: mach_msg_type_number_t =
(size_of::<vm_statistics64_data_t>() / size_of::<integer_t>()) as mach_msg_type_number_t;
ct! {
pub const THREAD_EXTENDED_POLICY_COUNT: mach_msg_type_number_t =
(size_of::<thread_extended_policy_data_t>() / size_of::<integer_t>()) as mach_msg_type_number_t;
pub const THREAD_TIME_CONSTRAINT_POLICY_COUNT: mach_msg_type_number_t =
(size_of::<thread_time_constraint_policy_data_t>() / size_of::<integer_t>())
as mach_msg_type_number_t;
pub const THREAD_PRECEDENCE_POLICY_COUNT: mach_msg_type_number_t =
(size_of::<thread_precedence_policy_data_t>() / size_of::<integer_t>())
as mach_msg_type_number_t;
pub const THREAD_AFFINITY_POLICY_COUNT: mach_msg_type_number_t =
(size_of::<thread_affinity_policy_data_t>() / size_of::<integer_t>()) as mach_msg_type_number_t;
pub const THREAD_BACKGROUND_POLICY_COUNT: mach_msg_type_number_t =
(size_of::<thread_background_policy_data_t>() / size_of::<integer_t>())
as mach_msg_type_number_t;
pub const THREAD_LATENCY_QOS_POLICY_COUNT: mach_msg_type_number_t =
(size_of::<thread_latency_qos_policy_data_t>() / size_of::<integer_t>())
as mach_msg_type_number_t;
pub const THREAD_THROUGHPUT_QOS_POLICY_COUNT: mach_msg_type_number_t =
(size_of::<thread_throughput_qos_policy_data_t>() / size_of::<integer_t>())
as mach_msg_type_number_t;
pub const THREAD_BASIC_INFO_COUNT: mach_msg_type_number_t =
(size_of::<thread_basic_info_data_t>() / size_of::<integer_t>()) as mach_msg_type_number_t;
pub const THREAD_IDENTIFIER_INFO_COUNT: mach_msg_type_number_t =
(size_of::<thread_identifier_info_data_t>() / size_of::<integer_t>()) as mach_msg_type_number_t;
pub const THREAD_EXTENDED_INFO_COUNT: mach_msg_type_number_t =
(size_of::<thread_extended_info_data_t>() / size_of::<integer_t>()) as mach_msg_type_number_t;

pub const TASK_THREAD_TIMES_INFO_COUNT: u32 =
(size_of::<task_thread_times_info_data_t>() / size_of::<natural_t>()) as u32;
pub const MACH_TASK_BASIC_INFO_COUNT: u32 =
(size_of::<mach_task_basic_info_data_t>() / size_of::<natural_t>()) as u32;
pub const HOST_VM_INFO64_COUNT: mach_msg_type_number_t =
(size_of::<vm_statistics64_data_t>() / size_of::<integer_t>()) as mach_msg_type_number_t;
}

// bsd/net/if_mib.h
/// Non-interface-specific
Expand Down
5 changes: 4 additions & 1 deletion src/unix/linux_like/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1569,7 +1569,10 @@ pub const NFNL_SUBSYS_CTNETLINK_TIMEOUT: c_int = 8;
pub const NFNL_SUBSYS_CTHELPER: c_int = 9;
pub const NFNL_SUBSYS_NFTABLES: c_int = 10;
pub const NFNL_SUBSYS_NFT_COMPAT: c_int = 11;
pub const NFNL_SUBSYS_COUNT: c_int = 12;

ct! {
pub const NFNL_SUBSYS_COUNT: c_int = 12;
}

pub const NFNL_MSG_BATCH_BEGIN: c_int = NLMSG_MIN_TYPE;
pub const NFNL_MSG_BATCH_END: c_int = NLMSG_MIN_TYPE + 1;
Expand Down
5 changes: 4 additions & 1 deletion src/unix/linux_like/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1899,7 +1899,10 @@ pub const NFNL_SUBSYS_CTHELPER: c_int = 9;
pub const NFNL_SUBSYS_NFTABLES: c_int = 10;
pub const NFNL_SUBSYS_NFT_COMPAT: c_int = 11;
pub const NFNL_SUBSYS_HOOK: c_int = 12;
pub const NFNL_SUBSYS_COUNT: c_int = 13;

ct! {
pub const NFNL_SUBSYS_COUNT: c_int = 13;
}

pub const NFNL_MSG_BATCH_BEGIN: c_int = crate::NLMSG_MIN_TYPE;
pub const NFNL_MSG_BATCH_END: c_int = crate::NLMSG_MIN_TYPE + 1;
Expand Down
5 changes: 4 additions & 1 deletion src/unix/solarish/illumos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,10 @@ pub const PRIV_USER: c_uint = PRIV_DEBUG
| PRIV_AWARE_RESET
| PRIV_PFEXEC;

pub const LGRP_RSRC_COUNT: crate::lgrp_rsrc_t = 2;
ct! {
pub const LGRP_RSRC_COUNT: crate::lgrp_rsrc_t = 2;
}

pub const LGRP_RSRC_CPU: crate::lgrp_rsrc_t = 0;
pub const LGRP_RSRC_MEM: crate::lgrp_rsrc_t = 1;

Expand Down
Loading