L4Re - L4 Runtime Environment
ipc_stream
Go to the documentation of this file.
1 // vi:set ft=cpp: -*- Mode: C++ -*-
6 /*
7  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
8  * Alexander Warg <warg@os.inf.tu-dresden.de>,
9  * Torsten Frenzel <frenzel@os.inf.tu-dresden.de>
10  * economic rights: Technische Universität Dresden (Germany)
11  *
12  * This file is part of TUD:OS and distributed under the terms of the
13  * GNU General Public License 2.
14  * Please see the COPYING-GPL-2 file for details.
15  *
16  * As a special exception, you may use this file as part of a free software
17  * library without restriction. Specifically, if other files instantiate
18  * templates or use macros or inline functions from this file, or you compile
19  * this file and link it with other files to produce an executable, this
20  * file does not by itself cause the resulting executable to be covered by
21  * the GNU General Public License. This exception does not however
22  * invalidate any other reasons why the executable file might be covered by
23  * the GNU General Public License.
24  */
25 #pragma once
26 
27 #include <l4/sys/ipc.h>
28 #include <l4/sys/capability>
29 #include <l4/sys/cxx/ipc_types>
30 #include <l4/sys/cxx/ipc_varg>
31 #include <l4/cxx/type_traits>
32 #include <l4/cxx/minmax>
33 
34 #define L4_CXX_IPC_BACKWARD_COMPAT
35 
36 namespace L4 {
37 namespace Ipc {
38 
39 class Ostream;
40 class Istream;
41 
42 namespace Internal {
60 template< typename T >
61 class Buf_cp_out
62 {
63 public:
70  Buf_cp_out(T const *v, unsigned long size) : _v(v), _s(size) {}
71 
79  unsigned long size() const { return _s; }
80 
88  T const *buf() const { return _v; }
89 
90 private:
91  friend class Ostream;
92  T const *_v;
93  unsigned long _s;
94 };
95 }
96 
112 template< typename T >
113 Internal::Buf_cp_out<T> buf_cp_out(T const *v, unsigned long size)
114 { return Internal::Buf_cp_out<T>(v, size); }
115 
116 
117 namespace Internal {
130 template< typename T >
131 class Buf_cp_in
132 {
133 public:
142  Buf_cp_in(T *v, unsigned long &size) : _v(v), _s(&size) {}
143 
144  unsigned long &size() const { return *_s; }
145  T *buf() const { return _v; }
146 
147 private:
148  friend class Istream;
149  T *_v;
150  unsigned long *_s;
151 };
152 }
153 
171 template< typename T >
172 Internal::Buf_cp_in<T> buf_cp_in(T *v, unsigned long &size)
173 { return Internal::Buf_cp_in<T>(v, size); }
174 
190 template< typename T >
192 {
193 public:
202  Str_cp_in(T *v, unsigned long &size) : _v(v), _s(&size) {}
203 
204  unsigned long &size() const { return *_s; }
205  T *buf() const { return _v; }
206 
207 private:
208  friend class Istream;
209  T *_v;
210  unsigned long *_s;
211 };
212 
225 template< typename T >
226 Str_cp_in<T> str_cp_in(T *v, unsigned long &size)
227 { return Str_cp_in<T>(v, size); }
228 
241 template< typename T >
242 class Msg_ptr
243 {
244 private:
245  T **_p;
246 public:
253  explicit Msg_ptr(T *&p) : _p(&p) {}
254  void set(T *p) const { *_p = p; }
255 };
256 
264 template< typename T >
266 { return Msg_ptr<T>(p); }
267 
268 
269 namespace Internal {
283 template< typename T >
284 class Buf_in
285 {
286 public:
293  Buf_in(T *&v, unsigned long &size) : _v(&v), _s(&size) {}
294 
295  void set_size(unsigned long s) const { *_s = s; }
296  T *&buf() const { return *_v; }
297 
298 private:
299  friend class Istream;
300  T **_v;
301  unsigned long *_s;
302 };
303 }
304 
322 template< typename T >
323 Internal::Buf_in<T> buf_in(T *&v, unsigned long &size)
324 { return Internal::Buf_in<T>(v, size); }
325 
326 namespace Utcb_stream_check
327 {
328  static bool check_utcb_data_offset(unsigned sz)
329  { return sz > sizeof(l4_umword_t) * L4_UTCB_GENERIC_DATA_SIZE; }
330 }
331 
332 
347 class Istream
348 {
349 public:
362  : _tag(), _utcb(utcb),
363  _current_msg(reinterpret_cast<char*>(l4_utcb_mr_u(utcb)->mr)),
364  _pos(0), _current_buf(0)
365  {}
366 
371  void reset()
372  {
373  _pos = 0;
374  _current_buf = 0;
375  _current_msg = reinterpret_cast<char*>(l4_utcb_mr_u(_utcb)->mr);
376  }
377 
381  template< typename T >
382  bool has_more(unsigned long count = 1)
383  {
384  auto const max_bytes = L4_UTCB_GENERIC_DATA_SIZE * sizeof(l4_umword_t);
385  unsigned apos = cxx::Type_traits<T>::align(_pos);
386  return (count <= max_bytes / sizeof(T))
387  && (apos + (sizeof(T) * count)
388  <= _tag.words() * sizeof(l4_umword_t));
389  }
390 
395 
404  template< typename T >
405  unsigned long get(T *buf, unsigned long elems)
406  {
407  if (L4_UNLIKELY(!has_more<T>(elems)))
408  return 0;
409 
410  unsigned long size = elems * sizeof(T);
411  _pos = cxx::Type_traits<T>::align(_pos);
412 
413  __builtin_memcpy(buf, _current_msg + _pos, size);
414  _pos += size;
415  return elems;
416  }
417 
418 
423  template< typename T >
424  void skip(unsigned long elems)
425  {
426  if (L4_UNLIKELY(!has_more<T>(elems)))
427  return;
428 
429  unsigned long size = elems * sizeof(T);
430  _pos = cxx::Type_traits<T>::align(_pos);
431  _pos += size;
432  }
433 
446  template< typename T >
447  unsigned long get(Msg_ptr<T> const &buf, unsigned long elems = 1)
448  {
449  if (L4_UNLIKELY(!has_more<T>(elems)))
450  return 0;
451 
452  unsigned long size = elems * sizeof(T);
453  _pos = cxx::Type_traits<T>::align(_pos);
454 
455  buf.set(reinterpret_cast<T*>(_current_msg + _pos));
456  _pos += size;
457  return elems;
458  }
459 
460 
468  template< typename T >
469  bool get(T &v)
470  {
471  if (L4_UNLIKELY(!has_more<T>()))
472  {
473  v = T();
474  return false;
475  }
476 
477  _pos = cxx::Type_traits<T>::align(_pos);
478  v = *(reinterpret_cast<T*>(_current_msg + _pos));
479  _pos += sizeof(T);
480  return true;
481  }
482 
483 
484  bool get(Ipc::Varg *va)
485  {
486  Ipc::Varg::Tag t;
487  if (!has_more<Ipc::Varg::Tag>())
488  {
489  va->tag(0);
490  return 0;
491  }
492  get(t);
493  va->tag(t);
494  char const *d;
495  get(msg_ptr(d), va->length());
496  va->data(d);
497 
498  return 1;
499  }
500 
510  l4_msgtag_t tag() const { return _tag; }
511 
512 
522  l4_msgtag_t &tag() { return _tag; }
523 
525 
530  inline bool put(Buf_item const &);
531 
536  inline bool put(Small_buf const &);
537 
538 
543 
554  { return wait(src, L4_IPC_NEVER); }
555 
566  inline l4_msgtag_t wait(l4_umword_t *src, l4_timeout_t timeout);
567 
578  { return receive(src, L4_IPC_NEVER); }
579  inline l4_msgtag_t receive(l4_cap_idx_t src, l4_timeout_t timeout);
580 
582 
586  inline l4_utcb_t *utcb() const { return _utcb; }
587 
588 protected:
589  l4_msgtag_t _tag;
590  l4_utcb_t *_utcb;
591  char *_current_msg;
592  unsigned _pos;
593  unsigned char _current_buf;
594 };
595 
596 class Istream_copy : public Istream
597 {
598 private:
599  l4_msg_regs_t _mrs;
600 
601 public:
602  Istream_copy(Istream const &o) : Istream(o), _mrs(*l4_utcb_mr_u(o.utcb()))
603  {
604  // do some reverse mr to utcb trickery
605  _utcb = (l4_utcb_t *)((l4_addr_t)&_mrs - (l4_addr_t)l4_utcb_mr_u((l4_utcb_t *)0));
606  _current_msg = reinterpret_cast<char*>(l4_utcb_mr_u(_utcb)->mr);
607  }
608 
609 };
610 
625 class Ostream
626 {
627 public:
632  : _tag(), _utcb(utcb),
633  _current_msg(reinterpret_cast<char *>(l4_utcb_mr_u(_utcb)->mr)),
634  _pos(0), _current_item(0)
635  {}
636 
640  void reset()
641  {
642  _pos = 0;
643  _current_item = 0;
644  _current_msg = reinterpret_cast<char*>(l4_utcb_mr_u(_utcb)->mr);
645  }
646 
654 
661  template< typename T >
662  bool put(T *buf, unsigned long size)
663  {
664  size *= sizeof(T);
665  _pos = cxx::Type_traits<T>::align(_pos);
666  if (Utcb_stream_check::check_utcb_data_offset(_pos + size))
667  return false;
668 
669  __builtin_memcpy(_current_msg + _pos, buf, size);
670  _pos += size;
671  return true;
672  }
673 
679  template< typename T >
680  bool put(T const &v)
681  {
682  _pos = cxx::Type_traits<T>::align(_pos);
683  if (Utcb_stream_check::check_utcb_data_offset(_pos + sizeof(T)))
684  return false;
685 
686  *(reinterpret_cast<T*>(_current_msg + _pos)) = v;
687  _pos += sizeof(T);
688  return true;
689  }
690 
691  int put(Varg const &va)
692  {
693  put(va.tag());
694  put(va.data(), va.length());
695 
696  return 0;
697  }
698 
699  template< typename T >
700  int put(Varg_t<T> const &va)
701  { return put(static_cast<Varg const &>(va)); }
702 
708  l4_msgtag_t tag() const { return _tag; }
709 
715  l4_msgtag_t &tag() { return _tag; }
716 
718 
723  inline bool put_snd_item(Snd_item const &);
724 
725 
730 
740  inline l4_msgtag_t send(l4_cap_idx_t dst, long proto = 0, unsigned flags = 0);
741 
743 
747  inline l4_utcb_t *utcb() const { return _utcb; }
748 #if 0
749 
752  unsigned long tell() const
753  {
754  unsigned w = (_pos + sizeof(l4_umword_t)-1) / sizeof(l4_umword_t);
755  w -= _current_item * 2;
756  _tag = l4_msgtag(0, w, _current_item, 0);
757  }
758 #endif
759 public:
760  l4_msgtag_t prepare_ipc(long proto = 0, unsigned flags = 0)
761  {
762  unsigned w = (_pos + sizeof(l4_umword_t) - 1) / sizeof(l4_umword_t);
763  w -= _current_item * 2;
764  return l4_msgtag(proto, w, _current_item, flags);
765  }
766 
767  // XXX: this is a hack for <l4/sys/cxx/ipc_server> adaption
768  void set_ipc_params(l4_msgtag_t tag)
769  {
770  _pos = (tag.words() + tag.items() * 2) * sizeof(l4_umword_t);
771  _current_item = tag.items();
772  }
773 protected:
774  l4_msgtag_t _tag;
775  l4_utcb_t *_utcb;
776  char *_current_msg;
777  unsigned _pos;
778  unsigned char _current_item;
779 };
780 
781 
793 class Iostream : public Istream, public Ostream
794 {
795 public:
796 
805  explicit Iostream(l4_utcb_t *utcb)
806  : Istream(utcb), Ostream(utcb)
807  {}
808 
809  // disambiguate those functions
810  l4_msgtag_t tag() const { return Istream::tag(); }
811  l4_msgtag_t &tag() { return Istream::tag(); }
812  l4_utcb_t *utcb() const { return Istream::utcb(); }
813 
819  void reset()
820  {
821  Istream::reset();
822  Ostream::reset();
823  }
824 
825 
833 
834  using Istream::get;
835  using Istream::put;
836  using Ostream::put;
837 
839 
844 
860  inline l4_msgtag_t call(l4_cap_idx_t dst, l4_timeout_t timeout, long proto = 0);
861  inline l4_msgtag_t call(l4_cap_idx_t dst, long proto = 0);
862 
878  inline l4_msgtag_t reply_and_wait(l4_umword_t *src_dst, long proto = 0)
879  { return reply_and_wait(src_dst, L4_IPC_SEND_TIMEOUT_0, proto); }
880 
881  inline l4_msgtag_t send_and_wait(l4_cap_idx_t dest, l4_umword_t *src,
882  long proto = 0)
883  { return send_and_wait(dest, src, L4_IPC_SEND_TIMEOUT_0, proto); }
884 
901  inline l4_msgtag_t reply_and_wait(l4_umword_t *src_dst,
902  l4_timeout_t timeout, long proto = 0);
903  inline l4_msgtag_t send_and_wait(l4_cap_idx_t dest, l4_umword_t *src,
904  l4_timeout_t timeout, long proto = 0);
905  inline l4_msgtag_t reply(l4_timeout_t timeout, long proto = 0);
906  inline l4_msgtag_t reply(long proto = 0)
907  { return reply(L4_IPC_SEND_TIMEOUT_0, proto); }
908 
910 };
911 
912 
913 inline bool
914 Ostream::put_snd_item(Snd_item const &v)
915 {
916  typedef Snd_item T;
917  _pos = cxx::Type_traits<Snd_item>::align(_pos);
918  if (Utcb_stream_check::check_utcb_data_offset(_pos + sizeof(T)))
919  return false;
920 
921  *(reinterpret_cast<T*>(_current_msg + _pos)) = v;
922  _pos += sizeof(T);
923  ++_current_item;
924  return true;
925 }
926 
927 
928 inline bool
929 Istream::put(Buf_item const &item)
930 {
931  if (_current_buf >= L4_UTCB_GENERIC_BUFFERS_SIZE - 3)
932  return false;
933 
934  l4_utcb_br_u(_utcb)->bdr &= ~L4_BDR_OFFSET_MASK;
935 
936  reinterpret_cast<Buf_item&>(l4_utcb_br_u(_utcb)->br[_current_buf]) = item;
937  _current_buf += 2;
938  return true;
939 }
940 
941 
942 inline bool
943 Istream::put(Small_buf const &item)
944 {
945  if (_current_buf >= L4_UTCB_GENERIC_BUFFERS_SIZE - 2)
946  return false;
947 
948  l4_utcb_br_u(_utcb)->bdr &= ~L4_BDR_OFFSET_MASK;
949 
950  reinterpret_cast<Small_buf&>(l4_utcb_br_u(_utcb)->br[_current_buf]) = item;
951  _current_buf += 1;
952  return true;
953 }
954 
955 
956 inline l4_msgtag_t
957 Ostream::send(l4_cap_idx_t dst, long proto, unsigned flags)
958 {
959  l4_msgtag_t tag = prepare_ipc(proto, L4_MSGTAG_FLAGS & flags);
960  return l4_ipc_send(dst, _utcb, tag, L4_IPC_NEVER);
961 }
962 
963 inline l4_msgtag_t
964 Iostream::call(l4_cap_idx_t dst, l4_timeout_t timeout, long label)
965 {
966  l4_msgtag_t tag = prepare_ipc(label);
967  tag = l4_ipc_call(dst, Ostream::_utcb, tag, timeout);
968  Istream::tag() = tag;
969  Istream::_pos = 0;
970  return tag;
971 }
972 
973 inline l4_msgtag_t
974 Iostream::call(l4_cap_idx_t dst, long label)
975 { return call(dst, L4_IPC_NEVER, label); }
976 
977 
978 inline l4_msgtag_t
979 Iostream::reply_and_wait(l4_umword_t *src_dst, l4_timeout_t timeout, long proto)
980 {
981  l4_msgtag_t tag = prepare_ipc(proto);
982  tag = l4_ipc_reply_and_wait(Ostream::_utcb, tag, src_dst, timeout);
983  Istream::tag() = tag;
984  Istream::_pos = 0;
985  return tag;
986 }
987 
988 
989 inline l4_msgtag_t
990 Iostream::send_and_wait(l4_cap_idx_t dest, l4_umword_t *src,
991  l4_timeout_t timeout, long proto)
992 {
993  l4_msgtag_t tag = prepare_ipc(proto);
994  tag = l4_ipc_send_and_wait(dest, Ostream::_utcb, tag, src, timeout);
995  Istream::tag() = tag;
996  Istream::_pos = 0;
997  return tag;
998 }
999 
1000 inline l4_msgtag_t
1001 Iostream::reply(l4_timeout_t timeout, long proto)
1002 {
1003  l4_msgtag_t tag = prepare_ipc(proto);
1004  tag = l4_ipc_send(L4_INVALID_CAP | L4_SYSF_REPLY, Ostream::_utcb, tag, timeout);
1005  Istream::tag() = tag;
1006  Istream::_pos = 0;
1007  return tag;
1008 }
1009 
1010 inline l4_msgtag_t
1012 {
1013  l4_msgtag_t res;
1014  res = l4_ipc_wait(_utcb, src, timeout);
1015  tag() = res;
1016  _pos = 0;
1017  return res;
1018 }
1019 
1020 
1021 inline l4_msgtag_t
1023 {
1024  l4_msgtag_t res;
1025  res = l4_ipc_receive(src, _utcb, timeout);
1026  tag() = res;
1027  _pos = 0;
1028  return res;
1029 }
1030 
1031 } // namespace Ipc
1032 } // namespace L4
1033 
1042 inline L4::Ipc::Istream &operator >> (L4::Ipc::Istream &s, bool &v) { s.get(v); return s; }
1043 inline L4::Ipc::Istream &operator >> (L4::Ipc::Istream &s, int &v) { s.get(v); return s; }
1044 inline L4::Ipc::Istream &operator >> (L4::Ipc::Istream &s, long int &v) { s.get(v); return s; }
1045 inline L4::Ipc::Istream &operator >> (L4::Ipc::Istream &s, long long int &v) { s.get(v); return s; }
1046 inline L4::Ipc::Istream &operator >> (L4::Ipc::Istream &s, unsigned int &v) { s.get(v); return s; }
1047 inline L4::Ipc::Istream &operator >> (L4::Ipc::Istream &s, unsigned long int &v) { s.get(v); return s; }
1048 inline L4::Ipc::Istream &operator >> (L4::Ipc::Istream &s, unsigned long long int &v) { s.get(v); return s; }
1049 inline L4::Ipc::Istream &operator >> (L4::Ipc::Istream &s, short int &v) { s.get(v); return s; }
1050 inline L4::Ipc::Istream &operator >> (L4::Ipc::Istream &s, unsigned short int &v) { s.get(v); return s; }
1051 inline L4::Ipc::Istream &operator >> (L4::Ipc::Istream &s, char &v) { s.get(v); return s; }
1052 inline L4::Ipc::Istream &operator >> (L4::Ipc::Istream &s, unsigned char &v) { s.get(v); return s; }
1053 inline L4::Ipc::Istream &operator >> (L4::Ipc::Istream &s, signed char &v) { s.get(v); return s; }
1054 inline L4::Ipc::Istream &operator << (L4::Ipc::Istream &s, L4::Ipc::Buf_item const &v) { s.put(v); return s; }
1055 inline L4::Ipc::Istream &operator << (L4::Ipc::Istream &s, L4::Ipc::Small_buf const &v) { s.put(v); return s; }
1057 {
1058  l4_umword_t b, d;
1059  s >> b >> d;
1060  v = L4::Ipc::Snd_item(b, d);
1061  return s;
1062 }
1064 { s.get(&v); return s; }
1065 
1066 
1075 inline
1077 {
1078  v = s.tag();
1079  return s;
1080 }
1081 
1099 template< typename T >
1100 inline
1102  L4::Ipc::Internal::Buf_in<T> const &v)
1103 {
1104  unsigned long si;
1105  if (s.get(si) && s.has_more<T>(si))
1106  v.set_size(s.get(L4::Ipc::Msg_ptr<T>(v.buf()), si));
1107  else
1108  v.set_size(0);
1109  return s;
1110 }
1111 
1126 template< typename T >
1127 inline
1129  L4::Ipc::Msg_ptr<T> const &v)
1130 {
1131  s.get(v);
1132  return s;
1133 }
1134 
1147 template< typename T >
1148 inline
1150  L4::Ipc::Internal::Buf_cp_in<T> const &v)
1151 {
1152  unsigned long sz;
1153  s.get(sz);
1154  v.size() = s.get(v.buf(), cxx::min(v.size(), sz));
1155  return s;
1156 }
1157 
1168 template< typename T >
1169 inline
1171  L4::Ipc::Str_cp_in<T> const &v)
1172 {
1173  unsigned long sz;
1174  s.get(sz);
1175  unsigned long rsz = s.get(v.buf(), cxx::min(v.size(), sz));
1176  if (rsz < v.size() && v.buf()[rsz - 1])
1177  ++rsz; // add the zero termination behind the received data
1178 
1179  if (rsz != 0)
1180  v.buf()[rsz - 1] = 0;
1181 
1182  v.size() = rsz;
1183  return s;
1184 }
1185 
1186 
1195 inline L4::Ipc::Ostream &operator << (L4::Ipc::Ostream &s, bool v) { s.put(v); return s; }
1196 inline L4::Ipc::Ostream &operator << (L4::Ipc::Ostream &s, int v) { s.put(v); return s; }
1197 inline L4::Ipc::Ostream &operator << (L4::Ipc::Ostream &s, long int v) { s.put(v); return s; }
1198 inline L4::Ipc::Ostream &operator << (L4::Ipc::Ostream &s, long long int v) { s.put(v); return s; }
1199 inline L4::Ipc::Ostream &operator << (L4::Ipc::Ostream &s, unsigned int v) { s.put(v); return s; }
1200 inline L4::Ipc::Ostream &operator << (L4::Ipc::Ostream &s, unsigned long int v) { s.put(v); return s; }
1201 inline L4::Ipc::Ostream &operator << (L4::Ipc::Ostream &s, unsigned long long int v) { s.put(v); return s; }
1202 inline L4::Ipc::Ostream &operator << (L4::Ipc::Ostream &s, short int v) { s.put(v); return s; }
1203 inline L4::Ipc::Ostream &operator << (L4::Ipc::Ostream &s, unsigned short int v) { s.put(v); return s; }
1204 inline L4::Ipc::Ostream &operator << (L4::Ipc::Ostream &s, char v) { s.put(v); return s; }
1205 inline L4::Ipc::Ostream &operator << (L4::Ipc::Ostream &s, unsigned char v) { s.put(v); return s; }
1206 inline L4::Ipc::Ostream &operator << (L4::Ipc::Ostream &s, signed char v) { s.put(v); return s; }
1207 inline L4::Ipc::Ostream &operator << (L4::Ipc::Ostream &s, L4::Ipc::Snd_item const &v) { s.put_snd_item(v); return s; }
1208 template< typename T >
1209 inline L4::Ipc::Ostream &operator << (L4::Ipc::Ostream &s, L4::Cap<T> const &v)
1210 { s << L4::Ipc::Snd_fpage(v.fpage()); return s; }
1211 
1213 { s.put(v); return s; }
1214 template< typename T >
1215 inline L4::Ipc::Ostream &operator << (L4::Ipc::Ostream &s, L4::Ipc::Varg_t<T> const &v)
1216 { s.put(v); return s; }
1217 
1229 inline
1231 {
1232  s.tag() = v;
1233  return s;
1234 }
1235 
1244 template< typename T >
1245 inline
1247  L4::Ipc::Internal::Buf_cp_out<T> const &v)
1248 {
1249  s.put(v.size());
1250  s.put(v.buf(), v.size());
1251  return s;
1252 }
1253 
1266 inline
1268 {
1269  unsigned long l = __builtin_strlen(v) + 1;
1270  s.put(l);
1271  s.put(v, l);
1272  return s;
1273 }
1274 
1275 
1276 #ifdef L4_CXX_IPC_BACKWARD_COMPAT
1277 namespace L4 {
1278 
1279 #if 0
1280 template< typename T > class Ipc_buf_cp_out : public Ipc::Buf_cp_out<T> {};
1281 template< typename T > class Ipc_buf_cp_in : public Ipc::Buf_cp_in<T> {};
1282 template< typename T > class Ipc_buf_in : public Ipc::Buf_in<T> {};
1283 template< typename T > class Msg_ptr : public Ipc::Msg_ptr<T> {};
1284 #endif
1285 
1286 template< typename T >
1287 Ipc::Internal::Buf_cp_out<T> ipc_buf_cp_out(T *v, unsigned long size)
1288  L4_DEPRECATED("Use L4::Ipc::buf_cp_out() now");
1289 
1290 template< typename T >
1291 Ipc::Internal::Buf_cp_out<T> ipc_buf_cp_out(T *v, unsigned long size)
1292 { return Ipc::Internal::Buf_cp_out<T>(v, size); }
1293 
1294 
1295 template< typename T >
1296 Ipc::Internal::Buf_cp_in<T> ipc_buf_cp_in(T *v, unsigned long &size)
1297  L4_DEPRECATED("Use L4::Ipc::buf_cp_in() now");
1298 
1299 template< typename T >
1300 Ipc::Internal::Buf_cp_in<T> ipc_buf_cp_in(T *v, unsigned long &size)
1301 { return Ipc::Internal::Buf_cp_in<T>(v, size); }
1302 
1303 
1304 template< typename T >
1305 Ipc::Internal::Buf_in<T> ipc_buf_in(T *&v, unsigned long &size)
1306  L4_DEPRECATED("Use L4::Ipc::buf_in() now");
1307 
1308 template< typename T >
1309 Ipc::Internal::Buf_in<T> ipc_buf_in(T *&v, unsigned long &size)
1310 { return Ipc::Internal::Buf_in<T>(v, size); }
1311 
1312 
1313 template< typename T >
1314 Ipc::Msg_ptr<T> msg_ptr(T *&p)
1315  L4_DEPRECATED("Use L4::Ipc::msg_ptr() now");
1316 
1317 template< typename T >
1318 Ipc::Msg_ptr<T> msg_ptr(T *&p)
1319 { return Ipc::Msg_ptr<T>(p); }
1320 
1321 typedef Ipc::Istream Ipc_istream L4_DEPRECATED("Use L4::Ipc::Istream now");
1322 typedef Ipc::Ostream Ipc_ostream L4_DEPRECATED("Use L4::Ipc::Ostream now");;
1323 typedef Ipc::Iostream Ipc_iostream L4_DEPRECATED("Use L4::Ipc::Iostream now");;
1324 typedef Ipc::Snd_fpage Snd_fpage L4_DEPRECATED("Use L4::Ipc::Snd_fpage now");;
1325 typedef Ipc::Rcv_fpage Rcv_fpage L4_DEPRECATED("Use L4::Ipc::Rcv_fpage now");;
1326 typedef Ipc::Small_buf Small_buf L4_DEPRECATED("Use L4::Ipc::Small_buf now");;
1327 
1328 
1329 namespace Ipc {
1330 template< typename T > class Buf_cp_in : public Internal::Buf_cp_in<T>
1331 {
1332 public:
1333  Buf_cp_in(T *v, unsigned long &size) : Internal::Buf_cp_in<T>(v, size) {}
1334 };
1335 
1336 template< typename T >
1337 class Buf_cp_out : public Internal::Buf_cp_out<T>
1338 {
1339 public:
1340  Buf_cp_out(T const *v, unsigned long size) : Internal::Buf_cp_out<T>(v, size) {}
1341 };
1342 
1343 template< typename T >
1344 class Buf_in : public Internal::Buf_in<T>
1345 {
1346 public:
1347  Buf_in(T *&v, unsigned long &size) : Internal::Buf_in<T>(v, size) {}
1348 };
1349 } // namespace Ipc
1350 } // namespace L4
1351 
1352 template< typename T >
1353 inline
1354 L4::Ipc::Istream &operator >> (L4::Ipc::Istream &s, L4::Ipc::Buf_cp_in<T> const &v)
1355  L4_DEPRECATED("Use L4::Ipc::buf_cp_in() now");
1356 
1357 template< typename T >
1358 inline
1359 L4::Ipc::Istream &operator >> (L4::Ipc::Istream &s, L4::Ipc::Buf_cp_in<T> const &v)
1360 { return operator>>(s, static_cast<L4::Ipc::Internal::Buf_cp_in<T> >(v)); }
1361 
1362 template< typename T >
1363 inline
1364 L4::Ipc::Istream &operator >> (L4::Ipc::Istream &s, L4::Ipc::Buf_in<T> const &v)
1365  L4_DEPRECATED("Use L4::Ipc::buf_in() now");
1366 
1367 template< typename T >
1368 inline
1369 L4::Ipc::Istream &operator >> (L4::Ipc::Istream &s, L4::Ipc::Buf_in<T> const &v)
1370 { return operator>>(s, static_cast<L4::Ipc::Internal::Buf_in<T> >(v)); }
1371 
1372 template< typename T >
1373 inline
1374 L4::Ipc::Ostream &operator << (L4::Ipc::Ostream &s, L4::Ipc::Buf_cp_out<T> const &v)
1375  L4_DEPRECATED("Use L4::Ipc::buf_cp_out() now");
1376 
1377 template< typename T >
1378 inline
1379 L4::Ipc::Ostream &operator << (L4::Ipc::Ostream &s, L4::Ipc::Buf_cp_out<T> const &v)
1380 { return operator<<(s, static_cast<L4::Ipc::Internal::Buf_cp_out<T> >(v)); }
1381 #endif
1382 
1383 namespace L4 { namespace Ipc {
1392 template< typename T >
1393 inline
1394 T read(Istream &s) { T t; s >> t; return t; }
1395 
1396 } // namespace Ipc
1397 } // namespace L4
Encapsulation of the message-register block in the UTCB.
Definition: utcb.h:78
l4_msgtag_t tag() const
Get the message tag of a received IPC.
Definition: ipc_stream:510
Msg_ptr(T *&p)
Create a Msg_ptr object that set pointer p to point into the message buffer.
Definition: ipc_stream:253
Iostream(l4_utcb_t *utcb)
Create an IPC IO stream with a single message buffer.
Definition: ipc_stream:805
Total number of message register (MRs) available.
Definition: utcb.h:47
Invalid capability selector.
Definition: consts.h:141
l4_msgtag_t l4_ipc_send_and_wait(l4_cap_idx_t dest, l4_utcb_t *utcb, l4_msgtag_t tag, l4_umword_t *label, l4_timeout_t timeout) L4_NOTHROW
Send a message and do an open wait.
Definition: ipc.h:461
l4_msgtag_t call(l4_cap_idx_t dst, l4_timeout_t timeout, long proto=0)
Do an IPC call using the message in the output stream and receiving to the input stream.
Definition: ipc_stream:964
Input stream for IPC unmarshalling.
Definition: ipc_stream:347
Input/Output stream for IPC [un]marshalling.
Definition: ipc_stream:793
l4_umword_t mr[L4_UTCB_GENERIC_DATA_SIZE]
Message registers.
Definition: utcb.h:80
l4_msgtag_t l4_ipc_call(l4_cap_idx_t object, l4_utcb_t *utcb, l4_msgtag_t tag, l4_timeout_t timeout) L4_NOTHROW
Object call (usual invocation).
Definition: ipc.h:445
Variably sized RPC argument.
Definition: ipc_varg:96
T read(Istream &s)
Read a value out of a stream.
Definition: ipc_stream:1394
L4 low-level kernel interface.
Istream(l4_utcb_t *utcb)
Create an input stream for the given message buffer.
Definition: ipc_stream:361
l4_msgtag_t tag() const
Extract the L4 message tag from the stream.
Definition: ipc_stream:708
A receive item for receiving a single capability.
Definition: ipc_types:268
unsigned words() const
Get the number of untyped words.
Definition: types.h:168
Mask for all flags.
Definition: types.h:139
Abstraction for extracting a zero-terminated string from an Ipc::Istream.
Definition: ipc_stream:191
void data(char const *d)
Set Varg to indirect data value (usually in UTCB)
Definition: ipc_varg:120
unsigned long l4_cap_idx_t
L4 Capability selector Type.
Definition: types.h:342
void reset()
Reset the stream to empty, and ready for receive()/wait().
Definition: ipc_stream:371
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition: utcb.h:67
l4_msgtag_t & tag()
Extract a reference to the L4 message tag from the stream.
Definition: ipc_stream:715
RPC wrapper for a send item.
Definition: ipc_types:294
Internal::Buf_in< T > buf_in(T *&v, unsigned long &size)
Return a pointer to stream array data.
Definition: ipc_stream:323
#define L4_IPC_NEVER
never timeout
Definition: __timeout.h:80
Timeout pair.
Definition: __timeout.h:57
L4::Cap related definitions.
l4_msgtag_t wait(l4_umword_t *src)
Wait for an incoming message from any sender.
Definition: ipc_stream:553
Reply flag.
Definition: consts.h:89
Internal::Buf_cp_in< T > buf_cp_in(T *v, unsigned long &size)
Extract an array from an Ipc::Istream.
Definition: ipc_stream:172
l4_msgtag_t send(l4_cap_idx_t dst, long proto=0, unsigned flags=0)
Send the message via IPC to the given receiver.
Definition: ipc_stream:957
RPC warpper for a receive item.
Definition: ipc_types:305
l4_msgtag_t reply_and_wait(l4_umword_t *src_dst, long proto=0)
Do an IPC reply and wait.
Definition: ipc_stream:878
bool has_more(unsigned long count=1)
Check whether a value of type T can be obtained from the stream.
Definition: ipc_stream:382
l4_umword_t bdr
Buffer descriptor.
Definition: utcb.h:96
Total number of buffer registers (BRs) available.
Definition: utcb.h:50
l4_umword_t Tag
The data type for the tag.
Definition: ipc_varg:106
bool put(T const &v)
Insert an element of type T into the stream.
Definition: ipc_stream:680
void skip(unsigned long elems)
Skip size elements of type T in the stream.
Definition: ipc_stream:424
#define L4_UNLIKELY(x)
Expression is unlikely to execute.
Definition: compiler.h:234
Str_cp_in(T *v, unsigned long &size)
Create a buffer for extracting an array from an Ipc::Istream.
Definition: ipc_stream:202
unsigned long l4_umword_t
Unsigned machine word.
Definition: l4int.h:52
void reset()
Reset the stream to its initial state.
Definition: ipc_stream:819
l4_utcb_t * utcb() const
Return utcb pointer.
Definition: ipc_stream:747
unsigned items() const
Get the number of typed items.
Definition: types.h:170
l4_utcb_t * utcb() const
Return utcb pointer.
Definition: ipc_stream:586
l4_msgtag_t l4_ipc_reply_and_wait(l4_utcb_t *utcb, l4_msgtag_t tag, l4_umword_t *label, l4_timeout_t timeout) L4_NOTHROW
Reply and wait operation (uses the reply capability).
Definition: ipc.h:453
Gen_fpage< Snd_item > Snd_fpage
Send flex-page.
Definition: ipc_types:477
l4_msgtag_t l4_msgtag(long label, unsigned words, unsigned items, unsigned flags) L4_NOTHROW
Create a message tag from the specified values.
Definition: types.h:408
l4_msgtag_t l4_ipc_send(l4_cap_idx_t dest, l4_utcb_t *utcb, l4_msgtag_t tag, l4_timeout_t timeout) L4_NOTHROW
Send a message to an object (do not wait for a reply).
Definition: ipc.h:470
unsigned long get(T *buf, unsigned long elems)
Copy out an array of type T with size elements.
Definition: ipc_stream:405
unsigned length() const
Get the size of the RPC argument.
Definition: ipc_varg:114
Internal::Buf_cp_out< T > buf_cp_out(T const *v, unsigned long size)
Insert an array into an Ipc::Ostream.
Definition: ipc_stream:113
Gen_fpage< Buf_item > Rcv_fpage
Rcv flex-page.
Definition: ipc_types:479
Tag tag() const
Definition: ipc_varg:116
Str_cp_in< T > str_cp_in(T *v, unsigned long &size)
Create a Str_cp_in for the given values.
Definition: ipc_stream:226
#define L4_IPC_SEND_TIMEOUT_0
0 send timeout
Definition: __timeout.h:82
l4_msgtag_t l4_ipc_receive(l4_cap_idx_t object, l4_utcb_t *utcb, l4_timeout_t timeout) L4_NOTHROW
Wait for a message from a specific source.
Definition: ipc.h:487
Ostream(l4_utcb_t *utcb)
Create an IPC output stream using the given message buffer utcb.
Definition: ipc_stream:631
bool put(T *buf, unsigned long size)
Put an array with size elements of type T into the stream.
Definition: ipc_stream:662
l4_msgtag_t l4_ipc_wait(l4_utcb_t *utcb, l4_umword_t *label, l4_timeout_t timeout) L4_NOTHROW
Wait for an incoming message from any possible sender.
Definition: ipc.h:478
L4::Ipc::Ostream & operator<<(L4::Ipc::Ostream &s, bool v)
Insert an element to type T into the stream s.
Definition: ipc_stream:1195
l4_msgtag_t & tag()
Get the message tag of a received IPC.
Definition: ipc_stream:522
Pointer to an element of type T in an Ipc::Istream.
Definition: ipc_stream:242
Output stream for IPC marshalling.
Definition: ipc_stream:625
Message tag data structure.
Definition: types.h:159
L4::Ipc::Istream & operator>>(L4::Ipc::Istream &s, bool &v)
Extract one element of type T from the stream s.
Definition: ipc_stream:1042
unsigned long l4_addr_t
Address type.
Definition: l4int.h:45
l4_msgtag_t receive(l4_cap_idx_t src)
Wait for a message from the specified sender.
Definition: ipc_stream:577
l4_umword_t br[L4_UTCB_GENERIC_BUFFERS_SIZE]
Buffer registers.
Definition: utcb.h:99
void reset()
Reset the stream to empty, same state as a newly created stream.
Definition: ipc_stream:640
Msg_ptr< T > msg_ptr(T *&p)
Create an Msg_ptr to adjust the given pointer.
Definition: ipc_stream:265
#define L4_DEPRECATED(s)
Mark symbol deprecated.
Definition: compiler.h:239
T1 min(T1 a, T1 b)
Get the minimum of a and b.
Definition: minmax:35