OLD | NEW |
1 // Copyright (c) 2006, Google Inc. | 1 // Copyright (c) 2006, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 #endif /* TH32CS_SNAPMODULE32 */ | 79 #endif /* TH32CS_SNAPMODULE32 */ |
80 #endif /* PLATFORM_WINDOWS */ | 80 #endif /* PLATFORM_WINDOWS */ |
81 | 81 |
82 // Re-run fn until it doesn't cause EINTR. | 82 // Re-run fn until it doesn't cause EINTR. |
83 #define NO_INTR(fn) do {} while ((fn) < 0 && errno == EINTR) | 83 #define NO_INTR(fn) do {} while ((fn) < 0 && errno == EINTR) |
84 | 84 |
85 // open/read/close can set errno, which may be illegal at this | 85 // open/read/close can set errno, which may be illegal at this |
86 // time, so prefer making the syscalls directly if we can. | 86 // time, so prefer making the syscalls directly if we can. |
87 #ifdef HAVE_SYS_SYSCALL_H | 87 #ifdef HAVE_SYS_SYSCALL_H |
88 # include <sys/syscall.h> | 88 # include <sys/syscall.h> |
| 89 #endif |
| 90 #ifdef SYS_open // solaris 11, at least sometimes, only defines SYS_openat |
89 # define safeopen(filename, mode) syscall(SYS_open, filename, mode) | 91 # define safeopen(filename, mode) syscall(SYS_open, filename, mode) |
| 92 #else |
| 93 # define safeopen(filename, mode) open(filename, mode) |
| 94 #endif |
| 95 #ifdef SYS_read |
90 # define saferead(fd, buffer, size) syscall(SYS_read, fd, buffer, size) | 96 # define saferead(fd, buffer, size) syscall(SYS_read, fd, buffer, size) |
| 97 #else |
| 98 # define saferead(fd, buffer, size) read(fd, buffer, size) |
| 99 #endif |
| 100 #ifdef SYS_close |
91 # define safeclose(fd) syscall(SYS_close, fd) | 101 # define safeclose(fd) syscall(SYS_close, fd) |
92 #else | 102 #else |
93 # define safeopen(filename, mode) open(filename, mode) | |
94 # define saferead(fd, buffer, size) read(fd, buffer, size) | |
95 # define safeclose(fd) close(fd) | 103 # define safeclose(fd) close(fd) |
96 #endif | 104 #endif |
97 | 105 |
98 // ---------------------------------------------------------------------- | 106 // ---------------------------------------------------------------------- |
99 // GetenvBeforeMain() | 107 // GetenvBeforeMain() |
100 // GetUniquePathFromEnv() | 108 // GetUniquePathFromEnv() |
101 // Some non-trivial getenv-related functions. | 109 // Some non-trivial getenv-related functions. |
102 // ---------------------------------------------------------------------- | 110 // ---------------------------------------------------------------------- |
103 | 111 |
104 // It's not safe to call getenv() in the malloc hooks, because they | 112 // It's not safe to call getenv() in the malloc hooks, because they |
(...skipping 868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
973 ProcMapsIterator::Buffer linebuf; | 981 ProcMapsIterator::Buffer linebuf; |
974 while (it.Next(&start, &end, &flags, &offset, &inode, &filename)) { | 982 while (it.Next(&start, &end, &flags, &offset, &inode, &filename)) { |
975 int written = it.FormatLine(linebuf.buf_, sizeof(linebuf.buf_), | 983 int written = it.FormatLine(linebuf.buf_, sizeof(linebuf.buf_), |
976 start, end, flags, offset, inode, filename, | 984 start, end, flags, offset, inode, filename, |
977 0); | 985 0); |
978 RawWrite(fd, linebuf.buf_, written); | 986 RawWrite(fd, linebuf.buf_, written); |
979 } | 987 } |
980 } | 988 } |
981 | 989 |
982 } // namespace tcmalloc | 990 } // namespace tcmalloc |
OLD | NEW |