Skip to content

Commit 0fcdcdc

Browse files
authored
Merge pull request #1267 from microsoft/feature-pdpix-sockopt
[pdpix] Expose System Calls for Setting / Getting Socket Options
2 parents c25fdd5 + 8d58858 commit 0fcdcdc

File tree

2 files changed

+57
-7
lines changed

2 files changed

+57
-7
lines changed

include/demi/libos.h

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ extern "C"
3333
ATTR_NONNULL(2)
3434
extern int demi_init(_In_ int argc, _In_reads_(argc) _Deref_pre_z_ char *const argv[]);
3535

36-
3736
/**
3837
* @brief Creates a new memory I/O queue.
3938
*
@@ -116,7 +115,6 @@ extern "C"
116115
extern int demi_connect(_Out_ demi_qtoken_t *qt_out, _In_ int sockqd,
117116
_In_reads_bytes_(size) const struct sockaddr *addr, _In_ socklen_t size);
118117

119-
120118
/**
121119
* @brief Closes an I/O queue descriptor.
122120
*
@@ -164,6 +162,34 @@ extern "C"
164162
ATTR_NONNULL(1)
165163
extern int demi_pop(_Out_ demi_qtoken_t *qt_out, _In_ int qd);
166164

165+
/**
166+
* @brief Sets socket options.
167+
*
168+
* @param qd Target I/O queue descriptor.
169+
* @param level Protocol level at which the option resides.
170+
* @param optname Socket option for which the value is to be set.
171+
* @param optval Pointer to the buffer containing the option value.
172+
* @param optlen Size of the buffer containing the option value.
173+
*
174+
* @return On successful completion, zero is returned. On failure, a positive error code is returned instead.
175+
*/
176+
ATTR_NONNULL(4)
177+
extern int demi_setsockopt(_In_ int qd, _In_ int level, _In_ int optname, _In_reads_bytes_(optlen) const void *optval, _In_ socklen_t optlen);
178+
179+
/**
180+
* @brief Gets socket options.
181+
*
182+
* @param qd Target I/O queue descriptor.
183+
* @param level Protocol level at which the option resides.
184+
* @param optname Socket option for which the value is to be retrieved.
185+
* @param optval Pointer to the buffer containing the option value.
186+
* @param optlen Size of the buffer containing the option value.
187+
*
188+
* @return On successful completion, zero is returned. On failure, a positive error code is returned instead.
189+
*/
190+
ATTR_NONNULL(4)
191+
extern int demi_getsockopt(_In_ int qd, _In_ int level, _In_ int optname, _Out_writes_to_(optlen, *optlen) void *optval, _In_ socklen_t *optlen);
192+
167193
#ifdef __cplusplus
168194
}
169195
#endif

tests/c/syscalls.c

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,34 @@ static bool inval_pop(void)
126126
return (demi_pop(qt, qd) != 0);
127127
}
128128

129+
/**
130+
* @brief Issues an invalid call to demi_setsockopt().
131+
*/
132+
static bool inval_setsockopt(void)
133+
{
134+
int qd = -1;
135+
int level = -1;
136+
int optname = -1;
137+
const void *optval = NULL;
138+
socklen_t optlen = 0;
139+
140+
return (demi_setsockopt(qd, level, optname, optval, optlen) != 0);
141+
}
142+
143+
/**
144+
* @brief Issues an invalid call to demi_getsockopt().
145+
*/
146+
static bool inval_getsockopt(void)
147+
{
148+
int qd = -1;
149+
int level = -1;
150+
int optname = -1;
151+
void *optval = NULL;
152+
socklen_t *optlen = NULL;
153+
154+
return (demi_getsockopt(qd, level, optname, optval, optlen) != 0);
155+
}
156+
129157
/*===================================================================================================================*
130158
* System Calls in demi/sga.h *
131159
*===================================================================================================================*/
@@ -199,11 +227,7 @@ struct test
199227
/**
200228
* @brief Tests for system calls in demi/libos.h
201229
*/
202-
static struct test tests_libos[] = {{inval_socket, "invalid demi_socket()"}, {inval_accept, "invalid demi_accept()"},
203-
{inval_bind, "invalid demi_bind()"}, {inval_close, "invalid_demi_close()"},
204-
{inval_connect, "invalid demi_connect()"}, {inval_listen, "invalid demi_listen()"},
205-
{inval_pop, "invalid demi_pop()"}, {inval_push, "invalid demi_push()"},
206-
{inval_pushto, "invalid demi_pushto()"}};
230+
static struct test tests_libos[] = {{inval_socket, "invalid demi_socket()"}, {inval_accept, "invalid demi_accept()"}, {inval_bind, "invalid demi_bind()"}, {inval_close, "invalid_demi_close()"}, {inval_connect, "invalid demi_connect()"}, {inval_listen, "invalid demi_listen()"}, {inval_pop, "invalid demi_pop()"}, {inval_push, "invalid demi_push()"}, {inval_pushto, "invalid demi_pushto()"}, {inval_setsockopt, "invalid demi_setsockopt()"}, {inval_getsockopt, "invalid demi_getsockopt()}"}};
207231

208232
/**
209233
* @brief Tests for system calls in demi/sga.h

0 commit comments

Comments
 (0)