Skip to content

Commit 4c2e298

Browse files
committed
support freebsd os
1 parent a32790e commit 4c2e298

File tree

70 files changed

+285
-74
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+285
-74
lines changed

extras/usd/examples/usdObj/pch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#if defined(ARCH_OS_DARWIN)
1414
#include <mach/mach_time.h>
1515
#endif
16-
#if defined(ARCH_OS_LINUX)
16+
#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
1717
#include <unistd.h>
1818
#include <x86intrin.h>
1919
#endif

extras/usd/examples/usdSchemaExamples/pch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#if defined(ARCH_OS_DARWIN)
1414
#include <mach/mach_time.h>
1515
#endif
16-
#if defined(ARCH_OS_LINUX)
16+
#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
1717
#include <unistd.h>
1818
#include <x86intrin.h>
1919
#endif

pxr/base/arch/assumptions.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
#if defined(ARCH_OS_LINUX)
2222
#include <unistd.h>
23+
#elif defined(ARCH_OS_FREEBSD)
24+
#include <sys/param.h>
2325
#elif defined(ARCH_OS_DARWIN)
2426
#include <sys/sysctl.h>
2527
#include <mach-o/arch.h>
@@ -35,6 +37,8 @@ Arch_ObtainCacheLineSize()
3537
{
3638
#if defined(ARCH_OS_LINUX)
3739
return sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
40+
#elif defined(ARCH_OS_FREEBSD)
41+
return CACHE_LINE_SIZE;
3842
#elif defined(ARCH_OS_WASM_VM)
3943
return 64;
4044
#elif defined(ARCH_OS_DARWIN)

pxr/base/arch/daemon.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ PXR_NAMESPACE_OPEN_SCOPE
2828
int
2929
ArchCloseAllFiles(int nExcept, const int* exceptFds)
3030
{
31-
#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_DARWIN)
31+
#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD) || defined(ARCH_OS_DARWIN)
3232

3333
int status, retStatus, retErrno;
3434
int i, j, maxfd, maxExcept = -1;

pxr/base/arch/debugger.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "pxr/base/arch/export.h"
1515
#include "pxr/base/arch/stackTrace.h"
1616
#include "pxr/base/arch/systemInfo.h"
17-
#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_DARWIN)
17+
#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD) || defined(ARCH_OS_DARWIN)
1818
#include "pxr/base/arch/inttypes.h"
1919
#include <sys/types.h>
2020
#if !defined(ARCH_OS_IPHONE)
@@ -59,7 +59,7 @@ static std::atomic<bool> _archDebuggerWait(false);
5959

6060
static char** _archDebuggerAttachArgs = 0;
6161

62-
#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_DARWIN)
62+
#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD) || defined(ARCH_OS_DARWIN)
6363
static
6464
void
6565
Arch_DebuggerTrapHandler(int)
@@ -74,7 +74,7 @@ Arch_DebuggerTrapHandler(int)
7474
}
7575
#endif
7676

77-
#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_DARWIN)
77+
#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD) || defined(ARCH_OS_DARWIN)
7878
static
7979
void
8080
Arch_DebuggerInitPosix()
@@ -108,7 +108,7 @@ static
108108
void
109109
Arch_DebuggerInit()
110110
{
111-
#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_DARWIN)
111+
#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD) || defined(ARCH_OS_DARWIN)
112112
#if defined(ARCH_CPU_INTEL) && defined(ARCH_BITS_64)
113113
// Save some registers that normally don't have to be preserved. We
114114
// do this so the caller of ArchDebuggerTrap() can see its arguments
@@ -153,7 +153,7 @@ Arch_DebuggerInit()
153153
}
154154

155155

156-
#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_DARWIN)
156+
#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD) || defined(ARCH_OS_DARWIN)
157157
// Use a 'non-locking' fork so that we won't get hung up if we've
158158
// had malloc corruption. We can't prevent fork() from using the
159159
// heap, unfortunately, since fork handlers can do whatever they
@@ -332,7 +332,7 @@ Arch_DebuggerAttachExecPosix(void* data)
332332

333333
#endif // defined(ARCH_OS_LINUX) || defined(ARCH_OS_DARWIN)
334334

335-
#if defined(ARCH_OS_LINUX)
335+
#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
336336

337337
// Reads /proc/self/status, finds the line starting with "field:", and
338338
// returns the portion following the ":".
@@ -443,7 +443,7 @@ Arch_DebuggerAttach()
443443
return false;
444444
}
445445

446-
#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_DARWIN)
446+
#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD) || defined(ARCH_OS_DARWIN)
447447

448448
// To attach to gdb under Unix/Linux and Gnome:
449449
// ARCH_DEBUGGER="gnome-terminal -e 'gdb -p %p'"
@@ -500,7 +500,7 @@ ARCH_HIDDEN
500500
void
501501
Arch_InitDebuggerAttach()
502502
{
503-
#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_DARWIN)
503+
#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD) || defined(ARCH_OS_DARWIN)
504504
// Maximum length of a pid written as a decimal. It's okay for this
505505
// to be greater than that.
506506
static const size_t _decimalPidLength = 20;
@@ -632,7 +632,7 @@ ArchDebuggerIsAttached()
632632
return IsDebuggerPresent() == TRUE;
633633
#elif defined(ARCH_OS_DARWIN)
634634
return AmIBeingDebugged();
635-
#elif defined(ARCH_OS_LINUX)
635+
#elif defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
636636
return Arch_DebuggerIsAttachedPosix();
637637
#endif
638638
return false;

pxr/base/arch/defines.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#define ARCH_OS_WASM_VM
1515
#elif defined(__linux__)
1616
#define ARCH_OS_LINUX
17+
#elif defined(__FreeBSD__)
18+
#define ARCH_OS_FREEBSD
1719
#elif defined(__APPLE__)
1820
#include "TargetConditionals.h"
1921
#define ARCH_OS_DARWIN
@@ -80,12 +82,12 @@
8082
//
8183

8284
// Only use the GNU STL extensions on Linux when using gcc.
83-
#if defined(ARCH_OS_LINUX) && defined(ARCH_COMPILER_GCC)
85+
#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD) && defined(ARCH_COMPILER_GCC)
8486
#define ARCH_HAS_GNU_STL_EXTENSIONS
8587
#endif
8688

8789
// The MAP_POPULATE flag for mmap calls only exists on Linux platforms.
88-
#if defined(ARCH_OS_LINUX)
90+
#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
8991
#define ARCH_HAS_MMAP_MAP_POPULATE
9092
#endif
9193

pxr/base/arch/fileSystem.cpp

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,24 @@
3535
#include <Windows.h>
3636
#include <WinIoCtl.h>
3737
#else
38+
#if !defined(ARCH_OS_FREEBSD)
3839
#include <alloca.h>
40+
#else
41+
#include <stdlib.h>
42+
#endif
3943
#include <sys/mman.h>
4044
#include <sys/file.h>
4145
#include <unistd.h>
4246
#endif
4347

48+
#if defined(ARCH_OS_FREEBSD)
49+
#include <sys/types.h>
50+
#include <sys/sysctl.h>
51+
#include <unistd.h>
52+
#include <stdlib.h>
53+
#include <sys/user.h>
54+
#endif
55+
4456
PXR_NAMESPACE_OPEN_SCOPE
4557

4658
using std::pair;
@@ -143,7 +155,7 @@ int ArchRmDir(const char* path)
143155
bool
144156
ArchStatIsWritable(const ArchStatType *st)
145157
{
146-
#if defined(ARCH_OS_LINUX) || defined (ARCH_OS_DARWIN) || \
158+
#if defined(ARCH_OS_LINUX) || defined (ARCH_OS_DARWIN) || defined(ARCH_OS_FREEBSD) || \
147159
defined(ARCH_OS_WASM_VM)
148160
if (st) {
149161
return (st->st_mode & S_IWOTH) ||
@@ -181,7 +193,7 @@ ArchGetModificationTime(const char* pathname, double* time)
181193
double
182194
ArchGetModificationTime(const ArchStatType& st)
183195
{
184-
#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_WASM_VM)
196+
#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_WASM_VM) || defined(ARCH_OS_FREEBSD)
185197
return st.st_mtim.tv_sec + 1e-9*st.st_mtim.tv_nsec;
186198
#elif defined(ARCH_OS_DARWIN)
187199
return st.st_mtimespec.tv_sec + 1e-9*st.st_mtimespec.tv_nsec;
@@ -433,7 +445,7 @@ ArchGetStatMode(const char *pathname, int *mode)
433445
double
434446
ArchGetAccessTime(const struct stat& st)
435447
{
436-
#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_WASM_VM)
448+
#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_WASM_VM) || defined(ARCH_OS_FREEBSD)
437449
return st.st_atim.tv_sec + 1e-9*st.st_atim.tv_nsec;
438450
#elif defined(ARCH_OS_DARWIN)
439451
return st.st_atimespec.tv_sec + 1e-9*st.st_atimespec.tv_nsec;
@@ -448,7 +460,7 @@ ArchGetAccessTime(const struct stat& st)
448460
double
449461
ArchGetStatusChangeTime(const struct stat& st)
450462
{
451-
#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_WASM_VM)
463+
#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_WASM_VM) || defined(ARCH_OS_FREEBSD)
452464
return st.st_ctim.tv_sec + 1e-9*st.st_ctim.tv_nsec;
453465
#elif defined(ARCH_OS_DARWIN)
454466
return st.st_ctimespec.tv_sec + 1e-9*st.st_ctimespec.tv_nsec;
@@ -479,7 +491,7 @@ ArchGetFileLength(FILE *file)
479491
if (!file)
480492
return -1;
481493
#if defined (ARCH_OS_LINUX) || defined (ARCH_OS_DARWIN) || \
482-
defined(ARCH_OS_WASM_VM)
494+
defined(ARCH_OS_WASM_VM) || defined(ARCH_OS_FREEBSD)
483495
struct stat buf;
484496
return fstat(fileno(file), &buf) < 0 ? -1 :
485497
static_cast<int64_t>(buf.st_size);
@@ -494,7 +506,7 @@ int64_t
494506
ArchGetFileLength(const char* fileName)
495507
{
496508
#if defined (ARCH_OS_LINUX) || defined (ARCH_OS_DARWIN) || \
497-
defined(ARCH_OS_WASM_VM)
509+
defined(ARCH_OS_WASM_VM) || defined(ARCH_OS_FREEBSD)
498510
struct stat buf;
499511
return stat(fileName, &buf) < 0 ? -1 : static_cast<int64_t>(buf.st_size);
500512
#elif defined (ARCH_OS_WINDOWS)
@@ -557,7 +569,49 @@ ArchGetFileName(FILE *file)
557569
std::filesystem::path(filePath.begin(), filePath.begin() + dwSize));
558570
result = ArchWindowsUtf16ToUtf8(canonicalPath.wstring());
559571
}
560-
return result;
572+
return result;
573+
#elif defined (ARCH_OS_FREEBSD)
574+
int mib[4];
575+
size_t i, len;
576+
char *buffer = NULL;
577+
struct kinfo_file *kf;
578+
string path;
579+
580+
mib[0] = CTL_KERN;
581+
mib[1] = KERN_PROC;
582+
mib[2] = KERN_PROC_FILEDESC;
583+
mib[3] = getpid();
584+
len = 0;
585+
if (sysctl( mib, sizeof(mib)/sizeof(mib[0]), NULL, &len, NULL, 0 ))
586+
goto end;
587+
len *= 2;
588+
buffer = (char*)malloc( len );
589+
if (!buffer)
590+
goto end;
591+
if (sysctl( mib, sizeof(mib)/sizeof(mib[0]), buffer, &len, NULL, 0 ))
592+
goto end;
593+
594+
for (i = 0; i < len; )
595+
{
596+
kf = (struct kinfo_file*) &buffer[i];
597+
if (kf->kf_structsize == 0)
598+
break;
599+
i += kf->kf_structsize;
600+
601+
if (kf->kf_fd == fileno(file))
602+
{
603+
if (kf->kf_path[0])
604+
{
605+
path.resize(strlen(kf->kf_path) + 1);
606+
sprintf(&path[0], "%s", kf->kf_path);
607+
}
608+
break;
609+
}
610+
}
611+
612+
end:
613+
free( buffer );
614+
return path;
561615
#else
562616
#error Unknown system architecture
563617
#endif
@@ -921,6 +975,9 @@ ArchQueryMappedMemoryResidency(
921975
reinterpret_cast<caddr_t>(const_cast<void *>(addr)), len,
922976
reinterpret_cast<char *>(pageMap));
923977
return ret == 0;
978+
#elif defined(ARCH_OS_FREEBSD)
979+
int ret = mincore(const_cast<const void *>(addr), len, (char *)(pageMap));
980+
return ret == 0;
924981
#endif
925982
// XXX: Not implemented for other platforms yet.
926983
return false;

pxr/base/arch/fileSystem.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
#include <unistd.h>
2929
#include <sys/statfs.h>
3030
#include <glob.h>
31+
#elif defined(ARCH_OS_FREEBSD)
32+
#include <unistd.h>
33+
#include <glob.h>
3134
#elif defined(ARCH_OS_DARWIN)
3235
#include <unistd.h>
3336
#include <sys/mount.h>

pxr/base/arch/math.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ inline double ArchBitPatternToDouble(uint64_t v) {
8989
#error Unknown system architecture.
9090
#endif
9191

92-
#if defined(ARCH_OS_LINUX) || defined(doxygen)
92+
#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD) || defined(doxygen)
9393

9494
/// Computes the sine and cosine of the specified value as a float.
9595
inline void ArchSinCosf(float v, float *s, float *c) { sincosf(v, s, c); }

pxr/base/arch/pch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include <mach-o/swap.h>
3131
#include <mach/mach_time.h>
3232
#endif
33-
#if defined(ARCH_OS_LINUX)
33+
#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
3434
#include <chrono>
3535
#include <dlfcn.h>
3636
#include <glob.h>

0 commit comments

Comments
 (0)