Skip to content

Commit b035574

Browse files
committed
Auto merge of #2070 - nielx:haiku-raw-pointers, r=JohnTitor
Haiku: use raw pointers instead of references in convenience functions The Haiku API has some convenience macros to make it easier to call certain functions. In the libc implementation, these are implemented as unsafe functions. The previous choice was to take certain pointer parameters as references, and do the conversion to raw pointers when the actual external function was called. However, this causes issues with the image_info struct, which needs to be initialized in Rust, before a native API call is used to enter data. Since part of this structure consists of function pointers, mem::zeroed() cannot be used, since in Rust function pointers cannot be NULL. Thus one needs to use the MaybeUnit<T> API to properly initialize it. This then makes it problematic to use the convenience functions, as a MaybeUnit<image_info> cannot be converted into an &mut image_info before it is marked as initialized with valid data. It can be converted into a raw *mut image_info, so if the function accepts this as a parameter it can be used. For consistency, all convenience functions have been converted from using references to using raw pointers.
2 parents d4080d1 + 59afbfe commit b035574

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/unix/haiku/native.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -1023,14 +1023,14 @@ pub unsafe fn get_next_area_info(
10231023
)
10241024
}
10251025

1026-
pub unsafe fn get_port_info(port: port_id, buf: &mut port_info) -> status_t {
1026+
pub unsafe fn get_port_info(port: port_id, buf: *mut port_info) -> status_t {
10271027
_get_port_info(port, buf, core::mem::size_of::<port_info>() as ::size_t)
10281028
}
10291029

10301030
pub unsafe fn get_next_port_info(
10311031
port: port_id,
1032-
cookie: &mut i32,
1033-
portInfo: &mut port_info,
1032+
cookie: *mut i32,
1033+
portInfo: *mut port_info,
10341034
) -> status_t {
10351035
_get_next_port_info(
10361036
port,
@@ -1042,7 +1042,7 @@ pub unsafe fn get_next_port_info(
10421042

10431043
pub unsafe fn get_port_message_info_etc(
10441044
port: port_id,
1045-
info: &mut port_message_info,
1045+
info: *mut port_message_info,
10461046
flags: u32,
10471047
timeout: bigtime_t,
10481048
) -> status_t {
@@ -1055,14 +1055,14 @@ pub unsafe fn get_port_message_info_etc(
10551055
)
10561056
}
10571057

1058-
pub unsafe fn get_sem_info(id: sem_id, info: &mut sem_info) -> status_t {
1058+
pub unsafe fn get_sem_info(id: sem_id, info: *mut sem_info) -> status_t {
10591059
_get_sem_info(id, info, core::mem::size_of::<sem_info>() as ::size_t)
10601060
}
10611061

10621062
pub unsafe fn get_next_sem_info(
10631063
team: team_id,
1064-
cookie: &mut i32,
1065-
info: &mut sem_info,
1064+
cookie: *mut i32,
1065+
info: *mut sem_info,
10661066
) -> status_t {
10671067
_get_next_sem_info(
10681068
team,
@@ -1072,13 +1072,13 @@ pub unsafe fn get_next_sem_info(
10721072
)
10731073
}
10741074

1075-
pub unsafe fn get_team_info(team: team_id, info: &mut team_info) -> status_t {
1075+
pub unsafe fn get_team_info(team: team_id, info: *mut team_info) -> status_t {
10761076
_get_team_info(team, info, core::mem::size_of::<team_info>() as ::size_t)
10771077
}
10781078

10791079
pub unsafe fn get_next_team_info(
1080-
cookie: &mut i32,
1081-
info: &mut team_info,
1080+
cookie: *mut i32,
1081+
info: *mut team_info,
10821082
) -> status_t {
10831083
_get_next_team_info(
10841084
cookie,
@@ -1090,7 +1090,7 @@ pub unsafe fn get_next_team_info(
10901090
pub unsafe fn get_team_usage_info(
10911091
team: team_id,
10921092
who: i32,
1093-
info: &mut team_usage_info,
1093+
info: *mut team_usage_info,
10941094
) -> status_t {
10951095
_get_team_usage_info(
10961096
team,
@@ -1102,15 +1102,15 @@ pub unsafe fn get_team_usage_info(
11021102

11031103
pub unsafe fn get_thread_info(
11041104
id: thread_id,
1105-
info: &mut thread_info,
1105+
info: *mut thread_info,
11061106
) -> status_t {
11071107
_get_thread_info(id, info, core::mem::size_of::<thread_info>() as ::size_t)
11081108
}
11091109

11101110
pub unsafe fn get_next_thread_info(
11111111
team: team_id,
1112-
cookie: &mut i32,
1113-
info: &mut thread_info,
1112+
cookie: *mut i32,
1113+
info: *mut thread_info,
11141114
) -> status_t {
11151115
_get_next_thread_info(
11161116
team,
@@ -1123,7 +1123,7 @@ pub unsafe fn get_next_thread_info(
11231123
// kernel/image.h
11241124
pub unsafe fn get_image_info(
11251125
image: image_id,
1126-
info: &mut image_info,
1126+
info: *mut image_info,
11271127
) -> status_t {
11281128
_get_image_info(
11291129
image,
@@ -1134,8 +1134,8 @@ pub unsafe fn get_image_info(
11341134

11351135
pub unsafe fn get_next_image_info(
11361136
team: team_id,
1137-
cookie: &mut i32,
1138-
info: &mut image_info,
1137+
cookie: *mut i32,
1138+
info: *mut image_info,
11391139
) -> status_t {
11401140
_get_next_image_info(
11411141
team,

0 commit comments

Comments
 (0)