L4Re/departure

Annotated servers/test_file_server.cc

391:bc65615a8fed
2022-06-30 Paul Boddie Added missing structure members. mmap-region-flags
paul@18 1
/*
paul@18 2
 * Test dataspace operations.
paul@18 3
 *
paul@18 4
 * Copyright (C) 2020, 2021 Paul Boddie <paul@boddie.org.uk>
paul@18 5
 *
paul@18 6
 * This program is free software; you can redistribute it and/or
paul@18 7
 * modify it under the terms of the GNU General Public License as
paul@18 8
 * published by the Free Software Foundation; either version 2 of
paul@18 9
 * the License, or (at your option) any later version.
paul@18 10
 *
paul@18 11
 * This program is distributed in the hope that it will be useful,
paul@18 12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
paul@18 13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
paul@18 14
 * GNU General Public License for more details.
paul@18 15
 *
paul@18 16
 * You should have received a copy of the GNU General Public License
paul@18 17
 * along with this program; if not, write to the Free Software
paul@18 18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
paul@18 19
 * Boston, MA  02110-1301, USA
paul@18 20
 */
paul@18 21
paul@18 22
#include <l4/sys/err.h>
paul@18 23
paul@29 24
#include <ipc/thread.h>
paul@18 25
paul@18 26
#include <stdio.h>
paul@18 27
#include <stdlib.h>
paul@18 28
paul@94 29
#include <mem/memory_incremental.h>
paul@94 30
#include <mem/memory_utils.h>
paul@94 31
#include <fsserver/page_queue_shared.h>
paul@94 32
#include <fsserver/pages.h>
paul@94 33
#include <fsserver/resource_server.h>
paul@94 34
#include <fsserver/test_file_opener.h>
paul@18 35
paul@18 36
paul@18 37
paul@26 38
const unsigned int REGION_PAGES = 8;
paul@26 39
const unsigned int MEMORY_PAGES = REGION_PAGES * 10;
paul@18 40
const unsigned int FILE_PAGES = 20;
paul@18 41
paul@38 42
int main(int argc, char *argv[])
paul@18 43
{
paul@44 44
  long err;
paul@44 45
paul@18 46
  /* Introduce concurrency control. */
paul@18 47
paul@44 48
  err = ipc_thread_init();
paul@44 49
paul@44 50
  if (err)
paul@44 51
  {
paul@44 52
    printf("Initialisation error: %s\n", l4sys_errtostr(err));
paul@44 53
    return 1;
paul@44 54
  }
paul@18 55
paul@38 56
  /* Configure the number of available pages using any argument. */
paul@38 57
paul@38 58
  unsigned int memory_pages = MEMORY_PAGES;
paul@38 59
paul@38 60
  if (argc > 1)
paul@38 61
    memory_pages = atoi(argv[1]) * REGION_PAGES;
paul@38 62
paul@18 63
  /* Some memory plus infrastructure. */
paul@18 64
paul@72 65
  MemoryIncremental mem(memory_pages, page(REGION_PAGES));
paul@72 66
  PageQueueShared queue;
paul@72 67
  Pages pages(&mem, &queue);
paul@224 68
  ResourceRegistry registry(&pages);
paul@209 69
  TestFileOpener opener(&registry, page(FILE_PAGES));
paul@18 70
paul@18 71
  /* Register a server associating it with the given object. */
paul@18 72
paul@97 73
  const char *server_name = (argc > 2) ? argv[2] : "server";
paul@97 74
paul@18 75
  ResourceServer server(&opener);
paul@97 76
  err = server.bind(server_name);
paul@18 77
paul@18 78
  if (err)
paul@18 79
  {
paul@18 80
    printf("Could not bind server: %s\n", l4sys_errtostr(err));
paul@18 81
    return 1;
paul@18 82
  }
paul@18 83
paul@18 84
  printf("Starting server...\n");
paul@18 85
  server.start();
paul@18 86
  return 0;
paul@18 87
}
paul@38 88
paul@38 89
// vim: tabstop=2 expandtab shiftwidth=2