Skip to content

Commit a2b9dbc

Browse files
balinaveenMark Stemm
authored andcommitted
Fix syntax and linker errors found while building latest sysdig code … (#1240)
* Fix syntax and linker errors found while building latest sysdig code on Windows (Visual Studio). * Fix Windows build errors - part 2 * Windows build - fix crash from get_main_thread() * Windows build failure - address code review comments * Windows build failure - address code review comments part 2 * Windows build failure - address code review comments part 3
1 parent d32e5c5 commit a2b9dbc

File tree

5 files changed

+62
-41
lines changed

5 files changed

+62
-41
lines changed

driver/flags_table.c

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const struct ppm_name_value socket_families[] = {
5050
{"AF_LOCAL", PPM_AF_LOCAL},
5151
{"AF_UNIX", PPM_AF_UNIX},
5252
{"AF_UNSPEC", PPM_AF_UNSPEC},
53-
{ },
53+
{0, 0},
5454
};
5555

5656
const struct ppm_name_value file_flags[] = {
@@ -69,7 +69,7 @@ const struct ppm_name_value file_flags[] = {
6969
{"O_RDONLY", PPM_O_RDONLY},
7070
{"O_CLOEXEC", PPM_O_CLOEXEC},
7171
{"O_NONE", PPM_O_NONE},
72-
{ },
72+
{0, 0},
7373
};
7474

7575
const struct ppm_name_value flock_flags[] = {
@@ -78,7 +78,7 @@ const struct ppm_name_value flock_flags[] = {
7878
{"LOCK_NB", PPM_LOCK_NB},
7979
{"LOCK_UN", PPM_LOCK_UN},
8080
{"LOCK_NONE", PPM_LOCK_NONE},
81-
{ },
81+
{0, 0},
8282
};
8383

8484
const struct ppm_name_value clone_flags[] = {
@@ -108,7 +108,7 @@ const struct ppm_name_value clone_flags[] = {
108108
{"CLONE_STOPPED", PPM_CL_CLONE_STOPPED},
109109
{"CLONE_VFORK", PPM_CL_CLONE_VFORK},
110110
{"CLONE_NEWCGROUP", PPM_CL_CLONE_NEWCGROUP},
111-
{ },
111+
{0, 0},
112112
};
113113

114114
const struct ppm_name_value futex_operations[] = {
@@ -127,7 +127,7 @@ const struct ppm_name_value futex_operations[] = {
127127
{"FUTEX_FD", PPM_FU_FUTEX_FD},
128128
{"FUTEX_WAKE", PPM_FU_FUTEX_WAKE},
129129
{"FUTEX_WAIT", PPM_FU_FUTEX_WAIT},
130-
{ },
130+
{0, 0},
131131
};
132132

133133
const struct ppm_name_value poll_flags[] = {
@@ -142,7 +142,7 @@ const struct ppm_name_value poll_flags[] = {
142142
{"POLLRDBAND", PPM_POLLRDBAND},
143143
{"POLLWRNORM", PPM_POLLWRNORM},
144144
{"POLLWRBAND", PPM_POLLWRBAND},
145-
{ },
145+
{0, 0},
146146
};
147147

148148
/* http://lxr.free-electrons.com/source/include/uapi/linux/fs.h?v=4.2#L65 */
@@ -175,7 +175,7 @@ const struct ppm_name_value mount_flags[] = {
175175
{"BORN", PPM_MS_BORN},
176176
{"ACTIVE", PPM_MS_ACTIVE},
177177
{"NOUSER", PPM_MS_NOUSER},
178-
{ },
178+
{0, 0},
179179
};
180180

181181
/* http://lxr.free-electrons.com/source/include/linux/fs.h?v=4.2#L1251 */
@@ -184,21 +184,21 @@ const struct ppm_name_value umount_flags[] = {
184184
{"DETACH", PPM_MNT_DETACH},
185185
{"EXPIRE", PPM_MNT_EXPIRE},
186186
{"NOFOLLOW", PPM_UMOUNT_NOFOLLOW},
187-
{ },
187+
{0, 0},
188188
};
189189

190190
const struct ppm_name_value lseek_whence[] = {
191191
{"SEEK_END", PPM_SEEK_END},
192192
{"SEEK_CUR", PPM_SEEK_CUR},
193193
{"SEEK_SET", PPM_SEEK_SET},
194-
{ },
194+
{0, 0},
195195
};
196196

197197
const struct ppm_name_value shutdown_how[] = {
198198
{"SHUT_RDWR", PPM_SHUT_RDWR},
199199
{"SHUT_WR", PPM_SHUT_WR},
200200
{"SHUT_RD", PPM_SHUT_RD},
201-
{ },
201+
{0, 0},
202202
};
203203

204204
const struct ppm_name_value rlimit_resources[] = {
@@ -219,7 +219,7 @@ const struct ppm_name_value rlimit_resources[] = {
219219
{"RLIMIT_DATA", PPM_RLIMIT_DATA},
220220
{"RLIMIT_FSIZE", PPM_RLIMIT_FSIZE},
221221
{"RLIMIT_CPU", PPM_RLIMIT_CPU},
222-
{ },
222+
{0, 0},
223223
};
224224

225225
const struct ppm_name_value fcntl_commands[] = {
@@ -253,7 +253,7 @@ const struct ppm_name_value fcntl_commands[] = {
253253
{"F_OFD_SETLK", PPM_FCNTL_F_OFD_SETLK},
254254
{"F_OFD_SETLKW", PPM_FCNTL_F_OFD_SETLKW},
255255
{"UNKNOWN", PPM_FCNTL_UNKNOWN},
256-
{ },
256+
{0, 0},
257257
};
258258

259259
const struct ppm_name_value ptrace_requests[] = {
@@ -296,7 +296,7 @@ const struct ppm_name_value ptrace_requests[] = {
296296
{"PTRACE_PEEKTEXT", PPM_PTRACE_PEEKTEXT},
297297
{"PTRACE_TRACEME", PPM_PTRACE_TRACEME},
298298
{"PTRACE_UNKNOWN", PPM_PTRACE_UNKNOWN},
299-
{ },
299+
{0, 0},
300300
};
301301

302302
const struct ppm_name_value prot_flags[] = {
@@ -308,7 +308,7 @@ const struct ppm_name_value prot_flags[] = {
308308
{"PROT_GROWSUP", PPM_PROT_GROWSUP},
309309
{"PROT_SAO", PPM_PROT_SAO},
310310
{"PROT_NONE", PPM_PROT_NONE},
311-
{ },
311+
{0, 0},
312312
};
313313

314314
const struct ppm_name_value mmap_flags[] = {
@@ -327,21 +327,21 @@ const struct ppm_name_value mmap_flags[] = {
327327
{"MAP_INHERIT", PPM_MAP_INHERIT},
328328
{"MAP_FILE", PPM_MAP_FILE},
329329
{"MAP_LOCKED", PPM_MAP_LOCKED},
330-
{ },
330+
{0, 0},
331331
};
332332

333333
const struct ppm_name_value splice_flags[] = {
334334
{"SPLICE_F_MOVE", PPM_SPLICE_F_MOVE},
335335
{"SPLICE_F_NONBLOCK", PPM_SPLICE_F_NONBLOCK},
336336
{"SPLICE_F_MORE", PPM_SPLICE_F_MORE},
337337
{"SPLICE_F_GIFT", PPM_SPLICE_F_GIFT},
338-
{ },
338+
{0, 0},
339339
};
340340

341341
const struct ppm_name_value quotactl_dqi_flags[] = {
342342
{"DQF_NONE", PPM_DQF_NONE},
343343
{"V1_DQF_RSQUASH", PPM_V1_DQF_RSQUASH},
344-
{ }
344+
{0, 0},
345345
};
346346

347347
const struct ppm_name_value quotactl_cmds[] = {
@@ -360,33 +360,33 @@ const struct ppm_name_value quotactl_cmds[] = {
360360
{"Q_XGETQSTAT", PPM_Q_XGETQSTAT},
361361
{"Q_XQUOTARM", PPM_Q_XQUOTARM},
362362
{"Q_XQUOTASYNC", PPM_Q_XQUOTASYNC},
363-
{ },
363+
{0, 0},
364364
};
365365

366366
const struct ppm_name_value quotactl_types[] = {
367367
{"USRQUOTA", PPM_USRQUOTA},
368368
{"GRPQUOTA", PPM_GRPQUOTA},
369-
{ },
369+
{0, 0},
370370
};
371371

372372
const struct ppm_name_value quotactl_quota_fmts[] = {
373373
{"QFMT_NOT_USED", PPM_QFMT_NOT_USED},
374374
{"QFMT_VFS_OLD", PPM_QFMT_VFS_OLD},
375375
{"QFMT_VFS_V0", PPM_QFMT_VFS_V0},
376376
{"QFMT_VFS_V1", PPM_QFMT_VFS_V1},
377-
{ }
377+
{0, 0},
378378
};
379379

380380
const struct ppm_name_value semop_flags[] = {
381381
{"IPC_NOWAIT", PPM_IPC_NOWAIT},
382382
{"SEM_UNDO", PPM_SEM_UNDO},
383-
{ },
383+
{0, 0},
384384
};
385385

386386
const struct ppm_name_value semget_flags[] = {
387387
{"IPC_EXCL", PPM_IPC_EXCL},
388388
{"IPC_CREAT", PPM_IPC_CREAT},
389-
{ },
389+
{0, 0},
390390
};
391391

392392
const struct ppm_name_value semctl_commands[] = {
@@ -403,15 +403,15 @@ const struct ppm_name_value semctl_commands[] = {
403403
{"GETZCNT", PPM_GETZCNT},
404404
{"SETALL", PPM_SETALL},
405405
{"SETVAL", PPM_SETVAL},
406-
{ },
406+
{0, 0},
407407
};
408408

409409
const struct ppm_name_value access_flags[] = {
410410
{"F_OK", PPM_F_OK},
411411
{"R_OK", PPM_R_OK},
412412
{"W_OK", PPM_W_OK},
413413
{"X_OK", PPM_X_OK},
414-
{ },
414+
{0, 0},
415415
};
416416

417417
const struct ppm_name_value pf_flags[] = {
@@ -423,16 +423,16 @@ const struct ppm_name_value pf_flags[] = {
423423
{"SUPERVISOR_FAULT", PPM_PF_SUPERVISOR_FAULT},
424424
{"RESERVED_PAGE", PPM_PF_RESERVED_PAGE},
425425
{"INSTRUCTION_FETCH", PPM_PF_INSTRUCTION_FETCH},
426-
{ },
426+
{0, 0},
427427
};
428428

429429
const struct ppm_name_value unlinkat_flags[] = {
430430
{"AT_REMOVEDIR", PPM_AT_REMOVEDIR},
431-
{ },
431+
{0, 0},
432432
};
433433

434434
const struct ppm_name_value linkat_flags[] = {
435435
{"AT_SYMLINK_FOLLOW", PPM_AT_SYMLINK_FOLLOW},
436436
{"AT_EMPTY_PATH", PPM_AT_EMPTY_PATH},
437-
{ },
437+
{0, 0},
438438
};

driver/ppm_events_public.h

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ or GPL2.txt for full copies of the license.
2020
#include "../userspace/common/sysdig_types.h"
2121
#endif
2222

23+
/*
24+
* Macros for packing in different build environments
25+
*/
26+
27+
#if defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32)
28+
#define _packed
29+
__pragma(pack(push, 1));
30+
__pragma(pack(pop))
31+
#else
32+
#define _packed
33+
__attribute__((packed))
34+
#endif
35+
2336
/*
2437
* Limits
2538
*/
@@ -1302,7 +1315,7 @@ struct ppm_param_info {
13021315
const void *info; /**< If this is a flags parameter, it points to an array of ppm_name_value,
13031316
else if this is a dynamic parameter it points to an array of ppm_param_info */
13041317
uint8_t ninfo; /**< Number of entry in the info array. */
1305-
} __attribute__((packed));
1318+
} _packed;
13061319

13071320
/*!
13081321
\brief Event information.
@@ -1315,7 +1328,7 @@ struct ppm_event_info {
13151328
enum ppm_event_flags flags; /**< flags for this event. */
13161329
uint32_t nparams; /**< Number of parameter in the params array. */
13171330
struct ppm_param_info params[PPM_MAX_EVENT_PARAMS]; /**< parameters descriptions. */
1318-
} __attribute__((packed));
1331+
} _packed;
13191332

13201333
#if defined _MSC_VER
13211334
#pragma pack(push)
@@ -1437,7 +1450,7 @@ struct syscall_evt_pair {
14371450
int flags;
14381451
enum ppm_event_type enter_event_type;
14391452
enum ppm_event_type exit_event_type;
1440-
} __attribute__((packed));
1453+
} _packed;
14411454

14421455
#define SYSCALL_TABLE_SIZE 512
14431456

@@ -1466,7 +1479,7 @@ struct ppm_autofill_arg {
14661479
#define AF_ID_USEDEFAULT -2
14671480
int16_t id;
14681481
long default_val;
1469-
} __attribute__((packed));
1482+
} _packed;
14701483

14711484
enum autofill_paramtype {
14721485
APT_REG,
@@ -1481,7 +1494,7 @@ struct ppm_event_entry {
14811494
uint16_t n_autofill_args;
14821495
enum autofill_paramtype paramtype;
14831496
struct ppm_autofill_arg autofill_args[PPM_MAX_AUTOFILL_ARGS];
1484-
} __attribute__((packed));
1497+
} _packed;
14851498

14861499
/*
14871500
* parse_readv_writev_bufs flags

userspace/libscap/scap_procs.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ limitations under the License.
4040
#include "windows_hal.h"
4141
#endif
4242

43+
#if defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32)
44+
#define strerror_r(errnum, buf, size) strerror_s(buf, size, errnum)
45+
#endif
46+
4347
#if defined(HAS_CAPTURE)
4448
#ifndef CYGWING_AGENT
4549
int32_t scap_proc_fill_cwd(scap_t *handle, char* procdirname, struct scap_threadinfo* tinfo)
@@ -1327,7 +1331,6 @@ void scap_proc_print_table(scap_t* handle)
13271331
const char *scap_strerror(scap_t *handle, int errnum)
13281332
{
13291333
int rc;
1330-
13311334
if((rc = strerror_r(errnum, handle->m_strerror_buf, SCAP_LASTERR_SIZE) != 0))
13321335
{
13331336
if(rc != ERANGE)

userspace/libsinsp/dns_manager.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ limitations under the License.
1818
*/
1919

2020
#include <sys/types.h>
21+
#if defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32)
22+
#include <WinSock2.h>
23+
#else
2124
#include <sys/socket.h>
2225
#include <netdb.h>
26+
#endif
2327
#include <string>
2428
#include <thread>
2529
#include <chrono>

userspace/libsinsp/threadinfo.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -559,17 +559,17 @@ void sinsp_threadinfo::set_env(const char* env, size_t len)
559559
bool sinsp_threadinfo::set_env_from_proc() {
560560
string environ_path = string(scap_get_host_root()) + "/proc/" + to_string(m_pid) + "/environ";
561561

562-
ifstream environ(environ_path);
563-
if (!environ)
562+
ifstream environment(environ_path);
563+
if (!environment)
564564
{
565565
// failed to read the environment from /proc, work with what we have
566566
return false;
567567
}
568568

569569
m_env.clear();
570-
while (environ) {
570+
while (environment) {
571571
string env;
572-
getline(environ, env, '\0');
572+
getline(environment, env, '\0');
573573
if (!env.empty())
574574
{
575575
m_env.emplace_back(env);
@@ -942,10 +942,11 @@ shared_ptr<sinsp_threadinfo> sinsp_threadinfo::lookup_thread()
942942
// Note: this is duplicated here because visual studio has trouble inlining
943943
// the method.
944944
//
945-
#ifdef _WIN32
945+
#if defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32)
946946
sinsp_threadinfo* sinsp_threadinfo::get_main_thread()
947947
{
948-
if (m_main_thread == NULL)
948+
auto main_thread = m_main_thread.lock();
949+
if (!main_thread)
949950
{
950951
//
951952
// Is this a child thread?
@@ -971,12 +972,12 @@ sinsp_threadinfo* sinsp_threadinfo::get_main_thread()
971972
{
972973
return NULL;
973974
}
974-
975975
m_main_thread = ptinfo;
976+
return &*ptinfo;
976977
}
977978
}
978979

979-
return &*m_main_thread;
980+
return &*main_thread;
980981
}
981982
#endif
982983

0 commit comments

Comments
 (0)