aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/rdma/input.c
blob: f5091db47192cb8a860d798ffa998a2f0189e41a (plain)
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
/*
 *------------------------------------------------------------------
 * Copyright (c) 2018 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *------------------------------------------------------------------
 */

#include <vlib/vlib.h>
#include <vlib/unix/unix.h>
#include <vlib/pci/pci.h>
#include <vnet/ethernet/ethernet.h>
#include <vnet/devices/devices.h>

#include <rdma/rdma.h>

#define foreach_rdma_input_error \
  _(BUFFER_ALLOC, "buffer alloc error")

typedef enum
{
#define _(f,s) RDMA_INPUT_ERROR_##f,
  foreach_rdma_input_error
#undef _
    RDMA_INPUT_N_ERROR,
} rdma_input_error_t;

static __clib_unused char *rdma_input_error_strings[] = {
#define _(n,s) s,
  foreach_rdma_input_error
#undef _
};

static_always_inline void
rdma_device_input_refill (vlib_main_t * vm, rdma_device_t * rd,
			  rdma_rxq_t * rxq)
{
  u32 n_alloc, n;
  u32 buffers[VLIB_FRAME_SIZE], *bi = buffers;
  vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
  struct ibv_recv_wr wr[VLIB_FRAME_SIZE], *w = wr;
  struct ibv_sge sge[VLIB_FRAME_SIZE], *s = sge;

  if (PREDICT_FALSE (rxq->n_enq >= rxq->size))
    return;

  n_alloc = clib_min (VLIB_FRAME_SIZE, rxq->size - rxq->n_enq);
  n_alloc = n = vlib_buffer_alloc (vm, buffers, n_alloc);
  vlib_get_buffers (vm, buffers, bufs, n_alloc);

  while (n >= 4)
    {
      if (PREDICT_TRUE (n >= 8))
	{
	  CLIB_PREFETCH (&s[4 + 0], 4 * sizeof (s[0]), STORE);
	  CLIB_PREFETCH (&w[4 + 0], 4 * sizeof (w[0]), STORE);
	}

      s[0].addr = vlib_buffer_get_va (b[0]);
      s[0].length = vlib_buffer_get_default_data_size (vm);
      s[0].lkey = rd->mr->lkey;

      s[1].addr = vlib_buffer_get_va (b[1]);
      s[1].length = vlib_buffer_get_default_data_size (vm);
      s[1].lkey = rd->mr->lkey;

      s[2].addr = vlib_buffer_get_va (b[2]);
      s[2].length = vlib_buffer_get_default_data_size (vm);
      s[2].lkey = rd->mr->lkey;

      s[3].addr = vlib_buffer_get_va (b[3]);
      s[3].length = vlib_buffer_get_default_data_size (vm);
      s[3].lkey = rd->mr->lkey;

      w[0].wr_id = bi[0];
      w[0].next = &w[0] + 1;
      w[0].sg_list = &s[0];
      w[0].num_sge = 1;

      w[1].wr_id = bi[1];
      w[1].next = &w[1] + 1;
      w[1].sg_list = &s[1];
      w[1].num_sge = 1;

      w[2].wr_id = bi[2];
      w[2].next = &w[2] + 1;
      w[2].sg_list = &s[2];
      w[2].num_sge = 1;

      w[3].wr_id = bi[3];
      w[3].next = &w[3] + 1;
      w[3].sg_list = &s[3];
      w[3].num_sge = 1;

      s += 4;
      bi += 4;
      w += 4;
      b += 4;
      n -= 4;
    }

  while (n >= 1)
    {
      s[0].addr = vlib_buffer_get_va (b[0]);
      s[0].length = vlib_buffer_get_default_data_size (vm);
      s[0].lkey = rd->mr->lkey;

      w[0].wr_id = bi[0];
      w[0].next = &w[0] + 1;
      w[0].sg_list = &s[0];
      w[0].num_sge = 1;

      s += 1;
      bi += 1;
      w += 1;
      b += 1;
      n -= 1;
    }

  w[-1].next = 0;		/* fix next pointer in WR linked-list last item */

  n = n_alloc;
  if (ibv_post_wq_recv (rxq->wq, wr, &w) != 0)
    {
      n = w - wr;
      vlib_buffer_free (vm, buffers + n, n_alloc - n);
    }

  rxq->n_enq += n;
}

static_always_inline void
rdma_device_input_trace (vlib_main_t * vm, vlib_node_runtime_t * node,
			 const rdma_device_t * rd, u32 n_left, const u32 * bi)
{
  u32 n_trace, i;

  if (PREDICT_TRUE (0 == (n_trace = vlib_get_trace_count (vm, node))))
    return;

  i = 0;
  while (n_trace && n_left)
    {
      vlib_buffer_t *b;
      rdma_input_trace_t *tr;
      b = vlib_get_buffer (vm, bi[0]);
      vlib_trace_buffer (vm, node, rd->per_interface_next_index, b,
			 /* follow_chain */ 0);
      tr = vlib_add_trace (vm, node, b, sizeof (*tr));
      tr->next_index = rd->per_interface_next_index;
      tr->hw_if_index = rd->hw_if_index;

      /* next */
      n_trace--;
      n_left--;
      bi++;
      i++;
    }
  vlib_set_trace_count (vm, node, n_trace);
}

static_always_inline void
rdma_device_input_ethernet (vlib_main_t * vm, vlib_node_runtime_t * node,
			    const rdma_device_t * rd)
{
  vlib_next_frame_t *nf;
  vlib_frame_t *f;
  ethernet_input_frame_t *ef;

  if (PREDICT_FALSE
      (VNET_DEVICE_INPUT_NEXT_ETHERNET_INPUT != rd->per_interface_next_index))
    return;

  nf =
    vlib_node_runtime_get_next_frame (vm, node, rd->per_interface_next_index);
  f = vlib_get_frame (vm, nf->frame);
  f->flags = ETH_INPUT_FRAME_F_SINGLE_SW_IF_IDX;
  /* FIXME: f->flags |= ETH_INPUT_FRAME_F_IP4_CKSUM_OK; */

  ef = vlib_frame_scalar_args (f);
  ef->sw_if_index = rd->sw_if_index;
  ef->hw_if_index = rd->hw_if_index;
}

static_always_inline u32
rdma_device_input_load_wc (u32 n_left_from, struct ibv_wc * wc, u32 * to_next,
			   u32 * bufsz)
{
  u32 n_rx_bytes[4] = { 0 };

  while (n_left_from >= 4)
    {
      if (PREDICT_TRUE (n_left_from >= 8))
	{
	  CLIB_PREFETCH (&wc[4 + 0], CLIB_CACHE_LINE_BYTES, LOAD);
	  CLIB_PREFETCH (&wc[4 + 1], CLIB_CACHE_LINE_BYTES, LOAD);
	  CLIB_PREFETCH (&wc[4 + 2], CLIB_CACHE_LINE_BYTES, LOAD);
	  CLIB_PREFETCH (&wc[4 + 3], CLIB_CACHE_LINE_BYTES, LOAD);
	  CLIB_PREFETCH (&bufsz[4 + 0], 4 * sizeof (bufsz[0]), STORE);
	  CLIB_PREFETCH (&to_next[4 + 0], 4 * sizeof (to_next[0]), STORE);
	}

      to_next[0] = wc[0].wr_id;
      to_next[1] = wc[1].wr_id;
      to_next[2] = wc[2].wr_id;
      to_next[3] = wc[3].wr_id;

      bufsz[0] = wc[0].byte_len;
      bufsz[1] = wc[1].byte_len;
      bufsz[2] = wc[2].byte_len;
      bufsz[3] = wc[3].byte_len;

      n_rx_bytes[0] += wc[0].byte_len;
      n_rx_bytes[1] += wc[1].byte_len;
      n_rx_bytes[2] += wc[2].byte_len;
      n_rx_bytes[3] += wc[3].byte_len;

      wc += 4;
      to_next += 4;
      bufsz += 4;
      n_left_from -= 4;
    }

  while (n_left_from >= 1)
    {
      to_next[0] = wc[0].wr_id;
      bufsz[0] = wc[0].byte_len;
      n_rx_bytes[0] += wc[0].byte_len;

      wc += 1;
      to_next += 1;
      bufsz += 1;
      n_left_from -= 1;
    }

  return n_rx_bytes[0] + n_rx_bytes[1] + n_rx_bytes[2] + n_rx_bytes[3];
}

static_always_inline void
rdma_device_input_bufs_init (u32 n_left_from, vlib_buffer_t ** bufs,
			     u32 * bufsz, u32 sw_if_index)
{
  while (n_left_from >= 4)
    {
      if (PREDICT_TRUE (n_left_from >= 8))
	{
	  vlib_prefetch_buffer_header (bufs[4 + 0], STORE);
	  vlib_prefetch_buffer_header (bufs[4 + 1], STORE);
	  vlib_prefetch_buffer_header (bufs[4 + 2], STORE);
	  vlib_prefetch_buffer_header (bufs[4 + 3], STORE);
	  CLIB_PREFETCH (&bufsz[4 + 0], 4 * sizeof (bufsz[0]), LOAD);
	}

      bufs[0]->current_length = bufsz[0];
      bufs[1]->current_length = bufsz[1];
      bufs[2]->current_length = bufsz[2];
      bufs[3]->current_length = bufsz[3];

      vnet_buffer (bufs[0])->sw_if_index[VLIB_RX] = sw_if_index;
      vnet_buffer (bufs[1])->sw_if_index[VLIB_RX] = sw_if_index;
      vnet_buffer (bufs[2])->sw_if_index[VLIB_RX] = sw_if_index;
      vnet_buffer (bufs[3])->sw_if_index[VLIB_RX] = sw_if_index;

      vnet_buffer (bufs[0])->sw_if_index[VLIB_TX] = ~0;
      vnet_buffer (bufs[1])->sw_if_index[VLIB_TX] = ~0;
      vnet_buffer (bufs[2])->sw_if_index[VLIB_TX] = ~0;
      vnet_buffer (bufs[3])->sw_if_index[VLIB_TX] = ~0;

      bufs += 4;
      bufsz += 4;
      n_left_from -= 4;
    }

  while (n_left_from >= 1)
    {
      bufs[0]->current_length = bufsz[0];
      vnet_buffer (bufs[0])->sw_if_index[VLIB_RX] = sw_if_index;
      vnet_buffer (bufs[0])->sw_if_index[VLIB_TX] = ~0;

      bufs += 1;
      bufsz += 1;
      n_left_from -= 1;
    }
}

static_always_inline uword
rdma_device_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
			  vlib_frame_t * frame, rdma_device_t * rd, u16 qid)
{
  vnet_main_t *vnm = vnet_get_main ();
  rdma_rxq_t *rxq = vec_elt_at_index (rd->rxqs, qid);
  struct ibv_wc wc[VLIB_FRAME_SIZE];
  u32 bufsz[VLIB_FRAME_SIZE];
  vlib_buffer_t *bufs[VLIB_FRAME_SIZE];
  u32 *to_next, n_left_to_next;
  u32 n_rx_packets, n_rx_bytes;

  n_rx_packets = ibv_poll_cq (rxq->cq, VLIB_FRAME_SIZE, wc);

  if (PREDICT_FALSE (n_rx_packets <= 0))
    {
      rdma_device_input_refill (vm, rd, rxq);
      return 0;
    }

  vlib_get_new_next_frame (vm, node, rd->per_interface_next_index, to_next,
			   n_left_to_next);
  n_rx_bytes = rdma_device_input_load_wc (n_rx_packets, wc, to_next, bufsz);
  vlib_get_buffers (vm, to_next, bufs, n_rx_packets);
  rdma_device_input_bufs_init (n_rx_packets, bufs, bufsz, rd->sw_if_index);
  rdma_device_input_trace (vm, node, rd, n_rx_packets, to_next);
  rdma_device_input_ethernet (vm, node, rd);

  vlib_put_next_frame (vm, node, rd->per_interface_next_index,
		       n_left_to_next - n_rx_packets);

  vlib_increment_combined_counter
    (vnm->interface_main.combined_sw_if_counters +
     VNET_INTERFACE_COUNTER_RX, vm->thread_index,
     rd->hw_if_index, n_rx_packets, n_rx_bytes);

  rxq->n_enq -= n_rx_packets;

  rdma_device_input_refill (vm, rd, rxq);

  return n_rx_packets;
}

VLIB_NODE_FN (rdma_input_node) (vlib_main_t * vm,
				vlib_node_runtime_t * node,
				vlib_frame_t * frame)
{
  u32 n_rx = 0;
  rdma_main_t *rm = &rdma_main;
  vnet_device_input_runtime_t *rt = (void *) node->runtime_data;
  vnet_device_and_queue_t *dq;

  foreach_device_and_queue (dq, rt->devices_and_queues)
  {
    rdma_device_t *rd;
    rd = vec_elt_at_index (rm->devices, dq->dev_instance);
    if (PREDICT_TRUE (rd->flags & RDMA_DEVICE_F_ADMIN_UP))
      n_rx += rdma_device_input_inline (vm, node, frame, rd, dq->queue_id);
  }
  return n_rx;
}

/* *INDENT-OFF* */
VLIB_REGISTER_NODE (rdma_input_node) = {
  .name = "rdma-input",
  .sibling_of = "device-input",
  .format_trace = format_rdma_input_trace,
  .type = VLIB_NODE_TYPE_INPUT,
  .state = VLIB_NODE_STATE_DISABLED,
  .n_errors = RDMA_INPUT_N_ERROR,
  .error_strings = rdma_input_error_strings,
};

/* *INDENT-ON* */


/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */
ss="n">recvfrom); SWRAP_SYMBOL_ENTRY (recvmsg); SWRAP_SYMBOL_ENTRY (send); SWRAP_SYMBOL_ENTRY (sendfile); SWRAP_SYMBOL_ENTRY (sendmsg); SWRAP_SYMBOL_ENTRY (sendto); SWRAP_SYMBOL_ENTRY (setsockopt); #ifdef HAVE_SIGNALFD SWRAP_SYMBOL_ENTRY (signalfd); #endif SWRAP_SYMBOL_ENTRY (socket); SWRAP_SYMBOL_ENTRY (socketpair); #ifdef HAVE_TIMERFD_CREATE SWRAP_SYMBOL_ENTRY (timerfd_create); #endif SWRAP_SYMBOL_ENTRY (write); SWRAP_SYMBOL_ENTRY (writev); SWRAP_SYMBOL_ENTRY (shutdown); SWRAP_SYMBOL_ENTRY (select); #ifdef __USE_XOPEN2K SWRAP_SYMBOL_ENTRY (pselect); #endif SWRAP_SYMBOL_ENTRY (epoll_create); SWRAP_SYMBOL_ENTRY (epoll_create1); SWRAP_SYMBOL_ENTRY (epoll_ctl); SWRAP_SYMBOL_ENTRY (epoll_wait); SWRAP_SYMBOL_ENTRY (epoll_pwait); SWRAP_SYMBOL_ENTRY (poll); #ifdef __USE_GNU SWRAP_SYMBOL_ENTRY (ppoll); #endif }; struct swrap { struct { void *handle; void *socket_handle; struct swrap_libc_symbols symbols; } libc; }; static struct swrap swrap; #define LIBC_NAME "libc.so" enum swrap_lib { SWRAP_LIBC, }; #ifndef NDEBUG static const char * swrap_str_lib (enum swrap_lib lib) { switch (lib) { case SWRAP_LIBC: return "libc"; } /* Compiler would warn us about unhandled enum value if we get here */ return "unknown"; } #endif static void * swrap_load_lib_handle (enum swrap_lib lib) { int flags = RTLD_LAZY; void *handle = NULL; int i; #if defined(RTLD_DEEPBIND) && !defined(CLIB_SANITIZE_ADDR) flags |= RTLD_DEEPBIND; #endif switch (lib) { case SWRAP_LIBC: handle = swrap.libc.handle; #ifdef LIBC_SO if (handle == NULL) { handle = dlopen (LIBC_SO, flags); swrap.libc.handle = handle; } #endif if (handle == NULL) { for (i = 10; i >= 0; i--) { char soname[256] = { 0 }; snprintf (soname, sizeof (soname), "libc.so.%d", i); handle = dlopen (soname, flags); if (handle != NULL) { break; } } swrap.libc.handle = handle; } break; } if (handle == NULL) { SWRAP_LOG (SWRAP_LOG_ERROR, "Failed to dlopen library: %s\n", dlerror ()); exit (-1); } return handle; } static void * _swrap_bind_symbol (enum swrap_lib lib, const char *fn_name) { void *handle; void *func; handle = swrap_load_lib_handle (lib); func = dlsym (handle, fn_name); if (func == NULL) { SWRAP_LOG (SWRAP_LOG_ERROR, "Failed to find %s: %s\n", fn_name, dlerror ()); exit (-1); } SWRAP_LOG (SWRAP_LOG_TRACE, "Loaded %s from %s", fn_name, swrap_str_lib (lib)); return func; } #define swrap_bind_symbol_libc(sym_name) \ SWRAP_LOCK(libc_symbol_binding); \ if (swrap.libc.symbols._libc_##sym_name.obj == NULL) { \ swrap.libc.symbols._libc_##sym_name.obj = \ _swrap_bind_symbol(SWRAP_LIBC, #sym_name); \ } \ SWRAP_UNLOCK(libc_symbol_binding) /* * IMPORTANT * * Functions especially from libc need to be loaded individually, you can't load * all at once or gdb will segfault at startup. The same applies to valgrind and * has probably something todo with with the linker. * So we need load each function at the point it is called the first time. */ int libc_accept4 (int sockfd, struct sockaddr *addr, socklen_t * addrlen, int flags) { swrap_bind_symbol_libc (accept4); return swrap.libc.symbols._libc_accept4.f (sockfd, addr, addrlen, flags); } int libc_accept (int sockfd, struct sockaddr *addr, socklen_t * addrlen) { swrap_bind_symbol_libc (accept); return swrap.libc.symbols._libc_accept.f (sockfd, addr, addrlen); } int libc_bind (int sockfd, const struct sockaddr *addr, socklen_t addrlen) { swrap_bind_symbol_libc (bind); return swrap.libc.symbols._libc_bind.f (sockfd, addr, addrlen); } int libc_close (int fd) { swrap_bind_symbol_libc (close); return swrap.libc.symbols._libc_close.f (fd); } int libc_connect (int sockfd, const struct sockaddr *addr, socklen_t addrlen) { swrap_bind_symbol_libc (connect); return swrap.libc.symbols._libc_connect.f (sockfd, addr, addrlen); } #if 0 /* TBD: dup and dup2 to be implemented later */ int libc_dup (int fd) { swrap_bind_symbol_libc (dup); return swrap.libc.symbols._libc_dup.f (fd); } int libc_dup2 (int oldfd, int newfd) { swrap_bind_symbol_libc (dup2); return swrap.libc.symbols._libc_dup2.f (oldfd, newfd); } #endif #ifdef HAVE_EVENTFD int libc_eventfd (int count, int flags) { swrap_bind_symbol_libc (eventfd); return swrap.libc.symbols._libc_eventfd.f (count, flags); } #endif int libc_vfcntl (int fd, int cmd, va_list ap) { swrap_bind_symbol_libc (fcntl); return swrap.libc.symbols._libc_fcntl.f (fd, cmd, va_arg (ap, long int)); } #ifdef HAVE_FCNTL64 int libc_vfcntl64 (int fd, int cmd, va_list ap) { swrap_bind_symbol_libc (fcntl64); return swrap.libc.symbols._libc_fcntl64.f (fd, cmd, va_arg (ap, long int)); } #endif int libc_vioctl (int fd, int cmd, va_list ap) { long int args[4]; int rc; int i; swrap_bind_symbol_libc (ioctl); for (i = 0; i < 4; i++) { args[i] = va_arg (ap, long int); } rc = swrap.libc.symbols._libc_ioctl.f (fd, cmd, args[0], args[1], args[2], args[3]); return rc; } int libc_getpeername (int sockfd, struct sockaddr *addr, socklen_t * addrlen) { swrap_bind_symbol_libc (getpeername); return swrap.libc.symbols._libc_getpeername.f (sockfd, addr, addrlen); } int libc_getsockname (int sockfd, struct sockaddr *addr, socklen_t * addrlen) { swrap_bind_symbol_libc (getsockname); return swrap.libc.symbols._libc_getsockname.f (sockfd, addr, addrlen); } int libc_getsockopt (int sockfd, int level, int optname, void *optval, socklen_t * optlen) { swrap_bind_symbol_libc (getsockopt); return swrap.libc.symbols._libc_getsockopt.f (sockfd, level, optname, optval, optlen); } int libc_listen (int sockfd, int backlog) { swrap_bind_symbol_libc (listen); return swrap.libc.symbols._libc_listen.f (sockfd, backlog); } /* TBD: libc_read() should return ssize_t not an int */ int libc_read (int fd, void *buf, size_t count) { swrap_bind_symbol_libc (read); return swrap.libc.symbols._libc_read.f (fd, buf, count); } ssize_t libc_readv (int fd, const struct iovec * iov, int iovcnt) { swrap_bind_symbol_libc (readv); return swrap.libc.symbols._libc_readv.f (fd, iov, iovcnt); } int libc_recv (int sockfd, void *buf, size_t len, int flags) { swrap_bind_symbol_libc (recv); return swrap.libc.symbols._libc_recv.f (sockfd, buf, len, flags); } int libc_recvfrom (int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t * addrlen) { swrap_bind_symbol_libc (recvfrom); return swrap.libc.symbols._libc_recvfrom.f (sockfd, buf, len, flags, src_addr, addrlen); } int libc_recvmsg (int sockfd, struct msghdr *msg, int flags) { swrap_bind_symbol_libc (recvmsg); return swrap.libc.symbols._libc_recvmsg.f (sockfd, msg, flags); } int libc_send (int sockfd, const void *buf, size_t len, int flags) { swrap_bind_symbol_libc (send); return swrap.libc.symbols._libc_send.f (sockfd, buf, len, flags); } ssize_t libc_sendfile (int out_fd, int in_fd, off_t * offset, size_t len) { swrap_bind_symbol_libc (sendfile); return swrap.libc.symbols._libc_sendfile.f (out_fd, in_fd, offset, len); } int libc_sendmsg (int sockfd, const struct msghdr *msg, int flags) { swrap_bind_symbol_libc (sendmsg); return swrap.libc.symbols._libc_sendmsg.f (sockfd, msg, flags); } int libc_sendto (int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dst_addr, socklen_t addrlen) { swrap_bind_symbol_libc (sendto); return swrap.libc.symbols._libc_sendto.f (sockfd, buf, len, flags, dst_addr, addrlen); } int libc_setsockopt (int sockfd, int level, int optname, const void *optval, socklen_t optlen) { swrap_bind_symbol_libc (setsockopt); return swrap.libc.symbols._libc_setsockopt.f (sockfd, level, optname, optval, optlen); } int libc_socket (int domain, int type, int protocol) { swrap_bind_symbol_libc (socket); return swrap.libc.symbols._libc_socket.f (domain, type, protocol); } int libc_socketpair (int domain, int type, int protocol, int sv[2]) { swrap_bind_symbol_libc (socketpair); return swrap.libc.symbols._libc_socketpair.f (domain, type, protocol, sv); } ssize_t libc_write (int fd, const void *buf, size_t count) { swrap_bind_symbol_libc (write); return swrap.libc.symbols._libc_write.f (fd, buf, count); } ssize_t libc_writev (int fd, const struct iovec * iov, int iovcnt) { swrap_bind_symbol_libc (writev); return swrap.libc.symbols._libc_writev.f (fd, iov, iovcnt); } int libc_shutdown (int fd, int how) { swrap_bind_symbol_libc (shutdown); return swrap.libc.symbols._libc_shutdown.f (fd, how); } int libc_select (int __nfds, fd_set * __restrict __readfds, fd_set * __restrict __writefds, fd_set * __restrict __exceptfds, struct timeval *__restrict __timeout) { swrap_bind_symbol_libc (select); return swrap.libc.symbols._libc_select.f (__nfds, __readfds, __writefds, __exceptfds, __timeout); } #ifdef __USE_XOPEN2K int libc_pselect (int __nfds, fd_set * __restrict __readfds, fd_set * __restrict __writefds, fd_set * __restrict __exceptfds, const struct timespec *__restrict __timeout, const __sigset_t * __restrict __sigmask) { swrap_bind_symbol_libc (pselect); return swrap.libc.symbols._libc_pselect.f (__nfds, __readfds, __writefds, __exceptfds, __timeout, __sigmask); } #endif int libc_epoll_create (int __size) { swrap_bind_symbol_libc (epoll_create); return swrap.libc.symbols._libc_epoll_create.f (__size); } int libc_epoll_create1 (int __flags) { swrap_bind_symbol_libc (epoll_create1); return swrap.libc.symbols._libc_epoll_create1.f (__flags); } int libc_epoll_ctl (int __epfd, int __op, int __fd, struct epoll_event *__event) { swrap_bind_symbol_libc (epoll_ctl); return swrap.libc.symbols._libc_epoll_ctl.f (__epfd, __op, __fd, __event); } int libc_epoll_wait (int __epfd, struct epoll_event *__events, int __maxevents, int __timeout) { swrap_bind_symbol_libc (epoll_wait); return swrap.libc.symbols._libc_epoll_wait.f (__epfd, __events, __maxevents, __timeout); } int libc_epoll_pwait (int __epfd, struct epoll_event *__events, int __maxevents, int __timeout, const __sigset_t * __ss) { swrap_bind_symbol_libc (epoll_pwait); return swrap.libc.symbols._libc_epoll_pwait.f (__epfd, __events, __maxevents, __timeout, __ss); } int libc_poll (struct pollfd *__fds, nfds_t __nfds, int __timeout) { swrap_bind_symbol_libc (poll); return swrap.libc.symbols._libc_poll.f (__fds, __nfds, __timeout); } #ifdef __USE_GNU int libc_ppoll (struct pollfd *__fds, nfds_t __nfds, const struct timespec *__timeout, const __sigset_t * __ss) { swrap_bind_symbol_libc (ppoll); return swrap.libc.symbols._libc_ppoll.f (__fds, __nfds, __timeout, __ss); } #endif static void swrap_thread_prepare (void) { SWRAP_LOCK_ALL; } static void swrap_thread_parent (void) { SWRAP_UNLOCK_ALL; } static void swrap_thread_child (void) { SWRAP_UNLOCK_ALL; } /**************************** * CONSTRUCTOR ***************************/ void swrap_constructor (void) { /* * If we hold a lock and the application forks, then the child * is not able to unlock the mutex and we are in a deadlock. * This should prevent such deadlocks. */ pthread_atfork (&swrap_thread_prepare, &swrap_thread_parent, &swrap_thread_child); } /**************************** * DESTRUCTOR ***************************/ /* * This function is called when the library is unloaded and makes sure that * sockets get closed and the unix file for the socket are unlinked. */ void swrap_destructor (void) { if (swrap.libc.handle != NULL) { dlclose (swrap.libc.handle); } if (swrap.libc.socket_handle) { dlclose (swrap.libc.socket_handle); } } /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */