Skip to content

Commit dc4ab16

Browse files
Andreagit97poiana
authored andcommitted
chore(libscap): generate uthash.h at build time
Signed-off-by: Andrea Terzolo <[email protected]>
1 parent 5492536 commit dc4ab16

File tree

9 files changed

+64
-6
lines changed

9 files changed

+64
-6
lines changed

Diff for: cmake/modules/libscap.cmake

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ include(GNUInstallDirs)
1212

1313
include(ExternalProject)
1414

15+
include(uthash)
16+
1517
include(CheckSymbolExists)
1618
check_symbol_exists(strlcpy "string.h" HAVE_STRLCPY)
1719
check_symbol_exists(strlcat "string.h" HAVE_STRLCAT)

Diff for: cmake/modules/uthash.cmake

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#
2+
# Copyright (C) 2023 The Falco Authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
# the License. You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
10+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
# specific language governing permissions and limitations under the License.
12+
#
13+
14+
set(UTHASH_DOWNLOAD_URL "https://raw.githubusercontent.com/troydhanson/uthash/v1.9.8/src/uthash.h")
15+
set(UTHASH_DOWNLOAD_DIR "${LIBSCAP_DIR}/userspace/libscap")
16+
17+
if(NOT EXISTS "${UTHASH_DOWNLOAD_DIR}/uthash.h")
18+
message(STATUS "Download 'uthash.h' from: ${UTHASH_DOWNLOAD_URL}")
19+
file(DOWNLOAD
20+
"${UTHASH_DOWNLOAD_URL}"
21+
"${UTHASH_DOWNLOAD_DIR}/uthash.h"
22+
)
23+
endif()

Diff for: userspace/libscap/linux/scap_cgroup.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ limitations under the License.
2020
#include "scap_assert.h"
2121
#include "scap_const.h"
2222
#include "strerror.h"
23-
#include "uthash.h"
23+
#include "uthash_ext.h"
2424

2525
#include <dirent.h>
2626
#include <errno.h>

Diff for: userspace/libscap/linux/scap_fds.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ limitations under the License.
2626
#include <sys/stat.h>
2727
#include <sys/types.h>
2828
#include <fcntl.h>
29-
#include "uthash.h"
29+
#include "uthash_ext.h"
3030
#include "compat/misc.h"
3131
#include <inttypes.h>
3232
#include <unistd.h>

Diff for: userspace/libscap/linux/scap_linux_int.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ limitations under the License.
2020
#include <stdbool.h>
2121
#include <stdint.h>
2222

23-
#include "uthash.h"
23+
#include "uthash_ext.h"
2424

2525
typedef struct scap_fdinfo scap_fdinfo;
2626

Diff for: userspace/libscap/scap.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ typedef struct ppm_evt_hdr scap_evt;
6060
//
6161
#include <time.h>
6262
#include <stdarg.h>
63-
#include "uthash.h"
63+
#include "uthash_ext.h"
6464
#include "../common/types.h"
6565
#include "../../driver/ppm_api_version.h"
6666
#include "../../driver/ppm_events_public.h"

Diff for: userspace/libscap/scap_fds.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ limitations under the License.
1919

2020
#include "scap.h"
2121
#include "scap-int.h"
22-
#include "uthash.h"
22+
#include "uthash_ext.h"
2323
#include <inttypes.h>
2424
#include <string.h>
2525

Diff for: userspace/libscap/scap_suppress.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ limitations under the License.
2424
extern "C" {
2525
#endif
2626

27-
#include "uthash.h"
27+
#include "uthash_ext.h"
2828

2929
typedef struct scap_tid
3030
{

Diff for: userspace/libscap/uthash_ext.h

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
Copyright (C) 2023 The Falco Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
*/
17+
18+
#pragma once
19+
20+
#define uthash_fatal(msg) uth_status = SCAP_FAILURE
21+
22+
/* `uthash.h` is generated at build time, see `uthash.cmake` */
23+
#include "uthash.h"
24+
25+
/* Further definitions on top of 'uthash.h' */
26+
#define HASH_FIND_INT32(head,findint,out) \
27+
HASH_FIND(hh,head,findint,sizeof(uint32_t),out)
28+
#define HASH_ADD_INT32(head,intfield,add) \
29+
HASH_ADD(hh,head,intfield,sizeof(uint32_t),add)
30+
#define HASH_FIND_INT64(head,findint,out) \
31+
HASH_FIND(hh,head,findint,sizeof(uint64_t),out)
32+
#define HASH_ADD_INT64(head,intfield,add) \
33+
HASH_ADD(hh,head,intfield,sizeof(uint64_t),add)

0 commit comments

Comments
 (0)