diff --git a/bindings/python/genbinds.py b/bindings/python/genbinds.py index a816d2e1..5e3e1e62 100644 --- a/bindings/python/genbinds.py +++ b/bindings/python/genbinds.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import sys import os, errno diff --git a/bindings/python/wscript b/bindings/python/wscript index 165acd59..cda0936b 100644 --- a/bindings/python/wscript +++ b/bindings/python/wscript @@ -314,7 +314,7 @@ int main () return gccxml_version_line = os.popen(gccxml[0] + " --version").readline().strip() - m = re.match( "^GCC-XML version (\d\.\d(\.\d)?)$", gccxml_version_line) + m = re.match(r'^GCC-XML version (\d\.\d(\.\d)?)$', gccxml_version_line) gccxml_version = m.group(1) gccxml_version_ok = ([int(s) for s in gccxml_version.split('.')] >= [0, 9]) conf.msg('Checking for gccxml version', gccxml_version) diff --git a/example/dce-tcp-simple.cc b/example/dce-tcp-simple.cc index 2a14f01a..ef5d5592 100644 --- a/example/dce-tcp-simple.cc +++ b/example/dce-tcp-simple.cc @@ -27,7 +27,7 @@ int main (int argc, char *argv[]) apps = dce.Install (nodes.Get (0)); apps.Start (Seconds (4.0)); - Simulator::Stop (Seconds (1000100.0)); + Simulator::Stop (Seconds (60.0)); Simulator::Run (); Simulator::Destroy (); diff --git a/example/examples-to-run.py b/example/examples-to-run.py index 55381295..4a510fb6 100644 --- a/example/examples-to-run.py +++ b/example/examples-to-run.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 ## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- # A list of C++ examples to run in order to ensure that they remain diff --git a/example/tcp-loopback.cc b/example/tcp-loopback.cc index dc9b8c50..20094b9d 100644 --- a/example/tcp-loopback.cc +++ b/example/tcp-loopback.cc @@ -3,6 +3,7 @@ #include #include #include +#include #include #define SERVER_PORT 2000 diff --git a/example/unix-client.cc b/example/unix-client.cc index 9e317ec1..6b3119a0 100644 --- a/example/unix-client.cc +++ b/example/unix-client.cc @@ -8,6 +8,7 @@ #include #include #include +#include #define SOCK_PATH "/tmp/socket" #define BUF_LEN 128 * 1024 + 255 diff --git a/example/unix-server.cc b/example/unix-server.cc index 0159243c..516e7569 100644 --- a/example/unix-server.cc +++ b/example/unix-server.cc @@ -10,6 +10,7 @@ #include #include #include +#include #define SOCK_PATH "/tmp/socket" #define BUF_LEN 256 diff --git a/helper/dce-manager-helper.cc b/helper/dce-manager-helper.cc index 722557f0..f76bafa2 100644 --- a/helper/dce-manager-helper.cc +++ b/helper/dce-manager-helper.cc @@ -30,7 +30,9 @@ TypeId DceManagerHelper::GetTypeId (void) { static TypeId tid = TypeId ("ns3::DceManagerHelper") - .SetParent () + .SetParent () + .SetGroupName ("Dce") + .AddConstructor () .AddAttribute ("LoaderFactory", "The kind of loader factory created when Install is called", StringValue ("ns3::CoojaLoaderFactory[]"), @@ -39,15 +41,10 @@ DceManagerHelper::GetTypeId (void) ; return tid; } -TypeId -DceManagerHelper::GetInstanceTypeId (void) const -{ - return DceManagerHelper::GetTypeId (); -} DceManagerHelper::DceManagerHelper () { - ConstructSelf (AttributeConstructionList ()); + m_loaderFactory.SetTypeId ("ns3::CoojaLoaderFactory"); m_taskManagerFactory.SetTypeId ("ns3::TaskManager"); m_schedulerFactory.SetTypeId ("ns3::RrTaskScheduler"); m_managerFactory.SetTypeId ("ns3::DceManager"); @@ -55,6 +52,12 @@ DceManagerHelper::DceManagerHelper () m_delayFactory.SetTypeId ("ns3::RandomProcessDelayModel"); m_virtualPath = ""; } + +void +DceManagerHelper::NotifyConstructionCompleted (void) +{ + Object::NotifyConstructionCompleted (); +} void DceManagerHelper::SetScheduler (std::string type, std::string n0, const AttributeValue &v0, diff --git a/helper/dce-manager-helper.h b/helper/dce-manager-helper.h index aa4af3ce..30fd6d0e 100644 --- a/helper/dce-manager-helper.h +++ b/helper/dce-manager-helper.h @@ -83,13 +83,14 @@ class DceManagerHelper : public Object { public: static TypeId GetTypeId (void); - virtual TypeId GetInstanceTypeId (void) const; /** * Construct a DceManagerHelper */ DceManagerHelper (); + void NotifyConstructionCompleted (void) override; + /** * \param type the name of the TaskScheduler to set * \param n0 the name of the attribute to set to the TaskScheduler diff --git a/model/dce-application.cc b/model/dce-application.cc index 8925841a..ea4f7200 100644 --- a/model/dce-application.cc +++ b/model/dce-application.cc @@ -70,7 +70,7 @@ DceApplication::StartApplication (void) Ptr node = GetNode (); Ptr manager = node->GetObject (); - if (manager == 0) + if (!manager) { NS_FATAL_ERROR ("You forgot to aggregate a DceManager to node=" << node->GetId ()); } diff --git a/model/dce-at.cc b/model/dce-at.cc index 7d6c7171..b88fdd0d 100644 --- a/model/dce-at.cc +++ b/model/dce-at.cc @@ -32,7 +32,7 @@ NS_LOG_COMPONENT_DEFINE ("DceAt"); using namespace ns3; -int dce___fxstatat (int ver, int fd, const char *pathname, struct stat *buf, int flag) +int dce_fstatat (int fd, const char *pathname, struct stat *buf, int flag) { Thread *current = Current (); NS_LOG_FUNCTION (current << UtilsGetNodeId () << pathname << buf); @@ -58,12 +58,12 @@ int dce___fxstatat (int ver, int fd, const char *pathname, struct stat *buf, int current->err = EBADF; return -1; } - retval = ::__fxstatat (ver, realFd, pathname, buf, flag); + retval = ::fstatat (realFd, pathname, buf, flag); } else { std::string path = UtilsGetCurrentDirName () + "/" + UtilsGetRealFilePath (pathname); - retval = ::__fxstatat (ver, fd, path.c_str (), buf, flag); + retval = ::fstatat (fd, path.c_str (), buf, flag); } if (retval == -1) { @@ -72,6 +72,48 @@ int dce___fxstatat (int ver, int fd, const char *pathname, struct stat *buf, int } return retval; } + +int dce_fstatat64(int dirfd, const char * path, struct stat64 * stat_buf, int flags) +{ + Thread *current = Current (); + NS_LOG_FUNCTION (current << UtilsGetNodeId () << path << stat_buf); + NS_ASSERT (current != 0); + int retval = -1; + + if ((0 == path) || (0 == stat_buf)) + { + current->err = EFAULT; + return -1; + } + if (std::string (path) == "") + { + current->err = ENOENT; + return -1; + } + if (dirfd != AT_FDCWD && path[0] != '/') + { + int realFd = getRealFd (dirfd, current); + + if (realFd < 0) + { + current->err = EBADF; + return -1; + } + retval = ::fstatat64 (realFd, path, stat_buf, flags); + } + else + { + std::string path = UtilsGetCurrentDirName () + "/" + UtilsGetRealFilePath (path); + retval = ::fstatat64 (dirfd, path.c_str (), stat_buf, flags); + } + if (retval == -1) + { + current->err = errno; + return -1; + } + return retval; +} + void unlink_notify (std::string fullpath); int dce_unlinkat (int fd, const char *pathname, int flags) { diff --git a/model/dce-fd.cc b/model/dce-fd.cc index d439e35b..9db7d5bc 100644 --- a/model/dce-fd.cc +++ b/model/dce-fd.cc @@ -212,12 +212,12 @@ void unlink_notify (std::string fullpath) Ptr factory = Current ()->process->manager->GetObject (); - if (0 != factory) + if (factory) { factory->UnlinkNotify (fullpath); } factory = Current ()->process->manager->GetObject (); - if (0 != factory) + if (factory) { factory->UnlinkNotify (fullpath); } diff --git a/model/dce-misc.cc b/model/dce-misc.cc index b692eb0e..235ba416 100644 --- a/model/dce-misc.cc +++ b/model/dce-misc.cc @@ -16,7 +16,7 @@ NS_LOG_COMPONENT_DEFINE ("DceMisc"); int dce_uname (struct utsname *buf) { Ptr nodeContext = DceNodeContext::GetNodeContext (); - NS_ASSERT (0 != nodeContext); + NS_ASSERT (nodeContext); return nodeContext->UName (buf); } diff --git a/model/dce-node-context.cc b/model/dce-node-context.cc index 740c6cbc..27ef5806 100644 --- a/model/dce-node-context.cc +++ b/model/dce-node-context.cc @@ -46,11 +46,6 @@ DceNodeContext::GetTypeId (void) return tid; } -TypeId -DceNodeContext::GetInstanceTypeId (void) const -{ - return DceNodeContext::GetTypeId (); -} DceNodeContext::DceNodeContext () { m_randomCtx = CreateObject (); @@ -79,7 +74,7 @@ DceNodeContext::UName (struct utsname *buf) { uint32_t nodeId = UtilsGetNodeId (); Ptr node = NodeList::GetNode (nodeId); - NS_ASSERT (node != 0); + NS_ASSERT (node); std::string nodeName = Names::FindName (node); std::ostringstream oss; diff --git a/model/dce-node-context.h b/model/dce-node-context.h index 80e46972..7dacb68c 100644 --- a/model/dce-node-context.h +++ b/model/dce-node-context.h @@ -43,7 +43,6 @@ class DceNodeContext : public Object { public: static TypeId GetTypeId (void); - virtual TypeId GetInstanceTypeId (void) const; DceNodeContext (); virtual ~DceNodeContext (); diff --git a/model/dce-stat.cc b/model/dce-stat.cc index 58b731b5..20e68d02 100644 --- a/model/dce-stat.cc +++ b/model/dce-stat.cc @@ -12,7 +12,7 @@ using namespace ns3; NS_LOG_COMPONENT_DEFINE ("DceStat"); -int dce___xstat (int ver, const char *path, struct stat *buf) +int dce_stat (const char *path, struct stat *buf) { Thread *current = Current (); NS_LOG_FUNCTION (current << UtilsGetNodeId () << path << buf); @@ -22,7 +22,7 @@ int dce___xstat (int ver, const char *path, struct stat *buf) current->err = ENOENT; return -1; } - int retval = ::__xstat (ver, UtilsGetRealFilePath (path).c_str (), buf); + int retval = ::stat (UtilsGetRealFilePath (path).c_str (), buf); if (retval == -1) { current->err = errno; @@ -30,7 +30,7 @@ int dce___xstat (int ver, const char *path, struct stat *buf) } return retval; } -int dce___xstat64 (int ver, const char *path, struct stat64 *buf) +int dce_stat64 (const char *path, struct stat64 *buf) { Thread *current = Current (); NS_LOG_FUNCTION (current << UtilsGetNodeId () << path << buf); @@ -40,7 +40,7 @@ int dce___xstat64 (int ver, const char *path, struct stat64 *buf) current->err = ENOENT; return -1; } - int retval = ::__xstat64 (ver, UtilsGetRealFilePath (path).c_str (), buf); + int retval = ::stat64 (UtilsGetRealFilePath (path).c_str (), buf); if (retval == -1) { current->err = errno; @@ -48,23 +48,23 @@ int dce___xstat64 (int ver, const char *path, struct stat64 *buf) } return retval; } -int dce___fxstat (int ver, int fd, struct stat *buf) +int dce_fstat (int fd, struct stat *buf) { Thread *current = Current (); NS_LOG_FUNCTION (current << UtilsGetNodeId () << fd); NS_ASSERT (current != 0); - OPENED_FD_METHOD (int, Fxstat (ver, buf)) + OPENED_FD_METHOD (int, Fxstat (0, buf)) } -int dce___fxstat64 (int ver, int fd, struct stat64 *buf) +int dce_fstat64 (int fd, struct stat64 *buf) { Thread *current = Current (); NS_LOG_FUNCTION (current << UtilsGetNodeId () << fd); NS_ASSERT (current != 0); - OPENED_FD_METHOD (int, Fxstat64 (ver, buf)) + OPENED_FD_METHOD (int, Fxstat64 (0, buf)) } -int dce___lxstat (int ver, const char *pathname, struct stat *buf) +int dce_lstat (const char *pathname, struct stat *buf) { Thread *current = Current (); NS_LOG_FUNCTION (current << UtilsGetNodeId () << pathname << buf); @@ -74,7 +74,7 @@ int dce___lxstat (int ver, const char *pathname, struct stat *buf) current->err = ENOENT; return -1; } - int retval = ::__lxstat (ver, UtilsGetRealFilePath (pathname).c_str (), buf); + int retval = ::lstat (UtilsGetRealFilePath (pathname).c_str (), buf); if (retval == -1) { current->err = errno; @@ -82,7 +82,7 @@ int dce___lxstat (int ver, const char *pathname, struct stat *buf) } return retval; } -int dce___lxstat64 (int ver, const char *pathname, struct stat64 *buf) +int dce_lstat64 (const char *pathname, struct stat64 *buf) { Thread *current = Current (); NS_LOG_FUNCTION (current << UtilsGetNodeId () << pathname << buf); @@ -92,7 +92,7 @@ int dce___lxstat64 (int ver, const char *pathname, struct stat64 *buf) current->err = ENOENT; return -1; } - int retval = ::__lxstat64 (ver, UtilsGetRealFilePath (pathname).c_str (), buf); + int retval = ::lstat64 (UtilsGetRealFilePath (pathname).c_str (), buf); if (retval == -1) { current->err = errno; @@ -100,12 +100,3 @@ int dce___lxstat64 (int ver, const char *pathname, struct stat64 *buf) } return retval; } - -int dce_fstat (int fd, struct stat *buf) -{ - return dce___fxstat (_STAT_VER, fd, buf); -} -int dce_fstat64 (int fd, struct stat64 *buf) -{ - return dce___fxstat64 (_STAT_VER, fd, buf); -} diff --git a/model/dce-stdio.cc b/model/dce-stdio.cc index 15b7e305..d0744146 100644 --- a/model/dce-stdio.cc +++ b/model/dce-stdio.cc @@ -22,27 +22,15 @@ using namespace ns3; namespace { -struct my_IO_jump_t -{ - size_t dummy0; - size_t dummy1; - void *functions[12]; - void *__read; - void *__write; - void *__seek; - void *__close; - void *__stat; - void *__showmanyc; - void *__imbue; -}; -struct my_IO_FILE_plus +struct my_cookie { - _IO_FILE file; - struct my_IO_jump_t *vtable; + int _fileno; + off64_t _offset; }; -ssize_t my_read (_IO_FILE *file, void *buffer, ssize_t size) +ssize_t my_read (void *c, char *buffer, size_t size) { + struct my_cookie *file = (struct my_cookie *)c; ssize_t data_read = dce_read (file->_fileno, buffer, size); if (data_read == -1) { @@ -50,8 +38,9 @@ ssize_t my_read (_IO_FILE *file, void *buffer, ssize_t size) } return data_read; } -ssize_t my_write (_IO_FILE *file, const void *buffer, ssize_t size) +ssize_t my_write (void *c, const char *buffer, size_t size) { + struct my_cookie *file = (struct my_cookie *)c; ssize_t data_written = dce_write (file->_fileno, buffer, size); if (data_written == -1) { @@ -63,46 +52,38 @@ ssize_t my_write (_IO_FILE *file, const void *buffer, ssize_t size) } return data_written; } -off64_t my_seek (_IO_FILE *file, off64_t where, int whence) +int my_seek(void *c, off64_t *where, int whence) { - off64_t result = dce_lseek (file->_fileno, where, whence); - if (result == -1) - { - errno = Current ()->err; - } - return result; -} -int my_close (_IO_FILE *file) -{ - int result = dce_close (file->_fileno); + struct my_cookie *file = (struct my_cookie *)c; + off64_t result = dce_lseek (file->_fileno, *where, whence); if (result == -1) { errno = Current ()->err; + return -1; } - return result; -} -int my_close_unconditional (_IO_FILE *file) -{ + file->_offset = result; + *where = result; return 0; } -int my_write_unconditional (_IO_FILE *file) +int my_close(void *c) { - errno = EBADF; - return -1; -} -off64_t my_seek_unconditional (_IO_FILE *file, off64_t where, int whence) -{ - return -1; -} -int my_stat (_IO_FILE *file, void *buf) -{ - int result = dce_fstat64 (file->_fileno, (struct stat64 *)buf); + struct my_cookie *file = (struct my_cookie *)c; + int result = dce_close (file->_fileno); if (result == -1) { errno = Current ()->err; } + free(file); return result; } + +cookie_io_functions_t my_func = { + .read = my_read, + .write = my_write, + .seek = my_seek, + .close = my_close, +}; + bool mode_seek_start (const char *mode) { return *mode != 'a'; @@ -186,24 +167,9 @@ FILE * dce_fdopen (int fildes, const char *mode) NS_LOG_FUNCTION (Current () << UtilsGetNodeId () << fildes << mode); NS_ASSERT (Current () != 0); Thread *current = Current (); - // no need to create or truncate. Just need to seek if needed. - FILE *file = fopen ("/dev/null", mode); - if (file == 0) - { - current->err = errno; - return 0; - } - struct my_IO_FILE_plus *fp = (struct my_IO_FILE_plus *)file; - static struct my_IO_jump_t vtable; - memcpy (&vtable, fp->vtable, sizeof(struct my_IO_jump_t)); - vtable.__read = (void*)my_read; - vtable.__write = (void*)my_write; - vtable.__seek = (void*)my_seek; - vtable.__close = (void*)my_close; - vtable.__stat = (void*)my_stat; - fp->vtable = &vtable; - close (file->_fileno); - file->_fileno = fildes; + struct my_cookie *fp = (struct my_cookie*)malloc(sizeof(struct my_cookie)); + fp->_fileno = fildes; + FILE *file = fopencookie(fp, mode, my_func); current->process->openStreams.push_back (file); dce_fseek (file, dce_lseek (fildes, 0, SEEK_CUR), SEEK_SET); @@ -258,6 +224,8 @@ FILE * dce_fopen (const char *path, const char *mode) mode_setup (file, fd, mode); return file; } +// FIXME: Ugly but less code movement. +static void remove_stream (FILE *fp); FILE * dce_freopen (const char *path, const char *mode, FILE *stream) { NS_LOG_FUNCTION (Current () << UtilsGetNodeId () << path << mode << stream); @@ -268,36 +236,25 @@ FILE * dce_freopen (const char *path, const char *mode, FILE *stream) current->err = EINVAL; return 0; } - int oldFd = stream->_fileno; - stream->_fileno = -1; - stream = freopen ("/dev/null", mode, stream); - if (stream == 0) - { - stream->_fileno = oldFd; - current->err = errno; - return 0; - } - struct my_IO_FILE_plus *fp = (struct my_IO_FILE_plus *)stream; - static struct my_IO_jump_t vtable; - memcpy (&vtable, fp->vtable, sizeof(struct my_IO_jump_t)); - vtable.__read = (void*)my_read; - vtable.__write = (void*)my_write; - vtable.__seek = (void*)my_seek; - vtable.__close = (void*)my_close; - vtable.__stat = (void*)my_stat; - fp->vtable = &vtable; - - int fd = dce_open (path, mode_posix_flags (mode), ~0); - if (fd == -1) - { - dce_close (oldFd); - fclose (stream); - current->err = errno; - return 0; - } - dce_close (oldFd); - stream->_fileno = fd; - mode_setup (stream, fd, mode); + if (path == NULL) { + // Just change mode + // Create a copy of the fd behind stream + int oldFdCopy = dup(fileno(stream)); + // Close the old + fclose(stream); + remove_stream(stream); + // And create a new dce_fdopen from the copied fd + // // And create a new dce_fdopen from the copied fd + stream = dce_fdopen(oldFdCopy, mode); + return stream; + } + if (stream) { + fclose(stream); + remove_stream(stream); + } + + stream = dce_fopen(path, mode); + return stream; } int dce_fcloseall (void) @@ -342,14 +299,9 @@ int dce_fclose_unconditional (FILE *file) // Note: it is important here not to call the Current function here // because we need to be able to run this function even if there is no context. // For example, this is why we have no call to NS_LOG_FUNCTION (Current () ...); - struct my_IO_FILE_plus *fp = (struct my_IO_FILE_plus *)file; - static struct my_IO_jump_t vtable; - memcpy (&vtable, fp->vtable, sizeof(struct my_IO_jump_t)); - vtable.__close = (void*)my_close_unconditional; - vtable.__write = (void*)my_write_unconditional; - vtable.__seek = (void*)my_seek_unconditional; - fp->vtable = &vtable; - fclose (file); + // TODO + //fclose(file); + // Maybee dce_close(fileno(file)) ? return 0; } int dce_fclose_onexec (FILE *file) @@ -357,12 +309,9 @@ int dce_fclose_onexec (FILE *file) // Note: it is important here not to call the Current function here // because we need to be able to run this function even if there is no context. // For example, this is why we have no call to NS_LOG_FUNCTION (Current () ...); - struct my_IO_FILE_plus *fp = (struct my_IO_FILE_plus *)file; - static struct my_IO_jump_t vtable; - memcpy (&vtable, fp->vtable, sizeof(struct my_IO_jump_t)); - vtable.__close = (void*)my_close_unconditional; - fp->vtable = &vtable; - fclose (file); + // TODO: fclose here might cause dce_write and will cause dce_close which calls Current()... + // but it works in the tests now. + fclose(file); return 0; } int dce_fclose (FILE *fp) @@ -375,6 +324,9 @@ int dce_fclose (FILE *fp) || (current->process->pstdin && fp == *current->process->pstderr) || (current->process->pstdin && fp == *current->process->pstdin)) { + // TODO: BUG: This is not right + // fcloseall says: + // The standard streams, stdin, stdout, and stderr are also closed. return 0; } @@ -460,6 +412,19 @@ int dce_fileno (FILE *stream) NS_LOG_FUNCTION (Current () << UtilsGetNodeId () << stream); NS_ASSERT (Current () != 0); Thread *current = Current (); + + // UGLY: FIXME: Use current->process->openStreams instead + if (current->process->pstdin && stream == *current->process->pstdin) { + return 0; + } else if (current->process->pstdout && stream == *current->process->pstdout) { + return 1; + } else if (current->process->pstderr && stream == *current->process->pstderr) { + return 2; + } + + // FIXME: Handle fopencookie things to. We need to detect those FILE* + // and return cookie->_fileno instead... But how? + int status = fileno (stream); if (status == -1) { @@ -498,13 +463,6 @@ int dce_getchar (void) return fgetc (*Current ()->process->pstdin); } -int dce__IO_getc (FILE *stream) -{ - NS_LOG_FUNCTION (Current () << UtilsGetNodeId ()); - NS_ASSERT (Current () != 0); - return fgetc (stream); -} - int dce_putchar (int __c) { NS_LOG_FUNCTION (Current () << UtilsGetNodeId () << (char)__c); @@ -512,13 +470,6 @@ int dce_putchar (int __c) return fputc (__c, *Current ()->process->pstdout); } -int dce__IO_putc (int __c, FILE *__stream) -{ - NS_LOG_FUNCTION (Current () << UtilsGetNodeId () << (char)__c); - NS_ASSERT (Current () != 0); - return fputc (__c, __stream); -} - int dce_puts (const char *__s) { NS_LOG_FUNCTION (Current () << UtilsGetNodeId () << __s); diff --git a/model/elf-cache.cc b/model/elf-cache.cc index 36183d2d..5d4f49db 100644 --- a/model/elf-cache.cc +++ b/model/elf-cache.cc @@ -239,6 +239,9 @@ ElfCache::EditBuffer (uint8_t *map, uint32_t selfId) const cur = dyn; while (cur->d_tag != DT_NULL) { + if (cur->d_tag == DT_FLAGS_1) { + cur->d_un.d_val = cur->d_un.d_val & ~DF_1_PIE; + } if (cur->d_tag == DT_FINI) { cur->d_tag = DT_INIT; diff --git a/model/freebsd-socket-fd-factory.cc b/model/freebsd-socket-fd-factory.cc index bc40ec39..70d0f81d 100644 --- a/model/freebsd-socket-fd-factory.cc +++ b/model/freebsd-socket-fd-factory.cc @@ -42,7 +42,7 @@ FreeBSDSocketFdFactory::NotifyNewAggregate (void) Ptr node = this->GetObject (); Ptr loaderFactory = this->GetObject (); Ptr taskManager = this->GetObject (); - if (node != 0 && loaderFactory != 0 && taskManager != 0 && m_loader == 0) + if (node && loaderFactory && taskManager && m_loader == 0) { m_manager = taskManager; m_loader = loaderFactory->Create (0, 0, 0); @@ -120,7 +120,7 @@ FreeBSDSocketFdFactory::SetTask (std::string path, std::string value) void FreeBSDSocketFdFactory::Set (std::string path, std::string value) { - if (m_manager == 0) + if (!m_manager) { m_earlySysfs.push_back (std::make_pair (path,value)); } diff --git a/model/freebsd/ipv4-freebsd.cc b/model/freebsd/ipv4-freebsd.cc index 2c1958cb..eeeea438 100644 --- a/model/freebsd/ipv4-freebsd.cc +++ b/model/freebsd/ipv4-freebsd.cc @@ -301,7 +301,7 @@ Ipv4FreeBSD::AddAddress (uint32_t i, Ipv4InterfaceAddress address) NS_LOG_FUNCTION (this << i << address); Ptr interface = GetInterface (i); bool retVal = interface->AddAddress (address); - if (m_routingProtocol != 0) + if (m_routingProtocol) { m_routingProtocol->NotifyAddAddress (i, address); } @@ -341,7 +341,7 @@ Ipv4FreeBSD::RemoveAddress (uint32_t i, uint32_t addressIndex) Ipv4InterfaceAddress address = interface->RemoveAddress (addressIndex); if (address != Ipv4InterfaceAddress ()) { - if (m_routingProtocol != 0) + if (m_routingProtocol) { m_routingProtocol->NotifyRemoveAddress (i, address); } @@ -364,7 +364,7 @@ Ipv4FreeBSD::RemoveAddress (uint32_t i, Ipv4Address address) Ipv4InterfaceAddress ifAddr = interface->RemoveAddress (address); if (ifAddr != Ipv4InterfaceAddress ()) { - if (m_routingProtocol != 0) + if (m_routingProtocol) { m_routingProtocol->NotifyRemoveAddress (i, ifAddr); } @@ -388,7 +388,7 @@ Ipv4FreeBSD::SelectSourceAddress (Ptr device, Ipv4InterfaceAddress iaddr; bool found = false; - if (device != 0) + if (device) { int32_t i = GetInterfaceForDevice (device); NS_ASSERT_MSG (i >= 0, "No device found on node"); @@ -477,7 +477,7 @@ Ipv4FreeBSD::SetUp (uint32_t i) Ptr interface = GetInterface (i); interface->SetUp (); - if (m_routingProtocol != 0) + if (m_routingProtocol) { m_routingProtocol->NotifyInterfaceUp (i); } @@ -490,7 +490,7 @@ Ipv4FreeBSD::SetDown (uint32_t ifaceIndex) Ptr interface = GetInterface (ifaceIndex); interface->SetDown (); - if (m_routingProtocol != 0) + if (m_routingProtocol) { m_routingProtocol->NotifyInterfaceDown (ifaceIndex); } @@ -542,6 +542,18 @@ Ipv4FreeBSD::GetWeakEsModel (void) const return m_weakEsModel; } +void +Ipv4FreeBSD::SetStrongEndSystemModel(bool model) +{ + m_strongEsModel = model; +} + +bool +Ipv4FreeBSD::GetStrongEndSystemModel() const +{ + return m_strongEsModel; +} + void Ipv4FreeBSD::InstallNode (Ptr node) { diff --git a/model/freebsd/ipv4-freebsd.h b/model/freebsd/ipv4-freebsd.h index e37a8c8d..e1c39d46 100644 --- a/model/freebsd/ipv4-freebsd.h +++ b/model/freebsd/ipv4-freebsd.h @@ -356,6 +356,8 @@ class Ipv4FreeBSD : public Ipv4 virtual bool GetIpForward (void) const; virtual void SetWeakEsModel (bool model); virtual bool GetWeakEsModel (void) const; + virtual void SetStrongEndSystemModel(bool model); + virtual bool GetStrongEndSystemModel() const; uint32_t AddIpv4Interface (Ptr interface); Ptr GetInterface (uint32_t i) const; @@ -363,6 +365,7 @@ class Ipv4FreeBSD : public Ipv4 Ptr m_routingProtocol; bool m_ipForward; bool m_weakEsModel; + bool m_strongEsModel; Ipv4InterfaceList m_interfaces; uint64_t m_nanoSec; }; diff --git a/model/ipv4-dce-routing.h b/model/ipv4-dce-routing.h index f51af374..9ae033ea 100644 --- a/model/ipv4-dce-routing.h +++ b/model/ipv4-dce-routing.h @@ -77,7 +77,7 @@ class Ipv4DceRouting : public Ipv4StaticRouting template Ptr Ipv4DceRouting::GetRouting (Ptr ipv4rp, T* type) { - if (ipv4rp == 0) + if (!ipv4rp) { return 0; } @@ -93,7 +93,7 @@ Ptr Ipv4DceRouting::GetRouting (Ptr ipv4rp, T* type) { int16_t priority; Ptr ret = GetRouting (lrp->GetRoutingProtocol (i, priority), type); - if (ret != 0) + if (ret) { return ret; } diff --git a/model/libc-dce.cc b/model/libc-dce.cc index 2c0528b2..ee00df9f 100644 --- a/model/libc-dce.cc +++ b/model/libc-dce.cc @@ -206,7 +206,9 @@ void libc_dce (struct Libc **libc) (*libc)->strstr_fn = dce_strstr; (*libc)->vsnprintf_fn = dce_vsnprintf; - extern struct dl_open_hook *_dl_open_hook; + // TODO: + //extern struct dl_open_hook *_dl_open_hook; + struct dl_open_hook *_dl_open_hook; _dl_open_hook = (struct dl_open_hook *)&dce_dl_open_hook; } } // extern "C" diff --git a/model/libc-ns3.h b/model/libc-ns3.h index c29da0d2..d6919ce8 100644 --- a/model/libc-ns3.h +++ b/model/libc-ns3.h @@ -342,12 +342,10 @@ DCE_WITH_ALIAS2 (fgetc,fgetc_unlocked) NATIVE (getc) NATIVE (getc_unlocked) DCE_WITH_ALIAS2 (getchar,getchar_unlocked) -DCE (_IO_getc) DCE_WITH_ALIAS2 (fputc,fputc_unlocked) NATIVE (putc) NATIVE (putc_unlocked) DCE_WITH_ALIAS2 (putchar, putchar_unlocked) -DCE (_IO_putc) DCE_WITH_ALIAS2 (fgets, fgets_unlocked) DCE_WITH_ALIAS2 (fputs, fputs_unlocked) DCE (puts) @@ -457,7 +455,7 @@ NATIVE (sigismember) DCE (sigprocmask) DCE (sigwait) DCE (kill) -NATIVE (sys_siglist) +//NATIVE (sys_siglist) NATIVE (killpg) // PTHREAD.H @@ -686,13 +684,13 @@ DCE (__errno_location) DCE (__h_errno_location) DCE (__vsnprintf_chk) -DCE (__xstat) -DCE (__lxstat) -DCE (__fxstat) -DCE (__xstat64) -DCE (__lxstat64) -DCE (__fxstat64) -DCE (__fxstatat) +DCE (stat) +DCE (lstat) +DCE (fstat) +DCE (stat64) +DCE (lstat64) +DCE (fstat64) +DCE (fstatat) NATIVE (__cmsg_nxthdr) // math.h diff --git a/model/linux-socket-fd-factory.cc b/model/linux-socket-fd-factory.cc index b24b3db8..441b92df 100644 --- a/model/linux-socket-fd-factory.cc +++ b/model/linux-socket-fd-factory.cc @@ -43,7 +43,7 @@ LinuxSocketFdFactory::NotifyNewAggregate (void) Ptr node = this->GetObject (); Ptr loaderFactory = this->GetObject (); Ptr taskManager = this->GetObject (); - if (node != 0 && loaderFactory != 0 && taskManager != 0 && m_loader == 0) + if (node && loaderFactory && taskManager && m_loader == 0) { m_manager = taskManager; m_loader = loaderFactory->Create (0, 0, 0); @@ -82,7 +82,7 @@ LinuxSocketFdFactory::SetTask (std::string path, std::string value) void LinuxSocketFdFactory::Set (std::string path, std::string value) { - if (m_manager == 0) + if (!m_manager) { m_earlySysfs.push_back (std::make_pair (path,value)); } diff --git a/model/linux/ipv4-linux.cc b/model/linux/ipv4-linux.cc index 21b0395e..3f61f0d7 100644 --- a/model/linux/ipv4-linux.cc +++ b/model/linux/ipv4-linux.cc @@ -279,7 +279,7 @@ Ipv4Linux::AddAddress (uint32_t i, Ipv4InterfaceAddress address) NS_LOG_FUNCTION (this << i << address); Ptr interface = GetInterface (i); bool retVal = interface->AddAddress (address); - if (m_routingProtocol != 0) + if (m_routingProtocol) { m_routingProtocol->NotifyAddAddress (i, address); } @@ -321,7 +321,7 @@ Ipv4Linux::RemoveAddress (uint32_t i, uint32_t addressIndex) Ipv4InterfaceAddress address = interface->RemoveAddress (addressIndex); if (address != Ipv4InterfaceAddress ()) { - if (m_routingProtocol != 0) + if (m_routingProtocol) { m_routingProtocol->NotifyRemoveAddress (i, address); } @@ -344,7 +344,7 @@ Ipv4Linux::RemoveAddress (uint32_t i, Ipv4Address address) Ipv4InterfaceAddress ifAddr = interface->RemoveAddress (address); if (ifAddr != Ipv4InterfaceAddress ()) { - if (m_routingProtocol != 0) + if (m_routingProtocol) { m_routingProtocol->NotifyRemoveAddress (i, ifAddr); } @@ -368,7 +368,7 @@ Ipv4Linux::SelectSourceAddress (Ptr device, Ipv4InterfaceAddress iaddr; bool found = false; - if (device != 0) + if (device) { int32_t i = GetInterfaceForDevice (device); NS_ASSERT_MSG (i >= 0, "No device found on node"); @@ -457,7 +457,7 @@ Ipv4Linux::SetUp (uint32_t i) Ptr interface = GetInterface (i); interface->SetUp (); - if (m_routingProtocol != 0) + if (m_routingProtocol) { m_routingProtocol->NotifyInterfaceUp (i); } @@ -470,7 +470,7 @@ Ipv4Linux::SetDown (uint32_t ifaceIndex) Ptr interface = GetInterface (ifaceIndex); interface->SetDown (); - if (m_routingProtocol != 0) + if (m_routingProtocol) { m_routingProtocol->NotifyInterfaceDown (ifaceIndex); } @@ -522,6 +522,18 @@ Ipv4Linux::GetWeakEsModel (void) const return m_weakEsModel; } +void +Ipv4Linux::SetStrongEndSystemModel(bool model) +{ + m_strongEsModel = model; +} + +bool +Ipv4Linux::GetStrongEndSystemModel() const +{ + return m_strongEsModel; +} + void Ipv4Linux::InstallNode (Ptr node) { diff --git a/model/linux/ipv4-linux.h b/model/linux/ipv4-linux.h index f4b14e4f..1cb7e107 100644 --- a/model/linux/ipv4-linux.h +++ b/model/linux/ipv4-linux.h @@ -355,6 +355,8 @@ class Ipv4Linux : public Ipv4 virtual bool GetIpForward (void) const; virtual void SetWeakEsModel (bool model); virtual bool GetWeakEsModel (void) const; + virtual void SetStrongEndSystemModel(bool model); + virtual bool GetStrongEndSystemModel() const; uint32_t AddIpv4Interface (Ptr interface); Ptr GetInterface (uint32_t i) const; @@ -362,6 +364,7 @@ class Ipv4Linux : public Ipv4 Ptr m_routingProtocol; bool m_ipForward; bool m_weakEsModel; + bool m_strongEsModel; Ipv4InterfaceList m_interfaces; uint64_t m_nanoSec; }; diff --git a/model/linux/ipv6-linux.cc b/model/linux/ipv6-linux.cc index 07fd39a0..20a8f580 100644 --- a/model/linux/ipv6-linux.cc +++ b/model/linux/ipv6-linux.cc @@ -217,7 +217,7 @@ Ipv6Linux::AddAddress (uint32_t i, Ipv6InterfaceAddress address, bool addOnLinkR Ptr interface = GetInterface (i); address.SetOnLink (addOnLinkRoute); bool retVal = interface->AddAddress (address); - if (m_routingProtocol != 0) + if (m_routingProtocol) { m_routingProtocol->NotifyAddAddress (i, address); } @@ -259,7 +259,7 @@ Ipv6Linux::RemoveAddress (uint32_t i, uint32_t addressIndex) Ipv6InterfaceAddress address = interface->RemoveAddress (addressIndex); if (address != Ipv6InterfaceAddress ()) { - if (m_routingProtocol != 0) + if (m_routingProtocol) { m_routingProtocol->NotifyRemoveAddress (i, address); } @@ -282,7 +282,7 @@ Ipv6Linux::RemoveAddress (uint32_t i, Ipv6Address address) Ipv6InterfaceAddress ifAddr = interface->RemoveAddress (address); if (ifAddr != Ipv6InterfaceAddress ()) { - if (m_routingProtocol != 0) + if (m_routingProtocol) { m_routingProtocol->NotifyRemoveAddress (i, ifAddr); } @@ -334,7 +334,7 @@ Ipv6Linux::SetUp (uint32_t i) Ptr interface = GetInterface (i); interface->SetUp (); - if (m_routingProtocol != 0) + if (m_routingProtocol) { m_routingProtocol->NotifyInterfaceUp (i); } @@ -347,7 +347,7 @@ Ipv6Linux::SetDown (uint32_t ifaceIndex) Ptr interface = GetInterface (ifaceIndex); interface->SetDown (); - if (m_routingProtocol != 0) + if (m_routingProtocol) { m_routingProtocol->NotifyInterfaceDown (ifaceIndex); } @@ -453,6 +453,18 @@ Ipv6Linux::GetWeakEsModel (void) const return m_weakEsModel; } +void +Ipv6Linux::SetStrongEndSystemModel(bool model) +{ + m_strongEsModel = model; +} + +bool +Ipv6Linux::GetStrongEndSystemModel() const +{ + return m_strongEsModel; +} + void Ipv6Linux::InstallNode (Ptr node) { diff --git a/model/linux/ipv6-linux.h b/model/linux/ipv6-linux.h index 79ff69e3..8658c836 100644 --- a/model/linux/ipv6-linux.h +++ b/model/linux/ipv6-linux.h @@ -327,6 +327,8 @@ class Ipv6Linux : public Ipv6 virtual void SetWeakEsModel (bool model); virtual bool GetWeakEsModel (void) const; + virtual void SetStrongEndSystemModel(bool model); + virtual bool GetStrongEndSystemModel() const; uint32_t AddIpv6Interface (Ptr interface); Ptr GetInterface (uint32_t i) const; @@ -336,6 +338,7 @@ class Ipv6Linux : public Ipv6 bool m_mtuDiscover; Ptr m_pmtuCache; bool m_weakEsModel; + bool m_strongEsModel; Ipv6InterfaceList m_interfaces; uint64_t m_nanoSec; }; diff --git a/model/linux/linux-dccp-socket-factory-impl.cc b/model/linux/linux-dccp-socket-factory-impl.cc index c85db01a..f01d3c6a 100644 --- a/model/linux/linux-dccp-socket-factory-impl.cc +++ b/model/linux/linux-dccp-socket-factory-impl.cc @@ -41,6 +41,9 @@ LinuxDccpSocketFactoryImpl::CreateSocket (void) socket->SetAttribute ("Protocol", UintegerValue (IPPROTO_DCCP)); socket->CreateSocket (); return socket; +#else + NS_LOG_WARN ("LinuxDccpSocketFactoryImpl::CreateSocket(): require KERNEL_STACK"); + return nullptr; #endif } diff --git a/model/linux/linux-dccp6-socket-factory-impl.cc b/model/linux/linux-dccp6-socket-factory-impl.cc index de1a3b79..c60057f3 100644 --- a/model/linux/linux-dccp6-socket-factory-impl.cc +++ b/model/linux/linux-dccp6-socket-factory-impl.cc @@ -41,6 +41,9 @@ LinuxDccp6SocketFactoryImpl::CreateSocket (void) socket->SetAttribute ("Protocol", UintegerValue (IPPROTO_DCCP)); socket->CreateSocket (); return socket; +#else + NS_LOG_WARN ("LinuxDccp6SocketFactoryImpl::CreateSocket(): require KERNEL_STACK"); + return nullptr; #endif } diff --git a/model/linux/linux-ipv4-raw-socket-factory-impl.cc b/model/linux/linux-ipv4-raw-socket-factory-impl.cc index d519bb62..7725e02e 100644 --- a/model/linux/linux-ipv4-raw-socket-factory-impl.cc +++ b/model/linux/linux-ipv4-raw-socket-factory-impl.cc @@ -41,6 +41,9 @@ LinuxIpv4RawSocketFactoryImpl::CreateSocket (void) socket->SetAttribute ("Protocol", UintegerValue (25)); socket->CreateSocket (); return socket; +#else + NS_LOG_WARN ("LinuxIpv4RawSocketFactoryImpl::CreateSocket(): require KERNEL_STACK"); + return nullptr; #endif } diff --git a/model/linux/linux-ipv6-raw-socket-factory-impl.cc b/model/linux/linux-ipv6-raw-socket-factory-impl.cc index c3860139..4322b9ca 100644 --- a/model/linux/linux-ipv6-raw-socket-factory-impl.cc +++ b/model/linux/linux-ipv6-raw-socket-factory-impl.cc @@ -41,6 +41,9 @@ LinuxIpv6RawSocketFactoryImpl::CreateSocket (void) socket->SetAttribute ("Protocol", UintegerValue (25)); socket->CreateSocket (); return socket; +#else + NS_LOG_WARN ("LinuxIpv6RawSocketFactoryImpl::CreateSocket(): require KERNEL_STACK"); + return nullptr; #endif } diff --git a/model/linux/linux-sctp-socket-factory-impl.cc b/model/linux/linux-sctp-socket-factory-impl.cc index 11c30363..8025034a 100644 --- a/model/linux/linux-sctp-socket-factory-impl.cc +++ b/model/linux/linux-sctp-socket-factory-impl.cc @@ -41,6 +41,9 @@ LinuxSctpSocketFactoryImpl::CreateSocket (void) socket->SetAttribute ("Protocol", UintegerValue (IPPROTO_SCTP)); socket->CreateSocket (); return socket; +#else + NS_LOG_WARN ("LinuxSctpSocketFactoryImpl::CreateSocket(): require KERNEL_STACK"); + return nullptr; #endif } diff --git a/model/linux/linux-sctp6-socket-factory-impl.cc b/model/linux/linux-sctp6-socket-factory-impl.cc index 7c930356..39b37445 100644 --- a/model/linux/linux-sctp6-socket-factory-impl.cc +++ b/model/linux/linux-sctp6-socket-factory-impl.cc @@ -41,6 +41,9 @@ LinuxSctp6SocketFactoryImpl::CreateSocket (void) socket->SetAttribute ("Protocol", UintegerValue (IPPROTO_SCTP)); socket->CreateSocket (); return socket; +#else + NS_LOG_WARN ("LinuxSctp6SocketFactoryImpl::CreateSocket(): require KERNEL_STACK"); + return nullptr; #endif } diff --git a/model/linux/linux-socket-impl.cc b/model/linux/linux-socket-impl.cc index 724eeffb..543d8f48 100644 --- a/model/linux/linux-socket-impl.cc +++ b/model/linux/linux-socket-impl.cc @@ -150,7 +150,7 @@ LinuxSocketImpl::LinuxSocketImpl () LinuxSocketImpl::~LinuxSocketImpl () { - if (m_poll.IsRunning ()) + if (m_poll.IsPending ()) { m_poll.Cancel (); } diff --git a/model/linux/linux-tcp-socket-factory-impl.cc b/model/linux/linux-tcp-socket-factory-impl.cc index a7019747..5b0db5ab 100644 --- a/model/linux/linux-tcp-socket-factory-impl.cc +++ b/model/linux/linux-tcp-socket-factory-impl.cc @@ -41,6 +41,9 @@ LinuxTcpSocketFactoryImpl::CreateSocket (void) socket->SetAttribute ("Protocol", UintegerValue (IPPROTO_TCP)); socket->CreateSocket (); return socket; +#else + NS_LOG_WARN ("LinuxTcpSocketFactoryImpl::CreateSocket(): require KERNEL_STACK"); + return nullptr; #endif } diff --git a/model/linux/linux-tcp6-socket-factory-impl.cc b/model/linux/linux-tcp6-socket-factory-impl.cc index 1b5d662c..40875c7b 100644 --- a/model/linux/linux-tcp6-socket-factory-impl.cc +++ b/model/linux/linux-tcp6-socket-factory-impl.cc @@ -41,6 +41,9 @@ LinuxTcp6SocketFactoryImpl::CreateSocket (void) socket->SetAttribute ("Protocol", UintegerValue (IPPROTO_TCP)); socket->CreateSocket (); return socket; +#else + NS_LOG_WARN ("LinuxTcp6SocketFactoryImpl::CreateSocket(): require KERNEL_STACK"); + return nullptr; #endif } diff --git a/model/linux/linux-udp-socket-factory-impl.cc b/model/linux/linux-udp-socket-factory-impl.cc index b1550e6a..e9d576be 100644 --- a/model/linux/linux-udp-socket-factory-impl.cc +++ b/model/linux/linux-udp-socket-factory-impl.cc @@ -41,6 +41,9 @@ LinuxUdpSocketFactoryImpl::CreateSocket (void) socket->SetAttribute ("Protocol", UintegerValue (IPPROTO_UDP)); socket->CreateSocket (); return socket; +#else + NS_LOG_WARN ("LinuxUdpSocketFactoryImpl::CreateSocket(): require KERNEL_STACK"); + return nullptr; #endif } diff --git a/model/linux/linux-udp6-socket-factory-impl.cc b/model/linux/linux-udp6-socket-factory-impl.cc index 37aab9d2..e4e7648b 100644 --- a/model/linux/linux-udp6-socket-factory-impl.cc +++ b/model/linux/linux-udp6-socket-factory-impl.cc @@ -41,6 +41,9 @@ LinuxUdp6SocketFactoryImpl::CreateSocket (void) socket->SetAttribute ("Protocol", UintegerValue (IPPROTO_UDP)); socket->CreateSocket (); return socket; +#else + NS_LOG_WARN ("LinuxUdp6SocketFactoryImpl::CreateSocket(): require KERNEL_STACK"); + return nullptr; #endif } diff --git a/model/local-datagram-socket-fd.cc b/model/local-datagram-socket-fd.cc index 3eb85017..eb9a2c61 100644 --- a/model/local-datagram-socket-fd.cc +++ b/model/local-datagram-socket-fd.cc @@ -44,11 +44,6 @@ LocalDatagramSocketFd::GetTypeId (void) return tid; } -TypeId -LocalDatagramSocketFd::GetInstanceTypeId (void) const -{ - return LocalDatagramSocketFd::GetTypeId (); -} LocalDatagramSocketFd::LocalDatagramSocketFd (Ptr f) : m_state (CREATED), m_peer (0) @@ -482,7 +477,7 @@ LocalDatagramSocketFd::Connect (const struct sockaddr *my_addr, socklen_t addrle NS_ASSERT (current != 0); // first seek bind one - if (0 == m_factory) + if (!m_factory) { Current ()->err = EINVAL; return -1; diff --git a/model/local-datagram-socket-fd.h b/model/local-datagram-socket-fd.h index 08460594..12614d88 100644 --- a/model/local-datagram-socket-fd.h +++ b/model/local-datagram-socket-fd.h @@ -48,7 +48,6 @@ class LocalDatagramSocketFd : public LocalSocketFd { public: static TypeId GetTypeId (void); - virtual TypeId GetInstanceTypeId (void) const; LocalDatagramSocketFd (Ptr f); virtual ~LocalDatagramSocketFd (); diff --git a/model/local-socket-fd-factory.cc b/model/local-socket-fd-factory.cc index 456bf4a3..edac6c07 100644 --- a/model/local-socket-fd-factory.cc +++ b/model/local-socket-fd-factory.cc @@ -40,11 +40,6 @@ LocalSocketFdFactory::GetTypeId (void) return tid; } -TypeId -LocalSocketFdFactory::GetInstanceTypeId (void) const -{ - return LocalSocketFdFactory::GetTypeId (); -} LocalSocketFdFactory::LocalSocketFdFactory () : m_totalBuffersSize (0) { @@ -86,6 +81,7 @@ LocalSocketFdFactory::CreateSocket (int domain, int type, int protocol) LocalSocketFd* LocalSocketFdFactory::FindBinder (std::string path, TypeId type) const { + NS_LOG_FUNCTION (this << path << type.GetName()); BindMap::const_iterator i = m_bindByPath.find (path); if (m_bindByPath.end () == i) { @@ -94,7 +90,7 @@ LocalSocketFdFactory::FindBinder (std::string path, TypeId type) const LocalSocketFd* winner = i->second; - if ((winner != 0) && (winner->GetInstanceTypeId () == type)) + if ((winner != 0)) { return winner; } diff --git a/model/local-socket-fd-factory.h b/model/local-socket-fd-factory.h index 46f421c6..f8cd6929 100644 --- a/model/local-socket-fd-factory.h +++ b/model/local-socket-fd-factory.h @@ -36,7 +36,6 @@ class LocalSocketFdFactory : public SocketFdFactory { public: static TypeId GetTypeId (void); - virtual TypeId GetInstanceTypeId (void) const; LocalSocketFdFactory (); virtual void DoDispose (); diff --git a/model/local-socket-fd.cc b/model/local-socket-fd.cc index cc8a8edc..de155593 100644 --- a/model/local-socket-fd.cc +++ b/model/local-socket-fd.cc @@ -41,11 +41,6 @@ LocalSocketFd::GetTypeId (void) return tid; } -TypeId -LocalSocketFd::GetInstanceTypeId (void) const -{ - return LocalSocketFd::GetTypeId (); -} LocalSocketFd::LocalSocketFd () : m_readBuffer (0), m_readBufferSize (0), m_sendTimeout (0), diff --git a/model/local-socket-fd.h b/model/local-socket-fd.h index d3368da2..e959a5ce 100644 --- a/model/local-socket-fd.h +++ b/model/local-socket-fd.h @@ -47,7 +47,6 @@ class LocalSocketFd : public UnixFd { public: static TypeId GetTypeId (void); - virtual TypeId GetInstanceTypeId (void) const; LocalSocketFd (); virtual ~LocalSocketFd (); diff --git a/model/local-stream-socket-fd.cc b/model/local-stream-socket-fd.cc index d5c692d4..e3603f28 100644 --- a/model/local-stream-socket-fd.cc +++ b/model/local-stream-socket-fd.cc @@ -45,11 +45,6 @@ LocalStreamSocketFd::GetTypeId (void) return tid; } -TypeId -LocalStreamSocketFd::GetInstanceTypeId (void) const -{ - return LocalStreamSocketFd::GetTypeId (); -} LocalStreamSocketFd::LocalStreamSocketFd (Ptr f) : m_state (CREATED), m_backLog (0) @@ -103,7 +98,7 @@ LocalStreamSocketFd::Close (void) case LISTENING: case ACCEPTING: { - NS_ASSERT (0 != m_factory); + NS_ASSERT (m_factory); m_factory->UnRegisterBinder (m_bindPath); m_bindPath = ""; ClearAll (ACCEPTING == m_state); @@ -785,7 +780,7 @@ LocalStreamSocketFd::Connect (const struct sockaddr *my_addr, socklen_t addrlen) NS_ASSERT (current != 0); // first seek bind one - if (0 == m_factory) + if (!m_factory) { Current ()->err = EINVAL; return -1; diff --git a/model/local-stream-socket-fd.h b/model/local-stream-socket-fd.h index b685d127..ba0e66c6 100644 --- a/model/local-stream-socket-fd.h +++ b/model/local-stream-socket-fd.h @@ -50,7 +50,6 @@ class LocalStreamSocketFd : public LocalSocketFd { public: static TypeId GetTypeId (void); - virtual TypeId GetInstanceTypeId (void) const; LocalStreamSocketFd (Ptr f); LocalStreamSocketFd (LocalStreamSocketFd *peer, std::string connectPath); diff --git a/model/ns3-socket-fd-factory.cc b/model/ns3-socket-fd-factory.cc index 23f5dd94..d91b4882 100644 --- a/model/ns3-socket-fd-factory.cc +++ b/model/ns3-socket-fd-factory.cc @@ -58,7 +58,7 @@ void Ns3SocketFdFactory::NotifyNewAggregate (void) { Ptr node = this->GetObject (); - if (m_netlink == 0) + if (!m_netlink) { m_netlink = CreateObject (); node->AggregateObject (m_netlink); diff --git a/model/sys/dce-stat.h b/model/sys/dce-stat.h index 5c124253..b84a9ad3 100644 --- a/model/sys/dce-stat.h +++ b/model/sys/dce-stat.h @@ -5,15 +5,17 @@ extern "C" { #endif -int dce___xstat (int ver, const char *path, struct stat *buf); -int dce___fxstat (int ver, int fd, struct stat *buf); -int dce___lxstat (int ver, const char *pathname, struct stat *buf); +int dce_stat (const char *path, struct stat *buf); +int dce_fstat (int fd, struct stat *buf); +int dce_lstat (const char *pathname, struct stat *buf); -int dce___xstat64 (int ver, const char *path, struct stat64 *buf); -int dce___fxstat64 (int ver, int fd, struct stat64 *buf); -int dce___lxstat64 (int ver, const char *pathname, struct stat64 *buf); -int dce___fxstatat (int ver, int fd, const char *filename, +int dce_stat64 (const char *path, struct stat64 *buf); +int dce_fstat64 (int fd, struct stat64 *buf); +int dce_lstat64 (const char *pathname, struct stat64 *buf); +int dce_fstatat (int fd, const char *filename, struct stat *buf, int flag); +int dce_fstatat64(int dirfd, const char * path, + struct stat64 * stat_buf, int flags); int dce_fstat (int fd, struct stat *buf); int dce_fstat64 (int fd, struct stat64 *buf); diff --git a/model/task-manager.cc b/model/task-manager.cc index e5fa4a57..6019a3ef 100644 --- a/model/task-manager.cc +++ b/model/task-manager.cc @@ -92,7 +92,7 @@ TaskManager::GetTypeId (void) "deallocate and switch among fibers.", TypeId::ATTR_CONSTRUCT, EnumValue (PTHREAD_FIBER_MANAGER), - MakeEnumAccessor (&TaskManager::SetFiberManagerType), + MakeEnumAccessor (&TaskManager::SetFiberManagerType), MakeEnumChecker (PTHREAD_FIBER_MANAGER, "PthreadFiberManager", UCONTEXT_FIBER_MANAGER, "UcontextFiberManager")) ; @@ -134,7 +134,7 @@ void TaskManager::DoDispose (void) // Flush every FILEs in every processes. Ptr dceManager = this->GetObject (); - if (0 != dceManager) + if (dceManager) { std::map procs = dceManager->GetProcs (); std::map::iterator it; @@ -200,7 +200,7 @@ TaskManager::SetDelayModel (Ptr model) static void SwitchNotifEatSignal (void) { TaskManager *manager = TaskManager::Current (); - if (manager == 0) + if (!manager) { return; } @@ -310,7 +310,7 @@ TaskManager::Wakeup (Task *task) } task->m_state = Task::ACTIVE; m_scheduler->Enqueue (task); - if ((0 == m_current) && (!m_nextSchedule.IsRunning ())) + if ((0 == m_current) && (!m_nextSchedule.IsPending ())) { m_nextSchedule = Simulator::ScheduleNow (&TaskManager::Schedule, this); } diff --git a/model/unix-datagram-socket-fd.cc b/model/unix-datagram-socket-fd.cc index 5aca6224..24f3f4ca 100644 --- a/model/unix-datagram-socket-fd.cc +++ b/model/unix-datagram-socket-fd.cc @@ -59,12 +59,12 @@ UnixDatagramSocketFd::UnixDatagramSocketFd (Ptr sock) bool UnixDatagramSocketFd::CanRecv (void) const { - return m_socket != 0 && m_socket->GetRxAvailable () != 0; + return m_socket && m_socket->GetRxAvailable () != 0; } bool UnixDatagramSocketFd::CanSend (void) const { - return m_socket != 0 && m_socket->GetTxAvailable () != 0; + return m_socket && m_socket->GetTxAvailable () != 0; } bool UnixDatagramSocketFd::HangupReceived (void) const @@ -186,7 +186,7 @@ UnixDatagramSocketFd::DoRecvmsg (struct msghdr *msg, int flags) Ptr packet = m_socket->RecvFrom (count, flags, from); uint32_t l = 0; - if (packet == 0) + if (!packet) { current->err = ErrnoToSimuErrno (); return -1; diff --git a/model/unix-file-fd.cc b/model/unix-file-fd.cc index 0ffe35cf..c7736960 100644 --- a/model/unix-file-fd.cc +++ b/model/unix-file-fd.cc @@ -206,7 +206,7 @@ UnixFileFdBase::Fxstat (int ver, struct ::stat *buf) Thread *current = Current (); NS_LOG_FUNCTION (this << current << buf); NS_ASSERT (current != 0); - int retval = ::__fxstat (ver, m_realFd, buf); + int retval = ::fstat (m_realFd, buf); if (retval == -1) { current->err = errno; @@ -219,7 +219,7 @@ UnixFileFdBase::Fxstat64 (int ver, struct ::stat64 *buf) Thread *current = Current (); NS_LOG_FUNCTION (this << current << buf); NS_ASSERT (current != 0); - int retval = ::__fxstat64 (ver, m_realFd, buf); + int retval = ::fstat64 (m_realFd, buf); if (retval == -1) { current->err = errno; @@ -444,7 +444,7 @@ ssize_t UnixRandomFd::Read (void *buf, size_t count) { Ptr nodeContext = DceNodeContext::GetNodeContext (); - NS_ASSERT (0 != nodeContext); + NS_ASSERT (nodeContext); return nodeContext->RandomRead (buf, count); } @@ -488,7 +488,7 @@ UnixRandomFd::Fxstat (int ver, struct ::stat *buf) } NS_ASSERT (current != 0); - int retval = ::__fxstat (ver, tmpFd, buf); + int retval = ::fstat (tmpFd, buf); if (retval == -1) { current->err = errno; @@ -510,7 +510,7 @@ UnixRandomFd::Fxstat64 (int ver, struct ::stat64 *buf) } NS_ASSERT (current != 0); - int retval = ::__fxstat64 (ver, tmpFd, buf); + int retval = ::fstat64 (tmpFd, buf); if (retval == -1) { current->err = errno; diff --git a/model/unix-socket-fd.cc b/model/unix-socket-fd.cc index 4f66419b..749a878d 100644 --- a/model/unix-socket-fd.cc +++ b/model/unix-socket-fd.cc @@ -1070,7 +1070,7 @@ UnixSocketFd::AddPeekedData (Ptr p) bool UnixSocketFd::isPeekedData (void) { - return ((0 != m_peekedData) && (m_peekedData->GetSize () > 0)); + return ((m_peekedData) && (m_peekedData->GetSize () > 0)); } Address UnixSocketFd::GetPeekedFrom (void) diff --git a/model/unix-stream-socket-fd.cc b/model/unix-stream-socket-fd.cc index 06126e18..06141425 100644 --- a/model/unix-stream-socket-fd.cc +++ b/model/unix-stream-socket-fd.cc @@ -106,7 +106,7 @@ UnixStreamSocketFd::DoRecvmsg (struct msghdr *msg, int flags) { Address from; packet = m_socket->RecvFrom (totalAvailable, flags & ~MSG_DONTWAIT & ~MSG_PEEK, from); - if (packet == 0) + if (!packet) { current->err = ErrnoToSimuErrno (); return -1; @@ -358,7 +358,7 @@ UnixStreamSocketFd::CanRecv (void) const bool ret = 0; uint32_t rx = 0; - if (0 == m_socket) + if (!m_socket) { ret = 0; } @@ -398,7 +398,7 @@ UnixStreamSocketFd::CanRecv (void) const bool UnixStreamSocketFd::CanSend (void) const { - return m_socket != 0 && m_socket->GetTxAvailable () != 0; + return m_socket && m_socket->GetTxAvailable () != 0; } bool UnixStreamSocketFd::HangupReceived (void) const diff --git a/model/unix-timer-fd.cc b/model/unix-timer-fd.cc index 39f1fc71..90f12ed0 100644 --- a/model/unix-timer-fd.cc +++ b/model/unix-timer-fd.cc @@ -249,7 +249,7 @@ UnixTimerFd::Settime (int flags, int UnixTimerFd::Gettime (struct itimerspec *cur_value) const { - if (!m_timer.IsRunning ()) + if (!m_timer.IsPending ()) { cur_value->it_value.tv_sec = 0; cur_value->it_value.tv_nsec = 0; diff --git a/model/utils.cc b/model/utils.cc index 3643dd26..7fe1fe5c 100644 --- a/model/utils.cc +++ b/model/utils.cc @@ -126,7 +126,7 @@ Thread * Current (void) } TaskManager *manager = TaskManager::Current (); - if (manager == 0) + if (!manager) { return 0; } diff --git a/netlink/netlink-socket.cc b/netlink/netlink-socket.cc index 858ba3b8..e566eb27 100644 --- a/netlink/netlink-socket.cc +++ b/netlink/netlink-socket.cc @@ -263,7 +263,7 @@ NetlinkSocket::DoBind (const NetlinkSocketAddress &address) Thread *current = Current (); if (current != 0) // will be 0 when opening socket from NS3 (e.g., Ipv4DceRouting) { - NS_ASSERT (m_node != 0); + NS_ASSERT (m_node); Ptr nsf = m_node->GetObject (); if (m_Pid == 0) @@ -285,12 +285,12 @@ NetlinkSocket::DoBind (const NetlinkSocketAddress &address) } Ptr ipv4 = m_node->GetObject (); - NS_ASSERT_MSG (ipv4 != 0, "Netlink Socket requires IPv4 stack to be installed on the node"); + NS_ASSERT_MSG (ipv4, "Netlink Socket requires IPv4 stack to be installed on the node"); // We only care about staticRouting for netlink support m_ipv4Routing = Ipv4DceRouting::GetRouting (ipv4->GetRoutingProtocol (), (Ipv4DceRouting*)0); - NS_ASSERT_MSG (m_ipv4Routing != 0, + NS_ASSERT_MSG (m_ipv4Routing, "Netlink Socket requires Ipv4DceRouting to be installed on the node"); return 0; @@ -342,7 +342,7 @@ NetlinkSocket::Close (void) ShutdownRecv (); // a little bit complicated, but this will allow us to keep track of every open netlink socket - if (m_node != 0) + if (m_node) { Ptr nsf = m_node->GetObject (); @@ -968,12 +968,12 @@ NetlinkSocket::BuildRouteDumpMessages (uint32_t seq) NS_LOG_FUNCTION (this); MultipartNetlinkMessage nlmsg_dump; - if (0 == m_ipv4Routing) + if (!m_ipv4Routing) { return nlmsg_dump; } - NS_ASSERT_MSG (m_ipv4Routing != 0, "Should not happen"); + NS_ASSERT_MSG (m_ipv4Routing, "Should not happen"); // We only care about staticRouting for netlink support for (uint32_t i = 0; i < m_ipv4Routing->GetNRoutes (); i++) @@ -1620,7 +1620,7 @@ NetlinkSocket::DoRouteMessage (const NetlinkMessage &nlmsg, uint16_t type, uint8 int32_t NetlinkSocket::NotifyIfLinkMessage (uint32_t interface_num) { - if (m_ipv4Routing == 0) + if (m_ipv4Routing == nullptr) { NS_LOG_ERROR ("No Ipv4 routing set"); return -1; //should be some nicer error code diff --git a/ns3waf/__init__.py b/ns3waf/__init__.py index b21c7d4b..a24574ef 100644 --- a/ns3waf/__init__.py +++ b/ns3waf/__init__.py @@ -142,12 +142,12 @@ def _check_win32(conf): if _check_compilation_flag(conf, '-Wl,--soname=foo'): env['WL_SONAME_SUPPORTED'] = True -def build_ns3_libname(version, module, profile): - return "lib{}-{}-{}".format(version, module, profile) +def build_ns3_libname(version, module): + return "{}-{}".format(version, module) def _check_dependencies(conf, required, mandatory): found = [] - libcore = build_ns3_libname("*", "core", conf.env['LIB_SUFFIX']) + libcore = build_ns3_libname("ns*", "core") ns3_dir_pkgconfig = conf.env['NS3_DIR'] + '/lib/pkgconfig' if not 'NS3_VERSION' in conf.env: @@ -158,12 +158,12 @@ def _check_dependencies(conf, required, mandatory): return elif len(pcfiles) == 1: match_pkg = os.path.basename(pcfiles[0]) - lib = re.search("(ns[0-9][\.\-][dev0-9\.]+)", match_pkg) - if lib.group(0) is None: - Logs.error("Could not find version for the match %s" % match_pkg) + # extract text before "-core" + match_pkg_ends = match_pkg.find("-core") + if match_pkg_ends == -1: + Logs.error("Could not find " + libcore) return - - version = lib.group(0) + version = match_pkg[0:match_pkg_ends] conf.env['NS3_VERSION'] = version else: Logs.error("Could not find " + libcore) @@ -172,7 +172,7 @@ def _check_dependencies(conf, required, mandatory): for module in required: if module in conf.env['NS3_MODULES_FOUND']: continue - libname = build_ns3_libname(conf.env['NS3_VERSION'], module.lower(), conf.env['LIB_SUFFIX']) + libname = build_ns3_libname(conf.env['NS3_VERSION'], module.lower()) retval = conf.check_cfg(package=libname, args='--cflags --libs' + (' --static' if conf.env['NS3_ENABLE_STATIC'] else ''), mandatory=mandatory, diff --git a/test.py b/test.py index ae0fe0ee..1e9d190d 100755 --- a/test.py +++ b/test.py @@ -792,6 +792,51 @@ def run_job_synchronously(shell_command, directory, valgrind, is_python, build_p retval = proc.returncode + # If the process crashed (segfault = 139, etc), re-run with GDB to get backtrace + if options.gdb and (retval < 0 or retval == 139): # 139 = 128 + 11 (SIGSEGV) + print("=" * 70) + print("CRASH DETECTED (exit code %d). Re-running with GDB to get backtrace..." % retval) + print("=" * 70) + + # Create GDB batch file + gdb_commands = """ +set pagination off +set print pretty on +handle SIGUSR1 nostop noprint pass +run +bt +bt full +thread apply all bt +quit +""" + gdb_script = os.path.join(os.getcwd(), "gdb_batch_%d.txt" % os.getpid()) + with open(gdb_script, 'w') as f: + f.write(gdb_commands) + + # Re-run with GDB + gdb_cmd = "gdb -batch -x %s --args %s" % (gdb_script, path_cmd) + if options.verbose: + print("GDB command: %s" % gdb_cmd) + + gdb_proc = subprocess.Popen(gdb_cmd, shell=True, universal_newlines=True, + cwd = directory, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + gdb_stdout, gdb_stderr = gdb_proc.communicate() + + print("\n" + "=" * 70) + print("GDB BACKTRACE OUTPUT:") + print("=" * 70) + print(gdb_stdout) + if gdb_stderr: + print("GDB STDERR:") + print(gdb_stderr) + print("=" * 70 + "\n") + + # Clean up + try: + os.remove(gdb_script) + except: + pass + # # valgrind sometimes has its own idea about what kind of memory management # errors are important. We want to detect *any* leaks, so the way to do @@ -1952,6 +1997,9 @@ def main(argv): parser.add_option("-z", "--dlm", action="store_true", dest="dlm_test_runner", default=False, help="execute test runner with external elf-loader.") + parser.add_option("--gdb", action="store_true", dest="gdb", default=False, + help="Re-run tests that crash with gdb") + global options options = parser.parse_args()[0] signal.signal(signal.SIGINT, sigint_hook) diff --git a/test/addons/dce-linux-ip6-test.cc b/test/addons/dce-linux-ip6-test.cc index 6827e827..2bf208e9 100644 --- a/test/addons/dce-linux-ip6-test.cc +++ b/test/addons/dce-linux-ip6-test.cc @@ -363,7 +363,7 @@ static class DceLinuxIp6TestSuite : public TestSuite DceLinuxIp6TestSuite::DceLinuxIp6TestSuite () - : TestSuite ("dce-linux-ip6", UNIT) + : TestSuite ("dce-linux-ip6", Type::UNIT) { typedef struct { @@ -393,7 +393,7 @@ DceLinuxIp6TestSuite::DceLinuxIp6TestSuite () AddTestCase (new DceLinuxIp6TestCase (std::string (tests[i].name), Seconds (tests[i].duration), tests[i].skip), - TestCase::QUICK); + Duration::QUICK); } } diff --git a/test/dce-cradle-test.cc b/test/dce-cradle-test.cc index 97ca0374..63a6ad77 100644 --- a/test/dce-cradle-test.cc +++ b/test/dce-cradle-test.cc @@ -137,7 +137,7 @@ static class DceCradleTestSuite : public TestSuite DceCradleTestSuite::DceCradleTestSuite () - : TestSuite ("dce-cradle", UNIT) + : TestSuite ("dce-cradle", Type::UNIT) { typedef struct { const char *name; @@ -172,8 +172,8 @@ DceCradleTestSuite::DceCradleTestSuite () Seconds (tests[i].duration), tests[i].sockf, tests[i].isSkip - ), - TestCase::QUICK); + ), + Duration::QUICK); } } diff --git a/test/dce-manager-test.cc b/test/dce-manager-test.cc index 36185779..3a9a1a93 100644 --- a/test/dce-manager-test.cc +++ b/test/dce-manager-test.cc @@ -166,7 +166,7 @@ static class DceManagerTestSuite : public TestSuite #define FREEBSD_STACK (1 << 2) DceManagerTestSuite::DceManagerTestSuite () - : TestSuite ("dce-process-manager", UNIT) + : TestSuite ("dce-process-manager", Type::UNIT) { typedef struct { @@ -257,7 +257,7 @@ DceManagerTestSuite::DceManagerTestSuite () (tests[i].stackMask & NS3_STACK) ? (isUctxFiber ? tests[i].skipUctx : false) : true ), - TestCase::QUICK); + Duration::QUICK); } // linux stack @@ -275,7 +275,7 @@ DceManagerTestSuite::DceManagerTestSuite () (tests[i].stackMask & LINUX_STACK) ? (isUctxFiber ? tests[i].skipUctx : false) : true ), - TestCase::QUICK); + Duration::QUICK); } } @@ -293,7 +293,7 @@ DceManagerTestSuite::DceManagerTestSuite () (tests[i].stackMask & FREEBSD_STACK) ? (isUctxFiber ? tests[i].skipUctx : false) : true ), - TestCase::QUICK); + Duration::QUICK); } } } diff --git a/test/dce-mptcp-test.cc b/test/dce-mptcp-test.cc index 73da3e5a..5f04d186 100644 --- a/test/dce-mptcp-test.cc +++ b/test/dce-mptcp-test.cc @@ -353,7 +353,7 @@ static class DceMptcpTestSuite : public TestSuite DceMptcpTestSuite::DceMptcpTestSuite () - : TestSuite ("dce-mptcp", UNIT) + : TestSuite ("dce-mptcp", Type::UNIT) { typedef struct { const char *name; @@ -382,7 +382,7 @@ DceMptcpTestSuite::DceMptcpTestSuite () tests[i].sockf, tests[i].isSkip ), - TestCase::QUICK); + Duration::QUICK); } } diff --git a/test/netlink-socket-test.cc b/test/netlink-socket-test.cc index 24f3915b..8aae86ba 100644 --- a/test/netlink-socket-test.cc +++ b/test/netlink-socket-test.cc @@ -598,9 +598,9 @@ static class NetlinkSocketTestSuite : public TestSuite } g_netlinkTestSuite; NetlinkSocketTestSuite::NetlinkSocketTestSuite () - : TestSuite ("dce-netlink-socket", UNIT) + : TestSuite ("dce-netlink-socket", Type::UNIT) { - AddTestCase (new NetlinkSocketTestCase (), TestCase::QUICK); + AddTestCase (new NetlinkSocketTestCase (), Duration::QUICK); } } // namespace ns3 diff --git a/utils.py b/utils.py index 5c79d28e..1bce1068 100644 --- a/utils.py +++ b/utils.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 # These methods are used by test.py and waf to look for and read the # .ns3rc configuration file, which is used to specify the modules that diff --git a/utils/check-style.py b/utils/check-style.py index 8d5a8386..55dcb547 100755 --- a/utils/check-style.py +++ b/utils/check-style.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import os import subprocess diff --git a/utils/dce-iostream-simple.h b/utils/dce-iostream-simple.h new file mode 100644 index 00000000..4d45447e --- /dev/null +++ b/utils/dce-iostream-simple.h @@ -0,0 +1,114 @@ +#ifndef DCE_IOSTREAM_SIMPLE_H +#define DCE_IOSTREAM_SIMPLE_H + +// Prevent standard iostream from being included +// This MUST be defined before any code tries to include +#ifndef _GLIBCXX_IOSTREAM +#define _GLIBCXX_IOSTREAM 1 +#endif + +#include +#include +#include + +namespace dce { + +/** + * Output stream for DCE binaries. + */ +class OutputStream { +public: + explicit OutputStream(int fd) : m_fd(fd) {} + + OutputStream& operator<<(const char* str) { + if (str) { + write(m_fd, str, strlen(str)); + } + return *this; + } + + OutputStream& operator<<(int val) { + char buf[32]; + snprintf(buf, sizeof(buf), "%d", val); + write(m_fd, buf, strlen(buf)); + return *this; + } + + OutputStream& operator<<(long val) { + char buf[32]; + snprintf(buf, sizeof(buf), "%ld", val); + write(m_fd, buf, strlen(buf)); + return *this; + } + + OutputStream& operator<<(unsigned int val) { + char buf[32]; + snprintf(buf, sizeof(buf), "%u", val); + write(m_fd, buf, strlen(buf)); + return *this; + } + + OutputStream& operator<<(unsigned long val) { + char buf[32]; + snprintf(buf, sizeof(buf), "%lu", val); + write(m_fd, buf, strlen(buf)); + return *this; + } + + OutputStream& operator<<(char c) { + write(m_fd, &c, 1); + return *this; + } + + // Manipulator support (for endl, flush) + OutputStream& operator<<(OutputStream& (*manip)(OutputStream&)) { + return manip(*this); + } + + void flush() { + // No buffering, nothing to flush + } + +private: + int m_fd; +}; + +// Global stream objects +static OutputStream cout(STDOUT_FILENO); +static OutputStream cerr(STDERR_FILENO); +static OutputStream clog(STDERR_FILENO); + +// Manipulators +inline OutputStream& endl(OutputStream& os) { + os << '\n'; + os.flush(); + return os; +} + +inline OutputStream& flush(OutputStream& os) { + os.flush(); + return os; +} + +} + +// Override std::cout with dce::cout +namespace std { + // Import dce::OutputStream into std namespace + using ::dce::OutputStream; + + // Create references to dce streams in std namespace + static ::dce::OutputStream& cout = ::dce::cout; + static ::dce::OutputStream& cerr = ::dce::cerr; + static ::dce::OutputStream& clog = ::dce::clog; + + // Also provide endl/flush in std namespace + inline ::dce::OutputStream& endl(::dce::OutputStream& os) { + return ::dce::endl(os); + } + inline ::dce::OutputStream& flush(::dce::OutputStream& os) { + return ::dce::flush(os); + } +} + +#endif // DCE_IOSTREAM_SIMPLE_H diff --git a/utils/dcemakeversion.c b/utils/dcemakeversion.c index 0318cfd0..100b2d33 100644 --- a/utils/dcemakeversion.c +++ b/utils/dcemakeversion.c @@ -203,11 +203,19 @@ int main (int argc, char *argv[]) { int i = 0; + void *dl_handle; createversion (seek4Lib ("libc.so"), argv[++i], "model/libc.version"); + dl_handle = dlopen("libpthread.so.0", RTLD_NOW); createversion (seek4Lib ("libpthread.so"), argv[++i], "model/libpthread.version"); + dlclose(dl_handle); + dl_handle = dlopen("librt.so.1", RTLD_NOW); createversion (seek4Lib ("librt.so"), argv[++i], "model/librt.version"); + dlclose(dl_handle); + // libm doesn't need dl-magic, it gets linked in via --no-as-needed createversion (seek4Lib ("libm.so"), argv[++i], "model/libm.version"); + dl_handle = dlopen("libdl.so.2", RTLD_NOW); createversion (seek4Lib ("libdl.so"), argv[++i], "model/libdl.version"); + dlclose(dl_handle); return 0; } diff --git a/waf-tools/clang_compilation_database.py b/waf-tools/clang_compilation_database.py index a9e61ff0..4dde47de 100644 --- a/waf-tools/clang_compilation_database.py +++ b/waf-tools/clang_compilation_database.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # encoding: utf-8 # Christoph Koke, 2013 @@ -14,14 +14,14 @@ def configure(conf): conf.load('clang_compilation_database') """ -import sys, os, json, shlex, pipes +import sys, os, json, shlex from waflib import Logs, TaskGen from waflib.Tools import c, cxx if sys.hexversion >= 0x3030000: quote = shlex.quote else: - quote = pipes.quote + raise Exception("pipes no longer supported") @TaskGen.feature('*') @TaskGen.after_method('process_use') diff --git a/waf-tools/misc.py b/waf-tools/misc.py index 61f98a58..2c4f35c2 100644 --- a/waf-tools/misc.py +++ b/waf-tools/misc.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # encoding: utf-8 # Thomas Nagy, 2006-2010 (ita) diff --git a/waf-tools/relocation.py b/waf-tools/relocation.py index 11f3d9cb..2adf3b0a 100644 --- a/waf-tools/relocation.py +++ b/waf-tools/relocation.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 # encoding: utf-8 """ diff --git a/wscript b/wscript index 4710389d..9a1175eb 100755 --- a/wscript +++ b/wscript @@ -35,10 +35,6 @@ def options(opt): help=('Specify the installed directory of elf-loader'), dest='with_elf_loader', type='string', default=None) - opt.add_option('--with-glibc', - help=('Specify the installed directory of Glibc-2.25'), - dest='with_glibc', type='string', - default=None) opt.add_option('--with-libaspect', help=('Specify the installed directory of libaspect.so'), dest='with_libaspect', type='string', @@ -91,13 +87,6 @@ def _check_nonfatal(conf, *args, **kwargs): def configure(conf): - conf.env.GLIBC_INSTALL_DIR = os.path.abspath(conf.options.with_glibc) - - if not os.path.exists(conf.env.GLIBC_INSTALL_DIR): - Logs.error("Custom glibc install directory does not exist ! Please pass a valid directory in --with-glibc argument") - raise SystemExit(1) - return - conf.load('relocation', tooldir=['waf-tools']) conf.load('compiler_c') cc_string = '.'.join(conf.env['CC_VERSION']) @@ -154,8 +143,8 @@ def configure(conf): conf.env.append_value('CXXDEFINES', 'HAVE_VALGRIND_H') - # Enable C++-11 support - conf.env.append_value('CXXFLAGS', '-std=c++11') + # Enable C++-20 support + conf.env.append_value('CXXFLAGS', '-std=c++20') if Options.options.kernel_stack: if not os.path.isdir(Options.options.kernel_stack): @@ -272,9 +261,13 @@ def dce_kw(**kw): nofortify = ['-U_FORTIFY_SOURCE'] #debug_dl = ['-Wl,--dynamic-linker=/usr/lib/debug/ld-linux-x86-64.so.2'] debug_dl = [] - d['cxxflags'] = d.get('cxxflags', []) + ['-fpie'] + mcmodel + nofortify + ['-Wno-deprecated-declarations'] + # Auto-include dce-iostream-simple.h to override std::cout + auto_include = ['-include', 'utils/dce-iostream-simple.h'] + d['cxxflags'] = d.get('cxxflags', []) + ['-fpie'] + mcmodel + nofortify + ['-Wno-deprecated-declarations'] + auto_include d['cflags'] = d.get('cflags', []) + ['-fpie'] + mcmodel + nofortify d['linkflags'] = d.get('linkflags', []) + ['-pie'] + ['-lrt'] + ['-rdynamic'] + debug_dl + # Add utils and model directories for dce-iostream-simple.h access + d['includes'] = d.get('includes', []) + ['.', 'utils', 'model'] return d def build_dce_tests(module, bld): @@ -771,21 +764,6 @@ def build(bld): 'helper/freebsd-stack-helper.h', ] - SYSROOT = bld.env.GLIBC_INSTALL_DIR - extra_cflags_root = [ - '-L'+SYSROOT+'/usr/lib64', - '-I'+SYSROOT+'/include', - '--sysroot='+SYSROOT, - '-Wl,--start-group', - '-Wl,-rpath='+SYSROOT+'/lib64', - '-Wl,-rpath-link=/usr/lib/x86_64-linux-gnu', - '-Wl,--dynamic-linker='+SYSROOT+'/lib64/ld-2.31.so' - ] - wl_end_group = [ - '-Wl,--end-group' - ] - - bld.env.append_value('LINKFLAGS',extra_cflags_root+wl_end_group) module_source = module_source + kernel_source module_headers = module_headers + kernel_headers uselib = ns3waf.modules_uselib(bld, ['core', 'network', 'internet', 'netlink']) @@ -794,7 +772,7 @@ def build(bld): headers=module_headers, use=uselib, includes=kernel_includes, - cxxflags= extra_cflags_root+['-Wno-deprecated-declarations']+wl_end_group, + cxxflags= ['-Wno-deprecated-declarations'], lib=['dl']) # lib=['dl','efence']) @@ -847,7 +825,7 @@ def build(bld): # and forward to the dce_* code bld.shlib(source = ['model/libc.cc', 'model/libc-setup.cc', 'model/libc-global-variables.cc'], target='lib/c-ns3', - cxxflags=extra_cflags_root+['-g', '-fno-profile-arcs', '-fno-test-coverage', '-Wno-builtin-declaration-mismatch']+wl_end_group, + cxxflags=['-g', '-fno-profile-arcs', '-fno-test-coverage', '-Wno-builtin-declaration-mismatch'], defines=['LIBSETUP=libc_setup'], linkflags=['-nostdlib', '-fno-profile-arcs', '-Wl,--version-script=' + os.path.join('model', 'libc.version'), @@ -856,7 +834,7 @@ def build(bld): # and forward to the dce_* code bld.shlib(source = ['model/libc.cc', 'model/libc-setup.cc'], target='lib/pthread-ns3', - cxxflags=extra_cflags_root+['-g', '-fno-profile-arcs', '-fno-test-coverage', '-Wno-builtin-declaration-mismatch']+wl_end_group, + cxxflags=['-g', '-fno-profile-arcs', '-fno-test-coverage', '-Wno-builtin-declaration-mismatch'], defines=['LIBSETUP=libpthread_setup'], linkflags=['-nostdlib', '-fno-profile-arcs', '-Wl,--version-script=' + os.path.join('model', 'libpthread.version'), @@ -866,7 +844,7 @@ def build(bld): # and forward to the dce_* code bld.shlib(source = ['model/libc.cc', 'model/libc-setup.cc'], target='lib/rt-ns3', - cxxflags=extra_cflags_root+['-g', '-fno-profile-arcs', '-fno-test-coverage', '-Wno-builtin-declaration-mismatch']+wl_end_group, + cxxflags=['-g', '-fno-profile-arcs', '-fno-test-coverage', '-Wno-builtin-declaration-mismatch'], defines=['LIBSETUP=librt_setup'], linkflags=['-nostdlib', '-fno-profile-arcs', '-Wl,--version-script=' + os.path.join('model', 'librt.version'), @@ -876,7 +854,7 @@ def build(bld): # and forward to the dce_* code bld.shlib(source = ['model/libc.cc', 'model/libc-setup.cc'], target='lib/m-ns3', - cxxflags=extra_cflags_root+['-g', '-fno-profile-arcs', '-fno-test-coverage', '-Wno-builtin-declaration-mismatch']+wl_end_group, + cxxflags=['-g', '-fno-profile-arcs', '-fno-test-coverage', '-Wno-builtin-declaration-mismatch'], defines=['LIBSETUP=libm_setup'], linkflags=['-nostdlib', '-fno-profile-arcs', '-Wl,--version-script=' + os.path.join('model', 'libm.version'), @@ -886,7 +864,7 @@ def build(bld): # and forward to the dce_* code bld.shlib(source = ['model/libc.cc', 'model/libc-setup.cc'], target='lib/dl-ns3', - cxxflags=extra_cflags_root+['-g', '-fno-profile-arcs', '-fno-test-coverage', '-Wno-builtin-declaration-mismatch']+wl_end_group, + cxxflags=['-g', '-fno-profile-arcs', '-fno-test-coverage', '-Wno-builtin-declaration-mismatch'], defines=['LIBSETUP=libdl_setup'], linkflags=['-nostdlib', '-fno-profile-arcs', '-Wl,--version-script=' + os.path.join('model', 'libdl.version'), @@ -898,7 +876,7 @@ def build(bld): # Write the build status file. build_status_file = os.path.join(bld.out_dir, 'build-status.py') out = open(build_status_file, 'w') - out.write('#! /usr/bin/env python\n') + out.write('#! /usr/bin/env python3\n') out.write('\n') out.write('# Programs that are runnable.\n') out.write('ns3_runnable_programs = ' + str(bld.env['NS3_RUNNABLE_PROGRAMS']) + '\n')