Skip to content

Commit 96b4c50

Browse files
committed
[bindings] Bug Fix: tweak and fix minor behavior in headers/bindings
1 parent 70bf887 commit 96b4c50

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

include/demi/cc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#define _In_opt_
1313
#define _In_reads_(s)
1414
#define _In_reads_bytes_(b)
15+
#define _Inout_
1516
#define _Out_
1617
#define _Out_writes_to_(s, c)
1718
#define _Deref_pre_z_

include/demi/libos.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,27 +156,28 @@ extern "C"
156156
/**
157157
* @brief Gets socket options.
158158
*
159-
* @param qd Target I/O queue descriptor.
160-
* @param level Protocol level at which the option resides.
159+
* @param qd Target I/O queue descriptor.
160+
* @param level Protocol level at which the option resides.
161161
* @param optname Socket option for which the value is to be retrieved.
162-
* @param optval Pointer to the buffer containing the option value.
163-
* @param optlen Size of the buffer containing the option value.
162+
* @param optval Pointer to the buffer containing the option value.
163+
* @param optlen On input, specified the size of the buffer containing the option value. Upon successful
164+
* completion, updated to indicate the number of bytes written to optval.
164165
*
165166
* @return On successful completion, zero is returned. On failure, a positive error code is returned instead.
166167
*/
167-
ATTR_NONNULL(4)
168-
extern int demi_getsockopt(_In_ int qd, _In_ int level, _In_ int optname, _Out_writes_to_(optlen, *optlen) void *optval, _In_ socklen_t *optlen);
169-
168+
ATTR_NONNULL(4, 5)
169+
extern int demi_getsockopt(_In_ int qd, _In_ int level, _In_ int optname, _Out_writes_to_(*optlen, *optlen) void *optval, _Inout_ socklen_t *optlen);
170170
/**
171171
* @brief Returns the address of the peer connected to qd.
172172
*
173173
* @param addr Peer address is returned in this parameter.
174-
* @param addrlen Indicates the amount of space pointed to by addr
174+
* @param addrlen Indicates the amount of space pointed to by addr; updated on success to indicate the number of
175+
* bytes written to addr.
175176
*
176177
* @return On success, zero is returned. On failure, a possitive error code is returned.
177178
*/
178-
ATTR_NONNULL(2)
179-
extern int demi_getpeername(_In_ int qd, _Out_writes_to_(addrlen, *addrlen) struct sockaddr *addr, _In_ socklen_t *addrlen);
179+
ATTR_NONNULL(2, 3)
180+
extern int demi_getpeername(_In_ int qd, _Out_writes_to_(*addrlen, *addrlen) struct sockaddr *addr, _Inout_ socklen_t *addrlen);
180181

181182
#ifdef __cplusplus
182183
}

include/demi/types.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515

1616
#ifdef _WIN32
1717
#include <WinSock2.h>
18+
19+
// NB push the structure packing onto the stack with a label to ensure we correctly restore it at the end of the
20+
// header.
21+
#pragma pack(push, demi0)
1822
#endif
1923

2024
#ifdef __cplusplus
@@ -157,4 +161,9 @@ extern "C"
157161
}
158162
#endif
159163

164+
#ifdef _WIN32
165+
// Restore the original packing alignment.
166+
#pragma pack(pop, demi0)
167+
#endif
168+
160169
#endif /* DEMI_TYPES_H_IS_INCLUDED */

src/rust/demikernel/bindings.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,10 @@ pub extern "C" fn demi_wait(qr_out: *mut demi_qresult_t, qt: demi_qtoken_t, time
395395
0
396396
},
397397
Err(e) => {
398-
trace!("demi_wait() failed: {:?}", e);
398+
// EDTIMEDOUT is not a "failure" per se; don't trace.
399+
if e.errno != libc::ETIMEDOUT {
400+
trace!("demi_wait() failed: {:?}", e);
401+
}
399402
e.errno
400403
},
401404
});
@@ -455,7 +458,10 @@ pub extern "C" fn demi_wait_any(
455458
0
456459
},
457460
Err(e) => {
458-
trace!("demi_wait_any() failed: {:?}", e);
461+
// EDTIMEDOUT is not a "failure" per se; don't trace.
462+
if e.errno != libc::ETIMEDOUT {
463+
trace!("demi_wait_any() failed: {:?}", e);
464+
}
459465
e.errno
460466
},
461467
});
@@ -510,6 +516,7 @@ pub extern "C" fn demi_wait_next_n(
510516
let ret: Result<i32, Fail> = do_syscall(|libos| match libos.wait_next_n(wait_callback, duration) {
511517
Ok(()) => 0,
512518
Err(e) => {
519+
// EDTIMEDOUT is not a "failure" per se; don't trace.
513520
if e.errno != libc::ETIMEDOUT {
514521
trace!("demi_wait_any() failed: {:?}", e)
515522
};
@@ -638,15 +645,15 @@ pub extern "C" fn demi_setsockopt(
638645
let ret: Result<(), Fail> = match do_syscall(|libos| libos.set_socket_option(qd.into(), opt)) {
639646
Ok(result) => result,
640647
Err(e) => {
641-
trace!("demi_getsockopt(): {:?}", e);
648+
trace!("demi_setsockopt(): {:?}", e);
642649
return e.errno;
643650
},
644651
};
645652

646653
match ret {
647654
Ok(_) => 0,
648655
Err(e) => {
649-
trace!("demi_getsockopt(): {:?}", e);
656+
trace!("demi_setsockopt(): {:?}", e);
650657
e.errno
651658
},
652659
}
@@ -753,7 +760,7 @@ pub extern "C" fn demi_getpeername(qd: c_int, addr: *mut SockAddr, addrlen: *mut
753760

754761
let expected_len = mem::size_of::<SockAddrIn>() as Socklen;
755762

756-
if unsafe { *addrlen != expected_len } {
763+
if unsafe { *addrlen < expected_len } {
757764
warn!("demi_getpeername(): addrlen does not match size of SockAddrIn");
758765
return libc::EINVAL;
759766
}

0 commit comments

Comments
 (0)