Skip to content

Commit

Permalink
chore(libscap): generate uthash.h at build time
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Terzolo <[email protected]>
  • Loading branch information
Andreagit97 authored and poiana committed Aug 7, 2023
1 parent 5492536 commit dc4ab16
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 6 deletions.
2 changes: 2 additions & 0 deletions cmake/modules/libscap.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ include(GNUInstallDirs)

include(ExternalProject)

include(uthash)

include(CheckSymbolExists)
check_symbol_exists(strlcpy "string.h" HAVE_STRLCPY)
check_symbol_exists(strlcat "string.h" HAVE_STRLCAT)
Expand Down
23 changes: 23 additions & 0 deletions cmake/modules/uthash.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#
# Copyright (C) 2023 The Falco Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
#

set(UTHASH_DOWNLOAD_URL "https://raw.githubusercontent.com/troydhanson/uthash/v1.9.8/src/uthash.h")
set(UTHASH_DOWNLOAD_DIR "${LIBSCAP_DIR}/userspace/libscap")

if(NOT EXISTS "${UTHASH_DOWNLOAD_DIR}/uthash.h")
message(STATUS "Download 'uthash.h' from: ${UTHASH_DOWNLOAD_URL}")
file(DOWNLOAD
"${UTHASH_DOWNLOAD_URL}"
"${UTHASH_DOWNLOAD_DIR}/uthash.h"
)
endif()
2 changes: 1 addition & 1 deletion userspace/libscap/linux/scap_cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ limitations under the License.
#include "scap_assert.h"
#include "scap_const.h"
#include "strerror.h"
#include "uthash.h"
#include "uthash_ext.h"

#include <dirent.h>
#include <errno.h>
Expand Down
2 changes: 1 addition & 1 deletion userspace/libscap/linux/scap_fds.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ limitations under the License.
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include "uthash.h"
#include "uthash_ext.h"
#include "compat/misc.h"
#include <inttypes.h>
#include <unistd.h>
Expand Down
2 changes: 1 addition & 1 deletion userspace/libscap/linux/scap_linux_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ limitations under the License.
#include <stdbool.h>
#include <stdint.h>

#include "uthash.h"
#include "uthash_ext.h"

typedef struct scap_fdinfo scap_fdinfo;

Expand Down
2 changes: 1 addition & 1 deletion userspace/libscap/scap.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ typedef struct ppm_evt_hdr scap_evt;
//
#include <time.h>
#include <stdarg.h>
#include "uthash.h"
#include "uthash_ext.h"
#include "../common/types.h"
#include "../../driver/ppm_api_version.h"
#include "../../driver/ppm_events_public.h"
Expand Down
2 changes: 1 addition & 1 deletion userspace/libscap/scap_fds.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ limitations under the License.

#include "scap.h"
#include "scap-int.h"
#include "uthash.h"
#include "uthash_ext.h"
#include <inttypes.h>
#include <string.h>

Expand Down
2 changes: 1 addition & 1 deletion userspace/libscap/scap_suppress.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ limitations under the License.
extern "C" {
#endif

#include "uthash.h"
#include "uthash_ext.h"

typedef struct scap_tid
{
Expand Down
33 changes: 33 additions & 0 deletions userspace/libscap/uthash_ext.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
Copyright (C) 2023 The Falco Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#pragma once

#define uthash_fatal(msg) uth_status = SCAP_FAILURE

/* `uthash.h` is generated at build time, see `uthash.cmake` */
#include "uthash.h"

/* Further definitions on top of 'uthash.h' */
#define HASH_FIND_INT32(head,findint,out) \
HASH_FIND(hh,head,findint,sizeof(uint32_t),out)
#define HASH_ADD_INT32(head,intfield,add) \
HASH_ADD(hh,head,intfield,sizeof(uint32_t),add)
#define HASH_FIND_INT64(head,findint,out) \
HASH_FIND(hh,head,findint,sizeof(uint64_t),out)
#define HASH_ADD_INT64(head,intfield,add) \
HASH_ADD(hh,head,intfield,sizeof(uint64_t),add)

0 comments on commit dc4ab16

Please sign in to comment.