1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
// Copyright 2025, TAIL OS. All Rights Reserved.
//
// You must obtain a written license from and pay applicable license fees to TAIL OS
// before you may reproduce, modify, or distribute this software, or any work that
// includes all or part of this software.
//
// Free development licenses are available for evaluation, research, and non-commercial
// purposes, which may include access to the source code under these terms. Redistribution
// or commercial use without a license is strictly prohibited.
//
// This file may contain contributions from others. Please review this entire file for
// other proprietary rights or license notices, as well as the TAIL OS License Guide at
// https://tail-os.com/license-guide/ for more information.
//
// For licensing inquiries, visit https://tail-os.com or email license@tail-os.com.
use cratesyscall;
use ptr;
use crateSERVER_NAME_MAX_LENGTH;
use crateServiceRequestData;
use crateServiceReplyData;
use crateErrorKind;
use mem;
/*
#[stable(feature = "client", since = "1.0.0")]
pub struct Client<T: Server> {
server_name: [u8; SERVER_NAME_MAX_LENGTH],
phantom: crate::marker::PhantomData<T>,
}
impl<T: Server> Client<T> {
#[stable(feature = "client", since = "1.0.0")]
#[rustc_const_stable(feature = "client", since = "1.0.0")]
pub const fn new(server_name: &str) -> Client<T> {
let mut client = Client {
server_name: [0; SERVER_NAME_MAX_LENGTH],
phantom: crate::marker::PhantomData,
};
unsafe { ptr::copy_nonoverlapping(server_name.as_ptr(), client.server_name.as_ptr() as *mut u8, server_name.len()) };
client
}
#[stable(feature = "client", since = "1.0.0")]
pub fn request_service(&self, request_type: u64, request_message: *const u8, request_message_size: usize) -> u64 {
let response = syscall::syscall_request_service(core::str::from_utf8(&self.server_name).unwrap_or(""), request_type, request_message, request_message_size);
return response;
}
}
*/
/*
#[stable(feature = "client", since = "1.0.0")]
pub fn request_service_as_ref_u8_slice<T: AsRef<[u8]>>(server_name: &str, request_message_type: u64, request_message_ref: &T,
request_message_size: usize, reply_message_ref: &T, reply_message_size: usize) -> Result<(), std::io::Error>
{
let result = syscall::syscall_request_service(server_name, request_message_type, request_message_ref.as_ref().as_ptr(),
request_message_size, reply_message_ref.as_ref().as_ptr(), reply_message_size);
if (result < 0) {
return Err(std::io::Error::new(std::io::ErrorKind::Other, "syscall failed"));
} else {
return Ok(());
}
}
#[stable(feature = "client", since = "1.0.0")]
pub fn request_service_sized<T>(server_name: &str, request_message_type: u64, request_message_ref: &T,
request_message_size: usize, reply_message_ref: &T, reply_message_size: usize) -> Result<(), std::io::Error>
{
let result = syscall::syscall_request_service(server_name, request_message_type, request_message_ref as *const T as *const u8,
request_message_size, reply_message_ref as *const T as *const u8, reply_message_size);
if (result < 0) {
return Err(std::io::Error::new(std::io::ErrorKind::Other, "syscall failed"));
} else {
return Ok(());
}
}
*/
/*
#[stable(feature = "client", since = "1.0.0")]
pub fn request_service_as_ref_u8_slice<T: AsRef<[u8]>>(server_name: &str, request_message_type: u64,
request_message_ref: &T, request_message_size: usize) -> Result<(&'static T, usize), crate::io::Error>
{
match syscall::syscall_request_service(server_name, request_message_type, request_message_ref.as_ref().as_ptr(),
request_message_size) {
Ok((reply_message_ptr, reply_message_size)) => {
let reply_message_ref = unsafe { &*(reply_message_ptr as *const T) };
Ok((reply_message_ref, reply_message_size))
}
Err(_) => Err(crate::io::Error::new(crate::io::ErrorKind::Other, "syscall failed")),
}
}
#[stable(feature = "client", since = "1.0.0")]
pub fn request_service_sized<T>(server_name: &str, request_message_type: u64, request_message_ref: &T, request_message_size: usize) -> Result<(&'static T, usize), crate::io::Error>
{
match syscall::syscall_request_service(server_name, request_message_type, request_message_ref as *const T as *const u8,
request_message_size) {
Ok((reply_message_ptr, reply_message_size)) => {
let reply_message_ref = unsafe { &*(reply_message_ptr as *const T) };
Ok((reply_message_ref, reply_message_size))
}
Err(_) => Err(crate::io::Error::new(crate::io::ErrorKind::Other, "syscall failed")),
}
}
*/
/// Sends a service request and waits for a reply.
///
/// The `request_data` buffer is treated as read-only once passed to this function.
/// The kernel will make the buffer read-only at the MMU level before sharing it with the server,
/// ensuring memory corruption safety and FFI compliance.
///
/// # Safety
/// The caller must ensure that `request_data` contains valid data and will not be modified
/// after this function is called (until the reply is received and the buffer is restored).
/*
#[stable(feature = "client", since = "1.0.0")]
pub fn request_service_primitive_slice<T: ?Sized, U: ?Sized>(server_name: &str, request_message_type: u64,
request_message_ref: Option<&T>, request_message_size: usize, reply_message_ref: Option<&mut U>, mut reply_message_size: usize) -> Result<(), crate::io::Error>
{
let request_message_ptr = request_message_ref.map_or(ptr::null(), |r| r as *const T as *const u8);
let reply_message_ptr = reply_message_ref.map_or(ptr::null(), |r| r as *mut U as *mut u8);
match syscall::syscall_request_service(server_name, request_message_type,
request_message_ptr, request_message_size, reply_message_ptr, reply_message_size) {
Ok(_) => {
Ok(())
},
Err(_) => Err(crate::io::Error::new(crate::io::ErrorKind::Other, "syscall failed")),
}
}
*/
/*
#[stable(feature = "client", since = "1.0.0")]
pub fn request_service_sized<T, U>(server_name: &str, request_message_type: u64,
request_message_ref: Option<&T>, request_message_size: usize, reply_message_ref: Option<&mut U>, mut reply_message_size: usize) -> Result<(), crate::io::Error>
{
let request_message_ptr = request_message_ref.map_or(ptr::null(), |r| r as *const T as *const u8);
let reply_message_ptr = reply_message_ref.map_or(ptr::null(), |r| r as *const U as *const u8);
match syscall::syscall_request_service(server_name, request_message_type,
request_message_ptr, request_message_size, reply_message_ptr, reply_message_size) {
Ok(_) => {
Ok(())
},
Err(_) => Err(crate::io::Error::new(crate::io::ErrorKind::Other, "syscall failed")),
}
}*/